[mutter] stage-x11: Move view management to renderer



commit 8a541c08fba3bc59eddde828f080fc9a62d58b36
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue May 12 08:54:56 2020 +0200

    stage-x11: Move view management to renderer
    
    In the native backend, the MetaRenderer manages the view by creating one
    per CRTC, but until now the MetaStageX11 managed the view for the X11
    backend. This caused some issues as it meant meta_renderer_get_views()
    not returning anything, and that the view of the X11 screen not being a
    MetaRendererView, while in the other backends, all views are.
    
    Fix this by moving the view management responsibility to
    MetaRendererX11Cm, and have MetaStageX11 only operate on it via
    meta_renderer_x11_cm_*() API. The MetaRendererX11Cm takes care of making
    sure the view is always added to the list in the renderer, and turning
    X11 screen sizes into "layouts" etc.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1251

 src/backends/x11/cm/meta-renderer-x11-cm.c | 64 ++++++++++++++++++++++++++
 src/backends/x11/cm/meta-renderer-x11-cm.h | 11 +++++
 src/backends/x11/meta-stage-x11.c          | 74 +++++++++++++++---------------
 src/backends/x11/meta-stage-x11.h          |  6 +--
 4 files changed, 114 insertions(+), 41 deletions(-)
---
diff --git a/src/backends/x11/cm/meta-renderer-x11-cm.c b/src/backends/x11/cm/meta-renderer-x11-cm.c
index 1bdc206be..2490b055d 100644
--- a/src/backends/x11/cm/meta-renderer-x11-cm.c
+++ b/src/backends/x11/cm/meta-renderer-x11-cm.c
@@ -24,14 +24,75 @@
 
 #include "backends/x11/cm/meta-renderer-x11-cm.h"
 
+#include "backends/meta-renderer-view.h"
+
 struct _MetaRendererX11Cm
 {
   MetaRendererX11 parent;
+
+  MetaRendererView *screen_view;
 };
 
 G_DEFINE_TYPE (MetaRendererX11Cm, meta_renderer_x11_cm,
                META_TYPE_RENDERER_X11)
 
