diff options
author | Andreas Kling <andreas.kling@nokia.com> | 2010-11-30 12:39:44 (GMT) |
---|---|---|
committer | Andreas Kling <andreas.kling@nokia.com> | 2010-11-30 13:56:51 (GMT) |
commit | 0211631bb8af96dfe2f6edc2d6c419f496ba89da (patch) | |
tree | 08fbe2a608d7b4cb1827350c63d71d40e80e4161 /src/gui/image/qpixmap_raster.cpp | |
parent | b498d78ce5cb62dce740fb366bbd76e3c66c7a85 (diff) | |
download | Qt-0211631bb8af96dfe2f6edc2d6c419f496ba89da.zip Qt-0211631bb8af96dfe2f6edc2d6c419f496ba89da.tar.gz Qt-0211631bb8af96dfe2f6edc2d6c419f496ba89da.tar.bz2 |
QRasterPixmapData: Reuse underlying QImage in fill() if possible.
When switching from a format without alpha channel to one that has it,
reuse the underlying QImage memory if the old & new color depths match.
This avoids one allocation when using the rather common pattern:
QPixmap pixmap(w, h);
pixmap.fill(Qt::transparent);
Reviewed-by: Samuel Rødal
Diffstat (limited to 'src/gui/image/qpixmap_raster.cpp')
-rw-r--r-- | src/gui/image/qpixmap_raster.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index 53f3559..65c0344 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -206,7 +206,13 @@ void QRasterPixmapData::fill(const QColor &color) else #endif toFormat = QImage::Format_ARGB32_Premultiplied; - image = QImage(image.width(), image.height(), toFormat); + + if (!image.isNull() && qt_depthForFormat(image.format()) == qt_depthForFormat(toFormat)) { + image.detach(); + image.d->format = toFormat; + } else { + image = QImage(image.width(), image.height(), toFormat); + } } switch (image.format()) { |