From 57469a8e10f11ee04964ed9f8f8d00de0d6d45c1 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 28 Jan 2015 15:52:30 +0100 Subject: 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 --- tests/auto/gui/painting/qbrush/qbrush.pro | 2 +- tests/auto/gui/painting/qbrush/tst_qbrush.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/auto/gui/painting') 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 #include +#include #include @@ -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" -- cgit v1.2.3