[mutter] stage-impl: Change the backend pointer to MetaBackend



commit 5eae0c84ed8951266d5ef34c9a8c409e3902e011
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Fri Sep 17 18:24:28 2021 +0200

    stage-impl: Change the backend pointer to MetaBackend
    
    A pointer to the real backend is more useful, so lets use that. This
    affects various places that now need to fetch e.g. the clutter backend
    via the real backend.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2014>

 src/backends/meta-stage-impl-private.h            |   6 +-
 src/backends/meta-stage-impl.c                    |  20 ++++-
 src/backends/native/meta-clutter-backend-native.c |   5 +-
 src/backends/x11/meta-clutter-backend-x11.c       |   6 +-
 src/backends/x11/meta-stage-x11.c                 | 102 ++++++++++++----------
 5 files changed, 84 insertions(+), 55 deletions(-)
---
diff --git a/src/backends/meta-stage-impl-private.h b/src/backends/meta-stage-impl-private.h
index ab3e0d391c..3620de50d7 100644
--- a/src/backends/meta-stage-impl-private.h
+++ b/src/backends/meta-stage-impl-private.h
@@ -28,6 +28,7 @@
 
 #include <cairo.h>
 
+#include "backends/meta-backend-types.h"
 #include "clutter/clutter.h"
 
 G_BEGIN_DECLS
@@ -52,9 +53,6 @@ struct _MetaStageImpl
 
  /* the stage wrapper */
   ClutterStage *wrapper;
-
-  /* back pointer to the backend */
-  ClutterBackend *backend;
 };
 
 struct _MetaStageImplClass
@@ -64,6 +62,8 @@ struct _MetaStageImplClass
 
 GType meta_stage_impl_get_type (void) G_GNUC_CONST;
 
+MetaBackend * meta_stage_impl_get_backend (MetaStageImpl *stage_impl);
+
 void meta_stage_impl_presented (MetaStageImpl    *stage_impl,
                                 CoglFrameEvent    frame_event,
                                 ClutterFrameInfo *frame_info);
diff --git a/src/backends/meta-stage-impl.c b/src/backends/meta-stage-impl.c
index 4ff30360c2..c45aaf852e 100644
--- a/src/backends/meta-stage-impl.c
+++ b/src/backends/meta-stage-impl.c
@@ -36,11 +36,13 @@
 #include "clutter/clutter-mutter.h"
 #include "cogl/cogl.h"
 #include "core/util-private.h"
+#include "meta/meta-backend.h"
 
 #define MAX_STACK_RECTS 256
 
 typedef struct _MetaStageImplPrivate
 {
+  MetaBackend *backend;
   int64_t global_frame_counter;
 } MetaStageImplPrivate;
 
