compositor: Get the stage via the backend

We would get the MetaDisplay from the backend singleton before creating
the MetaCompositor, then in MetaCompositor, get the backend singleton
again to get the stage. To get rid of the extra singleton fetching, just
pass the backend the MetaCompositor constructors, and fetch the stage
directly from the backend everytime it's needed.

This also makes it available earlier than before, as we didn't set our
instance private stage pointer until the manage() call.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1289
This commit is contained in:
Jonas Ådahl 2020-04-16 19:14:21 +02:00 committed by Georges Basile Stavracas Neto
parent 9fc428f2e7
commit 25f9406e69
8 changed files with 49 additions and 24 deletions

View File

@ -91,6 +91,7 @@ enum
PROP_0,
PROP_DISPLAY,
PROP_BACKEND,
N_PROPS
};
@ -111,6 +112,7 @@ typedef struct _MetaCompositorPrivate
GObject parent;
MetaDisplay *display;
MetaBackend *backend;
guint pre_paint_func_id;
guint post_paint_func_id;
@ -231,7 +233,7 @@ meta_get_stage_for_display (MetaDisplay *display)
g_return_val_if_fail (compositor, NULL);
priv = meta_compositor_get_instance_private (compositor);
return priv->stage;
return meta_backend_get_stage (priv->backend);
}
/**
@ -564,12 +566,11 @@ meta_compositor_do_manage (MetaCompositor *compositor,
MetaCompositorPrivate *priv =
meta_compositor_get_instance_private (compositor);
MetaDisplay *display = priv->display;
MetaBackend *backend = meta_get_backend ();
priv->stage = meta_backend_get_stage (backend);
MetaBackend *backend = priv->backend;
ClutterActor *stage = meta_backend_get_stage (backend);
priv->stage_presented_id =
g_signal_connect (priv->stage, "presented",
g_signal_connect (stage, "presented",
G_CALLBACK (on_presented),
compositor);
@ -582,18 +583,18 @@ meta_compositor_do_manage (MetaCompositor *compositor,
* matter.
*/
priv->stage_after_paint_id =
g_signal_connect_after (priv->stage, "after-paint",
g_signal_connect_after (stage, "after-paint",
G_CALLBACK (after_stage_paint), compositor);
clutter_stage_set_sync_delay (CLUTTER_STAGE (priv->stage), META_SYNC_DELAY);
clutter_stage_set_sync_delay (CLUTTER_STAGE (stage), META_SYNC_DELAY);
priv->window_group = meta_window_group_new (display);
priv->top_window_group = meta_window_group_new (display);
priv->feedback_group = meta_window_group_new (display);
clutter_actor_add_child (priv->stage, priv->window_group);
clutter_actor_add_child (priv->stage, priv->top_window_group);
clutter_actor_add_child (priv->stage, priv->feedback_group);
clutter_actor_add_child (stage, priv->window_group);
clutter_actor_add_child (stage, priv->top_window_group);
clutter_actor_add_child (stage, priv->feedback_group);
if (!META_COMPOSITOR_GET_CLASS (compositor)->manage (compositor, error))
return FALSE;
@ -1162,7 +1163,7 @@ meta_compositor_real_post_paint (MetaCompositor *compositor)
case COGL_GRAPHICS_RESET_STATUS_PURGED_CONTEXT_RESET:
g_signal_emit_by_name (priv->display, "gl-video-memory-purged");
clutter_actor_queue_redraw (CLUTTER_ACTOR (priv->stage));
clutter_actor_queue_redraw (meta_backend_get_stage (priv->backend));
break;
default:
@ -1211,6 +1212,9 @@ meta_compositor_set_property (GObject *object,
case PROP_DISPLAY:
priv->display = g_value_get_object (value);
break;
case PROP_BACKEND:
priv->backend = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -1231,6 +1235,9 @@ meta_compositor_get_property (GObject *object,
case PROP_DISPLAY:
g_value_set_object (value, priv->display);
break;
case PROP_BACKEND:
g_value_set_object (value, priv->backend);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -1266,11 +1273,12 @@ meta_compositor_dispose (GObject *object)
MetaCompositor *compositor = META_COMPOSITOR (object);
MetaCompositorPrivate *priv =
meta_compositor_get_instance_private (compositor);
ClutterActor *stage = meta_backend_get_stage (priv->backend);
g_clear_pointer (&priv->laters, meta_laters_free);
g_clear_signal_handler (&priv->stage_after_paint_id, priv->stage);
g_clear_signal_handler (&priv->stage_presented_id, priv->stage);
g_clear_signal_handler (&priv->stage_after_paint_id, stage);
g_clear_signal_handler (&priv->stage_presented_id, stage);
g_clear_handle_id (&priv->pre_paint_func_id,
clutter_threads_remove_repaint_func);
@ -1309,6 +1317,14 @@ meta_compositor_class_init (MetaCompositorClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_props[PROP_BACKEND] =
g_param_spec_object ("backend",
"backend",
"MetaBackend",
META_TYPE_BACKEND,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, obj_props);
signals[PRE_PAINT] =
@ -1615,7 +1631,7 @@ meta_compositor_get_stage (MetaCompositor *compositor)
MetaCompositorPrivate *priv =
meta_compositor_get_instance_private (compositor);
return CLUTTER_STAGE (priv->stage);
return CLUTTER_STAGE (meta_backend_get_stage (priv->backend));
}
MetaWindowActor *

View File

@ -127,10 +127,12 @@ meta_compositor_native_pre_paint (MetaCompositor *compositor)
}
MetaCompositorNative *
meta_compositor_native_new (MetaDisplay *display)
meta_compositor_native_new (MetaDisplay *display,
MetaBackend *backend)
{
return g_object_new (META_TYPE_COMPOSITOR_NATIVE,
"display", display,
"backend", backend,
NULL);
}

View File

@ -27,6 +27,7 @@
G_DECLARE_FINAL_TYPE (MetaCompositorNative, meta_compositor_native,
META, COMPOSITOR_NATIVE, MetaCompositor)
MetaCompositorNative * meta_compositor_native_new (MetaDisplay *display);
MetaCompositorNative * meta_compositor_native_new (MetaDisplay *display,
MetaBackend *backend);
#endif /* META_COMPOSITOR_NATIVE_H */

View File

@ -37,10 +37,12 @@ meta_compositor_server_unmanage (MetaCompositor *compositor)
}
MetaCompositorServer *
meta_compositor_server_new (MetaDisplay *display)
meta_compositor_server_new (MetaDisplay *display,
MetaBackend *backend)
{
return g_object_new (META_TYPE_COMPOSITOR_SERVER,
"display", display,
"backend", backend,
NULL);
}

View File

@ -32,6 +32,7 @@ struct _MetaCompositorServerClass
MetaCompositorClass parent_class;
};
MetaCompositorServer * meta_compositor_server_new (MetaDisplay *display);
MetaCompositorServer * meta_compositor_server_new (MetaDisplay *display,
MetaBackend *backend);
#endif /* META_COMPOSITOR_SERVER_H */

