[mutter/gnome-40] crtc-mode-xrandr: Take RR_DoubleScan and RR_Interlace flags into account



commit 0792c7cc71332f4144cfec91799e971961f4f471
Author: Robert Mader <robert mader collabora com>
Date:   Thu Dec 30 21:29:25 2021 +0100

    crtc-mode-xrandr: Take RR_DoubleScan and RR_Interlace flags into account
    
    Otherwise we often advertise wrongly calculated modes.
    Original patch from Jonas Ã…dahl and the xrandr project.
    
    Closes https://gitlab.gnome.org/GNOME/mutter/-/issues/275
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2190>

 src/backends/x11/meta-gpu-xrandr.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/src/backends/x11/meta-gpu-xrandr.c b/src/backends/x11/meta-gpu-xrandr.c
index bc3292d368..6c84be6ce8 100644
--- a/src/backends/x11/meta-gpu-xrandr.c
+++ b/src/backends/x11/meta-gpu-xrandr.c
@@ -86,6 +86,24 @@ get_xmode_name (XRRModeInfo *xmode)
   return g_strdup_printf ("%dx%d", width, height);
 }
 
+static float
+calculate_xrandr_refresh_rate (XRRModeInfo *xmode)
+{
+  float h_total;
+  float v_total;
+
+  h_total = (float) xmode->hTotal;
+  v_total = (float) xmode->vTotal;
+
+  if (xmode->modeFlags & RR_DoubleScan)
+    v_total *= 2.0;
+
+  if (xmode->modeFlags & RR_Interlace)
+    v_total /= 2.0;
+
+  return xmode->dotClock / (h_total * v_total);
+}
+
 static gboolean
 meta_gpu_xrandr_read_current (MetaGpu  *gpu,
                               GError  **error)
@@ -148,8 +166,7 @@ meta_gpu_xrandr_read_current (MetaGpu  *gpu,
       crtc_mode_info = meta_crtc_mode_info_new ();
       crtc_mode_info->width = xmode->width;
       crtc_mode_info->height = xmode->height;
-      crtc_mode_info->refresh_rate = (xmode->dotClock /
-                                      ((float)xmode->hTotal * xmode->vTotal));
+      crtc_mode_info->refresh_rate = calculate_xrandr_refresh_rate (xmode);
       crtc_mode_info->flags = xmode->modeFlags;
 
       crtc_mode_name = get_xmode_name (xmode);


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