[clutter/clutter-1.18] paint-node: Get the framebuffer from the root node



commit a64742f3e4cadf754405be274b4ca0a6750c410e
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Dec 3 12:50:39 2013 +0000

    paint-node: Get the framebuffer from the root node
    
    The PaintNode hierarchy should have the ability to retrieve the
    current active framebuffer by itself, instead of asking Cogl using the
    global state API.
    
    In order to do this, we ask the root node of a PaintNode graph for the
    active framebuffer. In the current, 1.x-compatibility mode we have two
    potential root node types: ClutterRootNode, used by ClutterStage; and
    ClutterDummyNode, used a local root for each actor. The former takes a
    framebuffer as part of its construction; the latter takes the actor that
    acts as the local top-level during the actor's paint sequence, which
    means we can get the active framebuffer from the stage associated to the
    actor.
    
    By keeping track of the active framebuffer on the node themselves we can
    drop the usage of cogl_get_draw_framebuffer() in their implementation.

 clutter/clutter-paint-node-private.h |    4 +++
 clutter/clutter-paint-node.c         |   28 ++++++++++++++++++++++
 clutter/clutter-paint-nodes.c        |   42 +++++++++++++++++++++++++--------
 3 files changed, 64 insertions(+), 10 deletions(-)
---
diff --git a/clutter/clutter-paint-node-private.h b/clutter/clutter-paint-node-private.h
index caa9dfc..2747b35 100644
--- a/clutter/clutter-paint-node-private.h
+++ b/clutter/clutter-paint-node-private.h
@@ -68,6 +68,8 @@ struct _ClutterPaintNodeClass
   void     (* post_draw) (ClutterPaintNode *node);
 
   JsonNode*(* serialize) (ClutterPaintNode *node);
+
+  CoglFramebuffer *(* get_framebuffer) (ClutterPaintNode *node);
 };
 
 #define PAINT_OP_INIT   { PAINT_OP_INVALID }
@@ -137,6 +139,8 @@ G_GNUC_INTERNAL
 ClutterPaintNode *      clutter_paint_node_get_last_child               (ClutterPaintNode      *node);
 G_GNUC_INTERNAL
 ClutterPaintNode *      clutter_paint_node_get_parent                   (ClutterPaintNode      *node);
+G_GNUC_INTERNAL
+CoglFramebuffer *       clutter_paint_node_get_framebuffer              (ClutterPaintNode      *node);
 
 #define CLUTTER_TYPE_LAYER_NODE                 (_clutter_layer_node_get_type ())
 #define CLUTTER_LAYER_NODE(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_LAYER_NODE, 
ClutterLayerNode))
diff --git a/clutter/clutter-paint-node.c b/clutter/clutter-paint-node.c
index 00987e6..705905c 100644
--- a/clutter/clutter-paint-node.c
+++ b/clutter/clutter-paint-node.c
@@ -1123,3 +1123,31 @@ _clutter_paint_node_create (GType gtype)
 
   return (gpointer) g_type_create_instance (gtype);
 }
+
+static ClutterPaintNode *
+clutter_paint_node_get_root (ClutterPaintNode *node)
+{
+  ClutterPaintNode *iter;
+
+  iter = node;
+  while (iter != NULL && iter->parent != NULL)
+    iter = iter->parent;
+
+  return iter;
+}
+
+CoglFramebuffer *
+clutter_paint_node_get_framebuffer (ClutterPaintNode *node)
+{
+  ClutterPaintNode *root = clutter_paint_node_get_root (node);
+  ClutterPaintNodeClass *klass;
+
+  if (root == NULL)
+    return NULL;
+
+  klass = CLUTTER_PAINT_NODE_GET_CLASS (root);
+  if (klass->get_framebuffer != NULL)
+    return klass->get_framebuffer (root);
+
+  return cogl_get_draw_framebuffer ();
+}
diff --git a/clutter/clutter-paint-nodes.c b/clutter/clutter-paint-nodes.c
index 0a4d6cc..acb87e5 100644
--- a/clutter/clutter-paint-nodes.c
+++ b/clutter/clutter-paint-nodes.c
@@ -135,6 +135,14 @@ clutter_root_node_finalize (ClutterPaintNode *node)
   CLUTTER_PAINT_NODE_CLASS (clutter_root_node_parent_class)->finalize (node);
 }
 
