[Cogl] [PATCH 2/2] Add a context member to CoglPath

Neil Roberts neil at linux.intel.com
Mon Apr 16 05:21:15 PDT 2012


cogl_path_new now takes a CoglContext pointer which it keeps a pointer
to instead of relying on the global context.
---
 cogl-pango/cogl-pango-display-list.c |    4 +++-
 cogl/cogl-path-private.h             |    2 ++
 cogl/cogl-path.c                     |   24 +++++++++++-------------
 cogl/cogl-path.h                     |    4 +++-
 tests/conform/test-path.c            |   10 +++++-----
 5 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/cogl-pango/cogl-pango-display-list.c b/cogl-pango/cogl-pango-display-list.c
index 6800c6c..72df3f4 100644
--- a/cogl-pango/cogl-pango-display-list.c
+++ b/cogl-pango/cogl-pango-display-list.c
@@ -440,6 +440,8 @@ _cogl_pango_display_list_render (CoglPangoDisplayList *dl,
             float points[8];
             CoglPath *path;
 
+            _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
             points[0] =  node->d.trapezoid.x_11;
             points[1] =  node->d.trapezoid.y_1;
             points[2] =  node->d.trapezoid.x_12;
@@ -449,7 +451,7 @@ _cogl_pango_display_list_render (CoglPangoDisplayList *dl,
             points[6] =  node->d.trapezoid.x_21;
             points[7] =  node->d.trapezoid.y_1;
 
-            path = cogl_path_new ();
+            path = cogl_path_new (ctx);
             cogl_path_polygon (path, points, 4);
             cogl_path_fill (path);
             cogl_object_unref (path);
diff --git a/cogl/cogl-path-private.h b/cogl/cogl-path-private.h
index fd2e1de..c64aa4b 100644
--- a/cogl/cogl-path-private.h
+++ b/cogl/cogl-path-private.h
@@ -70,6 +70,8 @@ struct _CoglPathData
 {
   unsigned int         ref_count;
 
+  CoglContext         *context;
+
   CoglPathFillRule     fill_rule;
 
   GArray              *path_nodes;
diff --git a/cogl/cogl-path.c b/cogl/cogl-path.c
index 571114b..ec22a2d 100644
--- a/cogl/cogl-path.c
+++ b/cogl/cogl-path.c
@@ -96,6 +96,8 @@ _cogl_path_data_unref (CoglPathData *data)
 
       g_array_free (data->path_nodes, TRUE);
 
+      cogl_object_unref (data->context);
+
       g_slice_free (CoglPathData, data);
     }
 }
@@ -122,6 +124,7 @@ _cogl_path_modify (CoglPath *path)
       path->data->fill_attribute_buffer = NULL;
       path->data->stroke_attribute_buffer = NULL;
       path->data->ref_count = 1;
+      cogl_object_ref (path->data->context);
 
       _cogl_path_data_unref (old_data);
     }
@@ -209,8 +212,6 @@ _cogl_path_stroke_nodes (CoglPath *path)
   int path_num = 0;
   CoglPathNode *node;
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
   source = cogl_get_source ();
 
   if (cogl_pipeline_get_n_layers (source) != 0)
@@ -276,9 +277,8 @@ _cogl_path_fill_nodes_with_clipped_rectangle (CoglPath *path)
 {
   CoglFramebuffer *fb;
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
-  if (!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_STENCIL_BUFFER))
+  if (!(path->data->context->private_feature_flags &
+        COGL_PRIVATE_FEATURE_STENCIL_BUFFER))
     {
       static gboolean seen_warning = FALSE;
 
@@ -868,7 +868,7 @@ cogl_path_rel_curve_to (CoglPath *path,
 }
 
 CoglPath *
-cogl_path_new (void)
+cogl_path_new (CoglContext *context)
 {
   CoglPath *path;
   CoglPathData *data;
@@ -877,6 +877,7 @@ cogl_path_new (void)
   data = path->data = g_slice_new (CoglPathData);
 
   data->ref_count = 1;
+  data->context = cogl_object_ref (context);
   data->fill_rule = COGL_PATH_FILL_RULE_EVEN_ODD;
   data->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode));
   data->last_path = 0;
@@ -1267,8 +1268,6 @@ _cogl_path_build_fill_attribute_buffer (CoglPath *path)
   CoglPathData *data = path->data;
   int i;
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
   /* If we've already got a vbo then we don't need to do anything */
   if (data->fill_attribute_buffer)
     return;
@@ -1354,7 +1353,7 @@ _cogl_path_build_fill_attribute_buffer (CoglPath *path)
   gluDeleteTess (tess.glu_tess);
 
   data->fill_attribute_buffer =
