context: Make the context own MetaWaylandCompositor

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
Jonas Ådahl 2021-03-03 22:00:05 +01:00
parent 6768b509ea
commit 0330ce1f15
13 changed files with 65 additions and 100 deletions

View File

@ -112,14 +112,6 @@ void meta_backend_destroy (MetaBackend *backend);
void meta_backend_prepare_shutdown (MetaBackend *backend);
#ifdef HAVE_WAYLAND
MetaWaylandCompositor * meta_backend_get_wayland_compositor (MetaBackend *backend);
void meta_backend_init_wayland_display (MetaBackend *backend);
void meta_backend_init_wayland (MetaBackend *backend);
#endif
ClutterBackend * meta_backend_get_clutter_backend (MetaBackend *backend);
ClutterSeat * meta_backend_get_default_seat (MetaBackend *bakcend);

View File

@ -57,8 +57,6 @@ typedef struct _MetaScreenCast MetaScreenCast;
typedef struct _MetaScreenCastSession MetaScreenCastSession;
typedef struct _MetaScreenCastStream MetaScreenCastStream;
typedef struct _MetaWaylandCompositor MetaWaylandCompositor;
typedef struct _MetaVirtualMonitor MetaVirtualMonitor;
typedef struct _MetaVirtualMonitorInfo MetaVirtualMonitorInfo;

View File

@ -154,10 +154,6 @@ struct _MetaBackendPrivate
MetaRemoteDesktop *remote_desktop;
#endif
#ifdef HAVE_WAYLAND
MetaWaylandCompositor *wayland_compositor;
#endif
#ifdef HAVE_PROFILER
MetaProfiler *profiler;
#endif
@ -960,32 +956,6 @@ system_bus_gotten_cb (GObject *object,
NULL);
}
#ifdef HAVE_WAYLAND
MetaWaylandCompositor *
meta_backend_get_wayland_compositor (MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
return priv->wayland_compositor;
}
void
meta_backend_init_wayland_display (MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
priv->wayland_compositor = meta_wayland_compositor_new (backend);
}
void
meta_backend_init_wayland (MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
meta_wayland_compositor_setup (priv->wayland_compositor);
}
#endif
/* Mutter is responsible for pulling events off the X queue, so Clutter
* doesn't need (and shouldn't) run its normal event source which polls
* the X fd, but we do have to deal with dispatching events that accumulate

View File

@ -577,11 +577,6 @@ meta_backend_native_initable_init (GInitable *initable,
}
native->device_pool = meta_device_pool_new (native->launcher);
#ifdef HAVE_WAYLAND
meta_backend_init_wayland_display (META_BACKEND (native));
#endif
native->udev = meta_udev_new (native);
kms_flags = META_KMS_FLAG_NONE;

View File

@ -250,10 +250,6 @@ meta_backend_x11_nested_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
#ifdef HAVE_WAYLAND
meta_backend_init_wayland_display (META_BACKEND (initable));
#endif
return initable_parent_iface->init (initable, cancellable, error);
}

View File

@ -23,6 +23,7 @@
#include "meta/meta-backend.h"
#include "meta/meta-context.h"
#include "wayland/meta-wayland-types.h"
struct _MetaContextClass
{
@ -44,4 +45,6 @@ struct _MetaContextClass
void (* notify_ready) (MetaContext *context);
};
MetaWaylandCompositor * meta_context_get_wayland_compositor (MetaContext *context);
#endif /* META_CONTEXT_PRIVATE_H */

View File

