From d03dce43786ddfaca86a0ec006264c1b0dfd74d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 2 Mar 2023 11:16:38 +0100 Subject: [PATCH] monitor: Use fractional scale result to decide the non-fractional scale We want to avoid using too high scales too easily, which started to happen 2f1dd049bf ("monitor-manager: Rework default scale factor selection"). Instead of using the closest non-fractional scale, which effectively is what we'd do, only round upwards if we're closer than 0.25 (25%). Since there are some wiggle room for scales to make the logical resolution on the integer pixel grid, make sure to compensate. This compensation is done by adding an extra 0.2 to scale difference. For example the following fractional scales will get these corresponding integer scales: * 1.25 -> 1.0 * 1.5 -> 1.0 * 1.75 -> 2.0 * 2.0 -> 2.0 * 2.50 -> 2.0 Part-of: --- src/backends/meta-monitor.c | 10 +++++++++- src/tests/monitor-unit-tests.c | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c index 9ecacb98c..289d0c620 100644 --- a/src/backends/meta-monitor.c +++ b/src/backends/meta-monitor.c @@ -1839,6 +1839,7 @@ calculate_scale (MetaMonitor *monitor, int n_scales; float best_scale, best_dpi; int target_dpi; + const float scale_epsilon = 0.2; /* * Somebody encoded the aspect ratio (16/9 or 16/10) instead of the physical @@ -1863,7 +1864,8 @@ calculate_scale (MetaMonitor *monitor, /* We'll only be considering the supported scale factors */ scales = meta_monitor_calculate_supported_scales (monitor, monitor_mode, - constraints, &n_scales); + META_MONITOR_SCALES_CONSTRAINT_NONE, + &n_scales); best_scale = scales[0]; for (int i = 0; i < n_scales; i++) { @@ -1894,6 +1896,12 @@ calculate_scale (MetaMonitor *monitor, } } + if (constraints & META_MONITOR_SCALES_CONSTRAINT_NO_FRAC) + { + best_scale = floorf (MIN (scales[n_scales - 1], + best_scale + 0.25 + scale_epsilon)); + } + return best_scale; } diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c index 8fbeeec9c..ffeafe1ef 100644 --- a/src/tests/monitor-unit-tests.c +++ b/src/tests/monitor-unit-tests.c @@ -9284,7 +9284,7 @@ meta_test_monitor_calculate_mode_scale (void) .width_mm = 303, /* 3:2 @ 14.34" */ .height_mm = 202, .exp = 1.5, - .exp_nofrac = 2.0, + .exp_nofrac = 1.0, }, { .name = "Generic 23\" 1080p", @@ -9311,7 +9311,7 @@ meta_test_monitor_calculate_mode_scale (void) .width_mm = 598, .height_mm = 336, .exp = 1.5, - .exp_nofrac = 2.0, + .exp_nofrac = 1.0, }, { .name = "Generic 32\" 4K",