[cairo] [PATCH 16/39] [OpenVG] Made linear, radial and image source patterns use a common setup for the transform of the pattern.

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


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

---
 src/cairo-openvg-surface.c |   87 +++++++++++++++++++-------------------------
 1 files changed, 37 insertions(+), 50 deletions(-)

diff --git a/src/cairo-openvg-surface.c b/src/cairo-openvg-surface.c
index a9e419d..162425d 100644
--- a/src/cairo-openvg-surface.c
+++ b/src/cairo-openvg-surface.c
@@ -49,6 +49,11 @@ typedef struct cairo_openvg_surface {
     VGImage         source_image;
 } cairo_openvg_surface_t;
 
+static void
+_cairo_openvg_cairo_matrix_to_openvg (const cairo_matrix_t *src,
+                                      VGfloat              *dst);
+
+
 static cairo_surface_t *
 _cairo_openvg_surface_create_similar (void *asurface,
                                       cairo_content_t content,
@@ -314,35 +319,34 @@ _cairo_openvg_setup_gradient_stops (cairo_openvg_surface_t   *vgsurface,
   return CAIRO_STATUS_SUCCESS;
 }
 
+static void setup_paint_matrix (cairo_pattern_t *pat)
+{
+    cairo_matrix_t         mat;
+    cairo_status_t         status;
+    VGfloat vmat[9];
+    cairo_pattern_get_matrix (pat, &mat);
+    status = cairo_matrix_invert (&mat);
+    assert (status == 0);
+
+    _cairo_openvg_cairo_matrix_to_openvg (&mat, vmat);
+    vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
+    vgLoadMatrix(vmat);
+    vgSeti(VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER);
+    vgLoadMatrix(vmat);
+
+    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
+}
+
 static cairo_status_t
 _cairo_openvg_setup_linear_source (cairo_openvg_surface_t *vgsurface,
                                    cairo_linear_pattern_t *lpat)
 {
-  cairo_status_t status;
-  cairo_pattern_t *abspat = (cairo_pattern_t *) lpat;
-  cairo_matrix_t   mat;
   VGfloat linear[4];
-  double x0, y0;
-  double x1, y1;
-
-  cairo_pattern_get_matrix (abspat, &mat);
-
-  status = cairo_matrix_invert (&mat);
-  if (status)
-   return status;
-
-  x0 = _cairo_fixed_to_double (lpat->p1.x);
-  y0 = _cairo_fixed_to_double (lpat->p1.y);
-  x1 = _cairo_fixed_to_double (lpat->p2.x);
-  y1 = _cairo_fixed_to_double (lpat->p2.y);
-
-  cairo_matrix_transform_point (&mat, &x0, &y0);
-  cairo_matrix_transform_point (&mat, &x1, &y1);
 
-  linear[0] = x0;
-  linear[1] = y0;
-  linear[2] = x1;
-  linear[3] = y1;
+  linear[0] = _cairo_fixed_to_double (lpat->p1.x);
+  linear[1] = _cairo_fixed_to_double (lpat->p1.y);
+  linear[2] = _cairo_fixed_to_double (lpat->p2.x);
+  linear[3] = _cairo_fixed_to_double (lpat->p2.y);
 
   vgSetParameteri (vgsurface->source_paint,
                    VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
@@ -350,6 +354,7 @@ _cairo_openvg_setup_linear_source (cairo_openvg_surface_t *vgsurface,
                    VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
   vgSetParameterfv (vgsurface->source_paint, VG_PAINT_LINEAR_GRADIENT, 4, linear);
 
+  setup_paint_matrix ((cairo_pattern_t*) lpat);
   return _cairo_openvg_setup_gradient_stops (vgsurface,
                                (cairo_gradient_pattern_t *) &lpat->base);
 
@@ -359,33 +364,12 @@ static cairo_status_t
 _cairo_openvg_setup_radial_source (cairo_openvg_surface_t *vgsurface,
                                    cairo_radial_pattern_t *rpat)
 {
-  cairo_pattern_t *abspat = (cairo_pattern_t *) rpat;
-  cairo_matrix_t   mat;
   VGfloat radial[5];
-  double cx, cy;
-  double fx, fy;
 
-
-  cairo_pattern_get_matrix (abspat, &mat);
-
-  if (cairo_matrix_invert (&mat) == CAIRO_STATUS_INVALID_MATRIX)
-    {
-      return CAIRO_STATUS_INVALID_MATRIX;
-    }
-  cx = _cairo_fixed_to_double (rpat->c1.x);
-  cy = _cairo_fixed_to_double (rpat->c1.y);
-  fx = _cairo_fixed_to_double (rpat->c2.x);
-  fy = _cairo_fixed_to_double (rpat->c2.y);
-
-  cairo_matrix_transform_point (&mat, &cx, &cy);
-  cairo_matrix_transform_point (&mat, &fx, &fy);
-
-  /* FIXME: if rpat->r1 != 0.0 return unsupported */
-
-  radial[0] = cx;
-  radial[1] = cy;
-  radial[2] = fx;
-  radial[3] = fy;
+  radial[0] = _cairo_fixed_to_double (rpat->c1.x);
+  radial[1] = _cairo_fixed_to_double (rpat->c1.y);
+  radial[2] = _cairo_fixed_to_double (rpat->c2.x);
+  radial[3] = _cairo_fixed_to_double (rpat->c2.y);
   radial[4] = _cairo_fixed_to_double (rpat->r2);
 
   vgSetParameteri (vgsurface->source_paint,
@@ -395,6 +379,8 @@ _cairo_openvg_setup_radial_source (cairo_openvg_surface_t *vgsurface,
   vgSetParameterfv (vgsurface->source_paint,
                     VG_PAINT_RADIAL_GRADIENT, 5, radial);
 
+  setup_paint_matrix ((cairo_pattern_t*) rpat);
+
   return _cairo_openvg_setup_gradient_stops (vgsurface,
                                             (cairo_gradient_pattern_t *) rpat);
 }
@@ -426,6 +412,7 @@ _cairo_openvg_setup_surface_source (cairo_openvg_surface_t  *vgsurface,
 
   if (!_cairo_surface_is_image (spat->surface))
     {
+      vgsurface->source_paint = 0; /* XXX */
       return CAIRO_INT_STATUS_UNSUPPORTED;
     }
 
@@ -493,10 +480,10 @@ _cairo_openvg_setup_surface_source (cairo_openvg_surface_t  *vgsurface,
       default:
         break;
     }
-
-
   vgPaintPattern(vgsurface->source_paint, vgsurface->source_image);
 
+  setup_paint_matrix ((cairo_pattern_t*) spat);
+
   return status;
 }
 
-- 
1.6.0.4



More information about the cairo mailing list