[cairo] [PATCH 27/39] [OpenVG] Batch upload of path segments in bundles of 16, removed logic to defines to avoid using vgMask. Now that ShivaVG supports all OpenVG features needed for the basic full coverage of cairo.

tardyp at gmail.com tardyp at gmail.com
Fri Jul 10 10:02:29 PDT 2009


From: Øyvind Kolås <pippin at gimp.org>

---
 src/cairo-openvg-surface.c |  109 ++++++++++++++++++++++++-------------------
 1 files changed, 61 insertions(+), 48 deletions(-)

diff --git a/src/cairo-openvg-surface.c b/src/cairo-openvg-surface.c
index 8cf8f97..66925d1 100644
--- a/src/cairo-openvg-surface.c
+++ b/src/cairo-openvg-surface.c
@@ -39,8 +39,6 @@
 #include "cairo-path-fixed-private.h"
 #include <vg/openvg.h>
 
-#define ENABLE_MASK
-
 typedef struct cairo_openvg_surface {
     cairo_surface_t base;
     cairo_content_t content;
@@ -93,7 +91,6 @@ _cairo_openvg_surface_intersect_clip_path (void               *asurface,
                                            cairo_antialias_t   antialias)
 {
   cairo_status_t status = CAIRO_STATUS_SUCCESS;
-#ifdef ENABLE_MASK
   cairo_openvg_surface_t *vgsurface = asurface;
   cairo_surface_t        *image;
   cairo_t                *cr;
@@ -154,7 +151,6 @@ _cairo_openvg_surface_intersect_clip_path (void               *asurface,
   cairo_destroy (cr);
   
   cairo_surface_destroy (image);
-#endif
   return status;
 }
 
@@ -170,18 +166,22 @@ _cairo_openvg_surface_get_extents (void                  *asurface,
     return CAIRO_STATUS_SUCCESS;
 }
 
+#define MAX_SEG  16  /* max number of knots to upload in a batch */
+
 typedef struct _openvg_stroke {
   VGPath path;
-  cairo_matrix_t *ctm_inverse; /* useful for somthing? */
+  cairo_matrix_t *ctm_inverse;
+
+  VGubyte gseg[MAX_SEG];
+  VGfloat gdata[MAX_SEG*3*2];
+  int dcount;
+  int scount;
 } openvg_stroke_t;
 
 static cairo_status_t
 _cairo_path_to_openvg_path_move_to (void          *closure,
                                     cairo_point_t *point)
 {
-  VGubyte seg[1]={VG_MOVE_TO};
-  VGfloat data[4];
-
   openvg_stroke_t *stroke = closure;
   double x = _cairo_fixed_to_double (point->x);
   double y = _cairo_fixed_to_double (point->y);
@@ -189,10 +189,17 @@ _cairo_path_to_openvg_path_move_to (void          *closure,
   if (stroke->ctm_inverse)
     cairo_matrix_transform_point (stroke->ctm_inverse, &x, &y);
 
-  data[0] = x;
-  data[1] = y;
+  stroke->gseg[stroke->scount++]=VG_MOVE_TO;
+  stroke->gdata[stroke->dcount++] = x;
+  stroke->gdata[stroke->dcount++] = y;
+
+  if (stroke->scount >= MAX_SEG-1)
+    {
+      vgAppendPathData(stroke->path, stroke->scount, stroke->gseg, stroke->gdata);
+      stroke->scount = 0;
+      stroke->dcount = 0;
+    }
 
-  vgAppendPathData(stroke->path, 1, seg, data);
   return CAIRO_STATUS_SUCCESS;
 }
 
@@ -200,9 +207,6 @@ static cairo_status_t
 _cairo_path_to_openvg_path_line_to (void          *closure,
                                     cairo_point_t *point)
 {
-  VGubyte seg[1]={VG_LINE_TO};
-  VGfloat data[4];
-
   openvg_stroke_t *stroke = closure;
   double x = _cairo_fixed_to_double (point->x);
   double y = _cairo_fixed_to_double (point->y);
@@ -210,10 +214,17 @@ _cairo_path_to_openvg_path_line_to (void          *closure,
   if (stroke->ctm_inverse)
     cairo_matrix_transform_point (stroke->ctm_inverse, &x, &y);
 
-  data[0] = x;
-  data[1] = y;
+  stroke->gseg[stroke->scount++]=VG_LINE_TO;
+  stroke->gdata[stroke->dcount++] = x;
+  stroke->gdata[stroke->dcount++] = y;
+
+  if (stroke->scount >= MAX_SEG-1)
+    {
+      vgAppendPathData(stroke->path, stroke->scount, stroke->gseg, stroke->gdata);
+      stroke->scount = 0;
+      stroke->dcount = 0;
+    }
 
-  vgAppendPathData(stroke->path, 1, seg, data);
   return CAIRO_STATUS_SUCCESS;
 }
 
@@ -223,9 +234,6 @@ _cairo_path_to_openvg_path_curve_to (void          *closure,
                                      cairo_point_t *p1,
                                      cairo_point_t *p2)
 {
-  VGubyte seg[1]={VG_CUBIC_TO};
-  VGfloat data[6];
-
   openvg_stroke_t *stroke = closure;
   double x0 = _cairo_fixed_to_double (p0->x);
   double y0 = _cairo_fixed_to_double (p0->y);
@@ -241,27 +249,35 @@ _cairo_path_to_openvg_path_curve_to (void          *closure,
       cairo_matrix_transform_point (stroke->ctm_inverse, &x2, &y2);
     }
 
-  data[0] = x0;
-  data[1] = y0;
-  data[2] = x1;
-  data[3] = y1;
-  data[4] = x2;
-  data[5] = y2;
+  stroke->gseg[stroke->scount++]=VG_CUBIC_TO;
+  stroke->gdata[stroke->dcount++] = x0;
+  stroke->gdata[stroke->dcount++] = y0;
+  stroke->gdata[stroke->dcount++] = x1;
+  stroke->gdata[stroke->dcount++] = y1;
+  stroke->gdata[stroke->dcount++] = x2;
+  stroke->gdata[stroke->dcount++] = y2;
 
-  vgAppendPathData(stroke->path, 1, seg, data);
+  if (stroke->scount >= MAX_SEG-1)
+    {
+      vgAppendPathData(stroke->path, stroke->scount, stroke->gseg, stroke->gdata);
+      stroke->scount = 0;
+      stroke->dcount = 0;
+    }
   return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_status_t
 _cairo_path_to_openvg_path_close_path (void *closure)
 {
-  VGubyte seg[1]={VG_CLOSE_PATH};
-  VGfloat data[4];
-
   openvg_stroke_t *stroke = closure;
+  stroke->gseg[stroke->scount++]=VG_CLOSE_PATH;
 
-  vgAppendPathData(stroke->path, 1, seg, data);
-
+  if (stroke->scount >= MAX_SEG-1)
+    {
+      vgAppendPathData(stroke->path, stroke->scount, stroke->gseg, stroke->gdata);
+      stroke->scount = 0;
+      stroke->dcount = 0;
+    }
   return CAIRO_STATUS_SUCCESS;
 }
 
@@ -270,13 +286,17 @@ static cairo_status_t
 _cairo_openvg_cairo_path_to_openvg_path (cairo_path_fixed_t *path,
                                          openvg_stroke_t    *stroke)
 {
-    return _cairo_path_fixed_interpret (path,
-                                        CAIRO_DIRECTION_FORWARD,
-                                        _cairo_path_to_openvg_path_move_to,
-                                        _cairo_path_to_openvg_path_line_to,
-                                        _cairo_path_to_openvg_path_curve_to,
-                                        _cairo_path_to_openvg_path_close_path,
-                                        stroke);
+    stroke->scount = 0;
+    stroke->dcount = 0;
+    _cairo_path_fixed_interpret (path,
+                                 CAIRO_DIRECTION_FORWARD,
+                                 _cairo_path_to_openvg_path_move_to,
+                                 _cairo_path_to_openvg_path_line_to,
+                                 _cairo_path_to_openvg_path_curve_to,
+                                 _cairo_path_to_openvg_path_close_path,
+                                 stroke);
+    vgAppendPathData(stroke->path, stroke->scount, stroke->gseg, stroke->gdata);
+    return CAIRO_STATUS_SUCCESS;
 }
 
 
@@ -489,6 +509,8 @@ _cairo_openvg_setup_surface_source (cairo_openvg_surface_t  *vgsurface,
     image->width, image->height, VG_IMAGE_QUALITY_FASTER);
   /* NONALIASED, FASTER, BETTER */
 
+  printf ("image: %ix%i\n", image->width, image->height);
+
   data = malloc (image->width * image->height * 4);
 
   /* This extra allocation and copy/conversion should not be neccesary if the
@@ -500,17 +522,10 @@ _cairo_openvg_setup_surface_source (cairo_openvg_surface_t  *vgsurface,
     int i;
     for (i=0; i<image->width * image->height; i++)
       {
-#if 1 /* ShivaVG (I wonder which one is correct) */
-        data[4*i+0] = image->data[4*i+2];
-        data[4*i+1] = image->data[4*i+1];
-        data[4*i+2] = image->data[4*i+0];
-        data[4*i+3] = image->data[4*i+3];
-#else /* Amanith */
         data[4*i+0] = image->data[4*i+3];
         data[4*i+1] = image->data[4*i+0];
         data[4*i+2] = image->data[4*i+1];
         data[4*i+3] = image->data[4*i+2];
-#endif
       }
   }
 
@@ -763,7 +778,6 @@ _cairo_openvg_surface_mask (void             *asurface,
                             cairo_pattern_t  *mask)
 {
   cairo_status_t status = CAIRO_STATUS_SUCCESS;
-#ifdef ENABLE_MASK
   cairo_openvg_surface_t *vgsurface = asurface;
   cairo_surface_t        *image;
   cairo_t                *cr;
@@ -794,7 +808,6 @@ _cairo_openvg_surface_mask (void             *asurface,
 
   cairo_destroy (cr);
   cairo_surface_destroy (image);
-#endif
 
   /* upload source as image */
   status = _cairo_openvg_surface_paint (asurface, op, source);
-- 
1.6.0.4



More information about the cairo mailing list