[mutter/wip/carlosg/rt-scheduler: 1/5] backends: Externalize the post-init backend phase



commit ea0a99856e4e613db1de2c18580f56603d6f6c21
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed May 8 12:43:52 2019 +0200

    backends: Externalize the post-init backend phase
    
    Call it from main.c, as we want things to happen between the ClutterBackend
    is created and the backend is fully initialized. Also allow the vfunc to
    return an error, this will be useful in the future.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/460

 src/backends/meta-backend-private.h       |  5 ++++-
 src/backends/meta-backend.c               | 18 ++++++++++++------
 src/backends/native/meta-backend-native.c |  9 ++++++---
 src/backends/x11/cm/meta-backend-x11-cm.c |  9 ++++++---
 src/backends/x11/meta-backend-x11.c       | 10 +++++++---
 src/core/main.c                           |  2 ++
 6 files changed, 37 insertions(+), 16 deletions(-)
---
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
index 7eba1806b..328845216 100644
--- a/src/backends/meta-backend-private.h
+++ b/src/backends/meta-backend-private.h
@@ -55,7 +55,8 @@ struct _MetaBackendClass
 
   ClutterBackend * (* create_clutter_backend) (MetaBackend *backend);
 
-  void (* post_init) (MetaBackend *backend);
+  gboolean (* post_init) (MetaBackend  *backend,
+                          GError      **error);
 
   MetaMonitorManager * (* create_monitor_manager) (MetaBackend *backend,
                                                    GError     **error);
@@ -107,6 +108,8 @@ struct _MetaBackendClass
 
 void meta_init_backend (GType backend_gtype);
 
+void meta_backend_post_init (MetaBackend *backend);
+
 ClutterBackend * meta_backend_get_clutter_backend (MetaBackend *backend);
 
 MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend,
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 23ab2faec..ae858aae5 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -469,8 +469,9 @@ meta_backend_create_input_settings (MetaBackend *backend)
   return META_BACKEND_GET_CLASS (backend)->create_input_settings (backend);
 }
 
-static void
-meta_backend_real_post_init (MetaBackend *backend)
+static gboolean
+meta_backend_real_post_init (MetaBackend  *backend,
+                             GError      **error)
 {
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
   ClutterDeviceManager *device_manager = clutter_device_manager_get_default ();
@@ -514,6 +515,8 @@ meta_backend_real_post_init (MetaBackend *backend)
       reset_pointer_position (backend);
       priv->is_pointer_position_initialized = TRUE;
     }
+
+  return TRUE;
 }
 
 static MetaCursorRenderer *
@@ -856,12 +859,17 @@ meta_backend_init (MetaBackend *backend)
   _backend = backend;
 }
 
-static void
+void
 meta_backend_post_init (MetaBackend *backend)
 {
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+  GError *error = NULL;
 
-  META_BACKEND_GET_CLASS (backend)->post_init (backend);
+  if (!META_BACKEND_GET_CLASS (backend)->post_init (backend, &error))
+    {
+      g_warning ("Failed to initialize backend: %s", error->message);
+      meta_exit (META_EXIT_ERROR);
+    }
 
   meta_settings_post_init (priv->settings);
 }
@@ -1309,8 +1317,6 @@ meta_clutter_init (void)
   source = g_source_new (&event_funcs, sizeof (GSource));
   g_source_attach (source, NULL);
   g_source_unref (source);
-
-  meta_backend_post_init (_backend);
 }
 
 /**
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index c473681cb..bac197567 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -327,17 +327,20 @@ meta_backend_native_create_clutter_backend (MetaBackend *backend)
   return g_object_new (META_TYPE_CLUTTER_BACKEND_NATIVE, NULL);
 }
 
-static void
-meta_backend_native_post_init (MetaBackend *backend)
+static gboolean
+meta_backend_native_post_init (MetaBackend  *backend,
+                               GError      **error)
 {
   ClutterDeviceManager *manager = clutter_device_manager_get_default ();
 
-  META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend);
+  if (!META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend, error))
+    return FALSE;
 
   clutter_evdev_set_pointer_constrain_callback (manager, pointer_constrain_callback,
                                                 NULL, NULL);
   clutter_evdev_set_relative_motion_filter (manager, relative_motion_filter,
                                             meta_backend_get_monitor_manager (backend));
+  return TRUE;
 }
 
 static MetaMonitorManager *
diff --git a/src/backends/x11/cm/meta-backend-x11-cm.c b/src/backends/x11/cm/meta-backend-x11-cm.c
index 1e377220b..58c2e6829 100644
--- a/src/backends/x11/cm/meta-backend-x11-cm.c
+++ b/src/backends/x11/cm/meta-backend-x11-cm.c
@@ -76,19 +76,22 @@ on_device_added (ClutterDeviceManager *device_manager,
     apply_keymap (x11);
 }
 
-static void
-meta_backend_x11_cm_post_init (MetaBackend *backend)
+static gboolean
+meta_backend_x11_cm_post_init (MetaBackend  *backend,
+                               GError      **error)
 {
   MetaBackendClass *parent_backend_class =
     META_BACKEND_CLASS (meta_backend_x11_cm_parent_class);
 
-  parent_backend_class->post_init (backend);
+  if (!parent_backend_class->post_init (backend, error))
+    return FALSE;
 
   g_signal_connect_object (clutter_device_manager_get_default (),
                            "device-added",
                            G_CALLBACK (on_device_added), backend, 0);
 
   take_touch_grab (backend);
+  return TRUE;
 }
 
 static MetaRenderer *
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index c10365f9d..7ca2894ca 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -480,8 +480,9 @@ on_monitors_changed (MetaMonitorManager *manager,
   priv->cached_current_logical_monitor = NULL;
 }
 
-static void
-meta_backend_x11_post_init (MetaBackend *backend)
+static gboolean
+meta_backend_x11_post_init (MetaBackend  *backend,
+                            GError      **error)
 {
   MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
   MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
@@ -529,11 +530,14 @@ meta_backend_x11_post_init (MetaBackend *backend)
     meta_fatal ("X server doesn't have the XKB extension, version %d.%d or newer\n",
                 XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION);
 
-  META_BACKEND_CLASS (meta_backend_x11_parent_class)->post_init (backend);
+  if (!META_BACKEND_CLASS (meta_backend_x11_parent_class)->post_init (backend, error))
+    return FALSE;
 
   monitor_manager = meta_backend_get_monitor_manager (backend);
   g_signal_connect (monitor_manager, "monitors-changed-internal",
                     G_CALLBACK (on_monitors_changed), backend);
+
+  return TRUE;
 }
 
 static ClutterBackend *
diff --git a/src/core/main.c b/src/core/main.c
index e8464720f..e28c4c406 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -591,6 +591,8 @@ meta_init (void)
 
   meta_clutter_init ();
 
+  meta_backend_post_init (meta_get_backend ());
+
 #ifdef HAVE_WAYLAND
   /* Bring up Wayland. This also launches Xwayland and sets DISPLAY as well... */
   if (meta_is_wayland_compositor ())


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