[mutter] compositor: Introduce MetaCompositorViewNative



commit 259a9998d80bfad0de253b585e6dd8540f12c687
Author: Dor Askayo <dor askayo gmail com>
Date:   Fri Jul 15 12:06:12 2022 +0300

    compositor: Introduce MetaCompositorViewNative
    
    This class is meant to hold logic specific to the native backend
    in the context of a MetaCompositorView.
    
    Its addition requires making MetaCompositorView inheritable, and an
    addition of a virtual function which allows each compositor to create
    its own MetaCompositorView instance.
    
    In the case of the MetaCompositorNative, a MetaCompositorViewNative
    is created. In all other cases, a MetaCompositorView is created.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2526>

 src/compositor/compositor-private.h          |  3 ++
 src/compositor/compositor.c                  | 11 +++++-
 src/compositor/meta-compositor-native.c      | 13 +++++++
 src/compositor/meta-compositor-server.c      |  9 +++++
 src/compositor/meta-compositor-view-native.c | 55 ++++++++++++++++++++++++++++
 src/compositor/meta-compositor-view-native.h | 37 +++++++++++++++++++
 src/compositor/meta-compositor-view.h        |  4 +-
 src/compositor/meta-compositor-x11.c         |  9 +++++
 src/meson.build                              |  2 +
 9 files changed, 140 insertions(+), 3 deletions(-)
---
diff --git a/src/compositor/compositor-private.h b/src/compositor/compositor-private.h
index 096373fbfb..4262f23cc7 100644
--- a/src/compositor/compositor-private.h
+++ b/src/compositor/compositor-private.h
@@ -35,6 +35,9 @@ struct _MetaCompositorClass
                                                   int64_t         time_us);
   void (* grab_begin) (MetaCompositor *compositor);
   void (* grab_end) (MetaCompositor *compositor);
+
+  MetaCompositorView * (* create_view) (MetaCompositor   *compositor,
+                                        ClutterStageView *stage_view);
 };
 
 gboolean meta_compositor_do_manage (MetaCompositor  *compositor,
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index a32f7affa6..f8ea427c3c 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -417,6 +417,14 @@ meta_compositor_redirect_x11_windows (MetaCompositor *compositor)
     redirect_windows (display->x11_display);
 }
 
+static MetaCompositorView *
+meta_compositor_create_view (MetaCompositor   *compositor,
+                             ClutterStageView *stage_view)
+{
+  return META_COMPOSITOR_GET_CLASS (compositor)->create_view (compositor,
+                                                              stage_view);
+}
+
 gboolean
 meta_compositor_do_manage (MetaCompositor  *compositor,
                            GError         **error)
@@ -1004,7 +1012,8 @@ meta_compositor_ensure_compositor_views (MetaCompositor *compositor)
       if (compositor_view)
         continue;
 
-      compositor_view = meta_compositor_view_new (stage_view);
+      compositor_view = meta_compositor_create_view (compositor,
+                                                     stage_view);
 
       g_object_set_qdata_full (G_OBJECT (stage_view),
                                quark_compositor_view,
diff --git a/src/compositor/meta-compositor-native.c b/src/compositor/meta-compositor-native.c
index c268905014..a156be7da2 100644
--- a/src/compositor/meta-compositor-native.c
+++ b/src/compositor/meta-compositor-native.c
@@ -24,6 +24,7 @@
 
 #include "backends/meta-logical-monitor.h"
 #include "backends/native/meta-crtc-kms.h"
+#include "compositor/meta-compositor-view-native.h"
 #include "compositor/meta-surface-actor-wayland.h"
 
 struct _MetaCompositorNative
@@ -169,6 +170,17 @@ meta_compositor_native_before_paint (MetaCompositor     *compositor,
   parent_class->before_paint (compositor, compositor_view);
 }
 
+static MetaCompositorView *
+meta_compositor_native_create_view (MetaCompositor   *compositor,
+                                    ClutterStageView *stage_view)
+{
+  MetaCompositorViewNative *compositor_view_native;
+
+  compositor_view_native = meta_compositor_view_native_new (stage_view);
+
+  return META_COMPOSITOR_VIEW (compositor_view_native);
+}
+
 MetaCompositorNative *
 meta_compositor_native_new (MetaDisplay *display,
                             MetaBackend *backend)
@@ -203,4 +215,5 @@ meta_compositor_native_class_init (MetaCompositorNativeClass *klass)
   object_class->finalize = meta_compositor_native_finalize;
 
   compositor_class->before_paint = meta_compositor_native_before_paint;
+  compositor_class->create_view = meta_compositor_native_create_view;
 }
diff --git a/src/compositor/meta-compositor-server.c b/src/compositor/meta-compositor-server.c
index f0d469172c..990aa1e770 100644
--- a/src/compositor/meta-compositor-server.c
+++ b/src/compositor/meta-compositor-server.c
@@ -22,6 +22,7 @@
 
 #include "backends/meta-dnd-private.h"
 #include "compositor/meta-compositor-server.h"
+#include "compositor/meta-compositor-view.h"
 #include "core/display-private.h"
 
 G_DEFINE_TYPE (MetaCompositorServer, meta_compositor_server, META_TYPE_COMPOSITOR)
@@ -66,6 +67,13 @@ meta_compositor_server_grab_end (MetaCompositor *compositor)
   meta_display_sync_wayland_input_focus (display);
 }
 
+static MetaCompositorView *
+meta_compositor_server_create_view (MetaCompositor   *compositor,
+                                    ClutterStageView *stage_view)
+{
+  return meta_compositor_view_new (stage_view);
+}
+
 MetaCompositorServer *
 meta_compositor_server_new (MetaDisplay *display,
                             MetaBackend *backend)
