From 776734576c2ba7bd4bdba6e09bc5dad5e093670a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 16 Mar 2021 17:17:53 +0100 Subject: Call updateHighDpiScaling() on screenAdded() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QHighDpiScaling has two init/update functions: - initHighDpiScaling(): called once during QGuiApplication construction - updateHighDpiScaling(): called whenever (relevant) screen configuration changes Currently the calls to updateHighDpiScaling() are made from multiple places including platform code. Simplify by calling it from two locations: - QWindowSystemInterface::handleScreenAdded() - QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange() Replace comment about early calls to qt_defaultDpi with a test which calls qt_defaultDpiX/Y with no screens attached. (Looking at the qt_defaultDpiX() implementation, it is unlikely that there will be a problem as long as updateHighDpiScaling() is called before QGuiApplication::primaryScreen() starts returning a non-null value.) Change-Id: I447db42894617495843a5cb531a1322b000fed62 Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/auto/gui/kernel') diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp index 31a41eeff6..4082611a0a 100644 --- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp +++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp @@ -314,6 +314,11 @@ void tst_QHighDpi::minimumDpr() } } +QT_BEGIN_NAMESPACE +extern int qt_defaultDpiX(); +extern int qt_defaultDpiY(); +QT_END_NAMESPACE + void tst_QHighDpi::noscreens() { // Create application object with a no-screens configuration (should not crash) @@ -321,6 +326,11 @@ void tst_QHighDpi::noscreens() std::unique_ptr app(createStandardOffscreenApp(noScreens)); QCOMPARE(qApp->devicePixelRatio(), 1); + + // Test calling qt_defaultDpiX/Y: These may be called early during QGuiApplication + // initialization, before the platform plugin has created screen objects. They + // should then 1) not crash and 2) return some default value. + QCOMPARE(qt_defaultDpiX(), qt_defaultDpiY()); } void tst_QHighDpi::screenAt_data() -- cgit v1.2.3