[mutter] compositor: Use stage signals instead of clutter repaint callbacks



commit 37326e4a32949598cd5840ec6df9f0749433fe71
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Sat May 30 00:02:42 2020 +0200

    compositor: Use stage signals instead of clutter repaint callbacks
    
    The repaint callbacks are not tied to repaint, thus a bit misleading.
    What the functionality in the pre/post-paint callbacks here cares about
    is when actually painting; the non-painting related parts has already
    moved out to a *-update signal.
    
    This also renames the related MetaWindowActorClass vfuncs, to align with
    naming convention of the signals that it listens to.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285

 src/compositor/compositor-private.h        |   4 +-
 src/compositor/compositor.c                | 116 +++++++++++------------------
 src/compositor/meta-compositor-native.c    |   6 +-
 src/compositor/meta-compositor-x11.c       |  12 +--
 src/compositor/meta-window-actor-private.h |   9 ++-
 src/compositor/meta-window-actor-wayland.c |   8 +-
 src/compositor/meta-window-actor-x11.c     |  10 +--
 src/compositor/meta-window-actor.c         |   8 +-
 8 files changed, 73 insertions(+), 100 deletions(-)
---
diff --git a/src/compositor/compositor-private.h b/src/compositor/compositor-private.h
index 1917aa03dd..f993ac300c 100644
--- a/src/compositor/compositor-private.h
+++ b/src/compositor/compositor-private.h
@@ -23,8 +23,8 @@ struct _MetaCompositorClass
   gboolean (* manage) (MetaCompositor  *compositor,
                        GError         **error);
   void (* unmanage) (MetaCompositor *compositor);
-  void (* pre_paint) (MetaCompositor *compositor);
-  void (* post_paint) (MetaCompositor *compositor);
+  void (* before_paint) (MetaCompositor *compositor);
+  void (* after_paint) (MetaCompositor *compositor);
   void (* remove_window) (MetaCompositor *compositor,
                           MetaWindow     *window);
 };
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index 65c1c30348..ca4cdfc0c7 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -105,11 +105,9 @@ typedef struct _MetaCompositorPrivate
   MetaDisplay *display;
   MetaBackend *backend;
 
-  guint pre_paint_func_id;
-  guint post_paint_func_id;
-
   gulong stage_presented_id;
-  gulong stage_after_paint_id;
+  gulong before_paint_handler_id;
+  gulong after_paint_handler_id;
 
   int64_t server_time_query_time;
   int64_t server_time_offset;
@@ -481,19 +479,6 @@ meta_end_modal_for_plugin (MetaCompositor *compositor,
                          grab_window, grab_op);
 }
 
-static void
-after_stage_paint (ClutterStage *stage,
-                   gpointer      data)
-{
-  MetaCompositor *compositor = data;
-  MetaCompositorPrivate *priv =
-    meta_compositor_get_instance_private (compositor);
-  GList *l;
-
-  for (l = priv->windows; l; l = l->next)
-    meta_window_actor_post_paint (l->data);
-}
-
 static void
 redirect_windows (MetaX11Display *x11_display)
 {
@@ -562,18 +547,6 @@ meta_compositor_do_manage (MetaCompositor  *compositor,
                       G_CALLBACK (on_presented),
                       compositor);
 
-  /* We use connect_after() here to accomodate code in GNOME Shell that,
-   * when benchmarking drawing performance, connects to ::after-paint
-   * and calls glFinish(). The timing information from that will be
-   * more accurate if we hold off until that completes before we signal
-   * apps to begin drawing the next frame. If there are no other
-   * connections to ::after-paint, connect() vs. connect_after() doesn't
-   * matter.
-   */
-  priv->stage_after_paint_id =
-    g_signal_connect_after (stage, "after-paint",
-                            G_CALLBACK (after_stage_paint), compositor);
-
   clutter_stage_set_sync_delay (CLUTTER_STAGE (stage), META_SYNC_DELAY);
 
   priv->window_group = meta_window_group_new (display);
@@ -1107,40 +1080,31 @@ on_presented (ClutterStage     *stage,
 }
 
 static void
-meta_compositor_real_pre_paint (MetaCompositor *compositor)
+meta_compositor_real_before_paint (MetaCompositor *compositor)
 {
   MetaCompositorPrivate *priv =
     meta_compositor_get_instance_private (compositor);
   GList *l;
 
   for (l = priv->windows; l; l = l->next)
-    meta_window_actor_pre_paint (l->data);
+    meta_window_actor_before_paint (l->data);
 }
 
 static void
-meta_compositor_pre_paint (MetaCompositor *compositor)
+meta_compositor_before_paint (MetaCompositor *compositor)
 {
   COGL_TRACE_BEGIN_SCOPED (MetaCompositorPrePaint,
-                           "Compositor (pre-paint)");
-  META_COMPOSITOR_GET_CLASS (compositor)->pre_paint (compositor);
-}
-
-static gboolean
-meta_pre_paint_func (gpointer data)
-{
-  MetaCompositor *compositor = data;
-
-  meta_compositor_pre_paint (compositor);
-
-  return TRUE;
+                           "Compositor (before-paint)");
+  META_COMPOSITOR_GET_CLASS (compositor)->before_paint (compositor);
 }
 
 static void
