[cairo] [PATCH 31/39] [OpenVG] keep track of opacities set for groups (solid masks) ourselves instead of uploading a mask

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


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

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

diff --git a/src/cairo-openvg-surface.c b/src/cairo-openvg-surface.c
index a430930..7b323e4 100644
--- a/src/cairo-openvg-surface.c
+++ b/src/cairo-openvg-surface.c
@@ -5,7 +5,7 @@
  *
  * This library is free software; you can redistribute it and/or
  * modify it either under the terms of the GNU Lesser General Public
- * License vesion 2.1 as published by the Free Software Foundation
+ * License version 2.1 as published by the Free Software Foundation
  * (the "LGPL") or, at your option, under the terms of the Mozilla
  * Public License Version 1.1 (the "MPL"). If you do not alter this
  * notice, a recipient may use your version of this file under either
@@ -37,6 +37,8 @@
 #include "cairo-meta-surface-private.h"
 #include <vg/openvg.h>
 
+#define MAX_OPACITIES 32
+
 typedef struct cairo_openvg_surface {
     cairo_surface_t base;
     cairo_content_t content;
@@ -45,6 +47,10 @@ typedef struct cairo_openvg_surface {
 
     VGPaint         source_paint;
     VGImage         source_image;
+
+    double          alpha;
+    double          opacity[MAX_OPACITIES];
+    int             opacity_level;
 } cairo_openvg_surface_t;
 
 static void
@@ -386,7 +392,7 @@ _cairo_openvg_setup_gradient_stops (cairo_openvg_surface_t   *vgsurface,
       stops[i*5 + 1] = pattern->stops[i].color.red;
       stops[i*5 + 2] = pattern->stops[i].color.green;
       stops[i*5 + 3] = pattern->stops[i].color.blue;
-      stops[i*5 + 4] = pattern->stops[i].color.alpha;
+      stops[i*5 + 4] = pattern->stops[i].color.alpha * vgsurface->alpha;
     }
   vgSetParameterfv (vgsurface->source_paint,
                     VG_PAINT_COLOR_RAMP_STOPS, numstops * 5, stops);
@@ -469,7 +475,7 @@ _cairo_openvg_setup_solid_source (cairo_openvg_surface_t *vgsurface,
   VGfloat color[] = {spat->color.red,
                      spat->color.green,
                      spat->color.blue,
-                     spat->color.alpha};
+                     spat->color.alpha * vgsurface->alpha};
   vgSetParameterfv (vgsurface->source_paint, VG_PAINT_COLOR, 4, color);
   return CAIRO_STATUS_SUCCESS;
 }
@@ -785,6 +791,27 @@ _cairo_openvg_surface_mask (void             *asurface,
   cairo_surface_t        *image;
   cairo_t                *cr;
 
+  if (mask->type == CAIRO_PATTERN_TYPE_SOLID)
+    {
+      cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) mask;
+
+      vgsurface->opacity_level++;
+      vgsurface->alpha = vgsurface->opacity[vgsurface->opacity_level] =
+           vgsurface->opacity[vgsurface->opacity_level-1] * solid->color.alpha;
+
+
+      assert (vgsurface->opacity_level < MAX_OPACITIES);
+
+      /* upload source as image */
+      status = _cairo_openvg_surface_paint (asurface, op, source);
+
+      vgsurface->opacity_level--;
+      vgsurface->alpha = vgsurface->opacity[vgsurface->opacity_level];
+      assert (vgsurface->opacity_level>=0);
+      return status;
+    }
+
+  /* should probably be the size of the source */
   image = cairo_image_surface_create (CAIRO_FORMAT_A8, vgsurface->width,
                                                        vgsurface->height);
   cr = cairo_create (image);
@@ -898,6 +925,10 @@ cairo_openvg_surface_create (int width, int height)
     s->width = width;
     s->height = height;
 
+    s->alpha = 1.0;
+    s->opacity_level = 0;
+    s->opacity[s->opacity_level] = 1.0;
+
     vgLoadIdentity();
     /* The default transform of cairo and OpenVG differ, (cairo has the
      * y axis pointing downwards while openvg has it pointing upwards,
-- 
1.6.0.4



More information about the cairo mailing list