From 657284acbc1869f5f93b2cc6e9b7530e2e145435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 12 Mar 2021 14:21:36 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20store=20screen=20scale=20factor?= =?UTF-8?q?s=20in=20GLOBAL=5FSTATIC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a normal static variable, like the other high-dpi variables. Clear the stored factors in initHighDpiScaling(). This makes auto-testing possible where the application object is recreated for each test case and should start with a clean slate. Change-Id: I1831c856b5d7a2c522e62c7ed0657da771c3144f Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qhighdpiscaling.cpp | 13 +++++-------- src/gui/kernel/qhighdpiscaling_p.h | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 4fa8b9378f..3a70e5acf7 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -64,11 +64,6 @@ static const char scaleFactorRoundingPolicyEnvVar[] = "QT_SCALE_FACTOR_ROUNDING_ static const char dpiAdjustmentPolicyEnvVar[] = "QT_DPI_ADJUSTMENT_POLICY"; static const char usePhysicalDpiEnvVar[] = "QT_USE_PHYSICAL_DPI"; -// Per-screen scale factors for named screens set with QT_SCREEN_SCALE_FACTORS -// are stored here. Use a global hash to keep the factor across screen -// disconnect/connect cycles where the screen object may be deleted. -typedef QHash QScreenScaleFactorHash; -Q_GLOBAL_STATIC(QScreenScaleFactorHash, qNamedScreenScaleFactors); static std::optional qEnvironmentVariableOptionalString(const char *name) { if (!qEnvironmentVariableIsSet(name)) @@ -287,6 +282,7 @@ bool QHighDpiScaling::m_screenFactorSet = false; // QHighDpiScaling::setScreenFa bool QHighDpiScaling::m_usePhysicalDpi = false; QHighDpiScaling::DpiAdjustmentPolicy QHighDpiScaling::m_dpiAdjustmentPolicy = QHighDpiScaling::DpiAdjustmentPolicy::Unset; QString QHighDpiScaling::m_screenFactorsSpec; +QHash QHighDpiScaling::m_namedScreenScaleFactors; // Per-screen scale factors (screen name -> factor) qreal QHighDpiScaling::rawScaleFactor(const QPlatformScreen *screen) { @@ -479,6 +475,7 @@ void QHighDpiScaling::initHighDpiScaling() // supports using screen names, which means that screen DPI cannot // be resolved at this point. QHighDpiScaling::m_screenFactorsSpec = envScreenFactors.value_or(QString()); + m_namedScreenScaleFactors.clear(); m_usePhysicalDpi = envUsePhysicalDpi.value_or(0) > 0; @@ -600,7 +597,7 @@ void QHighDpiScaling::setScreenFactor(QScreen *screen, qreal factor) if (name.isEmpty()) screen->setProperty(scaleFactorProperty, QVariant(factor)); else - qNamedScreenScaleFactors()->insert(name, factor); + QHighDpiScaling::m_namedScreenScaleFactors.insert(name, factor); // hack to force re-evaluation of screen geometry if (screen->handle()) @@ -647,8 +644,8 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen) } if (!screenPropertyUsed) { - auto byNameIt = qNamedScreenScaleFactors()->constFind(screen->name()); - if ((screenPropertyUsed = byNameIt != qNamedScreenScaleFactors()->cend())) + auto byNameIt = QHighDpiScaling::m_namedScreenScaleFactors.constFind(screen->name()); + if ((screenPropertyUsed = byNameIt != QHighDpiScaling::m_namedScreenScaleFactors.cend())) factor = *byNameIt; } } diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h index e3522d41c1..e85a9b4bd6 100644 --- a/src/gui/kernel/qhighdpiscaling_p.h +++ b/src/gui/kernel/qhighdpiscaling_p.h @@ -141,6 +141,7 @@ private: static bool m_usePhysicalDpi; static QString m_screenFactorsSpec; static DpiAdjustmentPolicy m_dpiAdjustmentPolicy; + static QHash m_namedScreenScaleFactors; }; namespace QHighDpi {