summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-02-11 00:24:46 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-02-13 13:55:01 +0100
commit515822de24e45e9c6d8d59b74c557640ba68a6ba (patch)
treea10623e2f97b54ed8e57c568fc70d32a0c6560f8 /tests/auto/gui/kernel
parentd21bfee667ce0c6a6c66bb1d1c9481af5816eb97 (diff)
QBackingStore: Take DPR into account when resizing with static contents
The plumbing from QBackingStore::resize to the platform backing store was missing a high-DPI conversion for the backing store's static contents, which is also expressed in the QtGui coordinate system. Pick-to: 6.7 6.6 6.5 6.2 Change-Id: Ifaac916cbf184b9386aa5feca1577a53bf2906ed Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r--tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp b/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp
index 7e2b9198d2..9fdf566988 100644
--- a/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp
+++ b/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp
@@ -30,6 +30,8 @@ private slots:
void scroll();
void flush();
+
+ void staticContents();
};
void tst_QBackingStore::initTestCase_data()
@@ -267,5 +269,79 @@ void tst_QBackingStore::flush()
QTRY_VERIFY(window.isExposed());
}
+void tst_QBackingStore::staticContents()
+{
+#if !defined(Q_OS_WIN)
+ QSKIP("Platform does not support static backingstore content");
+#endif
+
+ QWindow window;
+ window.create();
+
+ const auto dpr = window.devicePixelRatio();
+
+ QBackingStore backingStore(&window);
+
+ QRect initialRect(0, 0, 100, 100);
+
+ // Static contents without paint first should not crash
+ backingStore.setStaticContents(initialRect);
+ backingStore.resize(initialRect.size());
+ QCOMPARE(backingStore.size(), initialRect.size());
+ backingStore.beginPaint(QRect(0, 0, 50, 50));
+ backingStore.endPaint();
+ backingStore.handle()->toImage();
+
+ {
+ backingStore.setStaticContents(QRect());
+ backingStore.beginPaint(initialRect);
+ QPainter p(backingStore.paintDevice());
+ p.fillRect(initialRect, Qt::green);
+ p.end();
+ backingStore.endPaint();
+
+ QImage image = backingStore.handle()->toImage();
+ if (image.isNull())
+ QSKIP("Platform backingstore does not implement toImage");
+
+ QCOMPARE(image.pixelColor(initialRect.topLeft() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.bottomLeft() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.topRight() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.bottomRight() * dpr), Qt::green);
+ }
+
+ {
+ backingStore.setStaticContents(initialRect);
+
+ QRect resizedRect(0, 0, 200, 200);
+ backingStore.resize(resizedRect.size());
+
+ QRegion repaintRegion = QRegion(resizedRect) - QRegion(initialRect);
+
+ backingStore.beginPaint(repaintRegion);
+ QPainter p(backingStore.paintDevice());
+ for (auto repaintRect : repaintRegion)
+ p.fillRect(repaintRect, Qt::red);
+ p.end();
+ backingStore.endPaint();
+
+ QImage image = backingStore.handle()->toImage();
+ if (image.isNull())
+ QSKIP("Platform backingstore does not implement toImage");
+
+ QCOMPARE(image.pixelColor(initialRect.topLeft() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.bottomLeft() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.topRight() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.bottomRight() * dpr), Qt::green);
+
+ for (auto repaintRect : repaintRegion) {
+ QCOMPARE(image.pixelColor(repaintRect.topLeft() * dpr), Qt::red);
+ QCOMPARE(image.pixelColor(repaintRect.bottomLeft() * dpr), Qt::red);
+ QCOMPARE(image.pixelColor(repaintRect.topRight() * dpr), Qt::red);
+ QCOMPARE(image.pixelColor(repaintRect.bottomRight() * dpr), Qt::red);
+ }
+ }
+}
+
#include <tst_qbackingstore.moc>
QTEST_MAIN(tst_QBackingStore);