View File

@ -371,10 +371,12 @@ meta_compositor_x11_get_output_xwindow (MetaCompositorX11 *compositor_x11)
}
MetaCompositorX11 *
meta_compositor_x11_new (MetaDisplay *display)
meta_compositor_x11_new (MetaDisplay *display,
MetaBackend *backend)
{
return g_object_new (META_TYPE_COMPOSITOR_X11,
"display", display,
"backend", backend,
NULL);
}

View File

@ -27,7 +27,8 @@
G_DECLARE_FINAL_TYPE (MetaCompositorX11, meta_compositor_x11,
META, COMPOSITOR_X11, MetaCompositor)
MetaCompositorX11 * meta_compositor_x11_new (MetaDisplay *display);
MetaCompositorX11 * meta_compositor_x11_new (MetaDisplay *display,
MetaBackend *backend);
void meta_compositor_x11_process_xevent (MetaCompositorX11 *compositor_x11,
XEvent *xevent,

View File

@ -573,17 +573,17 @@ meta_display_remove_pending_pings_for_window (MetaDisplay *display,
static MetaCompositor *
create_compositor (MetaDisplay *display)
{
#ifdef HAVE_WAYLAND
MetaBackend *backend = meta_get_backend ();
#ifdef HAVE_WAYLAND
#ifdef HAVE_NATIVE_BACKEND
if (META_IS_BACKEND_NATIVE (backend))
return META_COMPOSITOR (meta_compositor_native_new (display));
return META_COMPOSITOR (meta_compositor_native_new (display, backend));
#endif
if (META_IS_BACKEND_X11_NESTED (backend))
return META_COMPOSITOR (meta_compositor_server_new (display));
return META_COMPOSITOR (meta_compositor_server_new (display, backend));
#endif
return META_COMPOSITOR (meta_compositor_x11_new (display));
return META_COMPOSITOR (meta_compositor_x11_new (display, backend));
}
static void