From 8182dc12b88727c647f9bac4d9a19914e3cd8307 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Mon, 19 Oct 2009 12:17:34 +0200 Subject: Fixed slow QPixmap::fill() when the pixmap is sharing data. If the pixmap is sharing data with other pixmaps, it must be detached before it is filled. Instead of detaching by making a copy, create a new uninitialized data object since all pixels are overwritten by fill() anyway. Task-number: QTBUG-3228 Reviewed-by: Trond --- src/gui/image/qpixmap.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index c03a364..bf6c9ae 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -959,7 +959,17 @@ void QPixmap::fill(const QColor &color) return; } - detach(); + if (data->ref == 1) { + // detach() will also remove this pixmap from caches, so + // it has to be called even when ref == 1. + detach(); + } else { + // Don't bother to make a copy of the data object, since + // it will be filled with new pixel data anyway. + QPixmapData *d = data->createCompatiblePixmapData(); + d->resize(data->width(), data->height()); + data = d; + } data->fill(color); } -- cgit v0.12