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



commit 679d8cbc4dbc1eddd05f31b38a8e07c6cb6b302d
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

 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 f3cc543c4..b47705697 100644
--- a/src/backends/native/meta-output-kms.c
+++ b/src/backends/native/meta-output-kms.c
@@ -95,7 +95,7 @@ meta_output_kms_set_underscan (MetaOutput *output)
         {
           uint64_t value;
 
-          value = MIN (128, crtc->current_mode->width * 0.05);
+          value = MIN (128, crtc->current_mode->width * OVERSCAN_COMPENSATION_BORDER);
           drmModeObjectSetProperty (kms_fd, connector_id,
                                     DRM_MODE_OBJECT_CONNECTOR,
                                     output_kms->underscan_hborder_prop_id,
@@ -105,7 +105,7 @@ meta_output_kms_set_underscan (MetaOutput *output)
         {
           uint64_t value;
 
-          value = MIN (128, crtc->current_mode->height * 0.05);
+          value = MIN (128, crtc->current_mode->height * OVERSCAN_COMPENSATION_BORDER);
           drmModeObjectSetProperty (kms_fd, connector_id,
                                     DRM_MODE_OBJECT_CONNECTOR,
                                     output_kms->underscan_vborder_prop_id,
diff --git a/src/backends/x11/meta-output-xrandr.c b/src/backends/x11/meta-output-xrandr.c
index 9bab05f65..26a32f406 100644
--- a/src/backends/x11/meta-output-xrandr.c
+++ b/src/backends/x11/meta-output-xrandr.c
@@ -48,6 +48,8 @@
 typedef struct
 {
   char *underscan_value;
+  int underscan_hborder;
+  int underscan_vborder;
 } MetaOutputXrandr;
 
 static void
@@ -119,28 +121,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
@@ -275,6 +286,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)
 {
@@ -850,6 +877,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]