+void
+meta_renderer_x11_cm_ensure_screen_view (MetaRendererX11Cm *renderer_x11_cm,
+                                         int                width,
+                                         int                height)
+{
+  cairo_rectangle_int_t view_layout;
+
+  if (renderer_x11_cm->screen_view)
+    return;
+
+  view_layout = (cairo_rectangle_int_t) {
+    .width = width,
+    .height = height,
+  };
+  renderer_x11_cm->screen_view = g_object_new (META_TYPE_RENDERER_VIEW,
+                                               "layout", &view_layout,
+                                               NULL);
+  meta_renderer_add_view (META_RENDERER (renderer_x11_cm),
+                          renderer_x11_cm->screen_view);
+}
+
+void
+meta_renderer_x11_cm_resize (MetaRendererX11Cm *renderer_x11_cm,
+                             int                width,
+                             int                height)
+{
+  cairo_rectangle_int_t view_layout;
+
+  view_layout = (cairo_rectangle_int_t) {
+    .width = width,
+    .height = height,
+  };
+
+  g_object_set (G_OBJECT (renderer_x11_cm->screen_view),
+                "layout", &view_layout,
+                NULL);
+}
+
+void
+meta_renderer_x11_cm_set_onscreen (MetaRendererX11Cm *renderer_x11_cm,
+                                   CoglOnscreen      *onscreen)
+{
+  g_object_set (G_OBJECT (renderer_x11_cm->screen_view),
+                "framebuffer", onscreen,
+                NULL);
+}
+
+static void
+meta_renderer_x11_cm_rebuild_views (MetaRenderer *renderer)
+{
+  MetaRendererX11Cm *renderer_x11_cm = META_RENDERER_X11_CM (renderer);
+
+  g_return_if_fail (!meta_renderer_get_views (renderer));
+
+  meta_renderer_add_view (renderer, renderer_x11_cm->screen_view);
+}
+
 static void
 meta_renderer_x11_cm_init (MetaRendererX11Cm *renderer_x11_cm)
 {
@@ -40,4 +101,7 @@ meta_renderer_x11_cm_init (MetaRendererX11Cm *renderer_x11_cm)
 static void
 meta_renderer_x11_cm_class_init (MetaRendererX11CmClass *klass)
 {
+  MetaRendererClass *renderer_class = META_RENDERER_CLASS (klass);
+
+  renderer_class->rebuild_views = meta_renderer_x11_cm_rebuild_views;
 }
diff --git a/src/backends/x11/cm/meta-renderer-x11-cm.h b/src/backends/x11/cm/meta-renderer-x11-cm.h
index e890a3dbb..65c5125bb 100644
--- a/src/backends/x11/cm/meta-renderer-x11-cm.h
+++ b/src/backends/x11/cm/meta-renderer-x11-cm.h
@@ -30,4 +30,15 @@ G_DECLARE_FINAL_TYPE (MetaRendererX11Cm, meta_renderer_x11_cm,
                       META, RENDERER_X11_CM,
                       MetaRendererX11)
 
+void meta_renderer_x11_cm_ensure_screen_view (MetaRendererX11Cm *renderer_x11_cm,
+                                              int                width,
+                                              int                height);
+
+void meta_renderer_x11_cm_resize (MetaRendererX11Cm *renderer_x11_cm,
+                                  int                width,
+                                  int                height);
+
+void meta_renderer_x11_cm_set_onscreen (MetaRendererX11Cm *renderer_x11_cm,
+                                        CoglOnscreen      *onscreen);
+
 #endif /* META_RENDERER_X11_CM_H */
diff --git a/src/backends/x11/meta-stage-x11.c b/src/backends/x11/meta-stage-x11.c
index 048bf9067..77e96f97e 100644
--- a/src/backends/x11/meta-stage-x11.c
+++ b/src/backends/x11/meta-stage-x11.c
@@ -26,6 +26,8 @@
 #include <unistd.h>
 #endif
 
+#include "backends/x11/cm/meta-backend-x11-cm.h"
+#include "backends/x11/cm/meta-renderer-x11-cm.h"
 #include "backends/x11/meta-backend-x11.h"
 #include "backends/x11/meta-seat-x11.h"
 #include "backends/x11/meta-stage-x11.h"
@@ -254,8 +256,6 @@ meta_stage_x11_unrealize (ClutterStageWindow *stage_window)
 
   clutter_stage_window_parent_iface->unrealize (stage_window);
 
-  g_list_free (stage_x11->legacy_views);
-  g_clear_object (&stage_x11->legacy_view);
   g_clear_pointer (&stage_x11->onscreen, cogl_object_unref);
 }
 
@@ -297,10 +297,13 @@ meta_stage_x11_realize (ClutterStageWindow *stage_window)
                                       stage_cogl,
                                       NULL);
 
-  if (stage_x11->legacy_view)
-    g_object_set (G_OBJECT (stage_x11->legacy_view),
-                  "framebuffer", stage_x11->onscreen,
-                  NULL);
+  if (META_IS_BACKEND_X11_CM (stage_x11->backend))
+    {
+      MetaRenderer *renderer = meta_backend_get_renderer (stage_x11->backend);
+      MetaRendererX11Cm *renderer_x11_cm = META_RENDERER_X11_CM (renderer);
+
+      meta_renderer_x11_cm_set_onscreen (renderer_x11_cm, stage_x11->onscreen);
+    }
 
   /* We just created a window of the size of the actor. No need to fix
      the size of the stage, just update it. */
@@ -468,34 +471,13 @@ meta_stage_x11_can_clip_redraws (ClutterStageWindow *stage_window)
   return stage_x11->clipped_redraws_cool_off == 0;
 }
 
