[mutter] native/cursor-renderer: Cleanup construction



commit d53b79f8c3c3c554d6b6d0a455d0904f84dcd315
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Jul 7 16:12:07 2017 +0800

    native/cursor-renderer: Cleanup construction
    
    Pass the backend to a new factory function, and keep a pointer to the
    monitor manager, which is accessed elsewhere in the same file instead of
    fetching the singleton. The HW cursor initialization part is also made
    more obvious, without depending on seemingly irrelevant clutter
    features.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785381

 src/backends/native/meta-backend-native.c         |    2 +-
 src/backends/native/meta-cursor-renderer-native.c |  110 +++++++++++++--------
 src/backends/native/meta-cursor-renderer-native.h |    2 +
 3 files changed, 70 insertions(+), 44 deletions(-)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 217f09b..216174b 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -409,7 +409,7 @@ meta_backend_native_create_monitor_manager (MetaBackend *backend,
 static MetaCursorRenderer *
 meta_backend_native_create_cursor_renderer (MetaBackend *backend)
 {
-  return g_object_new (META_TYPE_CURSOR_RENDERER_NATIVE, NULL);
+  return META_CURSOR_RENDERER (meta_cursor_renderer_native_new (backend));
 }
 
 static MetaRenderer *
diff --git a/src/backends/native/meta-cursor-renderer-native.c 
b/src/backends/native/meta-cursor-renderer-native.c
index fe1ec8a..07af07b 100644
--- a/src/backends/native/meta-cursor-renderer-native.c
+++ b/src/backends/native/meta-cursor-renderer-native.c
@@ -72,6 +72,8 @@ struct _MetaCursorRendererNative
 
 struct _MetaCursorRendererNativePrivate
 {
+  MetaMonitorManager *monitor_manager;
+
   gboolean hw_state_invalidated;
   gboolean has_hw_cursor;
   gboolean hw_cursor_broken;
@@ -307,9 +309,7 @@ update_hw_cursor (MetaCursorRendererNative *native,
 {
   MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
   MetaCursorRenderer *renderer = META_CURSOR_RENDERER (native);
-  MetaBackend *backend = meta_get_backend ();
-  MetaMonitorManager *monitor_manager =
-    meta_backend_get_monitor_manager (backend);
+  MetaMonitorManager *monitor_manager = priv->monitor_manager;
   GList *logical_monitors;
   GList *l;
   ClutterRect rect;
@@ -392,9 +392,11 @@ static gboolean
 cursor_over_transformed_logical_monitor (MetaCursorRenderer *renderer,
                                          MetaCursorSprite   *cursor_sprite)
 {
-  MetaBackend *backend = meta_get_backend ();
-  MetaMonitorManager *monitor_manager =
-    meta_backend_get_monitor_manager (backend);
+  MetaCursorRendererNative *cursor_renderer_native =
+    META_CURSOR_RENDERER_NATIVE (renderer);
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
+  MetaMonitorManager *monitor_manager = priv->monitor_manager;
   GList *logical_monitors;
   GList *l;
   ClutterRect cursor_rect;
@@ -438,8 +440,11 @@ static gboolean
 can_draw_cursor_unscaled (MetaCursorRenderer *renderer,
                           MetaCursorSprite   *cursor_sprite)
 {
-  MetaBackend *backend;
-  MetaMonitorManager *monitor_manager;
+  MetaCursorRendererNative *cursor_renderer_native =
+    META_CURSOR_RENDERER_NATIVE (renderer);
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
+  MetaMonitorManager *monitor_manager = priv->monitor_manager;
   ClutterRect cursor_rect;
   GList *logical_monitors;
   GList *l;
@@ -448,8 +453,6 @@ can_draw_cursor_unscaled (MetaCursorRenderer *renderer,
   if (!meta_is_stage_views_scaled ())
    return meta_cursor_sprite_get_texture_scale (cursor_sprite) == 1.0;
 
-  backend = meta_get_backend ();
-  monitor_manager = meta_backend_get_monitor_manager (backend);
   logical_monitors =
     meta_monitor_manager_get_logical_monitors (monitor_manager);
 
@@ -850,45 +853,66 @@ on_monitors_changed (MetaMonitorManager       *monitors,
 }
 
 static void
-meta_cursor_renderer_native_init (MetaCursorRendererNative *native)
+init_hw_cursor_support (MetaCursorRendererNative *cursor_renderer_native,
+                        MetaBackend              *backend)
 {
-  MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
-  MetaMonitorManager *monitors;
+  MetaRendererNative *renderer_native =
+    META_RENDERER_NATIVE (meta_backend_get_renderer (backend));
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
+  MetaMonitorManagerKms *monitor_manager_kms =
+    META_MONITOR_MANAGER_KMS (priv->monitor_manager);
+  uint64_t width, height;
+  struct gbm_device *gbm_device;
 
-  monitors = meta_monitor_manager_get ();
-  g_signal_connect_object (monitors, "monitors-changed",
-                           G_CALLBACK (on_monitors_changed), native, 0);
+  gbm_device = meta_renderer_native_get_gbm (renderer_native);
+  if (!gbm_device)
+    return;
 
-  priv->hw_state_invalidated = TRUE;
+  priv->gbm = gbm_device;
+  priv->drm_fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
 
-#if defined(CLUTTER_WINDOWING_EGL)
-  if (clutter_check_windowing_backend (CLUTTER_WINDOWING_EGL))
+  if (drmGetCap (priv->drm_fd, DRM_CAP_CURSOR_WIDTH, &width) == 0 &&
+      drmGetCap (priv->drm_fd, DRM_CAP_CURSOR_HEIGHT, &height) == 0)
     {
-      MetaBackend *backend = meta_get_backend ();
-      MetaRenderer *renderer = meta_backend_get_renderer (backend);
-      MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
-      MetaMonitorManager *monitor_manager =
-        meta_backend_get_monitor_manager (backend);
-      MetaMonitorManagerKms *monitor_manager_kms =
-        META_MONITOR_MANAGER_KMS (monitor_manager);
-
-      priv->drm_fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
-      priv->gbm = meta_renderer_native_get_gbm (renderer_native);
-
-      uint64_t width, height;
-      if (drmGetCap (priv->drm_fd, DRM_CAP_CURSOR_WIDTH, &width) == 0 &&
-          drmGetCap (priv->drm_fd, DRM_CAP_CURSOR_HEIGHT, &height) == 0)
-        {
-          priv->cursor_width = width;
-          priv->cursor_height = height;
-        }
-      else
-        {
-          priv->cursor_width = 64;
-          priv->cursor_height = 64;
-        }
+      priv->cursor_width = width;
+      priv->cursor_height = height;
     }
-#endif
+  else
+    {
+      priv->cursor_width = 64;
+      priv->cursor_height = 64;
+    }
+}
+
+MetaCursorRendererNative *
+meta_cursor_renderer_native_new (MetaBackend *backend)
+{
+  MetaMonitorManager *monitor_manager =
+    meta_backend_get_monitor_manager (backend);
+  MetaCursorRendererNative *cursor_renderer_native;
+  MetaCursorRendererNativePrivate *priv;
+
+  cursor_renderer_native =
+    g_object_new (META_TYPE_CURSOR_RENDERER_NATIVE, NULL);
+  priv =
+    meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
+
+  g_signal_connect_object (monitor_manager, "monitors-changed",
+                           G_CALLBACK (on_monitors_changed),
+                           cursor_renderer_native, 0);
+
+  priv->monitor_manager = monitor_manager;
+  priv->hw_state_invalidated = TRUE;
+
+  init_hw_cursor_support (cursor_renderer_native, backend);
+
+  return cursor_renderer_native;
+}
+
+static void
+meta_cursor_renderer_native_init (MetaCursorRendererNative *native)
+{
 }
 
 void
diff --git a/src/backends/native/meta-cursor-renderer-native.h 
b/src/backends/native/meta-cursor-renderer-native.h
index 3baf994..09203a5 100644
--- a/src/backends/native/meta-cursor-renderer-native.h
+++ b/src/backends/native/meta-cursor-renderer-native.h
@@ -34,4 +34,6 @@ G_DECLARE_FINAL_TYPE (MetaCursorRendererNative, meta_cursor_renderer_native,
 
 void meta_cursor_renderer_native_force_update (MetaCursorRendererNative *renderer);
 
+MetaCursorRendererNative * meta_cursor_renderer_native_new (MetaBackend *backend);
+
 #endif /* META_CURSOR_RENDERER_NATIVE_H */


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