+static CoglFramebuffer *
+clutter_root_node_get_framebuffer (ClutterPaintNode *node)
+{
+  ClutterRootNode *rnode = (ClutterRootNode *) node;
+
+  return rnode->framebuffer;
+}
+
 static void
 clutter_root_node_class_init (ClutterRootNodeClass *klass)
 {
@@ -143,6 +151,7 @@ clutter_root_node_class_init (ClutterRootNodeClass *klass)
   node_class->pre_draw = clutter_root_node_pre_draw;
   node_class->post_draw = clutter_root_node_post_draw;
   node_class->finalize = clutter_root_node_finalize;
+  node_class->get_framebuffer = clutter_root_node_get_framebuffer;
 }
 
 static void
@@ -262,6 +271,7 @@ struct _ClutterDummyNode
   ClutterPaintNode parent_instance;
 
   ClutterActor *actor;
+  CoglFramebuffer *framebuffer;
 };
 
 G_DEFINE_TYPE (ClutterDummyNode, clutter_dummy_node, CLUTTER_TYPE_PAINT_NODE)
@@ -296,6 +306,14 @@ clutter_dummy_node_serialize (ClutterPaintNode *node)
   return res;
 }
 
+static CoglFramebuffer *
+clutter_dummy_node_get_framebuffer (ClutterPaintNode *node)
+{
+  ClutterDummyNode *dnode = (ClutterDummyNode *) node;
+
+  return dnode->framebuffer;
+}
+
 static void
 clutter_dummy_node_class_init (ClutterDummyNodeClass *klass)
 {
@@ -303,6 +321,7 @@ clutter_dummy_node_class_init (ClutterDummyNodeClass *klass)
 
   node_class->pre_draw = clutter_dummy_node_pre_draw;
   node_class->serialize = clutter_dummy_node_serialize;
+  node_class->get_framebuffer = clutter_dummy_node_get_framebuffer;
 }
 
 static void
@@ -314,10 +333,13 @@ ClutterPaintNode *
 _clutter_dummy_node_new (ClutterActor *actor)
 {
   ClutterPaintNode *res;
+  ClutterDummyNode *dnode;
 
   res = _clutter_paint_node_create (_clutter_dummy_node_get_type ());
 
-  ((ClutterDummyNode *) res)->actor = actor;
+  dnode = (ClutterDummyNode *) res;
+  dnode->actor = actor;
+  dnode->framebuffer = _clutter_actor_get_active_framebuffer (actor);
 
   return res;
 }
@@ -378,6 +400,7 @@ static void
 clutter_pipeline_node_draw (ClutterPaintNode *node)
 {
   ClutterPipelineNode *pnode = CLUTTER_PIPELINE_NODE (node);
+  CoglFramebuffer *fb;
   guint i;
 
   if (pnode->pipeline == NULL)
@@ -386,6 +409,8 @@ clutter_pipeline_node_draw (ClutterPaintNode *node)
   if (node->operations == NULL)
     return;
 
+  fb = clutter_paint_node_get_framebuffer (node);
+
   for (i = 0; i < node->operations->len; i++)
     {
       const ClutterPaintOperation *op;
@@ -413,12 +438,9 @@ clutter_pipeline_node_draw (ClutterPaintNode *node)
           break;
 
         case PAINT_OP_PRIMITIVE:
-          {
-            CoglFramebuffer *fb = cogl_get_draw_framebuffer ();
-
-            cogl_framebuffer_draw_primitive (fb, pnode->pipeline,
-                                             op->op.primitive);
-          }
+          cogl_framebuffer_draw_primitive (fb,
+                                           pnode->pipeline,
+                                           op->op.primitive);
           break;
         }
     }
@@ -764,7 +786,7 @@ clutter_text_node_draw (ClutterPaintNode *node)
   if (node->operations == NULL)
     return;
 
-  fb = cogl_get_draw_framebuffer ();
+  fb = clutter_paint_node_get_framebuffer (node);
 
   pango_layout_get_pixel_extents (tnode->layout, NULL, &extents);
 
@@ -948,7 +970,7 @@ clutter_clip_node_pre_draw (ClutterPaintNode *node)
   if (node->operations == NULL)
     return FALSE;
 
-  fb = cogl_get_draw_framebuffer ();
+  fb = clutter_paint_node_get_framebuffer (node);
 
   for (i = 0; i < node->operations->len; i++)
     {
@@ -990,7 +1012,7 @@ clutter_clip_node_post_draw (ClutterPaintNode *node)
   if (node->operations == NULL)
     return;
 
-  fb = cogl_get_draw_framebuffer ();
+  fb = clutter_paint_node_get_framebuffer (node);
 
   for (i = 0; i < node->operations->len; i++)
     {


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