-meta_compositor_real_post_paint (MetaCompositor *compositor)
+meta_compositor_real_after_paint (MetaCompositor *compositor)
 {
   MetaCompositorPrivate *priv =
     meta_compositor_get_instance_private (compositor);
   CoglGraphicsResetStatus status;
+  GList *l;
 
   status = cogl_get_graphics_reset_status (priv->context);
   switch (status)
@@ -1164,24 +1128,35 @@ meta_compositor_real_post_paint (MetaCompositor *compositor)
       meta_restart (NULL);
       break;
     }
+
+  for (l = priv->windows; l; l = l->next)
+    {
+      ClutterActor *actor = l->data;
+
+      meta_window_actor_after_paint (META_WINDOW_ACTOR (actor));
+    }
 }
 
 static void
-meta_compositor_post_paint (MetaCompositor *compositor)
+meta_compositor_after_paint (MetaCompositor *compositor)
 {
   COGL_TRACE_BEGIN_SCOPED (MetaCompositorPostPaint,
-                           "Compositor (post-paint)");
-  META_COMPOSITOR_GET_CLASS (compositor)->post_paint (compositor);
+                           "Compositor (after-paint)");
+  META_COMPOSITOR_GET_CLASS (compositor)->after_paint (compositor);
 }
 
-static gboolean
-meta_post_paint_func (gpointer data)
+static void
+on_before_paint (ClutterStage   *stage,
+                 MetaCompositor *compositor)
 {
-  MetaCompositor *compositor = data;
-
-  meta_compositor_post_paint (compositor);
+  meta_compositor_before_paint (compositor);
+}
 
-  return TRUE;
+static void
+on_after_paint (ClutterStage   *stage,
+                MetaCompositor *compositor)
+{
+  meta_compositor_after_paint (compositor);
 }
 
 static void
@@ -1243,19 +1218,20 @@ meta_compositor_constructed (GObject *object)
     meta_compositor_get_instance_private (compositor);
   ClutterBackend *clutter_backend =
     meta_backend_get_clutter_backend (priv->backend);
+  ClutterActor *stage = meta_backend_get_stage (priv->backend);
 
   priv->context = clutter_backend->cogl_context;
 
-  priv->pre_paint_func_id =
-    clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_PRE_PAINT,
-                                           meta_pre_paint_func,
-                                           compositor,
-                                           NULL);
-  priv->post_paint_func_id =
-    clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_POST_PAINT,
-                                           meta_post_paint_func,
-                                           compositor,
-                                           NULL);
+  priv->before_paint_handler_id =
+    g_signal_connect (stage,
+                      "before-paint",
+                      G_CALLBACK (on_before_paint),
+                      compositor);
+  priv->after_paint_handler_id =
+    g_signal_connect_after (stage,
+                            "after-paint",
+                            G_CALLBACK (on_after_paint),
+                            compositor);
 
   priv->laters = meta_laters_new (compositor);
 
