From fe1616668e9d82e87f6c518b3b4bacff3afefdf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 3 Nov 2017 11:27:57 +0100 Subject: [PATCH] backends: Add logical monitor -> monitor -> output -> crtc ref chain Make it so that each logical monitor has a reference to all the monitors that are assigned to it. All monitors has a reference to each output that belongs to it. Each output has a reference to any CRTC it has been assigned. https://bugzilla.gnome.org/show_bug.cgi?id=786929 (cherry picked from commit 768ec15ea072df21dd6caeb2507d41223ade9116) --- src/backends/meta-logical-monitor.c | 14 +++++++++----- src/backends/meta-monitor.c | 22 +++++++++++++++++++--- src/backends/meta-output.c | 16 ++++++++++++++-- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/backends/meta-logical-monitor.c b/src/backends/meta-logical-monitor.c index 3f6986880..693c83dcb 100644 --- a/src/backends/meta-logical-monitor.c +++ b/src/backends/meta-logical-monitor.c @@ -146,7 +146,7 @@ meta_logical_monitor_add_monitor (MetaLogicalMonitor *logical_monitor, is_presentation = logical_monitor->is_presentation; logical_monitor->monitors = g_list_append (logical_monitor->monitors, - monitor); + g_object_ref (monitor)); for (l = logical_monitor->monitors; l; l = l->next) { @@ -257,13 +257,17 @@ meta_logical_monitor_init (MetaLogicalMonitor *logical_monitor) } static void -meta_logical_monitor_finalize (GObject *object) +meta_logical_monitor_dispose (GObject *object) { MetaLogicalMonitor *logical_monitor = META_LOGICAL_MONITOR (object); - g_list_free (logical_monitor->monitors); + if (logical_monitor->monitors) + { + g_list_free_full (logical_monitor->monitors, g_object_unref); + logical_monitor->monitors = NULL; + } - G_OBJECT_CLASS (meta_logical_monitor_parent_class)->finalize (object); + G_OBJECT_CLASS (meta_logical_monitor_parent_class)->dispose (object); } static void @@ -271,7 +275,7 @@ meta_logical_monitor_class_init (MetaLogicalMonitorClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = meta_logical_monitor_finalize; + object_class->dispose = meta_logical_monitor_dispose; } gboolean diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c index 1e1af3950..98330661e 100644 --- a/src/backends/meta-monitor.c +++ b/src/backends/meta-monitor.c @@ -387,6 +387,21 @@ meta_monitor_crtc_to_logical_transform (MetaMonitor *monitor, return new_transform; } +static void +meta_monitor_dispose (GObject *object) +{ + MetaMonitor *monitor = META_MONITOR (object); + MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor); + + if (priv->outputs) + { + g_list_free_full (priv->outputs, g_object_unref); + priv->outputs = NULL; + } + + G_OBJECT_CLASS (meta_monitor_parent_class)->dispose (object); +} + static void meta_monitor_finalize (GObject *object) { @@ -395,7 +410,6 @@ meta_monitor_finalize (GObject *object) g_hash_table_destroy (priv->mode_ids); g_list_free_full (priv->modes, (GDestroyNotify) meta_monitor_mode_free); - g_clear_pointer (&priv->outputs, g_list_free); meta_monitor_spec_free (priv->spec); G_OBJECT_CLASS (meta_monitor_parent_class)->finalize (object); @@ -414,6 +428,7 @@ meta_monitor_class_init (MetaMonitorClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->dispose = meta_monitor_dispose; object_class->finalize = meta_monitor_finalize; } @@ -550,7 +565,7 @@ meta_monitor_normal_new (MetaGpu *gpu, monitor_priv->gpu = gpu; - monitor_priv->outputs = g_list_append (NULL, output); + monitor_priv->outputs = g_list_append (NULL, g_object_ref (output)); monitor_priv->winsys_id = output->winsys_id; meta_monitor_generate_spec (monitor); @@ -665,7 +680,8 @@ add_tiled_monitor_outputs (MetaGpu *gpu, g_warn_if_fail (output->subpixel_order == monitor_tiled->origin_output->subpixel_order); - monitor_priv->outputs = g_list_append (monitor_priv->outputs, output); + monitor_priv->outputs = g_list_append (monitor_priv->outputs, + g_object_ref (output)); } } diff --git a/src/backends/meta-output.c b/src/backends/meta-output.c index b5ecccd2b..2139a17a3 100644 --- a/src/backends/meta-output.c +++ b/src/backends/meta-output.c @@ -43,7 +43,7 @@ meta_output_assign_crtc (MetaOutput *output, g_assert (crtc); - priv->crtc = crtc; + g_set_object (&priv->crtc, crtc); } void @@ -51,7 +51,7 @@ meta_output_unassign_crtc (MetaOutput *output) { MetaOutputPrivate *priv = meta_output_get_instance_private (output); - priv->crtc = NULL; + g_clear_object (&priv->crtc); } MetaCrtc * @@ -62,6 +62,17 @@ meta_output_get_assigned_crtc (MetaOutput *output) return priv->crtc; } +static void +meta_output_dispose (GObject *object) +{ + MetaOutput *output = META_OUTPUT (object); + MetaOutputPrivate *priv = meta_output_get_instance_private (output); + + g_clear_object (&priv->crtc); + + G_OBJECT_CLASS (meta_output_parent_class)->dispose (object); +} + static void meta_output_finalize (GObject *object) { @@ -91,5 +102,6 @@ meta_output_class_init (MetaOutputClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->dispose = meta_output_dispose; object_class->finalize = meta_output_finalize; }