@ -56,6 +56,9 @@ typedef struct _MetaContextPrivate
MetaBackend *backend;
MetaDisplay *display;
#ifdef HAVE_WAYLAND
MetaWaylandCompositor *wayland_compositor;
#endif
GMainLoop *main_loop;
GError *termination_error;
@ -142,6 +145,16 @@ meta_context_get_display (MetaContext *context)
return priv->display;
}
#ifdef HAVE_WAYLAND
MetaWaylandCompositor *
meta_context_get_wayland_compositor (MetaContext *context)
{
MetaContextPrivate *priv = meta_context_get_instance_private (context);
return priv->wayland_compositor;
}
#endif
MetaCompositorType
meta_context_get_compositor_type (MetaContext *context)
{
@ -304,6 +317,10 @@ meta_context_setup (MetaContext *context,
init_introspection (context);
#ifdef HAVE_WAYLAND
priv->wayland_compositor = meta_wayland_compositor_new (context);
#endif
return META_CONTEXT_GET_CLASS (context)->setup (context, error);
}
@ -318,7 +335,7 @@ meta_context_start (MetaContext *context,
#ifdef HAVE_WAYLAND
if (meta_context_get_compositor_type (context) ==
META_COMPOSITOR_TYPE_WAYLAND)
meta_backend_init_wayland (meta_get_backend ());
meta_wayland_compositor_setup (priv->wayland_compositor);
#endif
priv->display = meta_display_new (context, error);
@ -420,18 +437,13 @@ meta_context_finalize (GObject *object)
{
MetaContext *context = META_CONTEXT (object);
MetaContextPrivate *priv = meta_context_get_instance_private (context);
#ifdef HAVE_WAYLAND
MetaWaylandCompositor *compositor;
MetaCompositorType compositor_type;
#endif
if (priv->backend)
meta_backend_prepare_shutdown (priv->backend);
#ifdef HAVE_WAYLAND
compositor = meta_wayland_compositor_get_default ();
if (compositor)
meta_wayland_compositor_prepare_shutdown (compositor);
if (priv->wayland_compositor)
meta_wayland_compositor_prepare_shutdown (priv->wayland_compositor);
#endif
if (priv->display)
@ -439,9 +451,7 @@ meta_context_finalize (GObject *object)
g_clear_object (&priv->display);
#ifdef HAVE_WAYLAND
compositor_type = meta_context_get_compositor_type (context);
if (compositor_type == META_COMPOSITOR_TYPE_WAYLAND)
meta_wayland_finalize ();
g_clear_object (&priv->wayland_compositor);
#endif
g_clear_pointer (&priv->backend, meta_backend_destroy);

View File

@ -302,12 +302,11 @@ meta_wayland_actor_surface_apply_state (MetaWaylandSurfaceRole *surface_role,
if (!wl_list_empty (&pending->frame_callback_list) &&
priv->actor &&
clutter_actor_is_mapped (CLUTTER_ACTOR (priv->actor)) &&
!meta_surface_actor_is_obscured (priv->actor))
{
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaBackend *backend = surface->compositor->backend;
ClutterActor *stage = meta_backend_get_stage (backend);
ClutterActor *stage =
clutter_actor_get_stage (CLUTTER_ACTOR (priv->actor));
clutter_stage_schedule_update (CLUTTER_STAGE (stage));
}

View File

@ -342,8 +342,9 @@ on_cursor_painted (MetaCursorRenderer *renderer,
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
guint32 time = (guint32) (g_get_monotonic_time () / 1000);
MetaBackend *backend = meta_get_backend ();
MetaContext *context = meta_backend_get_context (backend);
MetaWaylandCompositor *compositor =
meta_backend_get_wayland_compositor (backend);
meta_context_get_wayland_compositor (context);
if (displayed_sprite != META_CURSOR_SPRITE (priv->cursor_sprite))
return;

View File

@ -212,7 +212,8 @@ on_monitors_changed (MetaMonitorManager *manager,
void
meta_wayland_init_presentation_time (MetaWaylandCompositor *compositor)
{
MetaBackend *backend = compositor->backend;
MetaContext *context = compositor->context;
MetaBackend *backend = meta_context_get_backend (context);
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
ClutterActor *stage = meta_backend_get_stage (backend);

View File

@ -82,7 +82,7 @@ struct _MetaWaylandCompositor
{
GObject parent;
MetaBackend *backend;
MetaContext *context;
struct wl_display *wayland_display;
char *display_name;

View File

@ -60,10 +60,12 @@ MetaWaylandCompositor *
meta_wayland_compositor_get_default (void)
{
MetaBackend *backend;
MetaContext *context;
MetaWaylandCompositor *wayland_compositor;
backend = meta_get_backend ();
wayland_compositor = meta_backend_get_wayland_compositor (backend);
context = meta_backend_get_context (backend);
wayland_compositor = meta_context_get_wayland_compositor (context);
g_assert (wayland_compositor);
return wayland_compositor;
@ -407,6 +409,28 @@ meta_wayland_log_func (const char *fmt,
g_free (str);
}
void
meta_wayland_compositor_prepare_shutdown (MetaWaylandCompositor *compositor)
{
meta_xwayland_shutdown (&compositor->xwayland_manager);
if (compositor->wayland_display)
wl_display_destroy_clients (compositor->wayland_display);
}
static void
meta_wayland_compositor_finalize (GObject *object)
{
MetaWaylandCompositor *compositor = META_WAYLAND_COMPOSITOR (object);
g_clear_pointer (&compositor->seat, meta_wayland_seat_free);
g_clear_pointer (&compositor->display_name, g_free);
g_clear_pointer (&compositor->wayland_display, wl_display_destroy);
G_OBJECT_CLASS (meta_wayland_compositor_parent_class)->finalize (object);
}
static void
meta_wayland_compositor_init (MetaWaylandCompositor *compositor)
{
@ -422,6 +446,9 @@ meta_wayland_compositor_init (MetaWaylandCompositor *compositor)
static void
meta_wayland_compositor_class_init (MetaWaylandCompositorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = meta_wayland_compositor_finalize;
}
static bool
@ -455,12 +482,12 @@ meta_wayland_get_xwayland_auth_file (MetaWaylandCompositor *compositor)
}
MetaWaylandCompositor *
meta_wayland_compositor_new (MetaBackend *backend)
meta_wayland_compositor_new (MetaContext *context)
{
MetaWaylandCompositor *compositor;
compositor = g_object_new (META_TYPE_WAYLAND_COMPOSITOR, NULL);
compositor->backend = backend;
compositor->context = context;
return compositor;
}
@ -498,7 +525,8 @@ meta_wayland_init_egl (MetaWaylandCompositor *compositor)
void
meta_wayland_compositor_setup (MetaWaylandCompositor *compositor)
{
ClutterActor *stage = meta_backend_get_stage (compositor->backend);
MetaBackend *backend = meta_context_get_backend (compositor->context);
ClutterActor *stage = meta_backend_get_stage (backend);
GSource *wayland_event_source;
wayland_event_source = wayland_event_source_new (compositor->wayland_display);
@ -616,28 +644,6 @@ meta_wayland_get_private_xwayland_display_name (MetaWaylandCompositor *composito
return compositor->xwayland_manager.private_connection.name;
}
void
meta_wayland_compositor_prepare_shutdown (MetaWaylandCompositor *compositor)
{
meta_xwayland_shutdown (&compositor->xwayland_manager);
if (compositor->wayland_display)
wl_display_destroy_clients (compositor->wayland_display);
}
void
meta_wayland_finalize (void)
{
MetaWaylandCompositor *compositor;
compositor = meta_wayland_compositor_get_default ();
g_clear_pointer (&compositor->seat, meta_wayland_seat_free);
g_clear_pointer (&compositor->display_name, g_free);
g_clear_pointer (&compositor->wayland_display, wl_display_destroy);
}
void
meta_wayland_compositor_restore_shortcuts (MetaWaylandCompositor *compositor,
ClutterInputDevice *source)

View File

@ -32,13 +32,7 @@
META_EXPORT_TEST
void meta_wayland_override_display_name (const char *display_name);
void meta_wayland_pre_clutter_init (void);
void meta_wayland_init (void);
void meta_wayland_finalize (void);
MetaWaylandCompositor * meta_wayland_compositor_new (MetaBackend *backend);
MetaWaylandCompositor * meta_wayland_compositor_new (MetaContext *context);
void meta_wayland_compositor_setup (MetaWaylandCompositor *compositor);