From f9f9004b40ed7a4f4d280ba48bf6422cac6d21a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 12 Mar 2021 14:49:09 +0100 Subject: Add auto-test for QT_USE_PHYSICAL_DPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test that setting QT_USE_PHYSICAL_DPI uses physical DPI instead of logical DPI. Change-Id: I7f89cf1af5e013454cc3d8ec3559f2719514fea3 Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp | 27 +++++++++++++++++++++++++ 1 file changed, 27 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 339ff0ed20..31a41eeff6 100644 --- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp +++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp @@ -56,6 +56,7 @@ private slots: void screenDpiAndDpr(); void environment_QT_SCALE_FACTOR(); void environment_QT_SCREEN_SCALE_FACTORS(); + void environment_QT_USE_PHYSICAL_DPI(); void screenAt_data(); void screenAt(); void screenGeometry_data(); @@ -187,6 +188,7 @@ void tst_QHighDpi::cleanup() // in order to avoid getting confusing follow-on errors on test failures. qunsetenv("QT_SCALE_FACTOR"); qunsetenv("QT_SCREEN_SCALE_FACTORS"); + qunsetenv("QT_USE_PHYSICAL_DPI"); } void tst_QHighDpi::qhighdpiscaling_data() @@ -273,6 +275,31 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS() } } +void tst_QHighDpi::environment_QT_USE_PHYSICAL_DPI() +{ + qputenv("QT_USE_PHYSICAL_DPI", "1"); + + QList dpiValues { 96, 144, 192 }; + std::unique_ptr app(createStandardOffscreenApp(dpiValues)); + + // Verify that the device pixel ratio is computed as physicalDpi / baseDpi. + // (which in practice uses physicalSize since this is what QPlatformScreen provides) + + // The default QPlatformScreen::physicalSize() implementation (which QOffscreenScreen + // currerently uses) assumes a default DPI of 100 and calculates a fake physical size + // based on that value. Use DPI 100 here as well: if you have changed the default value + // in QPlatformScreen and get a test failure then update the value below. + const qreal platformScreenDefualtDpi = 100; + qreal expextedDpr = (platformScreenDefualtDpi / qreal(standardBaseDpi)); + + for (QScreen *screen : app->screens()) { + QCOMPARE(screen->devicePixelRatio(), expextedDpr); + QCOMPARE(screen->logicalDotsPerInch(), 96); + QWindow window(screen); + QCOMPARE(window.devicePixelRatio(), expextedDpr); + } +} + void tst_QHighDpi::minimumDpr() { QList dpiValues { 40, 60, 95 }; -- cgit v1.2.3