@@ -1272,13 +1248,9 @@ meta_compositor_dispose (GObject *object)
 
   g_clear_pointer (&priv->laters, meta_laters_free);
 
-  g_clear_signal_handler (&priv->stage_after_paint_id, stage);
   g_clear_signal_handler (&priv->stage_presented_id, stage);
-
-  g_clear_handle_id (&priv->pre_paint_func_id,
-                     clutter_threads_remove_repaint_func);
-  g_clear_handle_id (&priv->post_paint_func_id,
-                     clutter_threads_remove_repaint_func);
+  g_clear_signal_handler (&priv->before_paint_handler_id, stage);
+  g_clear_signal_handler (&priv->after_paint_handler_id, stage);
 
   g_clear_signal_handler (&priv->top_window_actor_destroy_id,
                           priv->top_window_actor);
@@ -1302,8 +1274,8 @@ meta_compositor_class_init (MetaCompositorClass *klass)
   object_class->dispose = meta_compositor_dispose;
 
   klass->remove_window = meta_compositor_real_remove_window;
-  klass->pre_paint = meta_compositor_real_pre_paint;
-  klass->post_paint = meta_compositor_real_post_paint;
+  klass->before_paint = meta_compositor_real_before_paint;
+  klass->after_paint = meta_compositor_real_after_paint;
 
   obj_props[PROP_DISPLAY] =
     g_param_spec_object ("display",
diff --git a/src/compositor/meta-compositor-native.c b/src/compositor/meta-compositor-native.c
index cbbca374ba..71e3c01b42 100644
--- a/src/compositor/meta-compositor-native.c
+++ b/src/compositor/meta-compositor-native.c
@@ -116,14 +116,14 @@ maybe_assign_primary_plane (MetaCompositor *compositor)
 }
 
 static void
-meta_compositor_native_pre_paint (MetaCompositor *compositor)
+meta_compositor_native_before_paint (MetaCompositor *compositor)
 {
   MetaCompositorClass *parent_class;
 
   maybe_assign_primary_plane (compositor);
 
   parent_class = META_COMPOSITOR_CLASS (meta_compositor_native_parent_class);
-  parent_class->pre_paint (compositor);
+  parent_class->before_paint (compositor);
 }
 
 MetaCompositorNative *
@@ -146,5 +146,5 @@ meta_compositor_native_class_init (MetaCompositorNativeClass *klass)
 {
   MetaCompositorClass *compositor_class = META_COMPOSITOR_CLASS (klass);
 
-  compositor_class->pre_paint = meta_compositor_native_pre_paint;
+  compositor_class->before_paint = meta_compositor_native_before_paint;
 }
diff --git a/src/compositor/meta-compositor-x11.c b/src/compositor/meta-compositor-x11.c
index 2cec7df1cb..251dee850f 100644
--- a/src/compositor/meta-compositor-x11.c
+++ b/src/compositor/meta-compositor-x11.c
@@ -330,7 +330,7 @@ on_before_update (ClutterStage   *stage,
 }
 
 static void
-meta_compositor_x11_pre_paint (MetaCompositor *compositor)
+meta_compositor_x11_before_paint (MetaCompositor *compositor)
 {
   MetaCompositorX11 *compositor_x11 = META_COMPOSITOR_X11 (compositor);
   MetaCompositorClass *parent_class;
@@ -338,11 +338,11 @@ meta_compositor_x11_pre_paint (MetaCompositor *compositor)
   maybe_unredirect_top_window (compositor_x11);
 
   parent_class = META_COMPOSITOR_CLASS (meta_compositor_x11_parent_class);
-  parent_class->pre_paint (compositor);
+  parent_class->before_paint (compositor);
 }
 
 static void
-meta_compositor_x11_post_paint (MetaCompositor *compositor)
+meta_compositor_x11_after_paint (MetaCompositor *compositor)
 {
   MetaCompositorX11 *compositor_x11 = META_COMPOSITOR_X11 (compositor);
   MetaCompositorClass *parent_class;
@@ -356,7 +356,7 @@ meta_compositor_x11_post_paint (MetaCompositor *compositor)
     }
 
   parent_class = META_COMPOSITOR_CLASS (meta_compositor_x11_parent_class);
