From 96d0f2af75aa069f2b6973a621b3bf6ebaafc9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Tue, 7 Nov 2023 14:44:13 +0100 Subject: [PATCH] Fix off-by-one surface pixel size on Android MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit m_window->size() may have been rounded for devices with DPI which results in a fractional DPR (e.g. 650 DPI / 160 DPI = 3.5 DPR). In this case scaling by devicePixelRatio does not give the correct result. Instead, use QPlatformWindow geometry and DPR to determine the device size, without using the (possibly) rounded device independent window size. Fixes: QTBUG-87334 Pick-to: 6.6 6.5 6.2 Change-Id: I280236a06516cdb2a1a259fd0cfa8084c1ce7f46 Reviewed-by: Tor Arne Vestbø Reviewed-by: Qt CI Bot Reviewed-by: Jøger Hansegård Reviewed-by: Laszlo Agocs --- src/gui/rhi/qrhigles2.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 7148d59d18..fc57cbd072 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -6222,7 +6223,12 @@ QRhiRenderTarget *QGles2SwapChain::currentFrameRenderTarget(StereoTargetBuffer t QSize QGles2SwapChain::surfacePixelSize() { Q_ASSERT(m_window); - return m_window->size() * m_window->devicePixelRatio(); + if (QPlatformWindow *platformWindow = m_window->handle()) + // Prefer using QPlatformWindow geometry and DPR in order to avoid + // errors due to rounded QWindow geometry. + return platformWindow->geometry().size() * platformWindow->devicePixelRatio(); + else + return m_window->size() * m_window->devicePixelRatio(); } bool QGles2SwapChain::isFormatSupported(Format f)