diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c index e4e803672..5fc8b1f85 100644 --- a/src/backends/meta-monitor.c +++ b/src/backends/meta-monitor.c @@ -1767,7 +1767,8 @@ meta_monitor_mode_should_be_advertised (MetaMonitorMode *monitor_mode) static float get_closest_scale_factor_for_resolution (float width, float height, - float scale) + float scale, + float threshold) { unsigned int i, j; float scaled_h; @@ -1799,8 +1800,8 @@ get_closest_scale_factor_for_resolution (float width, current_scale = width / scaled_w; scaled_h = height / current_scale; - if (current_scale >= scale + SCALE_FACTORS_STEPS || - current_scale <= scale - SCALE_FACTORS_STEPS || + if (current_scale >= scale + threshold || + current_scale <= scale - threshold || current_scale < MINIMUM_SCALE_FACTOR || current_scale > MAXIMUM_SCALE_FACTOR) { @@ -1851,14 +1852,22 @@ meta_monitor_calculate_supported_scales (MetaMonitor *monitor, } else { + float max_bound; + + if (i == floorf (MINIMUM_SCALE_FACTOR) || + i == ceilf (MAXIMUM_SCALE_FACTOR)) + max_bound = SCALE_FACTORS_STEPS; + else + max_bound = SCALE_FACTORS_STEPS / 2.0; + for (j = 0; j < SCALE_FACTORS_PER_INTEGER; j++) { float scale; float scale_value = i + j * SCALE_FACTORS_STEPS; scale = get_closest_scale_factor_for_resolution (width, height, - scale_value); - + scale_value, + max_bound); if (scale > 0.0) g_array_append_val (supported_scales, scale); } diff --git a/src/tests/monitor-test-utils.c b/src/tests/monitor-test-utils.c index 00823d22f..c5e838c85 100644 --- a/src/tests/monitor-test-utils.c +++ b/src/tests/monitor-test-utils.c @@ -811,6 +811,13 @@ check_expected_scales (MetaMonitor *monitor, g_assert_cmpfloat (fmodf (width / scales[i], 1.0), ==, 0.0); g_assert_cmpfloat (fmodf (height / scales[i], 1.0), ==, 0.0); } + + if (i > 0) + { + /* And that scales are sorted and unique */ + g_assert_cmpfloat (scales[i], >, scales[i-1]); + g_assert_false (G_APPROX_VALUE (scales[i], scales[i-1], 0.000001)); + } } } diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c index 06b170318..d7d3fdc35 100644 --- a/src/tests/monitor-unit-tests.c +++ b/src/tests/monitor-unit-tests.c @@ -6273,9 +6273,9 @@ meta_test_monitor_supported_fractional_scales (void) { .width = 4096, .height = 2160, - .n_scales = 10, + .n_scales = 8, .scales = { 1.000000, 1.333333, 1.454545, 1.777778, 2.000000, - 2.666667, 2.666667, 3.200000, 3.200000, 4.000000 + 2.666667, 3.200000, 4.000000 } }, {