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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1878>
This commit is contained in:
Marco Trevisan (Treviño) 2021-05-28 19:19:36 +02:00
parent f6e2059a65
commit 98f3f96978

View File

@ -1840,31 +1840,30 @@ meta_monitor_calculate_supported_scales (MetaMonitor *monitor,
for (i = floorf (MINIMUM_SCALE_FACTOR);
i <= ceilf (MAXIMUM_SCALE_FACTOR);
i++)
{
if (constraints & META_MONITOR_SCALES_CONSTRAINT_NO_FRAC)
{
if (is_scale_valid_for_size (width, height, i))
{
float scale = i;
g_array_append_val (supported_scales, scale);
}
}
else
{
for (j = 0; j < SCALE_FACTORS_PER_INTEGER; j++)
{
float scale;
float scale_value = i + j * SCALE_FACTORS_STEPS;
if (constraints & META_MONITOR_SCALES_CONSTRAINT_NO_FRAC)
{
if (fmodf (scale_value, 1.0) != 0.0 ||
!is_scale_valid_for_size (width, height, scale_value))
continue;
scale = scale_value;
}
else
{
scale = get_closest_scale_factor_for_resolution (width,
height,
scale = get_closest_scale_factor_for_resolution (width, height,
scale_value);
}
if (scale > 0.0f)
if (scale > 0.0)
g_array_append_val (supported_scales, scale);
}
}
}
if (supported_scales->len == 0)
{