Fix off-by-one surface pixel size on Android

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.5 6.2
Change-Id: I280236a06516cdb2a1a259fd0cfa8084c1ce7f46
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
(cherry picked from commit 96d0f2af75aa069f2b6973a621b3bf6ebaafc9a5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Morten Sørvig 2023-11-07 14:44:13 +01:00 committed by Qt Cherry-pick Bot
parent 81f9c77c3c
commit 901515fe03

View File

@ -7,6 +7,7 @@
#include <QtCore/qmap.h>
#include <QtGui/private/qopenglextensions_p.h>
#include <QtGui/private/qopenglprogrambinarycache_p.h>
#include <QtGui/private/qwindow_p.h>
#include <qpa/qplatformopenglcontext.h>
#include <qmath.h>
@ -6116,7 +6117,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)