-    cogl_attribute_buffer_new (ctx,
+    cogl_attribute_buffer_new (data->context,
                                sizeof (CoglPathTesselatorVertex) *
                                tess.vertices->len,
                                tess.vertices->data);
@@ -1375,7 +1374,7 @@ _cogl_path_build_fill_attribute_buffer (CoglPath *path)
                         2, /* n_components */
                         COGL_ATTRIBUTE_TYPE_FLOAT);
 
-  data->fill_vbo_indices = cogl_indices_new (ctx,
+  data->fill_vbo_indices = cogl_indices_new (data->context,
                                              tess.indices_type,
                                              tess.indices->data,
                                              tess.indices->len);
@@ -1394,14 +1393,13 @@ _cogl_path_build_stroke_attribute_buffer (CoglPath *path)
   floatVec2 *buffer_p;
   unsigned int i;
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
   /* If we've already got a cached vbo then we don't need to do anything */
   if (data->stroke_attribute_buffer)
     return;
 
   data->stroke_attribute_buffer =
-    cogl_attribute_buffer_new (ctx, data->path_nodes->len * sizeof (floatVec2),
+    cogl_attribute_buffer_new (data->context,
+                               data->path_nodes->len * sizeof (floatVec2),
                                NULL);
 
   buffer = COGL_BUFFER (data->stroke_attribute_buffer);
diff --git a/cogl/cogl-path.h b/cogl/cogl-path.h
index 5ab976f..c0973cf 100644
--- a/cogl/cogl-path.h
+++ b/cogl/cogl-path.h
@@ -29,6 +29,7 @@
 #define __COGL_PATH_H__
 
 #include <cogl/cogl-types.h>
+#include <cogl/cogl-context.h>
 
 G_BEGIN_DECLS
 
@@ -57,6 +58,7 @@ typedef struct _CoglPath CoglPath;
 
 /**
  * cogl_path_new:
+ * @context: A #CoglContext pointer
  *
  * Creates a new, empty path object. The default fill rule is
  * %COGL_PATH_FILL_RULE_EVEN_ODD.
@@ -67,7 +69,7 @@ typedef struct _CoglPath CoglPath;
  * Since: 2.0
  */
 CoglPath *
-cogl_path_new (void);
+cogl_path_new (CoglContext *context);
 
 /**
  * cogl_path_copy:
diff --git a/tests/conform/test-path.c b/tests/conform/test-path.c
index 67f433e..b5f604e 100644
--- a/tests/conform/test-path.c
+++ b/tests/conform/test-path.c
@@ -76,7 +76,7 @@ paint (TestState *state)
 
   /* Create a path filling just a quarter of a block. It will use two
      rectangles so that we have a sub path in the path */
-  path_a = cogl_path_new ();
+  path_a = cogl_path_new (test_ctx);
   cogl_path_rectangle (path_a,
                        BLOCK_SIZE * 3 / 4, BLOCK_SIZE / 2,
                        BLOCK_SIZE, BLOCK_SIZE);
@@ -86,7 +86,7 @@ paint (TestState *state)
   draw_path_at (path_a, 0, 0);
 
   /* Create another path filling the whole block */
-  path_b = cogl_path_new ();
+  path_b = cogl_path_new (test_ctx);
   cogl_path_rectangle (path_b, 0, 0, BLOCK_SIZE, BLOCK_SIZE);
   draw_path_at (path_b, 1, 0);
 
@@ -129,7 +129,7 @@ paint (TestState *state)
 
   /* Draw a self-intersecting path. The part that intersects should be
      inverted */
-  path_a = cogl_path_new ();
+  path_a = cogl_path_new (test_ctx);
   cogl_path_rectangle (path_a, 0, 0, BLOCK_SIZE, BLOCK_SIZE);
   cogl_path_line_to (path_a, 0, BLOCK_SIZE / 2);
   cogl_path_line_to (path_a, BLOCK_SIZE / 2, BLOCK_SIZE / 2);
@@ -140,7 +140,7 @@ paint (TestState *state)
 
   /* Draw two sub paths. Where the paths intersect it should be
      inverted */
-  path_a = cogl_path_new ();
+  path_a = cogl_path_new (test_ctx);
   cogl_path_rectangle (path_a, 0, 0, BLOCK_SIZE, BLOCK_SIZE);
   cogl_path_rectangle (path_a,
                        BLOCK_SIZE / 2, BLOCK_SIZE / 2, BLOCK_SIZE, BLOCK_SIZE);
@@ -148,7 +148,7 @@ paint (TestState *state)
   cogl_object_unref (path_a);
 
   /* Draw a clockwise outer path */
-  path_a = cogl_path_new ();
+  path_a = cogl_path_new (test_ctx);
   cogl_path_move_to (path_a, 0, 0);
   cogl_path_line_to (path_a, BLOCK_SIZE, 0);
   cogl_path_line_to (path_a, BLOCK_SIZE, BLOCK_SIZE);
-- 
1.7.3.16.g9464b



More information about the Cogl mailing list