From fa8030a935acaacee570eee320e7510a4cfdc853 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 17 Jun 2009 11:36:40 +0200 Subject: 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 --- src/gui/image/qpixmap_x11.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/gui/image/qpixmap_x11.cpp') diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index b7fe92aa38..86cf515da7 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -312,7 +312,7 @@ static int qt_pixmap_serial = 0; int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth = 0; QX11PixmapData::QX11PixmapData(PixelType type) - : QPixmapData(type, X11Class), hd(0), w(0), h(0), d(0), + : QPixmapData(type, X11Class), hd(0), uninit(true), read_only(false), x11_mask(0), picture(0), mask_picture(0), hd2(0), share_mode(QPixmap::ImplicitlyShared), pengine(0) { @@ -324,6 +324,7 @@ void QX11PixmapData::resize(int width, int height) w = width; h = height; + is_null = (w <= 0 || h <= 0); if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) { QX11InfoData* xd = xinfo.getX11Data(true); @@ -347,6 +348,7 @@ void QX11PixmapData::resize(int width, int height) if (make_null || d == 0) { w = 0; h = 0; + is_null = true; hd = 0; picture = 0; d = 0; @@ -375,6 +377,7 @@ void QX11PixmapData::fromImage(const QImage &img, w = img.width(); h = img.height(); d = img.depth(); + is_null = (w <= 0 || h <= 0); if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) { QX11InfoData* xd = xinfo.getX11Data(true); @@ -395,6 +398,7 @@ void QX11PixmapData::fromImage(const QImage &img, if (uint(w) >= 32768 || uint(h) >= 32768) { w = h = 0; + is_null = true; return; } @@ -1109,6 +1113,7 @@ void QX11PixmapData::bitmapFromImage(const QImage &image) w = img.width(); h = img.height(); d = 1; + is_null = (w <= 0 || h <= 0); int bpl = (w + 7) / 8; int ibpl = img.bytesPerLine(); if (bpl != ibpl) { @@ -1876,6 +1881,7 @@ QPixmap QX11PixmapData::transformed(const QTransform &transform, x11Data->d = d; x11Data->w = w; x11Data->h = h; + x11Data->is_null = (w <= 0 || h <= 0); x11Data->hd = (Qt::HANDLE)XCreatePixmap(X11->display, RootWindow(X11->display, xinfo.screen()), w, h, d); @@ -2132,6 +2138,7 @@ void QX11PixmapData::copy(const QPixmapData *data, const QRect &rect) d = x11Data->d; w = rect.width(); h = rect.height(); + is_null = (w <= 0 || h <= 0); hd = (Qt::HANDLE)XCreatePixmap(X11->display, RootWindow(X11->display, x11Data->xinfo.screen()), w, h, d); @@ -2250,6 +2257,7 @@ QPixmap QPixmap::fromX11Pixmap(Qt::HANDLE pixmap, QPixmap::ShareMode mode) data->uninit = false; data->w = width; data->h = height; + data->is_null = (width <= 0 || height <= 0); data->d = depth; data->hd = pixmap; -- cgit v1.2.3