[clutter/wip/apocalypses/apocalypse-3: 2/35] actor: Add paint_node virtual function



commit 830b1a1d8733ac25467561256d3ca7feabd6bc87
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Wed Feb 1 17:47:15 2012 +0000

    actor: Add paint_node virtual function
    
    The ::paint-node virtual inside ClutterActor is what we want people to
    use when painting their actors.
    
    Right now, it's a new code path, that gets called while painting; the
    paint_node() implementation should only paint the actor itself, and not
    its children â they will get their own paint_node() called when needed.
    
    Internally, ClutterActor will automatically create a dummy PaintNode and
    paint the background color; then control will be handed out to the
    implementation on the class. This is required to maintain compatibility
    with the old ::paint signal emission.
    
    Once we are able to get rid of the paint (and pick) sequences, we'll
    switch to a fully retained render tree.

 clutter/clutter-actor.c |   69 ++++++++++++++++++++++++++++++++++++----------
 clutter/clutter-actor.h |    7 +++-
 2 files changed, 59 insertions(+), 17 deletions(-)
---
diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c
index ecf94e6..fd252d9 100644
--- a/clutter/clutter-actor.c
+++ b/clutter/clutter-actor.c
@@ -342,6 +342,8 @@
 #include "clutter-interval.h"
 #include "clutter-main.h"
 #include "clutter-marshal.h"
+#include "clutter-paint-nodes.h"
+#include "clutter-paint-node-private.h"
 #include "clutter-paint-volume-private.h"
 #include "clutter-private.h"
 #include "clutter-profile.h"
@@ -3035,30 +3037,42 @@ add_or_remove_flatten_effect (ClutterActor *self)
 }
 
 static void
-clutter_actor_real_paint (ClutterActor *actor)
+clutter_actor_paint_node (ClutterActor     *actor,
+                          ClutterPaintNode *root)
 {
   ClutterActorPrivate *priv = actor->priv;
-  ClutterActor *iter;
 
-  /* paint the background color, if set */
   if (priv->bg_color_set)
     {
-      float width, height;
-      guint8 real_alpha;
+      ClutterPaintNode *node;
+      ClutterColor bg_color;
 
-      clutter_actor_box_get_size (&priv->allocation, &width, &height);
+      bg_color = priv->bg_color;
+      bg_color.alpha = clutter_actor_get_paint_opacity_internal (actor)
+                     * priv->bg_color.alpha
+                     / 255;
 
-      real_alpha = clutter_actor_get_paint_opacity_internal (actor)
-                 * priv->bg_color.alpha
-                 / 255;
+      node = clutter_color_node_new (&bg_color);
+      clutter_paint_node_set_name (node, "backgroundColor");
+      clutter_paint_node_add_rectangle (node, &priv->allocation);
+      clutter_paint_node_add_child (root, node);
+      clutter_paint_node_unref (node);
+    }
 
-      cogl_set_source_color4ub (priv->bg_color.red,
-                                priv->bg_color.green,
-                                priv->bg_color.blue,
-                                real_alpha);
+  if (CLUTTER_ACTOR_GET_CLASS (actor)->paint_node != NULL)
+    CLUTTER_ACTOR_GET_CLASS (actor)->paint_node (actor, root);
 
-      cogl_rectangle (0, 0, width, height);
-    }
+  if (clutter_paint_node_get_n_children (root) == 0)
+    return;
+
+  _clutter_paint_node_paint (root);
+}
+
+static void
+clutter_actor_real_paint (ClutterActor *actor)
+{
+  ClutterActorPrivate *priv = actor->priv;
+  ClutterActor *iter;
 
   for (iter = priv->first_child;
        iter != NULL;
@@ -3351,6 +3365,31 @@ clutter_actor_continue_paint (ClutterActor *self)
     {
       if (_clutter_context_get_pick_mode () == CLUTTER_PICK_NONE)
         {
+          ClutterPaintNode *dummy;
+
+          /* XXX - this will go away in 2.0, when we can get rid of this
+           * stuff and switch to a pure retained render tree of PaintNodes
+           * for the entire frame, starting from the Stage.
+           */
+          dummy = _clutter_dummy_node_new ();
+          clutter_paint_node_set_name (dummy, "Root");
+          clutter_actor_paint_node (self, dummy);
+
+          if (clutter_paint_node_get_n_children (dummy) != 0)
+            {
+#ifdef CLUTTER_ENABLE_DEBUG
+              if (CLUTTER_HAS_DEBUG (PAINT))
+                {
+                  /* dump the tree only if we have one */
+                  _clutter_paint_node_dump_tree (dummy);
+                }
+#endif /* CLUTTER_ENABLE_DEBUG */
+
+              _clutter_paint_node_paint (dummy);
+            }
+
+          clutter_paint_node_unref (dummy);
+
           g_signal_emit (self, actor_signals[PAINT], 0);
         }
       else
diff --git a/clutter/clutter-actor.h b/clutter/clutter-actor.h
index de932d5..e5631bc 100644
--- a/clutter/clutter-actor.h
+++ b/clutter/clutter-actor.h
@@ -253,14 +253,17 @@ struct _ClutterActorClass
   /* accessibility support */
   AtkObject * (* get_accessible)    (ClutterActor         *self);
 
-  gboolean    (* get_paint_volume)  (ClutterActor         *actor,
+  gboolean (* get_paint_volume)     (ClutterActor         *actor,
                                      ClutterPaintVolume   *volume);
 
   gboolean (* has_overlaps)         (ClutterActor         *self);
 
+  void     (* paint_node)           (ClutterActor         *self,
+                                     ClutterPaintNode     *root);
+
   /*< private >*/
   /* padding for future expansion */
-  gpointer _padding_dummy[28];
+  gpointer _padding_dummy[27];
 };
 
 /**



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