[mutter] monitor: Never return fractional scale values when NO_FRAC is used



commit 98f3f9697863a23977754a1c8ecaa04d17868fd1
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Fri May 28 19:19:36 2021 +0200

    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>

 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 8eb0dc1e8f..e4e8036724 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);
+            }
         }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]