[mutter] backends: Move MonitorManager creation to MetaBackend as well



commit c44b1d730d9981e0254ef5732f3d82dedfb63f2f
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Apr 21 19:41:11 2014 -0400

    backends: Move MonitorManager creation to MetaBackend as well

 src/backends/meta-backend-private.h       |    1 +
 src/backends/meta-backend.c               |   29 +++++++++++++++-
 src/backends/meta-backend.h               |    2 +
 src/backends/meta-monitor-manager.c       |   55 ++---------------------------
 src/backends/meta-monitor-manager.h       |    1 -
 src/backends/native/meta-backend-native.c |    8 ++++
 src/backends/x11/meta-backend-x11.c       |   15 ++++++++
 src/core/screen.c                         |    3 --
 src/wayland/meta-wayland.c                |    1 -
 9 files changed, 57 insertions(+), 58 deletions(-)
---
diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h
index b936dc5..d0de72b 100644
--- a/src/backends/meta-backend-private.h
+++ b/src/backends/meta-backend-private.h
@@ -51,6 +51,7 @@ struct _MetaBackendClass
 
   MetaIdleMonitor * (* create_idle_monitor) (MetaBackend *backend,
                                              int          device_id);
+  MetaMonitorManager * (* create_monitor_manager) (MetaBackend *backend);
 };
 
 #endif /* META_BACKEND_PRIVATE_H */
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 0cf95c7..f8e6738 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -42,14 +42,32 @@ meta_get_backend (void)
   return _backend;
 }
 
-G_DEFINE_ABSTRACT_TYPE (MetaBackend, meta_backend, G_TYPE_OBJECT);
+struct _MetaBackendPrivate
+{
+  MetaMonitorManager *monitor_manager;
+};
+typedef struct _MetaBackendPrivate MetaBackendPrivate;
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaBackend, meta_backend, G_TYPE_OBJECT);
+
+static void
+meta_backend_constructed (GObject *object)
+{
+  MetaBackend *backend = META_BACKEND (object);
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+
+  priv->monitor_manager = META_BACKEND_GET_CLASS (backend)->create_monitor_manager (backend);
+}
 
 static void
 meta_backend_finalize (GObject *object)
 {
   MetaBackend *backend = META_BACKEND (object);
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
   int i;
 
+  g_clear_object (&priv->monitor_manager);
+
   for (i = 0; i <= backend->device_id_max; i++)
     {
       if (backend->device_monitors[i])
@@ -64,6 +82,7 @@ meta_backend_class_init (MetaBackendClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->constructed = meta_backend_constructed;
   object_class->finalize = meta_backend_finalize;
 }
 
@@ -105,6 +124,14 @@ meta_backend_get_idle_monitor (MetaBackend *backend,
   return backend->device_monitors[device_id];
 }
 
+MetaMonitorManager *
+meta_backend_get_monitor_manager (MetaBackend *backend)
+{
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
+
+  return priv->monitor_manager;
+}
+
 static GType
 get_backend_type (void)
 {
diff --git a/src/backends/meta-backend.h b/src/backends/meta-backend.h
index 7047c5e..83aef23 100644
--- a/src/backends/meta-backend.h
+++ b/src/backends/meta-backend.h
@@ -28,6 +28,7 @@
 #include <glib-object.h>
 
 #include <meta/meta-idle-monitor.h>
+#include "meta-monitor-manager.h"
 
 typedef struct _MetaBackend        MetaBackend;
 typedef struct _MetaBackendClass   MetaBackendClass;
@@ -38,6 +39,7 @@ MetaBackend * meta_get_backend (void);
 
 MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend,
                                                  int          device_id);
+MetaMonitorManager * meta_backend_get_monitor_manager (MetaBackend *backend);
 
 void meta_clutter_init (void);
 
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
index 4a53c97..f9cf778 100644
--- a/src/backends/meta-monitor-manager.c
+++ b/src/backends/meta-monitor-manager.c
@@ -36,9 +36,8 @@
 #include "util-private.h"
 #include <meta/errors.h>
 #include "meta-monitor-config.h"
-#include "backends/native/meta-monitor-manager-kms.h"
 #include "backends/x11/meta-monitor-manager-xrandr.h"
-#include "meta-monitor-manager-dummy.h"
+#include "meta-backend.h"
 
 enum {
   CONFIRM_DISPLAY_CHANGE,
@@ -168,46 +167,6 @@ make_logical_config (MetaMonitorManager *manager)
   manager->monitor_infos = (void*)g_array_free (monitor_infos, FALSE);
 }
 
-static GType
-get_default_backend (void)
-{
-#if defined(CLUTTER_WINDOWING_EGL)
-  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_EGL))
-    return META_TYPE_MONITOR_MANAGER_KMS;
-#endif
-
-#if defined(CLUTTER_WINDOWING_X11)
-  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11))
-    {
-      /* If we're a Wayland compositor using the X11 backend,
-       * we're a nested configuration, so return the dummy
-       * monitor setup. */
-      if (meta_is_wayland_compositor ())
-        return META_TYPE_MONITOR_MANAGER_DUMMY;
-      else
-        return META_TYPE_MONITOR_MANAGER_XRANDR;
-    }
-#endif
-
-#if defined(CLUTTER_WINDOWING_WAYLAND)
-  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WAYLAND))
-    {
-      /* Use the dummy implementation on Wayland for now.
-       * In the future, we should support wl_fullscreen_output
-       * which will have CRTC management in the protocol. */
-      return META_TYPE_MONITOR_MANAGER_DUMMY;
-    }
-#endif
-
-  g_assert_not_reached ();
-}
-
-static MetaMonitorManager *
-meta_monitor_manager_new (void)
-{
-  return g_object_new (get_default_backend (), NULL);
-}
-
 static void
 meta_monitor_manager_constructed (GObject *object)
 {
@@ -1167,20 +1126,12 @@ initialize_dbus_interface (MetaMonitorManager *manager)
                                           g_object_unref);
 }
 
