From 114c8eb7a55630282e2349345d75f49f69705b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 21 Aug 2023 16:19:00 +0200 Subject: [PATCH] Add catch-all DPR update to expose event handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The platform plugin should already DPR (or DPI) change events, however if that does not happen we update in the expose event as well as a last resort to make sure the window's DPR value is in sync. Also print a warning and ask for a bug report. Pick-to: 6.0 Change-Id: Ibb144f163281a28216c2fa3353ed50237e91ce25 Reviewed-by: Tor Arne Vestbø Reviewed-by: Morten Johan Sørvig (cherry picked from commit 5f1c29376c02f722450f6bf1aa5f0647601e0e59) Reviewed-by: Qt Cherry-pick Bot --- src/gui/kernel/qguiapplication.cpp | 8 ++++++++ src/gui/kernel/qwindow.cpp | 6 ++++-- src/gui/kernel/qwindow_p.h | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index a05f0d69d54..8c13aff577d 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -3264,6 +3264,14 @@ void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::E const bool wasExposed = p->exposed; p->exposed = e->isExposed && window->screen(); + // We expect that the platform plugins send DevicePixelRatioChange events. + // As a fail-safe make a final check here to make sure the cached DPR value is + // always up to date before sending the expose event. + const bool dprWasChanged = QWindowPrivate::get(window)->updateDevicePixelRatio(); + if (dprWasChanged) + qWarning() << "The cached device pixel ratio value was stale on window expose. " + << "Please file a QTBUG which explains how to reproduce."; + // We treat expose events for an already exposed window as paint events if (wasExposed && p->exposed && shouldSynthesizePaintEvents) { QPaintEvent paintEvent(e->region); diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 3c9194cb6ed..0aeb1514057 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1359,8 +1359,9 @@ qreal QWindow::devicePixelRatio() const /* Updates the cached devicePixelRatio value by polling for a new value. Sends QEvent::DevicePixelRatioChange to the window if the DPR has changed. + Returns true if the DPR was changed. */ -void QWindowPrivate::updateDevicePixelRatio() +bool QWindowPrivate::updateDevicePixelRatio() { Q_Q(QWindow); @@ -1371,11 +1372,12 @@ void QWindowPrivate::updateDevicePixelRatio() platformWindow->devicePixelRatio() * QHighDpiScaling::factor(q) : q->screen()->devicePixelRatio(); if (newDevicePixelRatio == devicePixelRatio) - return; + return false; devicePixelRatio = newDevicePixelRatio; QEvent dprChangeEvent(QEvent::DevicePixelRatioChange); QGuiApplication::sendEvent(q, &dprChangeEvent); + return true; } Qt::WindowState QWindowPrivate::effectiveState(Qt::WindowStates state) diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index 96beb17becf..7b1aad4838c 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -89,7 +89,7 @@ public: void setAutomaticPositionAndResizeEnabled(bool a) { positionAutomatic = resizeAutomatic = a; } - void updateDevicePixelRatio(); + bool updateDevicePixelRatio(); static QWindowPrivate *get(QWindow *window) { return window->d_func(); }