From 6f0782e0a41deb34e8eeedd492d33f1efa8b3a90 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 1 Feb 2012 17:47:15 +0000 Subject: [PATCH] actor: Add paint_node virtual function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 3eee5d9..6336dc4 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -388,6 +388,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" @@ -3085,30 +3087,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; + + bg_color = priv->bg_color; + bg_color.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); + } - clutter_actor_box_get_size (&priv->allocation, &width, &height); + if (CLUTTER_ACTOR_GET_CLASS (actor)->paint_node != NULL) + CLUTTER_ACTOR_GET_CLASS (actor)->paint_node (actor, root); - real_alpha = clutter_actor_get_paint_opacity_internal (actor) - * priv->bg_color.alpha - / 255; + if (clutter_paint_node_get_n_children (root) == 0) + return; - cogl_set_source_color4ub (priv->bg_color.red, - priv->bg_color.green, - priv->bg_color.blue, - real_alpha); + _clutter_paint_node_paint (root); +} - cogl_rectangle (0, 0, width, height); - } +static void +clutter_actor_real_paint (ClutterActor *actor) +{ + ClutterActorPrivate *priv = actor->priv; + ClutterActor *iter; for (iter = priv->first_child; iter != NULL; @@ -3401,6 +3415,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 af832d2..81fa794 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]; }; /** -- 2.7.4