-static MetaMonitorManager *global_monitor_manager;
-
-void
-meta_monitor_manager_initialize (void)
-{
-  global_monitor_manager = meta_monitor_manager_new ();
-}
-
 MetaMonitorManager *
 meta_monitor_manager_get (void)
 {
-  g_assert (global_monitor_manager != NULL);
+  MetaBackend *backend = meta_get_backend ();
 
-  return global_monitor_manager;
+  return meta_backend_get_monitor_manager (backend);
 }
 
 MetaMonitorInfo *
diff --git a/src/backends/meta-monitor-manager.h b/src/backends/meta-monitor-manager.h
index 0feb73d..7f7fa8f 100644
--- a/src/backends/meta-monitor-manager.h
+++ b/src/backends/meta-monitor-manager.h
@@ -292,7 +292,6 @@ struct _MetaMonitorManagerClass
 
 GType meta_monitor_manager_get_type (void);
 
-void                meta_monitor_manager_initialize (void);
 MetaMonitorManager *meta_monitor_manager_get  (void);
 
 void                meta_monitor_manager_rebuild_derived   (MetaMonitorManager *manager);
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 01ce26d..d0d3a43 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -28,6 +28,7 @@
 #include "meta-backend-native.h"
 
 #include "meta-idle-monitor-native.h"
+#include "meta-monitor-manager-kms.h"
 #include "meta-weston-launch.h"
 
 struct _MetaBackendNativePrivate
@@ -47,12 +48,19 @@ meta_backend_native_create_idle_monitor (MetaBackend *backend,
                        NULL);
 }
 
+static MetaMonitorManager *
+meta_backend_native_create_monitor_manager (MetaBackend *backend)
+{
+  return g_object_new (META_TYPE_MONITOR_MANAGER_KMS, NULL);
+}
+
 static void
 meta_backend_native_class_init (MetaBackendNativeClass *klass)
 {
   MetaBackendClass *backend_class = META_BACKEND_CLASS (klass);
 
   backend_class->create_idle_monitor = meta_backend_native_create_idle_monitor;
+  backend_class->create_monitor_manager = meta_backend_native_create_monitor_manager;
 }
 
 static void
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index 61de444..c8fa772 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -31,6 +31,8 @@
 
 #include <meta/util.h>
 #include "meta-idle-monitor-xsync.h"
+#include "meta-monitor-manager-xrandr.h"
+#include "backends/meta-monitor-manager-dummy.h"
 
 G_DEFINE_TYPE (MetaBackendX11, meta_backend_x11, META_TYPE_BACKEND);
 
@@ -43,12 +45,25 @@ meta_backend_x11_create_idle_monitor (MetaBackend *backend,
                        NULL);
 }
 
+static MetaMonitorManager *
+meta_backend_x11_create_monitor_manager (MetaBackend *backend)
+{
+  /* If we're a Wayland compositor using the X11 backend,
+   * we're a nested configuration, so return the dummy
+   * monitor setup. */
+  if (meta_is_wayland_compositor ())
+    return g_object_new (META_TYPE_MONITOR_MANAGER_DUMMY, NULL);
+
+  return g_object_new (META_TYPE_MONITOR_MANAGER_XRANDR, NULL);
+}
+
 static void
 meta_backend_x11_class_init (MetaBackendX11Class *klass)
 {
   MetaBackendClass *backend_class = META_BACKEND_CLASS (klass);
 
   backend_class->create_idle_monitor = meta_backend_x11_create_idle_monitor;
+  backend_class->create_monitor_manager = meta_backend_x11_create_monitor_manager;
 }
 
 static void
diff --git a/src/core/screen.c b/src/core/screen.c
index 6cd3f3d..14c8a37 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -679,9 +679,6 @@ meta_screen_new (MetaDisplay *display,
   screen->xroot = xroot;
   screen->rect.x = screen->rect.y = 0;
 
-  if (!meta_is_wayland_compositor ())
-    meta_monitor_manager_initialize ();
-
   manager = meta_monitor_manager_get ();
   g_signal_connect (manager, "monitors-changed",
                     G_CALLBACK (on_monitors_changed), screen);
diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c
index 8f3fc07..98c1660 100644
--- a/src/wayland/meta-wayland.c
+++ b/src/wayland/meta-wayland.c
@@ -630,7 +630,6 @@ meta_wayland_init (void)
 
   meta_clutter_init ();
 
-  meta_monitor_manager_initialize ();
   monitors = meta_monitor_manager_get ();
   g_signal_connect (monitors, "monitors-changed",
                     G_CALLBACK (on_monitors_changed), compositor);


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