diff options
author | Steve Mokris <smokris@softpixel.com> | 2018-12-08 12:28:02 -0500 |
---|---|---|
committer | Steve Mokris <smokris@softpixel.com> | 2018-12-10 01:45:29 +0000 |
commit | ba304af284f4cbb579d35046c0cf4c1537af0fec (patch) | |
tree | 4395e4941fb55333b37dd5417797d911925f88d1 /src | |
parent | b2297e595c43a5986a082c40443576436f8497d0 (diff) |
Refresh QGuiApplication's devicePixelRatio cache when screens change
Task-number: QTBUG-63548
Change-Id: Id934cda6e15449c00c80a646055899f49580da88
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 24 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 6 | ||||
-rw-r--r-- | src/gui/kernel/qplatformintegration.cpp | 5 |
3 files changed, 27 insertions, 8 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index b5e9b233e1..8f4c674952 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -208,6 +208,8 @@ bool QGuiApplicationPrivate::obey_desktop_settings = true; QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = 0; +qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0; + static qreal fontSmoothingGamma = 1.7; extern void qRegisterGuiVariant(); @@ -1093,17 +1095,19 @@ QScreen *QGuiApplication::screenAt(const QPoint &point) */ qreal QGuiApplication::devicePixelRatio() const { - // Cache topDevicePixelRatio, iterate through the screen list once only. - static qreal topDevicePixelRatio = 0.0; - if (!qFuzzyIsNull(topDevicePixelRatio)) { - return topDevicePixelRatio; - } + if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio)) + return QGuiApplicationPrivate::m_maxDevicePixelRatio; - topDevicePixelRatio = 1.0; // make sure we never return 0. + QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0; // make sure we never return 0. for (QScreen *screen : qAsConst(QGuiApplicationPrivate::screen_list)) - topDevicePixelRatio = qMax(topDevicePixelRatio, screen->devicePixelRatio()); + QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio()); - return topDevicePixelRatio; + return QGuiApplicationPrivate::m_maxDevicePixelRatio; +} + +void QGuiApplicationPrivate::resetCachedDevicePixelRatio() +{ + m_maxDevicePixelRatio = 0.0; } /*! @@ -3000,6 +3004,8 @@ void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfaceP for (QScreen* sibling : siblings) emit sibling->virtualGeometryChanged(sibling->virtualGeometry()); } + + resetCachedDevicePixelRatio(); } void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e) @@ -3015,6 +3021,8 @@ void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystem s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY); emit s->logicalDotsPerInchChanged(s->logicalDotsPerInch()); + + resetCachedDevicePixelRatio(); } void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 79c1a1c820..a5f3f99a31 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -311,6 +311,8 @@ public: static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false); + static void resetCachedDevicePixelRatio(); + protected: virtual void notifyThemeChanged(); bool tryCloseRemainingWindows(QWindowList processedWindows); @@ -330,6 +332,10 @@ private: bool ownGlobalShareContext; static QInputDeviceManager *m_inputDeviceManager; + + // Cache the maximum device pixel ratio, to iterate through the screen list + // only the first time it's required, or when devices are added or removed. + static qreal m_maxDevicePixelRatio; }; Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k); diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index 9836f569fc..bff1c907d6 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -482,6 +482,9 @@ void QPlatformIntegration::screenAdded(QPlatformScreen *ps, bool isPrimary) } else { QGuiApplicationPrivate::screen_list.append(screen); } + + QGuiApplicationPrivate::resetCachedDevicePixelRatio(); + emit qGuiApp->screenAdded(screen); if (isPrimary) @@ -499,6 +502,8 @@ void QPlatformIntegration::removeScreen(QScreen *screen) const bool wasPrimary = (!QGuiApplicationPrivate::screen_list.isEmpty() && QGuiApplicationPrivate::screen_list.at(0) == screen); QGuiApplicationPrivate::screen_list.removeOne(screen); + QGuiApplicationPrivate::resetCachedDevicePixelRatio(); + if (wasPrimary && qGuiApp && !QGuiApplicationPrivate::screen_list.isEmpty()) emit qGuiApp->primaryScreenChanged(QGuiApplicationPrivate::screen_list.at(0)); } |