diff options
-rw-r--r-- | src/gui/painting/qbrush.cpp | 32 | ||||
-rw-r--r-- | tests/auto/gui/painting/qbrush/qbrush.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/painting/qbrush/tst_qbrush.cpp | 19 |
3 files changed, 49 insertions, 4 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: diff --git a/tests/auto/gui/painting/qbrush/qbrush.pro b/tests/auto/gui/painting/qbrush/qbrush.pro index 526de12815..0cb11398dc 100644 --- a/tests/auto/gui/painting/qbrush/qbrush.pro +++ b/tests/auto/gui/painting/qbrush/qbrush.pro @@ -1,5 +1,5 @@ CONFIG += testcase CONFIG += parallel_test TARGET = tst_qbrush -QT += testlib +QT += testlib gui-private SOURCES += tst_qbrush.cpp diff --git a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp index 8be9973c64..5ffba431ff 100644 --- a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp +++ b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp @@ -37,6 +37,7 @@ #include "qbrush.h" #include <QPainter> #include <QBitmap> +#include <private/qpixmap_raster_p.h> #include <qdebug.h> @@ -71,6 +72,7 @@ private slots: void debug(); void textureBrushStream(); + void textureBrushComparison(); }; @@ -446,5 +448,22 @@ void tst_QBrush::textureBrushStream() QCOMPARE(loadedBrush2.textureImage(), image_source); } +void tst_QBrush::textureBrushComparison() +{ + QImage image1(10, 10, QImage::Format_RGB32); + QRasterPlatformPixmap* ppixmap = new QRasterPlatformPixmap(QPlatformPixmap::PixmapType); + ppixmap->fromImage(image1, Qt::NoFormatConversion); + QPixmap pixmap(ppixmap); + QImage image2(image1); + + QBrush pixmapBrush, imageBrush1, imageBrush2; + pixmapBrush.setTexture(pixmap); + imageBrush1.setTextureImage(image1); + imageBrush2.setTextureImage(image2); + + QVERIFY(imageBrush1 == imageBrush2); + QVERIFY(pixmapBrush == imageBrush1); +} + QTEST_MAIN(tst_QBrush) #include "tst_qbrush.moc" |