-  parent_class->post_paint (compositor);
+  parent_class->after_paint (compositor);
 }
 
 static void
@@ -437,7 +437,7 @@ meta_compositor_x11_class_init (MetaCompositorX11Class *klass)
 
   compositor_class->manage = meta_compositor_x11_manage;
   compositor_class->unmanage = meta_compositor_x11_unmanage;
-  compositor_class->pre_paint = meta_compositor_x11_pre_paint;
-  compositor_class->post_paint = meta_compositor_x11_post_paint;
+  compositor_class->before_paint = meta_compositor_x11_before_paint;
+  compositor_class->after_paint = meta_compositor_x11_after_paint;
   compositor_class->remove_window = meta_compositor_x11_remove_window;
 }
diff --git a/src/compositor/meta-window-actor-private.h b/src/compositor/meta-window-actor-private.h
index 31cc37702d..4d0091f27b 100644
--- a/src/compositor/meta-window-actor-private.h
+++ b/src/compositor/meta-window-actor-private.h
@@ -23,8 +23,9 @@ struct _MetaWindowActorClass
   void (*queue_frame_drawn) (MetaWindowActor *actor,
                              gboolean         skip_sync_delay);
 
-  void (*pre_paint) (MetaWindowActor *actor);
-  void (*post_paint) (MetaWindowActor *actor);
+  void (*before_paint) (MetaWindowActor *actor);
+  void (*after_paint) (MetaWindowActor *actor);
+
   void (*queue_destroy) (MetaWindowActor *actor);
   void (*set_frozen) (MetaWindowActor *actor,
                       gboolean         frozen);
@@ -49,8 +50,8 @@ void meta_window_actor_size_change   (MetaWindowActor *self,
                                       MetaRectangle   *old_frame_rect,
                                       MetaRectangle   *old_buffer_rect);
 
-void meta_window_actor_pre_paint      (MetaWindowActor    *self);
-void meta_window_actor_post_paint     (MetaWindowActor    *self);
+void meta_window_actor_before_paint   (MetaWindowActor    *self);
+void meta_window_actor_after_paint    (MetaWindowActor    *self);
 void meta_window_actor_frame_complete (MetaWindowActor    *self,
                                        ClutterFrameInfo   *frame_info,
                                        gint64              presentation_time);
diff --git a/src/compositor/meta-window-actor-wayland.c b/src/compositor/meta-window-actor-wayland.c
index bd890256c6..c41d85f334 100644
--- a/src/compositor/meta-window-actor-wayland.c
+++ b/src/compositor/meta-window-actor-wayland.c
@@ -119,12 +119,12 @@ meta_window_actor_wayland_queue_frame_drawn (MetaWindowActor *actor,
 }
 
 static void
-meta_window_actor_wayland_pre_paint (MetaWindowActor *actor)
+meta_window_actor_wayland_before_paint (MetaWindowActor *actor)
 {
 }
 
 static void
-meta_window_actor_wayland_post_paint (MetaWindowActor *actor)
+meta_window_actor_wayland_after_paint (MetaWindowActor *actor)
 {
 }
 
@@ -178,8 +178,8 @@ meta_window_actor_wayland_class_init (MetaWindowActorWaylandClass *klass)
   window_actor_class->assign_surface_actor = meta_window_actor_wayland_assign_surface_actor;
   window_actor_class->frame_complete = meta_window_actor_wayland_frame_complete;
   window_actor_class->queue_frame_drawn = meta_window_actor_wayland_queue_frame_drawn;
-  window_actor_class->pre_paint = meta_window_actor_wayland_pre_paint;
-  window_actor_class->post_paint = meta_window_actor_wayland_post_paint;
+  window_actor_class->before_paint = meta_window_actor_wayland_before_paint;
+  window_actor_class->after_paint = meta_window_actor_wayland_after_paint;
   window_actor_class->queue_destroy = meta_window_actor_wayland_queue_destroy;
   window_actor_class->set_frozen = meta_window_actor_wayland_set_frozen;
   window_actor_class->update_regions = meta_window_actor_wayland_update_regions;
