summaryrefslogtreecommitdiff
path: root/src/gui/image/qpixmap_raster.cpp
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-06-17 11:36:40 +0200
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-06-17 11:44:48 +0200
commitfa8030a935acaacee570eee320e7510a4cfdc853 (patch)
tree51d48d56c94739aa569bb60f5ef6998da35ff110 /src/gui/image/qpixmap_raster.cpp
parent24580f35a58390b4177aef8edef1192dc05f8ac2 (diff)
downloadqt4-tools-fa8030a935acaacee570eee320e7510a4cfdc853.tar.gz
Speed up QPixmap::width(), height(), isNull() and depth().
This change moves the w, h, d variables to QPixmapData and introduces is_null to keep track of nullness. This is possible only because QPixmapData is internal API; otherwise we'd have to be smarter. The optimization makes the QPixmap::width() function take 7 instructions, down from 34 before. For the calculator demo in the declarative ui branch this reduces a block of 750000 instructions (out of 30000000) to around 100000-150000 instructions. Tested on Windows, Linux, Mac. Raster, X11 and OpenGL paint engines. Have not tested the DirectFB engine. Reviewed-by: Trond
Diffstat (limited to 'src/gui/image/qpixmap_raster.cpp')
-rw-r--r--src/gui/image/qpixmap_raster.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp
index 2c57eded94..9cc896b473 100644
--- a/src/gui/image/qpixmap_raster.cpp
+++ b/src/gui/image/qpixmap_raster.cpp
@@ -85,6 +85,10 @@ void QRasterPixmapData::resize(int width, int height)
#endif
image = QImage(width, height, format);
+ w = width;
+ h = height;
+ d = image.depth();
+ is_null = (w <= 0 || h <= 0);
if (pixelType() == BitmapType && !image.isNull()) {
image.setNumColors(2);
@@ -168,6 +172,10 @@ void QRasterPixmapData::fromImage(const QImage &sourceImage,
}
}
#endif
+ w = image.d->width;
+ h = image.d->height;
+ d = image.d->depth;
+ is_null = (w <= 0 || h <= 0);
setSerialNumber(image.serialNumber());
}
@@ -329,9 +337,9 @@ int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
// override the image dpi with the screen dpi when rendering to a pixmap
switch (metric) {
case QPaintDevice::PdmWidth:
- return d->width;
+ return w;
case QPaintDevice::PdmHeight:
- return d->height;
+ return h;
case QPaintDevice::PdmWidthMM:
return qRound(d->width * 25.4 / qt_defaultDpiX());
case QPaintDevice::PdmHeightMM:
@@ -339,7 +347,7 @@ int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
case QPaintDevice::PdmNumColors:
return d->colortable.size();
case QPaintDevice::PdmDepth:
- return d->depth;
+ return this->d;
case QPaintDevice::PdmDpiX: // fall-through
case QPaintDevice::PdmPhysicalDpiX:
return qt_defaultDpiX();