@@ -91,4 +99,5 @@ meta_compositor_server_class_init (MetaCompositorServerClass *klass)
    meta_compositor_server_monotonic_to_high_res_xserver_time;
   compositor_class->grab_begin = meta_compositor_server_grab_begin;
   compositor_class->grab_end = meta_compositor_server_grab_end;
+  compositor_class->create_view = meta_compositor_server_create_view;
 }
diff --git a/src/compositor/meta-compositor-view-native.c b/src/compositor/meta-compositor-view-native.c
new file mode 100644
index 0000000000..0841c954a6
--- /dev/null
+++ b/src/compositor/meta-compositor-view-native.c
@@ -0,0 +1,55 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/*
+ * Copyright (C) 2022 Dor Askayo
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ *     Dor Askayo <dor askayo gmail com>
+ */
+
+#include "config.h"
+
+#include "compositor/meta-compositor-view-native.h"
+
+struct _MetaCompositorViewNative
+{
+  MetaCompositorView parent;
+};
+
+G_DEFINE_TYPE (MetaCompositorViewNative, meta_compositor_view_native,
+               META_TYPE_COMPOSITOR_VIEW)
+
+MetaCompositorViewNative *
+meta_compositor_view_native_new (ClutterStageView *stage_view)
+{
+  g_assert (stage_view != NULL);
+
+  return g_object_new (META_TYPE_COMPOSITOR_VIEW_NATIVE,
+                       "stage-view", stage_view,
+                       NULL);
+}
+
+static void
+meta_compositor_view_native_class_init (MetaCompositorViewNativeClass *klass)
+{
+}
+
+static void
+meta_compositor_view_native_init (MetaCompositorViewNative *view_native)
+{
+}
diff --git a/src/compositor/meta-compositor-view-native.h b/src/compositor/meta-compositor-view-native.h
new file mode 100644
index 0000000000..d0971cef34
--- /dev/null
+++ b/src/compositor/meta-compositor-view-native.h
@@ -0,0 +1,37 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+/*
+ * Copyright (C) 2022 Dor Askayo
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ *     Dor Askayo <dor askayo gmail com>
+ */
+
+#ifndef META_COMPOSITOR_VIEW_NATIVE_H
+#define META_COMPOSITOR_VIEW_NATIVE_H
+
+#include "clutter/clutter-mutter.h"
+#include "compositor/meta-compositor-view.h"
+
+#define META_TYPE_COMPOSITOR_VIEW_NATIVE (meta_compositor_view_native_get_type ())
+G_DECLARE_FINAL_TYPE (MetaCompositorViewNative, meta_compositor_view_native,
+                      META, COMPOSITOR_VIEW_NATIVE, MetaCompositorView)
+
+MetaCompositorViewNative *meta_compositor_view_native_new (ClutterStageView *stage_view);
+
+#endif /* META_COMPOSITOR_VIEW_NATIVE_H */
diff --git a/src/compositor/meta-compositor-view.h b/src/compositor/meta-compositor-view.h
index 5588867fd7..7adc41fc15 100644
--- a/src/compositor/meta-compositor-view.h
+++ b/src/compositor/meta-compositor-view.h
@@ -36,8 +36,8 @@ struct _MetaCompositorViewClass
 };
 
 #define META_TYPE_COMPOSITOR_VIEW (meta_compositor_view_get_type ())
-G_DECLARE_FINAL_TYPE (MetaCompositorView, meta_compositor_view,
-                      META, COMPOSITOR_VIEW, GObject)
+G_DECLARE_DERIVABLE_TYPE (MetaCompositorView, meta_compositor_view,
+                          META, COMPOSITOR_VIEW, GObject)
 
 MetaCompositorView *meta_compositor_view_new (ClutterStageView *stage_view);
 
diff --git a/src/compositor/meta-compositor-x11.c b/src/compositor/meta-compositor-x11.c
index 8145efb5dc..e7cb39abe5 100644
--- a/src/compositor/meta-compositor-x11.c
+++ b/src/compositor/meta-compositor-x11.c
@@ -28,6 +28,7 @@
 #include "backends/x11/meta-backend-x11.h"
 #include "backends/x11/meta-clutter-backend-x11.h"
 #include "backends/x11/meta-event-x11.h"
+#include "compositor/meta-compositor-view.h"
 #include "compositor/meta-sync-ring.h"
 #include "compositor/meta-window-actor-x11.h"
 #include "core/display-private.h"
@@ -458,6 +459,13 @@ meta_compositor_x11_grab_end (MetaCompositor *compositor)
   meta_backend_x11_sync_pointer (backend_x11);
 }
 
+static MetaCompositorView *
+meta_compositor_x11_create_view (MetaCompositor   *compositor,
+                                 ClutterStageView *stage_view)
+{
+  return meta_compositor_view_new (stage_view);
+}
+
 Window
 meta_compositor_x11_get_output_xwindow (MetaCompositorX11 *compositor_x11)
 {
@@ -532,4 +540,5 @@ meta_compositor_x11_class_init (MetaCompositorX11Class *klass)
    meta_compositor_x11_monotonic_to_high_res_xserver_time;
   compositor_class->grab_begin = meta_compositor_x11_grab_begin;
   compositor_class->grab_end = meta_compositor_x11_grab_end;
+  compositor_class->create_view = meta_compositor_x11_create_view;
 }
diff --git a/src/meson.build b/src/meson.build
index 504dc20eec..fbe9fb8354 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -793,6 +793,8 @@ if have_native_backend
     'backends/native/meta-xkb-utils.h',
     'compositor/meta-compositor-native.c',
     'compositor/meta-compositor-native.h',
+    'compositor/meta-compositor-view-native.c',
+    'compositor/meta-compositor-view-native.h',
   ]
 endif
 


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