summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorRitt Konstantin <ritt.ks@gmail.com>2011-06-06 11:52:04 (GMT)
committerHarald Fernengel <harald.fernengel@nokia.com>2011-06-06 11:52:04 (GMT)
commit597e690c92243b47ac2191c8de8b12cd689bf2a6 (patch)
treef8c99f24a0fd513a3d69ac5d1ded7ffa628dd7bb /src/gui
parent2410a5b869e3ccee98cd0606ad64690a3c0e1003 (diff)
downloadQt-597e690c92243b47ac2191c8de8b12cd689bf2a6.zip
Qt-597e690c92243b47ac2191c8de8b12cd689bf2a6.tar.gz
Qt-597e690c92243b47ac2191c8de8b12cd689bf2a6.tar.bz2
don't reallocate memory if the old buffer has sufficient capacity
Merge-request: 2627 Reviewed-by: Harald Fernengel <harald.fernengel@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/painting/qwindowsurface_qws.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/gui/painting/qwindowsurface_qws.cpp b/src/gui/painting/qwindowsurface_qws.cpp
index 9d4f985..5bd56d3 100644
--- a/src/gui/painting/qwindowsurface_qws.cpp
+++ b/src/gui/painting/qwindowsurface_qws.cpp
@@ -964,10 +964,12 @@ void QWSLocalMemSurface::setGeometry(const QRect &rect)
} else {
const QImage::Format format = preferredImageFormat(win);
const int bpl = nextMulOf4(bytesPerPixel(format) * size.width());
- if (memsize)
+ const int imagesize = bpl * size.height();
+ if (memsize < imagesize) {
delete[] mem;
- memsize = bpl * size.height();
- mem = new uchar[memsize];
+ memsize = imagesize;
+ mem = new uchar[memsize];
+ }
img = QImage(mem, size.width(), size.height(), bpl, format);
setImageMetrics(img, win);
}
@@ -1132,8 +1134,6 @@ void QWSSharedMemSurface::setGeometry(const QRect &rect)
mem.detach();
img = QImage();
} else {
- mem.detach();
-
QWidget *win = window();
const QImage::Format format = preferredImageFormat(win);
const int bpl = nextMulOf4(bytesPerPixel(format) * size.width());
@@ -1142,9 +1142,12 @@ void QWSSharedMemSurface::setGeometry(const QRect &rect)
#else
const int imagesize = bpl * size.height();
#endif
- if (!mem.create(imagesize)) {
- perror("QWSSharedMemSurface::setGeometry allocating shared memory");
- qFatal("Error creating shared memory of size %d", imagesize);
+ if (mem.size() < imagesize) {
+ mem.detach();
+ if (!mem.create(imagesize)) {
+ perror("QWSSharedMemSurface::setGeometry allocating shared memory");
+ qFatal("Error creating shared memory of size %d", imagesize);
+ }
}
#ifdef QT_QWS_CLIENTBLIT
*((uint *)mem.address()) = 0;