From f5174abec3720b7deec3157e482ca62c0d90fb19 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Wed, 6 Apr 2022 20:26:29 +0200 Subject: Fix backingstore fractional DPR glitches for widgets in child windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For such widgets, QBackingStore::flush() takes both a region and an offset. Both must to be DPR scaled to the native backingstore coordinates. When the DPR is fractional, it can happen that the rounding of both effectively accumulate into an off-by-one error. Detect and adjust for this situation to avoid painting glitches. Task-number: QTBUG-96223 Fixes: QTBUG-102366 Pick-to: 6.3 6.2 5.15 Change-Id: I9ccd4ee54660419a1db8c27358f1419de58ae932 Reviewed-by: Morten Johan Sørvig --- src/gui/painting/qbackingstore.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp index bd3e54a5c0..c78c603103 100644 --- a/src/gui/painting/qbackingstore.cpp +++ b/src/gui/painting/qbackingstore.cpp @@ -220,8 +220,18 @@ void QBackingStore::flush(const QRegion ®ion, QWindow *window, const QPoint & Q_ASSERT(window == topLevelWindow || topLevelWindow->isAncestorOf(window, QWindow::ExcludeTransients)); - handle()->flush(window, QHighDpi::toNativeLocalRegion(region, window), - QHighDpi::toNativeLocalPosition(offset, window)); + QRegion nativeRegion = QHighDpi::toNativeLocalRegion(region, window); + QPoint nativeOffset; + if (!offset.isNull()) { + nativeOffset = QHighDpi::toNativeLocalPosition(offset, window); + // Under fractional DPR, rounding of region and offset may accumulate to an off-by-one + QPoint topLeft = region.boundingRect().topLeft() + offset; + QPoint nativeTopLeft = QHighDpi::toNativeLocalPosition(topLeft, window); + QPoint diff = nativeTopLeft - (nativeRegion.boundingRect().topLeft() + nativeOffset); + Q_ASSERT(qMax(qAbs(diff.x()), qAbs(diff.y())) <= 1); + nativeRegion.translate(diff); + } + handle()->flush(window, nativeRegion, nativeOffset); } /*! -- cgit v1.2.3