-static void
-ensure_legacy_view (ClutterStageWindow *stage_window)
-{
-  MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
-  cairo_rectangle_int_t view_layout;
-  CoglFramebuffer *framebuffer;
-
-  if (stage_x11->legacy_view)
-    return;
-
-  _clutter_stage_window_get_geometry (stage_window, &view_layout);
-  framebuffer = COGL_FRAMEBUFFER (stage_x11->onscreen);
-  stage_x11->legacy_view = g_object_new (CLUTTER_TYPE_STAGE_VIEW_COGL,
-                                         "layout", &view_layout,
-                                         "framebuffer", framebuffer,
-                                         NULL);
-  stage_x11->legacy_views = g_list_append (stage_x11->legacy_views,
-                                           stage_x11->legacy_view);
-}
-
 static GList *
 meta_stage_x11_get_views (ClutterStageWindow *stage_window)
 {
   MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
+  MetaRenderer *renderer = meta_backend_get_renderer (stage_x11->backend);
 
-  ensure_legacy_view (stage_window);
-
-  return stage_x11->legacy_views;
+  return meta_renderer_get_views (renderer);
 }
 
 static int64_t
@@ -527,6 +509,9 @@ meta_stage_x11_class_init (MetaStageX11Class *klass)
 static void
 meta_stage_x11_init (MetaStageX11 *stage)
 {
+  MetaRenderer *renderer;
+  MetaRendererX11Cm *renderer_x11_cm;
+
   stage->xwin = None;
   stage->xwin_width = 640;
   stage->xwin_height = 480;
@@ -534,6 +519,19 @@ meta_stage_x11_init (MetaStageX11 *stage)
   stage->wm_state = STAGE_X11_WITHDRAWN;
 
   stage->title = NULL;
+
+  stage->backend = meta_get_backend ();
+  g_assert (stage->backend);
+
+  if (META_IS_BACKEND_X11_CM (stage->backend))
+    {
+      renderer = meta_backend_get_renderer (stage->backend);
+      renderer_x11_cm = META_RENDERER_X11_CM (renderer);
+
+      meta_renderer_x11_cm_ensure_screen_view (renderer_x11_cm,
+                                               stage->xwin_width,
+                                               stage->xwin_height);
+    }
 }
 
 static void
@@ -719,16 +717,16 @@ meta_stage_x11_translate_event (MetaStageX11 *stage_x11,
                * X11 compositing manager, we need to reset the legacy
                * stage view, now that it has a new size.
                */
-              if (stage_x11->legacy_view)
+              if (META_IS_BACKEND_X11_CM (stage_x11->backend))
                 {
-                  cairo_rectangle_int_t view_layout = {
-                    .width = stage_width,
-                    .height = stage_height
-                  };
-
-                  g_object_set (G_OBJECT (stage_x11->legacy_view),
-                                "layout", &view_layout,
-                                NULL);
+                  MetaBackend *backend = stage_x11->backend;
+                  MetaRenderer *renderer = meta_backend_get_renderer (backend);
+                  MetaRendererX11Cm *renderer_x11_cm =
+                    META_RENDERER_X11_CM (renderer);
+
+                  meta_renderer_x11_cm_resize (renderer_x11_cm,
+                                               stage_width,
+                                               stage_height);
                 }
             }
         }
diff --git a/src/backends/x11/meta-stage-x11.h b/src/backends/x11/meta-stage-x11.h
index 9ca4da551..bcfc536e4 100644
--- a/src/backends/x11/meta-stage-x11.h
+++ b/src/backends/x11/meta-stage-x11.h
@@ -25,6 +25,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 
+#include "backends/meta-backend-private.h"
 #include "clutter/clutter-mutter.h"
 #include "clutter/x11/clutter-x11.h"
 
@@ -51,14 +52,13 @@ struct _MetaStageX11
 {
   ClutterStageCogl parent_instance;
 
+  MetaBackend *backend;
+
   CoglOnscreen *onscreen;
   Window xwin;
   gint xwin_width;
   gint xwin_height; /* FIXME target_width / height */
 
-  ClutterStageView *legacy_view;
-  GList *legacy_views;
-
   CoglFrameClosure *frame_closure;
 
   gchar *title;


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