From 98f3f9697863a23977754a1c8ecaa04d17868fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 28 May 2021 19:19:36 +0200 Subject: [PATCH] monitor: Never return fractional scale values when NO_FRAC is used We introduced META_MONITOR_SCALES_CONSTRAINT_NO_FRAC to get global scale values however, this didn't work properly for some resolutions. In fact it may happen that for some resolutions (such as 3200x1800) that we did not compute some odd scaling levels (such as 3.0) but instead its closest fractional value that allowed to get an integer resolution (2.98507452 in this case). Now this is something relevant when using fractional scaling because we want to ensure that the returned value, when multiplied to the scaled sizes, will produce an integer resolution, but it's not in global scale mode where we don't use a scaled framebuffer. So, take a short path when using no fractional mode and just return all the applicable values without waste iterations on fractional values. Part-of: --- src/backends/meta-monitor.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c index 8eb0dc1e8..e4e803672 100644 --- a/src/backends/meta-monitor.c +++ b/src/backends/meta-monitor.c @@ -1841,28 +1841,27 @@ meta_monitor_calculate_supported_scales (MetaMonitor *monitor, i <= ceilf (MAXIMUM_SCALE_FACTOR); i++) { - for (j = 0; j < SCALE_FACTORS_PER_INTEGER; j++) + if (constraints & META_MONITOR_SCALES_CONSTRAINT_NO_FRAC) { - float scale; - float scale_value = i + j * SCALE_FACTORS_STEPS; - - if (constraints & META_MONITOR_SCALES_CONSTRAINT_NO_FRAC) + if (is_scale_valid_for_size (width, height, i)) { - if (fmodf (scale_value, 1.0) != 0.0 || - !is_scale_valid_for_size (width, height, scale_value)) - continue; - - scale = scale_value; + float scale = i; + g_array_append_val (supported_scales, scale); } - else + } + else + { + for (j = 0; j < SCALE_FACTORS_PER_INTEGER; j++) { - scale = get_closest_scale_factor_for_resolution (width, - height, + float scale; + float scale_value = i + j * SCALE_FACTORS_STEPS; + + scale = get_closest_scale_factor_for_resolution (width, height, scale_value); - } - if (scale > 0.0f) - g_array_append_val (supported_scales, scale); + if (scale > 0.0) + g_array_append_val (supported_scales, scale); + } } }