[mutter/gbsneto/effects-paint-nodes: 168/172] clutter/effect: Add paint_node vfunc




commit ab5c9f4f900fb94203c03028ad5a65cf7f4280f2
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Jun 27 12:12:03 2020 -0300

    clutter/effect: Add paint_node vfunc
    
    Introduce a new paint_node vfunc that, if implemented, allows
    the effect to add nodes to a transient paint node that is
    immediately painted. This is a transitional step until we
    have fully delegated paint node rendering.
    
    The most basic implementation of a ClutterEffect.paint_node
    vfunc, and also the default implementation, is with an actor
    node, as follows:
    
    ```
    static void
    foo_bar_paint_node (ClutterEffect           *effect,
                        ClutterPaintNode        *node,
                        ClutterPaintContext     *paint_context,
                        ClutterEffectPaintFlags  flags)
    {
      g_autoptr (ClutterPaintNode) actor_node = NULL;
    
      actor_node = clutter_actor_node_new (effect->actor);
      clutter_paint_node_add_child (node, actor_node);
    }
    ```
    
    This example gives the exact same behavior of simply calling
    clutter_actor_continue_paint(). In the future, the paint node
    itself will be a parameter of clutter_actor_continue_paint()
    and we'll be able to simplify it event more.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1340

 clutter/clutter/clutter-effect.c | 30 ++++++++++++++++++++++++++----
 clutter/clutter/clutter-effect.h |  4 ++++
 2 files changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/clutter/clutter/clutter-effect.c b/clutter/clutter/clutter-effect.c
index 9ef269daff..ec28aae997 100644
--- a/clutter/clutter/clutter-effect.c
+++ b/clutter/clutter/clutter-effect.c
@@ -169,6 +169,8 @@
 #include "clutter-effect-private.h"
 #include "clutter-enum-types.h"
 #include "clutter-marshal.h"
+#include "clutter-paint-node-private.h"
+#include "clutter-paint-nodes.h"
 #include "clutter-private.h"
 #include "clutter-actor-private.h"
 
@@ -196,14 +198,29 @@ clutter_effect_real_modify_paint_volume (ClutterEffect      *effect,
   return TRUE;
 }
 
+static void
+clutter_effect_real_paint_node (ClutterEffect           *effect,
+                                ClutterPaintNode        *node,
+                                ClutterPaintContext     *paint_context,
+                                ClutterEffectPaintFlags  flags)
+{
+  ClutterPaintNode *actor_node;
+  ClutterActor *actor;
+
+  actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect));
+
+  actor_node = clutter_actor_node_new (actor);
+  clutter_paint_node_add_child (node, actor_node);
+  clutter_paint_node_unref (actor_node);
+}
+
 static void
 clutter_effect_real_paint (ClutterEffect           *effect,
                            ClutterPaintContext     *paint_context,
                            ClutterEffectPaintFlags  flags)
 {
   ClutterEffectClass *effect_class = CLUTTER_EFFECT_GET_CLASS (effect);
-  ClutterActorMeta *actor_meta = CLUTTER_ACTOR_META (effect);
-  ClutterActor *actor;
+  ClutterPaintNode *node;
   gboolean pre_paint_succeeded;
 
   /* The default implementation provides a compatibility wrapper for
@@ -212,11 +229,15 @@ clutter_effect_real_paint (ClutterEffect           *effect,
 
   pre_paint_succeeded = effect_class->pre_paint (effect, paint_context);
 
-  actor = clutter_actor_meta_get_actor (actor_meta);
-  clutter_actor_continue_paint (actor, paint_context);
+  node = clutter_effect_node_new (effect);
+
+  effect_class->paint_node (effect, node, paint_context, flags);
+  clutter_paint_node_paint (node, paint_context);
 
   if (pre_paint_succeeded)
     effect_class->post_paint (effect, paint_context);
+
+  clutter_paint_node_unref (node);
 }
 
 static void
@@ -256,6 +277,7 @@ clutter_effect_class_init (ClutterEffectClass *klass)
   klass->post_paint = clutter_effect_real_post_paint;
   klass->modify_paint_volume = clutter_effect_real_modify_paint_volume;
   klass->paint = clutter_effect_real_paint;
+  klass->paint_node = clutter_effect_real_paint_node;
   klass->pick = clutter_effect_real_pick;
 }
 
diff --git a/clutter/clutter/clutter-effect.h b/clutter/clutter/clutter-effect.h
index 8e8b57b92f..d15015cf9e 100644
--- a/clutter/clutter/clutter-effect.h
+++ b/clutter/clutter/clutter-effect.h
@@ -87,6 +87,10 @@ struct _ClutterEffectClass
   void     (* paint)               (ClutterEffect           *effect,
                                     ClutterPaintContext     *paint_context,
                                     ClutterEffectPaintFlags  flags);
+  void     (* paint_node)          (ClutterEffect           *effect,
+                                    ClutterPaintNode        *node,
+                                    ClutterPaintContext     *paint_context,
+                                    ClutterEffectPaintFlags  flags);
   void     (* pick)                (ClutterEffect           *effect,
                                     ClutterPickContext      *pick_context);
 


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