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.6 6.5 6.2 Change-Id: Ifaac916cbf184b9386aa5feca1577a53bf2906ed Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 515822de24e45e9c6d8d59b74c557640ba68a6ba) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9d7eb4bf8b
commit
4a39d2039f
@ -230,7 +230,8 @@ void QBackingStore::flush(const QRegion ®ion, QWindow *window, const QPoint &
|
||||
void QBackingStore::resize(const QSize &size)
|
||||
{
|
||||
d_ptr->size = size;
|
||||
handle()->resize(QHighDpi::scale(size, d_ptr->deviceIndependentToNativeFactor()), d_ptr->staticContents);
|
||||
const qreal factor = d_ptr->deviceIndependentToNativeFactor();
|
||||
handle()->resize(QHighDpi::scale(size, factor), QHighDpi::scale(d_ptr->staticContents, factor));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user