summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-01-28 15:52:30 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-02-04 22:10:17 +0000
commit57469a8e10f11ee04964ed9f8f8d00de0d6d45c1 (patch)
tree875b8ca4bcbafedad54ff0483fc5a19b07660254 /src/gui
parenta29374fc8ecb9fc17ac125d730eed9c8ec98badb (diff)
Avoid creating a QPixmap on QBrush comparisons
We shouldn't create QPixmaps when comparing QBrushes that do not contain a QPixmap. This patch extends the comparison logic to comparing QImage cachekeys if the brushes are QImage based. Note the comparison still produces false negatives on equal content on different pixmaps and images, but this is preserving existing behavior. Task-number: QTBUG-43766 Change-Id: I001b4032172c1e568aad311f7df2eaae6aee8dc6 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/painting/qbrush.cpp32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp
index 40dad85cde..06b2ca2b36 100644
--- a/src/gui/painting/qbrush.cpp
+++ b/src/gui/painting/qbrush.cpp
@@ -35,6 +35,7 @@
#include "qpixmap.h"
#include "qbitmap.h"
#include "qpixmapcache.h"
+#include "qplatformpixmap.h"
#include "qdatastream.h"
#include "qvariant.h"
#include "qline.h"
@@ -950,9 +951,34 @@ bool QBrush::operator==(const QBrush &b) const
switch (d->style) {
case Qt::TexturePattern:
{
- const QPixmap &us = (static_cast<QTexturedBrushData *>(d.data()))->pixmap();
- const QPixmap &them = (static_cast<QTexturedBrushData *>(b.d.data()))->pixmap();
- return ((us.isNull() && them.isNull()) || us.cacheKey() == them.cacheKey());
+ // Note this produces false negatives if the textures have identical data,
+ // but does not share the same data in memory. Since equality is likely to
+ // be used to avoid iterating over the data for a texture update, this should
+ // still be better than doing an accurate comparison.
+ const QPixmap *us = 0, *them = 0;
+ qint64 cacheKey1, cacheKey2;
+ if (qHasPixmapTexture(*this)) {
+ us = (static_cast<QTexturedBrushData *>(d.data()))->m_pixmap;
+ cacheKey1 = us->cacheKey();
+ } else
+ cacheKey1 = (static_cast<QTexturedBrushData *>(d.data()))->image().cacheKey();
+
+ if (qHasPixmapTexture(b)) {
+ them = (static_cast<QTexturedBrushData *>(b.d.data()))->m_pixmap;
+ cacheKey2 = them->cacheKey();
+ } else
+ cacheKey2 = (static_cast<QTexturedBrushData *>(b.d.data()))->image().cacheKey();
+
+ if (cacheKey1 != cacheKey2)
+ return false;
+ if (!us == !them) // both images or both pixmaps
+ return true;
+ // Only raster QPixmaps use the same cachekeys as QImages.
+ if (us && us->handle()->classId() == QPlatformPixmap::RasterClass)
+ return true;
+ if (them && them->handle()->classId() == QPlatformPixmap::RasterClass)
+ return true;
+ return false;
}
case Qt::LinearGradientPattern:
case Qt::RadialGradientPattern: