[mutter] output: Move configureable state to instance private



commit f71316c8508b3864876fc5ef9fb8e59a97c24f87
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Feb 25 18:37:21 2020 +0100

    output: Move configureable state to instance private
    
    That is is_presentation, is_primary, is_underscanning and backlight.
    
    The first three are set during CRTC assignment as they are only valid
    when active. The other is set separately, as it is untied to
    monitor configuration.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1287

 src/backends/meta-logical-monitor.c            |  3 +-
 src/backends/meta-monitor-manager-dummy.c      | 42 +++++------------
 src/backends/meta-monitor-manager-private.h    | 18 ++++++++
 src/backends/meta-monitor-manager.c            | 16 ++++---
 src/backends/meta-monitor.c                    |  4 +-
 src/backends/meta-output.c                     | 63 +++++++++++++++++++++++++-
 src/backends/meta-output.h                     | 24 +++++++---
 src/backends/native/meta-monitor-manager-kms.c | 37 ++++-----------
 src/backends/native/meta-output-kms.c          | 32 +++++++------
 src/backends/x11/meta-monitor-manager-xrandr.c | 28 +++++-------
 src/backends/x11/meta-output-xrandr.c          | 44 ++++++++++++------
 src/tests/meta-monitor-manager-test.c          | 41 +++++------------
 src/tests/monitor-test-utils.c                 | 18 +++++---
 13 files changed, 215 insertions(+), 155 deletions(-)
---
diff --git a/src/backends/meta-logical-monitor.c b/src/backends/meta-logical-monitor.c
index 77d0f15a80..52f4833fc6 100644
--- a/src/backends/meta-logical-monitor.c
+++ b/src/backends/meta-logical-monitor.c
@@ -178,7 +178,8 @@ meta_logical_monitor_add_monitor (MetaLogicalMonitor *logical_monitor,
         {
           MetaOutput *output = l_output->data;
 
-          is_presentation = is_presentation && output->is_presentation;
+          is_presentation = (is_presentation &&
+                             meta_output_is_presentation (output));
         }
     }
 
diff --git a/src/backends/meta-monitor-manager-dummy.c b/src/backends/meta-monitor-manager-dummy.c
index ff96df749b..8b803ceccb 100644
--- a/src/backends/meta-monitor-manager-dummy.c
+++ b/src/backends/meta-monitor-manager-dummy.c
@@ -228,7 +228,6 @@ append_monitor (MetaMonitorManager *manager,
   output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
   output->preferred_mode = g_list_last (*modes)->data;
   output->n_possible_clones = 0;
-  output->backlight = -1;
   output->connector_type = META_CONNECTOR_TYPE_LVDS;
   output->driver_private = output_dummy;
   output->driver_notify =
@@ -336,7 +335,6 @@ append_tiled_monitor (MetaMonitorManager *manager,
       output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
       output->preferred_mode = preferred_mode;
       output->n_possible_clones = 0;
-      output->backlight = -1;
       output->connector_type = META_CONNECTOR_TYPE_LVDS;
       output->tile_info = (MetaTileInfo) {
         .group_id = tile_group_id,
@@ -508,7 +506,6 @@ apply_crtc_assignments (MetaMonitorManager *manager,
 {
   g_autoptr (GList) to_configure_outputs = NULL;
   g_autoptr (GList) to_configure_crtcs = NULL;
-  GList *l;
   unsigned i;
 
   to_configure_outputs = g_list_copy (meta_gpu_get_outputs (get_gpu (manager)));
@@ -527,7 +524,6 @@ apply_crtc_assignments (MetaMonitorManager *manager,
         }
       else
         {
-          MetaOutput *output;
           unsigned int j;
 
           meta_crtc_set_config (crtc,
@@ -537,40 +533,26 @@ apply_crtc_assignments (MetaMonitorManager *manager,
 
           for (j = 0; j < crtc_info->outputs->len; j++)
             {
+              MetaOutput *output;
+              MetaOutputInfo *output_info;
+
               output = ((MetaOutput**)crtc_info->outputs->pdata)[j];
 
               to_configure_outputs = g_list_remove (to_configure_outputs,
                                                     output);
-              meta_output_assign_crtc (output, crtc);
+
+              output_info = meta_find_output_info (outputs, n_outputs, output);
+              meta_output_assign_crtc (output, crtc, output_info);
             }
         }
     }
 
-  for (i = 0; i < n_outputs; i++)
-    {
-      MetaOutputInfo *output_info = outputs[i];
-      MetaOutput *output = output_info->output;
-
-      output->is_primary = output_info->is_primary;
-      output->is_presentation = output_info->is_presentation;
-    }
-
-  /* Disable CRTCs not mentioned in the list */
-  for (l = to_configure_crtcs; l; l = l->next)
-    {
-      MetaCrtc *crtc = l->data;
-
-      meta_crtc_unset_config (crtc);
-    }
-
-  /* Disable outputs not mentioned in the list */
-  for (l = to_configure_outputs; l; l = l->next)
-    {
-      MetaOutput *output = l->data;
-
-      meta_output_unassign_crtc (output);
-      output->is_primary = FALSE;
-    }
+  g_list_foreach (to_configure_crtcs,
+                  (GFunc) meta_crtc_unset_config,
+                  NULL);
+  g_list_foreach (to_configure_outputs,
+                  (GFunc) meta_output_unassign_crtc,
+                  NULL);
 }
 
 static void
diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h
index a0a28b6c25..5dc752a348 100644
--- a/src/backends/meta-monitor-manager-private.h
+++ b/src/backends/meta-monitor-manager-private.h
@@ -387,4 +387,22 @@ gboolean meta_monitor_has_aspect_as_size (MetaMonitor *monitor);
 char * meta_monitor_manager_get_vendor_name (MetaMonitorManager *manager,
                                              const char         *vendor);
 
+static inline MetaOutputInfo *
+meta_find_output_info (MetaOutputInfo **outputs,
+                       unsigned int     n_outputs,
+                       MetaOutput      *output)
+{
+  unsigned int i;
+
+  for (i = 0; i < n_outputs; i++)
+    {
+      MetaOutputInfo *output_info = outputs[i];
+
+      if (output == output_info->output)
+        return output_info;
+    }
+
+  return NULL;
+}
+
 #endif /* META_MONITOR_MANAGER_PRIVATE_H */
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
index 060e3ed68e..224239040f 100644
--- a/src/backends/meta-monitor-manager.c
+++ b/src/backends/meta-monitor-manager.c
@@ -1107,18 +1107,18 @@ meta_monitor_manager_handle_get_resources (MetaDBusDisplayConfig *skeleton,
       g_variant_builder_add (&properties, "{sv}", "display-name",
                              g_variant_new_string (output->name));
       g_variant_builder_add (&properties, "{sv}", "backlight",
-                             g_variant_new_int32 (output->backlight));
+                             g_variant_new_int32 (meta_output_get_backlight (output)));
       g_variant_builder_add (&properties, "{sv}", "min-backlight-step",
                              g_variant_new_int32 ((output->backlight_max - output->backlight_min) ?
                                                   100 / (output->backlight_max - output->backlight_min) : 
-1));
       g_variant_builder_add (&properties, "{sv}", "primary",
-                             g_variant_new_boolean (output->is_primary));
+                             g_variant_new_boolean (meta_output_is_primary (output)));
       g_variant_builder_add (&properties, "{sv}", "presentation",
-                             g_variant_new_boolean (output->is_presentation));
+                             g_variant_new_boolean (meta_output_is_presentation (output)));
       g_variant_builder_add (&properties, "{sv}", "connector-type",
                              g_variant_new_string (get_connector_type_name (output->connector_type)));
       g_variant_builder_add (&properties, "{sv}", "underscanning",
-                             g_variant_new_boolean (output->is_underscanning));
+                             g_variant_new_boolean (meta_output_is_underscanning (output)));
       g_variant_builder_add (&properties, "{sv}", "supports-underscanning",
                              g_variant_new_boolean (output->supports_underscanning));
 
@@ -2103,6 +2103,7 @@ meta_monitor_manager_handle_change_backlight  (MetaDBusDisplayConfig *skeleton,
 {
   GList *combined_outputs;
   MetaOutput *output;
+  int new_backlight;
 
   if (serial != manager->serial)
     {
@@ -2133,7 +2134,7 @@ meta_monitor_manager_handle_change_backlight  (MetaDBusDisplayConfig *skeleton,
       return TRUE;
     }
 
-  if (output->backlight == -1 ||
+  if (meta_output_get_backlight (output) == -1 ||
       (output->backlight_min == 0 && output->backlight_max == 0))
     {
       g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
@@ -2144,7 +2145,10 @@ meta_monitor_manager_handle_change_backlight  (MetaDBusDisplayConfig *skeleton,
 
   META_MONITOR_MANAGER_GET_CLASS (manager)->change_backlight (manager, output, value);
 
-  meta_dbus_display_config_complete_change_backlight (skeleton, invocation, output->backlight);
+  new_backlight = meta_output_get_backlight (output);
+  meta_dbus_display_config_complete_change_backlight (skeleton,
+                                                      invocation,
+                                                      new_backlight);
   return TRUE;
 }
 
diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c
index 92184eea74..c6817d4708 100644
--- a/src/backends/meta-monitor.c
+++ b/src/backends/meta-monitor.c
@@ -316,7 +316,7 @@ meta_monitor_is_primary (MetaMonitor *monitor)
 
   output = meta_monitor_get_main_output (monitor);
 
-  return output->is_primary;
+  return meta_output_is_primary (output);
 }
 
 gboolean
@@ -336,7 +336,7 @@ meta_monitor_is_underscanning (MetaMonitor *monitor)
 
   output = meta_monitor_get_main_output (monitor);
 
-  return output->is_underscanning;
+  return meta_output_is_underscanning (output);
 }
 
 gboolean
diff --git a/src/backends/meta-output.c b/src/backends/meta-output.c
index 6a2ceb71f3..8bd396c439 100644
--- a/src/backends/meta-output.c
+++ b/src/backends/meta-output.c
@@ -41,6 +41,13 @@ typedef struct _MetaOutputPrivate
 
   /* The CRTC driving this output, NULL if the output is not enabled */
   MetaCrtc *crtc;
+
+  gboolean is_primary;
+  gboolean is_presentation;
+
+  gboolean is_underscanning;
+
+  int backlight;
 } MetaOutputPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (MetaOutput, meta_output, G_TYPE_OBJECT)
@@ -67,15 +74,61 @@ meta_output_get_name (MetaOutput *output)
   return output->name;
 }
 
+gboolean
+meta_output_is_primary (MetaOutput *output)
+{
+  MetaOutputPrivate *priv = meta_output_get_instance_private (output);
+
+  return priv->is_primary;
+}
+
+gboolean
+meta_output_is_presentation (MetaOutput *output)
+{
+  MetaOutputPrivate *priv = meta_output_get_instance_private (output);
+
+  return priv->is_presentation;
+}
+
+gboolean
+meta_output_is_underscanning (MetaOutput *output)
+{
+  MetaOutputPrivate *priv = meta_output_get_instance_private (output);
+
+  return priv->is_underscanning;
+}
+
+void
+meta_output_set_backlight (MetaOutput *output,
+                           int         backlight)
+{
+  MetaOutputPrivate *priv = meta_output_get_instance_private (output);
+
+  priv->backlight = backlight;
+}
+
+int
+meta_output_get_backlight (MetaOutput *output)
+{
+  MetaOutputPrivate *priv = meta_output_get_instance_private (output);
+
+  return priv->backlight;
+}
+
 void
-meta_output_assign_crtc (MetaOutput *output,
-                         MetaCrtc   *crtc)
+meta_output_assign_crtc (MetaOutput           *output,
+                         MetaCrtc             *crtc,
+                         const MetaOutputInfo *output_info)
 {
   MetaOutputPrivate *priv = meta_output_get_instance_private (output);
 
   g_assert (crtc);
 
   g_set_object (&priv->crtc, crtc);
+
+  priv->is_primary = output_info->is_primary;
+  priv->is_presentation = output_info->is_presentation;
+  priv->is_underscanning = output_info->is_underscanning;
 }
 
 void
@@ -84,6 +137,9 @@ meta_output_unassign_crtc (MetaOutput *output)
   MetaOutputPrivate *priv = meta_output_get_instance_private (output);
 
   g_clear_object (&priv->crtc);
+
+  priv->is_primary = FALSE;
+  priv->is_presentation = FALSE;
 }
 
 MetaCrtc *
@@ -194,6 +250,9 @@ meta_output_finalize (GObject *object)
 static void
 meta_output_init (MetaOutput *output)
 {
+  MetaOutputPrivate *priv = meta_output_get_instance_private (output);
+
+  priv->backlight = -1;
 }
 
 static void
diff --git a/src/backends/meta-output.h b/src/backends/meta-output.h
index 18850baf9e..86d338c061 100644
--- a/src/backends/meta-output.h
+++ b/src/backends/meta-output.h
@@ -85,14 +85,9 @@ struct _MetaOutput
   MetaOutput **possible_clones;
   unsigned int n_possible_clones;
 
-  int backlight;
   int backlight_min;
   int backlight_max;
 
-  gboolean is_primary;
-  gboolean is_presentation;
-
-  gboolean is_underscanning;
   gboolean supports_underscanning;
 
   gpointer driver_private;
@@ -121,8 +116,23 @@ MetaGpu * meta_output_get_gpu (MetaOutput *output);
 const char * meta_output_get_name (MetaOutput *output);
 
 META_EXPORT_TEST
-void meta_output_assign_crtc (MetaOutput *output,
-                              MetaCrtc   *crtc);
+gboolean meta_output_is_primary (MetaOutput *output);
+
+META_EXPORT_TEST
+gboolean meta_output_is_presentation (MetaOutput *output);
+
+META_EXPORT_TEST
+gboolean meta_output_is_underscanning (MetaOutput *output);
+
+void meta_output_set_backlight (MetaOutput *output,
+                                int         backlight);
+
+int meta_output_get_backlight (MetaOutput *output);
+
+META_EXPORT_TEST
+void meta_output_assign_crtc (MetaOutput           *output,
+                              MetaCrtc             *crtc,
+                              const MetaOutputInfo *output_info);
 
 META_EXPORT_TEST
 void meta_output_unassign_crtc (MetaOutput *output);
diff --git a/src/backends/native/meta-monitor-manager-kms.c b/src/backends/native/meta-monitor-manager-kms.c
index 4d1ca7e21e..469c5b6e88 100644
--- a/src/backends/native/meta-monitor-manager-kms.c
+++ b/src/backends/native/meta-monitor-manager-kms.c
@@ -219,40 +219,23 @@ apply_crtc_assignments (MetaMonitorManager *manager,
           for (j = 0; j < crtc_info->outputs->len; j++)
             {
               MetaOutput *output = g_ptr_array_index (crtc_info->outputs, j);
+              MetaOutputInfo *output_info;
 
               to_configure_outputs = g_list_remove (to_configure_outputs,
                                                     output);
-              meta_output_assign_crtc (output, crtc);
+
+              output_info = meta_find_output_info (outputs, n_outputs, output);
+              meta_output_assign_crtc (output, crtc, output_info);
             }
         }
     }
 
-  /* Disable CRTCs yet to be configured. */
-  for (l = to_configure_crtcs; l; l = l->next)
-    {
-      MetaCrtc *crtc = l->data;
-
-      meta_crtc_unset_config (crtc);
-    }
-
-  for (i = 0; i < n_outputs; i++)
-    {
-      MetaOutputInfo *output_info = outputs[i];
-      MetaOutput *output = output_info->output;
-
-      output->is_primary = output_info->is_primary;
-      output->is_presentation = output_info->is_presentation;
-      output->is_underscanning = output_info->is_underscanning;
-    }
-
-  /* Disable outputs yet to be configured. */
-  for (l = to_configure_outputs; l; l = l->next)
-    {
-      MetaOutput *output = l->data;
-
-      meta_output_unassign_crtc (output);
-      output->is_primary = FALSE;
-    }
+  g_list_foreach (to_configure_crtcs,
+                  (GFunc) meta_crtc_unset_config,
+                  NULL);
+  g_list_foreach (to_configure_outputs,
+                  (GFunc) meta_output_unassign_crtc,
+                  NULL);
 }
 
 static void
