From 2d76f991d01763f5432fc6ba7ae073393f224557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 20 Feb 2023 20:31:03 +0100 Subject: [PATCH] Fix QT_WIDGETS_HIGHDPI_DOWNSCALE The source rect scaling implemented in 79bead6c was incorrect for child windows with an offset, and was reverted in commit d59b2fde, after causing QTBUG-107814. Scale the window rect by the source device pixel ratio to get the source rect. This source DPR can be different from the (target) DPR when HIGHDPI_DOWNSCALE is enabled and will then be a rounded DPR value. Pick-to: 6.5 Fixes: QTBUG-111102 Task-number: QTBUG-107814 Change-Id: I59801bc22c47fc83d63ae4d96e509ab7fffeb760 Reviewed-by: Eirik Aavitsland --- src/gui/painting/qbackingstoredefaultcompositor.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gui/painting/qbackingstoredefaultcompositor.cpp b/src/gui/painting/qbackingstoredefaultcompositor.cpp index 383fb651dd..db8e5ddce8 100644 --- a/src/gui/painting/qbackingstoredefaultcompositor.cpp +++ b/src/gui/painting/qbackingstoredefaultcompositor.cpp @@ -522,14 +522,16 @@ QPlatformBackingStore::FlushResult QBackingStoreDefaultCompositor::flush(QPlatfo const qreal dpr = window->devicePixelRatio(); const QRect deviceWindowRect = scaledRect(QRect(QPoint(), window->size()), dpr); - const QPoint deviceWindowOffset = scaledOffset(offset, dpr); const bool invertTargetY = rhi->clipSpaceCorrMatrix().data()[5] < 0.0f; const bool invertSource = rhi->isYUpInFramebuffer() != rhi->isYUpInNDC(); if (m_texture) { - // The backingstore is for the entire tlw. - // In case of native children offset tells the position relative to the tlw. - const QRect srcRect = toBottomLeftRect(deviceWindowRect.translated(deviceWindowOffset), m_texture->pixelSize().height()); + // The backingstore is for the entire tlw. In case of native children, offset tells the position + // relative to the tlw. The window rect is scaled by the source device pixel ratio to get + // the source rect. + const QRect sourceWindowRect = scaledRect(QRect(QPoint(), window->size()), sourceDevicePixelRatio); + const QPoint sourceWindowOffset = scaledOffset(offset, sourceDevicePixelRatio); + const QRect srcRect = toBottomLeftRect(sourceWindowRect.translated(sourceWindowOffset), m_texture->pixelSize().height()); const QMatrix3x3 source = sourceTransform(srcRect, m_texture->pixelSize(), origin); QMatrix4x4 target; // identity if (invertTargetY)