diff --git a/src/compositor/meta-window-actor-x11.c b/src/compositor/meta-window-actor-x11.c
index c3067be027..b79e014d19 100644
--- a/src/compositor/meta-window-actor-x11.c
+++ b/src/compositor/meta-window-actor-x11.c
@@ -470,7 +470,7 @@ meta_window_actor_x11_queue_frame_drawn (MetaWindowActor *actor,
       /* A frame was marked by the client without actually doing any
        * damage or any unobscured, or while we had the window frozen
        * (e.g. during an interactive resize.) We need to make sure that the
-       * pre_paint/post_paint functions get called, enabling us to
+       * before_paint/after_paint functions get called, enabling us to
        * send a _NET_WM_FRAME_DRAWN. We do a 1-pixel redraw to get
        * consistent timing with non-empty frames. If the window
        * is completely obscured we fire off the send_frame_messages timeout.
@@ -1226,7 +1226,7 @@ handle_updates (MetaWindowActorX11 *actor_x11)
 }
 
 static void
-meta_window_actor_x11_pre_paint (MetaWindowActor *actor)
+meta_window_actor_x11_before_paint (MetaWindowActor *actor)
 {
   MetaWindowActorX11 *actor_x11 = META_WINDOW_ACTOR_X11 (actor);
 
@@ -1304,7 +1304,7 @@ meta_window_actor_x11_paint (ClutterActor        *actor,
 }
 
 static void
-meta_window_actor_x11_post_paint (MetaWindowActor *actor)
+meta_window_actor_x11_after_paint (MetaWindowActor *actor)
 {
   MetaWindowActorX11 *actor_x11 = META_WINDOW_ACTOR_X11 (actor);
   MetaWindow *window;
@@ -1598,8 +1598,8 @@ meta_window_actor_x11_class_init (MetaWindowActorX11Class *klass)
   window_actor_class->frame_complete = meta_window_actor_x11_frame_complete;
   window_actor_class->assign_surface_actor = meta_window_actor_x11_assign_surface_actor;
   window_actor_class->queue_frame_drawn = meta_window_actor_x11_queue_frame_drawn;
-  window_actor_class->pre_paint = meta_window_actor_x11_pre_paint;
-  window_actor_class->post_paint = meta_window_actor_x11_post_paint;
+  window_actor_class->before_paint = meta_window_actor_x11_before_paint;
+  window_actor_class->after_paint = meta_window_actor_x11_after_paint;
   window_actor_class->queue_destroy = meta_window_actor_x11_queue_destroy;
   window_actor_class->set_frozen = meta_window_actor_x11_set_frozen;
   window_actor_class->update_regions = meta_window_actor_x11_update_regions;
diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c
index b35d90d247..5e4b07ab69 100644
--- a/src/compositor/meta-window-actor.c
+++ b/src/compositor/meta-window-actor.c
@@ -1021,21 +1021,21 @@ meta_window_actor_sync_visibility (MetaWindowActor *self)
 }
 
 void
-meta_window_actor_pre_paint (MetaWindowActor *self)
+meta_window_actor_before_paint (MetaWindowActor *self)
 {
   if (meta_window_actor_is_destroyed (self))
     return;
 
-  META_WINDOW_ACTOR_GET_CLASS (self)->pre_paint (self);
+  META_WINDOW_ACTOR_GET_CLASS (self)->before_paint (self);
 }
 
 void
-meta_window_actor_post_paint (MetaWindowActor *self)
+meta_window_actor_after_paint (MetaWindowActor *self)
 {
   MetaWindowActorPrivate *priv =
     meta_window_actor_get_instance_private (self);
 
-  META_WINDOW_ACTOR_GET_CLASS (self)->post_paint (self);
+  META_WINDOW_ACTOR_GET_CLASS (self)->after_paint (self);
 
   if (meta_window_actor_is_destroyed (self))
     return;


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