@@ -770,6 +772,7 @@ meta_stage_impl_set_property (GObject      *gobject,
                               GParamSpec   *pspec)
 {
   MetaStageImpl *self = META_STAGE_IMPL (gobject);
+  MetaStageImplPrivate *priv = meta_stage_impl_get_instance_private (self);
 
   switch (prop_id)
     {
@@ -778,7 +781,7 @@ meta_stage_impl_set_property (GObject      *gobject,
       break;
 
     case PROP_BACKEND:
-      self->backend = g_value_get_object (value);
+      priv->backend = g_value_get_object (value);
       break;
 
     default:
@@ -804,9 +807,9 @@ meta_stage_impl_class_init (MetaStageImplClass *klass)
                          G_PARAM_STATIC_STRINGS);
   obj_props[PROP_BACKEND] =
     g_param_spec_object ("backend",
-                         "ClutterBackend",
-                         "ClutterBackend",
-                         CLUTTER_TYPE_BACKEND,
+                         "MetaBackend",
+                         "MetaBackend",
+                         META_TYPE_BACKEND,
                          G_PARAM_WRITABLE |
                          G_PARAM_CONSTRUCT_ONLY |
                          G_PARAM_STATIC_STRINGS);
@@ -817,3 +820,12 @@ static void
 meta_stage_impl_init (MetaStageImpl *stage)
 {
 }
+
+MetaBackend *
+meta_stage_impl_get_backend (MetaStageImpl *stage_impl)
+{
+  MetaStageImplPrivate *priv =
+    meta_stage_impl_get_instance_private (stage_impl);
+
+  return priv->backend;
+}
diff --git a/src/backends/native/meta-clutter-backend-native.c 
b/src/backends/native/meta-clutter-backend-native.c
index 87963e78e6..97affc7b8e 100644
--- a/src/backends/native/meta-clutter-backend-native.c
+++ b/src/backends/native/meta-clutter-backend-native.c
@@ -78,8 +78,11 @@ meta_clutter_backend_native_create_stage (ClutterBackend  *clutter_backend,
                                           ClutterStage    *wrapper,
                                           GError         **error)
 {
+  MetaClutterBackendNative *clutter_backend_native =
+    META_CLUTTER_BACKEND_NATIVE (clutter_backend);
+
   return g_object_new (META_TYPE_STAGE_NATIVE,
-                       "backend", clutter_backend,
+                       "backend", clutter_backend_native->backend,
                        "wrapper", wrapper,
                        NULL);
 }
diff --git a/src/backends/x11/meta-clutter-backend-x11.c b/src/backends/x11/meta-clutter-backend-x11.c
index fafe319413..4a023a1d46 100644
--- a/src/backends/x11/meta-clutter-backend-x11.c
+++ b/src/backends/x11/meta-clutter-backend-x11.c
@@ -311,6 +311,10 @@ meta_clutter_backend_x11_create_stage (ClutterBackend  *clutter_backend,
                                        ClutterStage    *wrapper,
                                        GError         **error)
 {
+  MetaClutterBackendX11 *clutter_backend_x11 =
+    META_CLUTTER_BACKEND_X11 (clutter_backend);
+  MetaClutterBackendX11Private *priv =
+    meta_clutter_backend_x11_get_instance_private (clutter_backend_x11);
   ClutterStageWindow *stage;
   GType stage_type;
 
@@ -320,7 +324,7 @@ meta_clutter_backend_x11_create_stage (ClutterBackend  *clutter_backend,
     stage_type  = META_TYPE_STAGE_X11;
 
   stage = g_object_new (stage_type,
-                       "backend", clutter_backend,
+                       "backend", priv->backend,
                        "wrapper", wrapper,
                        NULL);
   return stage;
diff --git a/src/backends/x11/meta-stage-x11.c b/src/backends/x11/meta-stage-x11.c
index 203ba91063..866fa17791 100644
--- a/src/backends/x11/meta-stage-x11.c
+++ b/src/backends/x11/meta-stage-x11.c
@@ -75,6 +75,15 @@ G_DEFINE_TYPE_WITH_CODE (MetaStageX11,
   ButtonReleaseMask | \
   PointerMotionMask
 
+static MetaClutterBackendX11 *
+clutter_backend_x11_from_stage (MetaStageX11 *stage_x11)
+{
+  MetaBackend *backend =
+    meta_stage_impl_get_backend (META_STAGE_IMPL (stage_x11));
+
+  return META_CLUTTER_BACKEND_X11 (meta_backend_get_clutter_backend (backend));
+}
+
 static void
 meta_stage_x11_fix_window_size (MetaStageX11 *stage_x11,
                                 int           new_width,
@@ -105,15 +114,14 @@ meta_stage_x11_fix_window_size (MetaStageX11 *stage_x11,
 static void
 meta_stage_x11_set_wm_protocols (MetaStageX11 *stage_x11)
 {
-  MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
-  MetaClutterBackendX11 *backend_x11 =
-    META_CLUTTER_BACKEND_X11 (stage_impl->backend);
+  MetaClutterBackendX11 *clutter_backend_x11 =
+    clutter_backend_x11_from_stage (stage_x11);
   Display *xdisplay = meta_clutter_x11_get_default_display ();
   Atom protocols[2];
   int n = 0;
   
-  protocols[n++] = backend_x11->atom_WM_DELETE_WINDOW;
-  protocols[n++] = backend_x11->atom_NET_WM_PING;
+  protocols[n++] = clutter_backend_x11->atom_WM_DELETE_WINDOW;
+  protocols[n++] = clutter_backend_x11->atom_NET_WM_PING;
 
   XSetWMProtocols (xdisplay, stage_x11->xwin, protocols, n);
 }
@@ -179,9 +187,11 @@ static inline void
 set_wm_pid (MetaStageX11 *stage_x11)
 {
   MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
-  MetaClutterBackendX11 *backend_x11 =
-    META_CLUTTER_BACKEND_X11 (stage_impl->backend);
-  Display *xdisplay = meta_clutter_x11_get_default_display ();
+  MetaBackend *backend = meta_stage_impl_get_backend (stage_impl);
+  MetaBackendX11 *backend_x11 = META_BACKEND_X11 (backend);
+  MetaClutterBackendX11 *clutter_backend_x11 =
+    clutter_backend_x11_from_stage (stage_x11);
+  Display *xdisplay = meta_backend_x11_get_xdisplay (backend_x11);
   long pid;
 
   if (stage_x11->xwin == None)
@@ -197,7 +207,7 @@ set_wm_pid (MetaStageX11 *stage_x11)
   pid = getpid ();
   XChangeProperty (xdisplay,
                    stage_x11->xwin,
-                   backend_x11->atom_NET_WM_PID, XA_CARDINAL, 32,
+                   clutter_backend_x11->atom_NET_WM_PID, XA_CARDINAL, 32,
                    PropModeReplace,
                    (guchar *) &pid, 1);
 }
@@ -205,9 +215,8 @@ set_wm_pid (MetaStageX11 *stage_x11)
 static inline void
 set_wm_title (MetaStageX11 *stage_x11)
 {
-  MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
-  MetaClutterBackendX11 *backend_x11 =
-    META_CLUTTER_BACKEND_X11 (stage_impl->backend);
+  MetaClutterBackendX11 *clutter_backend_x11 =
+    clutter_backend_x11_from_stage (stage_x11);
   Display *xdisplay = meta_clutter_x11_get_default_display ();
 
   if (stage_x11->xwin == None)
@@ -217,14 +226,14 @@ set_wm_title (MetaStageX11 *stage_x11)
     {
       XDeleteProperty (xdisplay,
                        stage_x11->xwin, 
-                       backend_x11->atom_NET_WM_NAME);
+                       clutter_backend_x11->atom_NET_WM_NAME);
     }
   else
     {
       XChangeProperty (xdisplay,
                        stage_x11->xwin, 
-                       backend_x11->atom_NET_WM_NAME,
-                       backend_x11->atom_UTF8_STRING,
+                       clutter_backend_x11->atom_NET_WM_NAME,
+                       clutter_backend_x11->atom_UTF8_STRING,
                        8, 
                        PropModeReplace, 
                        (unsigned char *) stage_x11->title,
@@ -285,19 +294,23 @@ meta_stage_x11_realize (ClutterStageWindow *stage_window)
 {
   MetaStageX11 *stage_x11 = META_STAGE_X11 (stage_window);
   MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_window);
-  ClutterBackend *backend = CLUTTER_BACKEND (stage_impl->backend);
-  MetaSeatX11 *seat_x11 = META_SEAT_X11 (clutter_backend_get_default_seat (backend));
-  Display *xdisplay = meta_clutter_x11_get_default_display ();
+  MetaBackend *backend = meta_stage_impl_get_backend (stage_impl);
+  MetaBackendX11 *backend_x11 = META_BACKEND_X11 (backend);
+  ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
+  MetaSeatX11 *seat_x11 =
+    META_SEAT_X11 (meta_backend_get_default_seat (backend));
+  Display *xdisplay = meta_backend_x11_get_xdisplay (backend_x11);
   float width, height;
   GError *error = NULL;
 
   clutter_actor_get_size (CLUTTER_ACTOR (stage_impl->wrapper), &width, &height);
 
-  stage_x11->onscreen = create_onscreen (backend->cogl_context, width, height);
+  stage_x11->onscreen = create_onscreen (clutter_backend->cogl_context,
+                                         width, height);
 
-  if (META_IS_BACKEND_X11_CM (stage_x11->backend))
+  if (META_IS_BACKEND_X11_CM (backend))
     {
-      MetaRenderer *renderer = meta_backend_get_renderer (stage_x11->backend);
+      MetaRenderer *renderer = meta_backend_get_renderer (backend);
       MetaRendererX11Cm *renderer_x11_cm = META_RENDERER_X11_CM (renderer);
 
       meta_renderer_x11_cm_init_screen_view (renderer_x11_cm,
@@ -542,17 +555,19 @@ clutter_stage_window_iface_init (ClutterStageWindowInterface *iface)
 }
 
 static inline void
-set_user_time (MetaClutterBackendX11 *backend_x11,
-               MetaStageX11          *stage_x11,
-               long                   timestamp)
+set_user_time (MetaStageX11 *stage_x11,
+               long          timestamp)
 {
+  MetaClutterBackendX11 *clutter_backend_x11 =
+    clutter_backend_x11_from_stage (stage_x11);
+
   if (timestamp != CLUTTER_CURRENT_TIME)
     {
       Display *xdisplay = meta_clutter_x11_get_default_display ();
 
       XChangeProperty (xdisplay,
                        stage_x11->xwin,
-                       backend_x11->atom_NET_WM_USER_TIME,
+                       clutter_backend_x11->atom_NET_WM_USER_TIME,
                        XA_CARDINAL, 32,
                        PropModeReplace,
                        (unsigned char *) &timestamp, 1);
@@ -560,26 +575,27 @@ set_user_time (MetaClutterBackendX11 *backend_x11,
 }
 
 static gboolean
-handle_wm_protocols_event (MetaClutterBackendX11 *backend_x11,
-                           MetaStageX11          *stage_x11,
-                           XEvent                *xevent)
+handle_wm_protocols_event (MetaStageX11 *stage_x11,
+                           XEvent       *xevent)
 {
+  MetaClutterBackendX11 *clutter_backend_x11 =
+    clutter_backend_x11_from_stage (stage_x11);
   Atom atom = (Atom) xevent->xclient.data.l[0];
 
-  if (atom == backend_x11->atom_WM_DELETE_WINDOW &&
+  if (atom == clutter_backend_x11->atom_WM_DELETE_WINDOW &&
       xevent->xany.window == stage_x11->xwin)
     {
-      set_user_time (backend_x11, stage_x11, xevent->xclient.data.l[1]);
+      set_user_time (stage_x11, xevent->xclient.data.l[1]);
 
       return TRUE;
     }
-  else if (atom == backend_x11->atom_NET_WM_PING &&
+  else if (atom == clutter_backend_x11->atom_NET_WM_PING &&
            xevent->xany.window == stage_x11->xwin)
     {
       XClientMessageEvent xclient = xevent->xclient;
       Display *xdisplay = meta_clutter_x11_get_default_display ();
 
-      xclient.window = backend_x11->xwin_root;
+      xclient.window = clutter_backend_x11->xwin_root;
       XSendEvent (xdisplay, xclient.window,
                   False,
                   SubstructureRedirectMask | SubstructureNotifyMask,
@@ -606,19 +622,19 @@ meta_stage_x11_translate_event (MetaStageX11 *stage_x11,
                                 XEvent       *xevent,
                                 ClutterEvent *event)
 {
+  MetaClutterBackendX11 *clutter_backend_x11 =
+    clutter_backend_x11_from_stage (stage_x11);
+  MetaBackend *backend;
   MetaStageImpl *stage_impl;
   gboolean res = FALSE;
-  MetaClutterBackendX11 *clutter_backend_x11;
   ClutterStage *stage;
-  MetaBackend *backend;
 
   stage_impl = meta_x11_get_stage_window_from_window (xevent->xany.window);
   if (stage_impl == NULL)
     return FALSE;
 
+  backend = meta_stage_impl_get_backend (stage_impl);
   stage = stage_impl->wrapper;
-  backend = stage_x11->backend;
-  clutter_backend_x11 = META_CLUTTER_BACKEND_X11 (stage_impl->backend);
 
   switch (xevent->type)
     {
@@ -644,7 +660,7 @@ meta_stage_x11_translate_event (MetaStageX11 *stage_x11,
           stage_width = xevent->xconfigure.width;
           stage_height = xevent->xconfigure.height;
 
-          if (META_IS_BACKEND_X11_CM (stage_x11->backend))
+          if (META_IS_BACKEND_X11_CM (backend))
             {
               clutter_actor_set_size (CLUTTER_ACTOR (stage),
                                       stage_width,
@@ -715,7 +731,7 @@ 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 (META_IS_BACKEND_X11_CM (stage_x11->backend))
+              if (META_IS_BACKEND_X11_CM (backend))
                 {
                   MetaRenderer *renderer = meta_backend_get_renderer (backend);
                   MetaRendererX11Cm *renderer_x11_cm =
@@ -774,9 +790,7 @@ meta_stage_x11_translate_event (MetaStageX11 *stage_x11,
 
       if (xevent->xclient.message_type == clutter_backend_x11->atom_WM_PROTOCOLS)
         {
-          if (handle_wm_protocols_event (clutter_backend_x11,
-                                         stage_x11,
-                                         xevent))
+          if (handle_wm_protocols_event (stage_x11, xevent))
             {
               g_return_val_if_fail (META_IS_STAGE_X11_NESTED (stage_x11),
                                     FALSE);
@@ -835,9 +849,5 @@ void
 meta_stage_x11_set_user_time (MetaStageX11 *stage_x11,
                               uint32_t      user_time)
 {
-  MetaStageImpl *stage_impl = META_STAGE_IMPL (stage_x11);
-  MetaClutterBackendX11 *backend_x11 =
-    META_CLUTTER_BACKEND_X11 (stage_impl->backend);
-
-  set_user_time (backend_x11, stage_x11, user_time);
+  set_user_time (stage_x11, user_time);
 }


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