From 7b2ae3faab15913e006ece25d785e6a8453dd27a Mon Sep 17 00:00:00 2001 From: Fushan Wen Date: Sun, 29 May 2022 19:08:17 +0800 Subject: [PATCH] Drop call to setPlatformScreen in QHighDpiScaling::setScreenFactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop call to setPlatformScreen since the only affected variables are logicalDpi and geometry. Replace setPlatformScreen with updateLogicalDpi which handles global scale factor changes in QScreen. Call updateGeometriesWithSignals() to check if there are any changes in geometry or availableGeometry, since the geometry or availableGeometry can also change when setting a scale factor. Move setPlatformScreen to QScreen ctor as the function is not used elsewhere. Pick-to: 6.4 6.3 6.2 Change-Id: I7acf40bf0643e89a1d9177674d66dc503829f98f Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qhighdpiscaling.cpp | 3 +-- src/gui/kernel/qplatformscreen.h | 2 +- src/gui/kernel/qscreen.cpp | 40 +++++++++++++++--------------- src/gui/kernel/qscreen_p.h | 2 +- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 8d6bb62594..2f759158ee 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -555,9 +555,8 @@ void QHighDpiScaling::setScreenFactor(QScreen *screen, qreal factor) else QHighDpiScaling::m_namedScreenScaleFactors.insert(name, factor); - // hack to force re-evaluation of screen geometry if (screen->handle()) - screen->d_func()->setPlatformScreen(screen->handle()); // updates geometries based on scale factor + screen->d_func()->updateLogicalDpi(); } QPoint QHighDpiScaling::mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen) diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h index ca828171ff..1d8e103606 100644 --- a/src/gui/kernel/qplatformscreen.h +++ b/src/gui/kernel/qplatformscreen.h @@ -135,7 +135,7 @@ protected: QScopedPointer d_ptr; private: - friend class QScreenPrivate; + friend QScreen; }; // Qt doesn't currently support running with no platform screen diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index fd0e2ba2f7..ac33185900 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -41,7 +41,26 @@ QScreen::QScreen(QPlatformScreen *screen) : QObject(*new QScreenPrivate(), nullptr) { Q_D(QScreen); - d->setPlatformScreen(screen); + d->platformScreen = screen; + d->platformScreen->d_func()->screen = this; + d->orientation = d->platformScreen->orientation(); + + d->logicalDpi = QPlatformScreen::overrideDpi(d->platformScreen->logicalDpi()); + + d->refreshRate = d->platformScreen->refreshRate(); + // safeguard ourselves against buggy platform behavior... + if (d->refreshRate < 1.0) + d->refreshRate = 60.0; + + d->updateHighDpi(); + d->updatePrimaryOrientation(); // derived from the geometry +} + +void QScreenPrivate::updateLogicalDpi() +{ + Q_Q(QScreen); + logicalDpi = QPlatformScreen::overrideDpi(q->handle()->logicalDpi()); + updateGeometriesWithSignals(); // updates geometries based on scale factor } void QScreenPrivate::updateGeometriesWithSignals() @@ -71,25 +90,6 @@ void QScreenPrivate::emitGeometryChangeSignals(bool geometryChanged, bool availa emit q->physicalDotsPerInchChanged(q->physicalDotsPerInch()); } -void QScreenPrivate::setPlatformScreen(QPlatformScreen *screen) -{ - Q_Q(QScreen); - platformScreen = screen; - platformScreen->d_func()->screen = q; - orientation = platformScreen->orientation(); - - logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi()); - - refreshRate = platformScreen->refreshRate(); - // safeguard ourselves against buggy platform behavior... - if (refreshRate < 1.0) - refreshRate = 60.0; - - updateHighDpi(); - updatePrimaryOrientation(); // derived from the geometry -} - - /*! Destroys the screen. */ diff --git a/src/gui/kernel/qscreen_p.h b/src/gui/kernel/qscreen_p.h index 1ba0c7c442..9d7ab504b2 100644 --- a/src/gui/kernel/qscreen_p.h +++ b/src/gui/kernel/qscreen_p.h @@ -28,12 +28,12 @@ class QScreenPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QScreen) public: - void setPlatformScreen(QPlatformScreen *screen); void updateHighDpi() { geometry = platformScreen->deviceIndependentGeometry(); availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(), QHighDpiScaling::factor(platformScreen), geometry.topLeft()); } + void updateLogicalDpi(); void updatePrimaryOrientation(); void updateGeometriesWithSignals();