diff --git a/src/backends/native/meta-output-kms.c b/src/backends/native/meta-output-kms.c
index 3b690ec3ed..170e63c796 100644
--- a/src/backends/native/meta-output-kms.c
+++ b/src/backends/native/meta-output-kms.c
@@ -61,7 +61,7 @@ meta_output_kms_set_underscan (MetaOutput    *output,
   if (!output->supports_underscanning)
     return;
 
-  if (output->is_underscanning)
+  if (meta_output_is_underscanning (output))
     {
       MetaCrtc *crtc;
       MetaCrtcConfig *crtc_config;
@@ -363,7 +363,23 @@ meta_create_kms_output (MetaGpuKms        *gpu_kms,
 
           if (meta_crtc_get_id (crtc) == connector_state->current_crtc_id)
             {
-              meta_output_assign_crtc (output, crtc);
+              MetaOutputInfo output_info;
+
+              if (old_output)
+                {
+                  output_info = (MetaOutputInfo) {
+                    .is_primary = meta_output_is_primary (old_output),
+                    .is_presentation = meta_output_is_presentation (old_output),
+                  };
+                }
+              else
+                {
+                  output_info = (MetaOutputInfo) {
+                    .is_primary = FALSE,
+                    .is_presentation = FALSE,
+                  };
+                }
+              meta_output_assign_crtc (output, crtc, &output_info);
               break;
             }
         }
@@ -373,17 +389,6 @@ meta_create_kms_output (MetaGpuKms        *gpu_kms,
       meta_output_unassign_crtc (output);
     }
 
-  if (old_output)
-    {
-      output->is_primary = old_output->is_primary;
-      output->is_presentation = old_output->is_presentation;
-    }
-  else
-    {
-      output->is_primary = FALSE;
-      output->is_presentation = FALSE;
-    }
-
   output->suggested_x = connector_state->suggested_x;
   output->suggested_y = connector_state->suggested_y;
   output->hotplug_mode_update = connector_state->hotplug_mode_update;
@@ -407,7 +412,6 @@ meta_create_kms_output (MetaGpuKms        *gpu_kms,
      */
   output->backlight_min = 0;
   output->backlight_max = 0;
-  output->backlight = -1;
 
   return output;
 }
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
index d06f7daffc..eab5f55eca 100644
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
@@ -278,13 +278,15 @@ is_output_assignment_changed (MetaOutput      *output,
       if (output_info->output != output)
         continue;
 
-      if (output->is_primary != output_info->is_primary)
+      if (meta_output_is_primary (output) != output_info->is_primary)
         return TRUE;
 
-      if (output->is_presentation != output_info->is_presentation)
+      if (meta_output_is_presentation (output) !=
+          output_info->is_presentation)
         return TRUE;
 
-      if (output->is_underscanning != output_info->is_underscanning)
+      if (meta_output_is_underscanning (output) !=
+          output_info->is_underscanning)
         return TRUE;
 
       output_is_found = TRUE;
@@ -484,12 +486,15 @@ apply_crtc_assignments (MetaMonitorManager *manager,
           for (j = 0; j < n_output_ids; j++)
             {
               MetaOutput *output;
+              MetaOutputInfo *output_info;
 
               output = ((MetaOutput**)crtc_info->outputs->pdata)[j];
 
               to_configure_outputs = g_list_remove (to_configure_outputs,
                                                     output);
-              meta_output_assign_crtc (output, crtc);
+
+              output_info = meta_find_output_info (outputs, n_outputs, output);
+              meta_output_assign_crtc (output, crtc, output_info);
 
               output_ids[j] = meta_output_get_id (output);
             }
@@ -528,21 +533,12 @@ apply_crtc_assignments (MetaMonitorManager *manager,
       MetaOutputInfo *output_info = outputs[i];
       MetaOutput *output = output_info->output;
 
-      output->is_primary = output_info->is_primary;
-      output->is_presentation = output_info->is_presentation;
-      output->is_underscanning = output_info->is_underscanning;
-
       meta_output_xrandr_apply_mode (output);
     }
 
-  /* Disable outputs not mentioned in the list */
-  for (l = to_configure_outputs; l; l = l->next)
-    {
-      MetaOutput *output = l->data;
-
-      meta_output_unassign_crtc (output);
-      output->is_primary = FALSE;
-    }
+  g_list_foreach (to_configure_outputs,
+                  (GFunc) meta_output_unassign_crtc,
+                  NULL);
 
   XUngrabServer (manager_xrandr->xdisplay);
   XFlush (manager_xrandr->xdisplay);
diff --git a/src/backends/x11/meta-output-xrandr.c b/src/backends/x11/meta-output-xrandr.c
index 264b3affdd..e134a8ab74 100644
--- a/src/backends/x11/meta-output-xrandr.c
+++ b/src/backends/x11/meta-output-xrandr.c
@@ -132,16 +132,19 @@ meta_output_xrandr_apply_mode (MetaOutput *output)
 {
   Display *xdisplay = xdisplay_from_output (output);
 
-  if (output->is_primary)
+  if (meta_output_is_primary (output))
     {
       XRRSetOutputPrimary (xdisplay, DefaultRootWindow (xdisplay),
                            (XID) meta_output_get_id (output));
     }
 
-  output_set_presentation_xrandr (output, output->is_presentation);
+  output_set_presentation_xrandr (output, meta_output_is_presentation (output));
 
   if (output->supports_underscanning)
-    output_set_underscanning_xrandr (output, output->is_underscanning);
+    {
+      output_set_underscanning_xrandr (output,
+                                       meta_output_is_underscanning (output));
+    }
 }
 
 static int
@@ -172,7 +175,7 @@ meta_output_xrandr_change_backlight (MetaOutput *output,
                                     1, &hw_value);
 
   /* We're not selecting for property notifies, so update the value immediately */
-  output->backlight = normalize_backlight (output, hw_value);
+  meta_output_set_backlight (output, normalize_backlight (output, hw_value));
 }
 
 static gboolean
@@ -730,8 +733,9 @@ output_get_modes (MetaOutput    *output,
 }
 
 static void
-output_get_crtcs (MetaOutput    *output,
-                  XRROutputInfo *xrandr_output)
+output_get_crtcs (MetaOutput     *output,
+                  XRROutputInfo  *xrandr_output,
+                  MetaCrtc      **assigned_crtc)
 {
   MetaGpu *gpu = meta_output_get_gpu (output);
   unsigned int i;
@@ -764,10 +768,12 @@ output_get_crtcs (MetaOutput    *output,
 
       if ((XID) meta_crtc_get_id (crtc) == xrandr_output->crtc)
         {
-          meta_output_assign_crtc (output, crtc);
-          break;
+          *assigned_crtc = crtc;
+          return;
         }
     }
+
+  *assigned_crtc = NULL;
 }
 
 MetaOutput *
@@ -778,6 +784,7 @@ meta_create_xrandr_output (MetaGpuXrandr *gpu_xrandr,
 {
   MetaOutput *output;
   GBytes *edid;
+  MetaCrtc *assigned_crtc;
   unsigned int i;
 
   output = g_object_new (META_TYPE_OUTPUT,
@@ -812,7 +819,19 @@ meta_create_xrandr_output (MetaGpuXrandr *gpu_xrandr,
 
   output_get_tile_info (output);
   output_get_modes (output, xrandr_output);
-  output_get_crtcs (output, xrandr_output);
+  output_get_crtcs (output, xrandr_output, &assigned_crtc);
+
+  if (assigned_crtc)
+    {
+      MetaOutputInfo output_info;
+
+      output_info = (MetaOutputInfo) {
+        .is_primary = (XID) meta_output_get_id (output) == primary_output,
+        .is_presentation = output_get_presentation_xrandr (output),
+        .is_underscanning = output_get_underscanning_xrandr (output),
+      };
+      meta_output_assign_crtc (output, assigned_crtc, &output_info);
+    }
 
   output->n_possible_clones = xrandr_output->nclone;
   output->possible_clones = g_new0 (MetaOutput *,
@@ -827,17 +846,12 @@ meta_create_xrandr_output (MetaGpuXrandr *gpu_xrandr,
       output->possible_clones[i] = GINT_TO_POINTER (xrandr_output->clones[i]);
     }
 
-  output->is_primary = (XID) meta_output_get_id (output) == primary_output;
-  output->is_presentation = output_get_presentation_xrandr (output);
-  output->is_underscanning = output_get_underscanning_xrandr (output);
   output->supports_underscanning =
     output_get_supports_underscanning_xrandr (output);
   output_get_backlight_limits_xrandr (output);
 
   if (!(output->backlight_min == 0 && output->backlight_max == 0))
-    output->backlight = output_get_backlight_xrandr (output);
-  else
-    output->backlight = -1;
+    meta_output_set_backlight (output, output_get_backlight_xrandr (output));
 
   if (output->n_modes == 0 || output->n_possible_crtcs == 0)
     {
diff --git a/src/tests/meta-monitor-manager-test.c b/src/tests/meta-monitor-manager-test.c
index d76ada57a9..b4eada6761 100644
--- a/src/tests/meta-monitor-manager-test.c
+++ b/src/tests/meta-monitor-manager-test.c
@@ -125,7 +125,6 @@ apply_crtc_assignments (MetaMonitorManager *manager,
   MetaGpu *gpu = meta_backend_test_get_gpu (backend_test);
   g_autoptr (GList) to_configure_outputs = NULL;
   g_autoptr (GList) to_configure_crtcs = NULL;
-  GList *l;
   unsigned int i;
 
   to_configure_outputs = g_list_copy (meta_gpu_get_outputs (gpu));
@@ -144,7 +143,6 @@ apply_crtc_assignments (MetaMonitorManager *manager,
         }
       else
         {
-          MetaOutput *output;
           unsigned int j;
 
           meta_crtc_set_config (crtc,
@@ -154,41 +152,26 @@ apply_crtc_assignments (MetaMonitorManager *manager,
 
           for (j = 0; j < crtc_info->outputs->len; j++)
             {
+              MetaOutput *output;
+              MetaOutputInfo *output_info;
+
               output = ((MetaOutput**)crtc_info->outputs->pdata)[j];
 
               to_configure_outputs = g_list_remove (to_configure_outputs,
                                                     output);
-              meta_output_assign_crtc (output, crtc);
+
+              output_info = meta_find_output_info (outputs, n_outputs, output);
+              meta_output_assign_crtc (output, crtc, output_info);
             }
         }
     }
 
-  for (i = 0; i < n_outputs; i++)
-    {
-      MetaOutputInfo *output_info = outputs[i];
-      MetaOutput *output = output_info->output;
-
-      output->is_primary = output_info->is_primary;
-      output->is_presentation = output_info->is_presentation;
-      output->is_underscanning = output_info->is_underscanning;
-    }
-
-  /* Disable CRTCs not mentioned in the list */
-  for (l = to_configure_crtcs; l; l = l->next)
-    {
-      MetaCrtc *crtc = l->data;
-
-      meta_crtc_unset_config (crtc);
-    }
-
-  /* Disable outputs not mentioned in the list */
-  for (l = to_configure_outputs; l; l = l->next)
-    {
-      MetaOutput *output = l->data;
-
-      meta_output_unassign_crtc (output);
-      output->is_primary = FALSE;
-    }
+  g_list_foreach (to_configure_crtcs,
+                  (GFunc) meta_crtc_unset_config,
+                  NULL);
+  g_list_foreach (to_configure_outputs,
+                  (GFunc) meta_output_unassign_crtc,
+                  NULL);
 }
 
 static void
diff --git a/src/tests/monitor-test-utils.c b/src/tests/monitor-test-utils.c
index 725c336233..921b8a2efb 100644
--- a/src/tests/monitor-test-utils.c
+++ b/src/tests/monitor-test-utils.c
@@ -285,7 +285,7 @@ check_logical_monitor (MetaMonitorManager            *monitor_manager,
           MetaOutput *output = l_output->data;
           MetaCrtc *crtc;
 
-          if (output->is_primary)
+          if (meta_output_is_primary (output))
             {
               g_assert_null (primary_output);
               primary_output = output;
@@ -296,7 +296,7 @@ check_logical_monitor (MetaMonitorManager            *monitor_manager,
                     meta_monitor_get_logical_monitor (monitor) == logical_monitor);
           g_assert_cmpint (logical_monitor->is_presentation,
                            ==,
-                           output->is_presentation);
+                           meta_output_is_presentation (output));
         }
     }
 
@@ -370,7 +370,7 @@ check_monitor_configuration (MonitorTestCaseExpect *expect)
           g_assert (output == output_from_winsys_id (backend, winsys_id));
           g_assert_cmpint (expect->monitors[i].is_underscanning,
                            ==,
-                           output->is_underscanning);
+                           meta_output_is_underscanning (output));
         }
 
       meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
@@ -655,7 +655,15 @@ create_monitor_test_setup (MonitorTestCaseSetup *setup,
                              NULL);
 
       if (crtc)
-        meta_output_assign_crtc (output, crtc);
+        {
+          MetaOutputInfo output_info;
+
+          output_info = (MetaOutputInfo) {
+            .is_underscanning = setup->outputs[i].is_underscanning,
+          };
+          meta_output_assign_crtc (output, crtc, &output_info);
+        }
+
       output->name = (is_laptop_panel ? g_strdup_printf ("eDP-%d",
                                                   ++n_laptop_panels)
                                : g_strdup_printf ("DP-%d",
@@ -676,11 +684,9 @@ create_monitor_test_setup (MonitorTestCaseSetup *setup,
       output->possible_crtcs = possible_crtcs;
       output->n_possible_clones = 0;
       output->possible_clones = NULL;
-      output->backlight = -1;
       output->connector_type = (is_laptop_panel ? META_CONNECTOR_TYPE_eDP
                                          : META_CONNECTOR_TYPE_DisplayPort);
       output->tile_info = setup->outputs[i].tile_info;
-      output->is_underscanning = setup->outputs[i].is_underscanning;
       output->panel_orientation_transform =
         setup->outputs[i].panel_orientation_transform;
       output->driver_private = output_test;


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