[metacity] compositor: move stack handling to MetaCompositor



commit d820fce97a3a34b8c17540b1b51a45ee0e2b9b7f
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Fri Sep 13 22:20:11 2019 +0300

    compositor: move stack handling to MetaCompositor

 src/compositor/meta-compositor-none.c    |  7 ---
 src/compositor/meta-compositor-private.h |  5 +-
 src/compositor/meta-compositor-vulkan.c  |  7 ---
 src/compositor/meta-compositor-xrender.c | 78 ++++++++++++--------------------
 src/compositor/meta-compositor.c         | 57 +++++++++++++++++++++--
 5 files changed, 85 insertions(+), 69 deletions(-)
---
diff --git a/src/compositor/meta-compositor-none.c b/src/compositor/meta-compositor-none.c
index 704d08b5..111e05fc 100644
--- a/src/compositor/meta-compositor-none.c
+++ b/src/compositor/meta-compositor-none.c
@@ -116,12 +116,6 @@ meta_compositor_none_sync_screen_size (MetaCompositor *compositor)
 {
 }
 
-static void
-meta_compositor_none_sync_stack (MetaCompositor *compositor,
-                                 GList          *stack)
-{
-}
-
 static void
 meta_compositor_none_sync_window_geometry (MetaCompositor *compositor,
                                            MetaWindow     *window)
@@ -155,7 +149,6 @@ meta_compositor_none_class_init (MetaCompositorNoneClass *none_class)
   compositor_class->maximize_window = meta_compositor_none_maximize_window;
   compositor_class->unmaximize_window = meta_compositor_none_unmaximize_window;
   compositor_class->sync_screen_size = meta_compositor_none_sync_screen_size;
-  compositor_class->sync_stack = meta_compositor_none_sync_stack;
   compositor_class->sync_window_geometry = meta_compositor_none_sync_window_geometry;
   compositor_class->redraw = meta_compositor_none_redraw;
 }
diff --git a/src/compositor/meta-compositor-private.h b/src/compositor/meta-compositor-private.h
index 0582f057..20a26a67 100644
--- a/src/compositor/meta-compositor-private.h
+++ b/src/compositor/meta-compositor-private.h
@@ -74,9 +74,6 @@ struct _MetaCompositorClass
 
   void              (* sync_screen_size)             (MetaCompositor     *compositor);
 
-  void              (* sync_stack)                   (MetaCompositor     *compositor,
-                                                      GList              *stack);
-
   void              (* sync_window_geometry)         (MetaCompositor     *compositor,
                                                       MetaWindow         *window);
 
@@ -100,6 +97,8 @@ gboolean     meta_compositor_redirect_windows        (MetaCompositor  *composito
 
 MetaDisplay *meta_compositor_get_display             (MetaCompositor  *compositor);
 
+GList       *meta_compositor_get_stack               (MetaCompositor  *compositor);
+
 void         meta_compositor_add_damage              (MetaCompositor  *compositor,
                                                       const gchar     *name,
                                                       XserverRegion    damage);
diff --git a/src/compositor/meta-compositor-vulkan.c b/src/compositor/meta-compositor-vulkan.c
index e737ce84..f4724e66 100644
--- a/src/compositor/meta-compositor-vulkan.c
+++ b/src/compositor/meta-compositor-vulkan.c
@@ -1350,12 +1350,6 @@ meta_compositor_vulkan_sync_screen_size (MetaCompositor *compositor)
 {
 }
 
-static void
-meta_compositor_vulkan_sync_stack (MetaCompositor *compositor,
-                                   GList          *stack)
-{
-}
-
 static void
 meta_compositor_vulkan_sync_window_geometry (MetaCompositor *compositor,
                                              MetaWindow     *window)
@@ -1393,7 +1387,6 @@ meta_compositor_vulkan_class_init (MetaCompositorVulkanClass *vulkan_class)
   compositor_class->maximize_window = meta_compositor_vulkan_maximize_window;
   compositor_class->unmaximize_window = meta_compositor_vulkan_unmaximize_window;
   compositor_class->sync_screen_size = meta_compositor_vulkan_sync_screen_size;
-  compositor_class->sync_stack = meta_compositor_vulkan_sync_stack;
   compositor_class->sync_window_geometry = meta_compositor_vulkan_sync_window_geometry;
   compositor_class->redraw = meta_compositor_vulkan_redraw;
 }
