[gnome-flashback] monitor: do not overlap when checking for applicable scaling values



commit 2debcd23f68c1113ed1faf14c82781eaccb0de09
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Sep 12 23:21:16 2021 +0300

    monitor: do not overlap when checking for applicable scaling values
    
    Based on mutter commit:
    https://gitlab.gnome.org/GNOME/mutter/-/commit/3e1e2cb91f6f

 backends/gf-monitor.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/backends/gf-monitor.c b/backends/gf-monitor.c
index fd98c80..0f8f0d5 100644
--- a/backends/gf-monitor.c
+++ b/backends/gf-monitor.c
@@ -318,9 +318,10 @@ is_scale_valid_for_size (float width,
 }
 
 static gfloat
-get_closest_scale_factor_for_resolution (gfloat width,
-                                         gfloat height,
-                                         gfloat scale)
+get_closest_scale_factor_for_resolution (float width,
+                                         float height,
+                                         float scale,
+                                         float threshold)
 {
   guint i, j;
   gfloat scaled_h;
@@ -352,8 +353,8 @@ get_closest_scale_factor_for_resolution (gfloat 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)
             {
@@ -1105,6 +1106,14 @@ gf_monitor_calculate_supported_scales (GfMonitor                 *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.0f;
+
           for (j = 0; j < SCALE_FACTORS_PER_INTEGER; j++)
             {
               gfloat scale;
@@ -1112,7 +1121,8 @@ gf_monitor_calculate_supported_scales (GfMonitor                 *monitor,
 
               scale = get_closest_scale_factor_for_resolution (width,
                                                                height,
-                                                               scale_value);
+                                                               scale_value,
+                                                               max_bound);
 
               if (scale > 0.0f)
                 g_array_append_val (supported_scales, scale);


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