[mutter/gbsneto/underscan: 297/299] monitor-manager: store and use underscan border xrandr values



commit d051c4b6f16da3392141fa4f26968f334b6fc70b
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Fri Mar 2 10:55:13 2018 +0000

    monitor-manager: store and use underscan border xrandr values
    
    Instead of always trying to derive them from the current mode, store the
    xrandr border values inside MetaOutputXrandr, and only calculate them if
    they haven't been set before.
    This fixes cases where the border would be doubly-applied.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=767804
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/549

 src/backends/meta-output.h            |  6 ++++
 src/backends/native/meta-output-kms.c |  4 +--
 src/backends/x11/meta-output-xrandr.c | 60 +++++++++++++++++++++++++----------
 3 files changed, 52 insertions(+), 18 deletions(-)
---
diff --git a/src/backends/meta-output.h b/src/backends/meta-output.h
index 5756669ba..95f66af74 100644
--- a/src/backends/meta-output.h
+++ b/src/backends/meta-output.h
@@ -26,6 +26,12 @@
 #include "backends/meta-gpu.h"
 #include "core/util-private.h"
 
+/* For now, underscan to 90% of the claimed display size whenever that
+ * option is enabled. In the future there may be a UI to configure this
+ * value.
+ */
+#define OVERSCAN_COMPENSATION_BORDER 0.05
+
 struct _MetaTileInfo
 {
   guint32 group_id;
diff --git a/src/backends/native/meta-output-kms.c b/src/backends/native/meta-output-kms.c
index 1ec17b9f9..99867f8b5 100644
--- a/src/backends/native/meta-output-kms.c
+++ b/src/backends/native/meta-output-kms.c
@@ -67,8 +67,8 @@ meta_output_kms_set_underscan (MetaOutput    *output,
       uint64_t hborder, vborder;
 
       crtc = meta_output_get_assigned_crtc (output);
-      hborder = MIN (128, (uint64_t) round (crtc->current_mode->width * 0.05));
-      vborder = MIN (128, (uint64_t) round (crtc->current_mode->height * 0.05));
+      hborder = MIN (128, (uint64_t) round (crtc->current_mode->width * OVERSCAN_COMPENSATION_BORDER));
+      vborder = MIN (128, (uint64_t) round (crtc->current_mode->height * OVERSCAN_COMPENSATION_BORDER));
 
       g_debug ("Setting underscan of connector %s to %lu x %lu",
                meta_kms_connector_get_name (output_kms->kms_connector),
diff --git a/src/backends/x11/meta-output-xrandr.c b/src/backends/x11/meta-output-xrandr.c
index 34fb7218e..f04515834 100644
--- a/src/backends/x11/meta-output-xrandr.c
+++ b/src/backends/x11/meta-output-xrandr.c
@@ -49,6 +49,8 @@
 typedef struct
 {
   char *underscan_value;
+  int underscan_hborder;
+  int underscan_vborder;
 } MetaOutputXrandr;
 
 static void
@@ -122,28 +124,37 @@ output_set_underscanning_xrandr (MetaOutput *output,
   if (underscanning)
     {
       MetaCrtc *crtc;
-      uint32_t border_value;
 
       crtc = meta_output_get_assigned_crtc (output);
 
-      prop = XInternAtom (xdisplay, "underscan hborder", False);
-      border_value = crtc->current_mode->width * 0.05;
+      /* If this function is called again when underscanning is already on,
+       * we don't want to touch the borders.
+       */
+      if (output_xrandr->underscan_hborder == 0)
+        output_xrandr->underscan_hborder = crtc->current_mode->width * OVERSCAN_COMPENSATION_BORDER;
+      if (output_xrandr->underscan_vborder == 0)
+        output_xrandr->underscan_vborder = crtc->current_mode->height * OVERSCAN_COMPENSATION_BORDER;
+    }
+  else
+    {
+      output_xrandr->underscan_hborder = 0;
+      output_xrandr->underscan_vborder = 0;
+    }
 
-      xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
-                                        (XID) output->winsys_id,
-                                        prop, XCB_ATOM_INTEGER, 32,
-                                        XCB_PROP_MODE_REPLACE,
-                                        1, &border_value);
+  prop = XInternAtom (xdisplay, "underscan hborder", False);
+  xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
+                                    (XID) output->winsys_id,
+                                    prop, XCB_ATOM_INTEGER, 32,
+                                    XCB_PROP_MODE_REPLACE,
+                                    1, &output_xrandr->underscan_hborder);
 
-      prop = XInternAtom (xdisplay, "underscan vborder", False);
-      border_value = crtc->current_mode->height * 0.05;
+  prop = XInternAtom (xdisplay, "underscan vborder", False);
+  xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
+                                    (XID) output->winsys_id,
+                                    prop, XCB_ATOM_INTEGER, 32,
+                                    XCB_PROP_MODE_REPLACE,
+                                    1, &output_xrandr->underscan_vborder);
 
-      xcb_randr_change_output_property (XGetXCBConnection (xdisplay),
-                                        (XID) output->winsys_id,
-                                        prop, XCB_ATOM_INTEGER, 32,
-                                        XCB_PROP_MODE_REPLACE,
-                                        1, &border_value);
-    }
 }
 
 void
@@ -278,6 +289,22 @@ output_get_presentation_xrandr (MetaOutput *output)
   return output_get_boolean_property (output, "_MUTTER_PRESENTATION_OUTPUT");
 }
 
+static void
+output_get_underscanning_borders_xrandr (MetaOutput *output)
+{
+  MetaOutputXrandr *output_xrandr = output->driver_private;
+  int hborder, vborder;
+
+  if (!output_get_integer_property (output, "underscan hborder", &hborder))
+    return;
+
+  if (!output_get_integer_property (output, "underscan vborder", &vborder))
+    return;
+
+  output_xrandr->underscan_hborder = hborder;
+  output_xrandr->underscan_vborder = vborder;
+}
+
 static gboolean
 output_get_underscanning_xrandr (MetaOutput *output)
 {
@@ -855,6 +882,7 @@ meta_create_xrandr_output (MetaGpuXrandr *gpu_xrandr,
     output_get_supports_underscanning_xrandr (output, &output_xrandr->underscan_value);
   output->is_underscanning = output_get_underscanning_xrandr (output);
   output_get_backlight_limits_xrandr (output);
+  output_get_underscanning_borders_xrandr (output);
 
   if (!(output->backlight_min == 0 && output->backlight_max == 0))
     output->backlight = output_get_backlight_xrandr (output);


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