diff --git a/src/compositor/meta-compositor-xrender.c b/src/compositor/meta-compositor-xrender.c
index fde92ef4..25fff3da 100644
--- a/src/compositor/meta-compositor-xrender.c
+++ b/src/compositor/meta-compositor-xrender.c
@@ -151,7 +151,6 @@ struct _MetaCompositorXRender
   Display        *xdisplay;
 
   MetaScreen     *screen;
-  GList          *windows;
   GHashTable     *windows_by_xid;
 
   Window          overlay_window;
@@ -1369,17 +1368,22 @@ get_window_mask (MetaDisplay    *display,
 
 static void
 paint_dock_shadows (MetaCompositorXRender *xrender,
+                    GList                 *surfaces,
                     Picture                root_buffer,
                     XserverRegion          region)
 {
   Display *xdisplay = xrender->xdisplay;
-  GList *window;
+  GList *l;
 
-  for (window = xrender->windows; window; window = window->next)
+  for (l = surfaces; l != NULL; l = l->next)
     {
-      MetaCompWindow *cw = window->data;
+      MetaSurface *surface;
+      MetaCompWindow *cw;
       XserverRegion shadow_clip;
 
+      surface = META_SURFACE (l->data);
+      cw = g_object_get_data (G_OBJECT (surface), "cw");
+
       if (cw->window->type == META_WINDOW_DOCK &&
           cw->needs_shadow && cw->shadow)
         {
@@ -1402,7 +1406,7 @@ paint_dock_shadows (MetaCompositorXRender *xrender,
 
 static void
 paint_windows (MetaCompositorXRender *xrender,
-               GList                 *windows,
+               GList                 *surfaces,
                Picture                root_buffer,
                XserverRegion          region)
 {
@@ -1437,12 +1441,16 @@ paint_windows (MetaCompositorXRender *xrender,
    * each iteration. Only the opaque windows are painted 1st.
    */
   last = NULL;
-  for (index = windows; index; index = index->next)
+  for (index = surfaces; index; index = index->next)
     {
+      MetaSurface *surface;
+
       /* Store the last window we dealt with */
       last = index;
 
-      cw = (MetaCompWindow *) index->data;
+      surface = META_SURFACE (index->data);
+      cw = g_object_get_data (G_OBJECT (surface), "cw");
+
       if (!cw->damaged)
         {
           /* Not damaged */
@@ -1543,7 +1551,7 @@ paint_windows (MetaCompositorXRender *xrender,
   XFixesSetPictureClipRegion (xdisplay, root_buffer, 0, 0, paint_region);
   paint_root (xrender, root_buffer);
 
-  paint_dock_shadows (xrender, root_buffer,
+  paint_dock_shadows (xrender, surfaces, root_buffer,
                       desktop_region == None ? paint_region : desktop_region);
 
   if (desktop_region != None)
@@ -1554,7 +1562,10 @@ paint_windows (MetaCompositorXRender *xrender,
    */
   for (index = last; index; index = index->prev)
     {
-      cw = (MetaCompWindow *) index->data;
+      MetaSurface *surface;
+
+      surface = META_SURFACE (index->data);
+      cw = g_object_get_data (G_OBJECT (surface), "cw");
 
       if (cw->picture)
         {
@@ -1660,6 +1671,7 @@ paint_all (MetaCompositorXRender *xrender,
   MetaDisplay *display = meta_screen_get_display (xrender->screen);
   Display *xdisplay = meta_display_get_xdisplay (display);
   int screen_width, screen_height;
+  GList *stack;
 
   /* Set clipping to the given region */
   XFixesSetPictureClipRegion (xdisplay, xrender->root_picture, 0, 0, region);
@@ -1688,7 +1700,8 @@ paint_all (MetaCompositorXRender *xrender,
   if (xrender->root_buffer == None)
     xrender->root_buffer = create_root_buffer (xrender);
 
-  paint_windows (xrender, xrender->windows, xrender->root_buffer, region);
+  stack = meta_compositor_get_stack (META_COMPOSITOR (xrender));
+  paint_windows (xrender, stack, xrender->root_buffer, region);
 
   XFixesSetPictureClipRegion (xdisplay, xrender->root_buffer, 0, 0, region);
   XRenderComposite (xdisplay, PictOpSrc, xrender->root_buffer, None,
@@ -2237,18 +2250,22 @@ update_shadows (MetaPreference pref,
                 gpointer       data)
 {
   MetaCompositorXRender *xrender;
+  GList *stack;
   GList *index;
 
   if (pref != META_PREF_THEME_TYPE)
     return;
 
   xrender = META_COMPOSITOR_XRENDER (data);
+  stack = meta_compositor_get_stack (META_COMPOSITOR (data));
 
-  for (index = xrender->windows; index; index = index->next)
+  for (index = stack; index; index = index->next)
     {
+      MetaSurface *surface;
       MetaCompWindow *cw;
 
-      cw = (MetaCompWindow *) index->data;
+      surface = META_SURFACE (index->data);
+      cw = g_object_get_data (G_OBJECT (surface), "cw");
 
       if (cw->shadow != None)
         {
@@ -2294,7 +2311,6 @@ meta_compositor_xrender_finalize (GObject *object)
     }
 
   /* Destroy the windows */
-  g_list_free (xrender->windows);
   g_clear_pointer (&xrender->windows_by_xid, g_hash_table_destroy);
 
   if (xrender->root_picture)
@@ -2384,7 +2400,6 @@ meta_compositor_xrender_manage (MetaCompositor  *compositor,
 
   xrender->root_tile = None;
 
-  xrender->windows = NULL;
   xrender->windows_by_xid = g_hash_table_new (g_direct_hash, g_direct_equal);
 
   xrender->clip_changed = TRUE;
@@ -2493,7 +2508,6 @@ meta_compositor_xrender_add_window (MetaCompositor *compositor,
   cw->needs_shadow = window_has_shadow (xrender, cw);
 
   xwindow = meta_window_get_xwindow (window);
-  xrender->windows = g_list_prepend (xrender->windows, cw);
   g_hash_table_insert (xrender->windows_by_xid, (gpointer) xwindow, cw);
 
   if (cw->window->mapped)
@@ -2526,7 +2540,6 @@ meta_compositor_xrender_remove_window (MetaCompositor *compositor,
     }
 
   xwindow = meta_window_get_xwindow (window);
-  xrender->windows = g_list_remove (xrender->windows, (gconstpointer) cw);
   g_hash_table_remove (xrender->windows_by_xid, (gpointer) xwindow);
 }
 
@@ -2853,38 +2866,6 @@ meta_compositor_xrender_sync_screen_size (MetaCompositor *compositor)
   meta_compositor_damage_screen (compositor);
 }
 
-static void
-meta_compositor_xrender_sync_stack (MetaCompositor *compositor,
-                                    GList          *stack)
-{
-  MetaCompositorXRender *xrender;
-  GList *tmp;
-
-  xrender = META_COMPOSITOR_XRENDER (compositor);
-
-  for (tmp = stack; tmp != NULL; tmp = tmp->next)
-    {
-      MetaWindow *window;
-      MetaCompWindow *cw;
-
-      window = (MetaWindow *) tmp->data;
-      cw = find_comp_window_by_window (xrender, window);
-
-      if (cw == NULL)
-        {
-          g_warning ("Failed to find MetaCompWindow for MetaWindow %p", window);
-          continue;
-        }
-
-      xrender->windows = g_list_remove (xrender->windows, cw);
-      xrender->windows = g_list_prepend (xrender->windows, cw);
-    }
-
-  xrender->windows = g_list_reverse (xrender->windows);
-
-  meta_compositor_damage_screen (compositor);
-}
-
 static void
 meta_compositor_xrender_sync_window_geometry (MetaCompositor *compositor,
                                               MetaWindow     *window)
@@ -3098,7 +3079,6 @@ meta_compositor_xrender_class_init (MetaCompositorXRenderClass *xrender_class)
   compositor_class->maximize_window = meta_compositor_xrender_maximize_window;
   compositor_class->unmaximize_window = meta_compositor_xrender_unmaximize_window;
   compositor_class->sync_screen_size = meta_compositor_xrender_sync_screen_size;
-  compositor_class->sync_stack = meta_compositor_xrender_sync_stack;
   compositor_class->sync_window_geometry = meta_compositor_xrender_sync_window_geometry;
   compositor_class->redraw = meta_compositor_xrender_redraw;
 }
diff --git a/src/compositor/meta-compositor.c b/src/compositor/meta-compositor.c
index a3d047f6..6a2079be 100644
--- a/src/compositor/meta-compositor.c
+++ b/src/compositor/meta-compositor.c
@@ -48,6 +48,7 @@ typedef struct
   XserverRegion  all_damage;
 
   GHashTable    *surfaces;
+  GList         *stack;
 
   /* meta_compositor_queue_redraw */
   guint          redraw_id;
@@ -176,6 +177,7 @@ meta_compositor_dispose (GObject *object)
   priv = meta_compositor_get_instance_private (compositor);
 
   g_clear_pointer (&priv->surfaces, g_hash_table_destroy);
+  g_clear_pointer (&priv->stack, g_list_free);
 
   G_OBJECT_CLASS (meta_compositor_parent_class)->dispose (object);
 }
@@ -358,6 +360,7 @@ meta_compositor_add_window (MetaCompositor *compositor,
     return;
 
   g_hash_table_insert (priv->surfaces, window, surface);
+  priv->stack = g_list_prepend (priv->stack, surface);
 }
 
 void
@@ -365,11 +368,18 @@ meta_compositor_remove_window (MetaCompositor *compositor,
                                MetaWindow     *window)
 {
   MetaCompositorPrivate *priv;
+  MetaSurface *surface;
 
   priv = meta_compositor_get_instance_private (compositor);
 
   META_COMPOSITOR_GET_CLASS (compositor)->remove_window (compositor, window);
 
+  surface = g_hash_table_lookup (priv->surfaces, window);
+
+  if (surface == NULL)
+    return;
+
+  priv->stack = g_list_remove (priv->stack, surface);
   g_hash_table_remove (priv->surfaces, window);
 }
 
@@ -501,11 +511,34 @@ void
 meta_compositor_sync_stack (MetaCompositor *compositor,
                             GList          *stack)
 {
-  MetaCompositorClass *compositor_class;
+  MetaCompositorPrivate *priv;
+  GList *l1;
 
-  compositor_class = META_COMPOSITOR_GET_CLASS (compositor);
+  priv = meta_compositor_get_instance_private (compositor);
+
+  if (priv->stack == NULL)
+    return;
+
+  for (l1 = stack; l1 != NULL; l1 = l1->next)
+    {
+      MetaWindow *window;
+      MetaSurface *surface;
+
+      window = META_WINDOW (l1->data);
+      surface = g_hash_table_lookup (priv->surfaces, window);
 
-  compositor_class->sync_stack (compositor, stack);
+      if (surface == NULL)
+        {
+          g_warning ("Failed to find MetaSurface for MetaWindow %p", window);
+          continue;
+        }
+
+      priv->stack = g_list_remove (priv->stack, surface);
+      priv->stack = g_list_prepend (priv->stack, surface);
+    }
+
+  priv->stack = g_list_reverse (priv->stack);
+  meta_compositor_damage_screen (compositor);
 }
 
 void
@@ -707,6 +740,24 @@ meta_compositor_get_display (MetaCompositor *compositor)
   return priv->display;
 }
 
+/**
+ * meta_compositor_get_stack:
+ * @compositor: a #MetaCompositor
+ *
+ * Returns the the list of surfaces in stacking order.
+ *
+ * Returns: (transfer none) (element-type MetaSurface): the list of surfaces
+ */
+GList *
+meta_compositor_get_stack (MetaCompositor *compositor)
+{
+  MetaCompositorPrivate *priv;
+
+  priv = meta_compositor_get_instance_private (compositor);
+
+  return priv->stack;
+}
+
 /**
  * meta_compositor_add_damage:
  * @compositor: a #MetaCompositor


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