[cairo] [PATCH] Speeding up clipping: Redux

Jeff Muizelaar jeff at infidigm.net
Wed Nov 21 19:04:18 PST 2007


I posted this patch back in June.
(http://lists.freedesktop.org/archives/cairo/2007-June/010856.html)
Back then, it apparently broke a test case. However, trying it now I
can't seem to reproduce the problem. It looks like a bunch of X test
cases are broken on my system, so I can't be sure. Anyways, if someone
could verify that this doesn't break anything, I'd love to check it in.

I also haven't rerun the performance test suite with it recently, so if
someone wants to try that, that could be helpful as well. I expect it
should similar results as it did in June.

-Jeff
-------------- next part --------------
commit 0bab5049bdeb4783424e7dc6ce72a4cb362d970a
Author: Jeff Muizelaar <jeff at infidigm.net>
Date:   Mon Jun 18 05:28:38 2007 -0400

    Use ADD instead of IN for clipping.
    
    ADD is already special-cased by pixman, so using it instead avoids hitting
    the slower general path.

diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index 0fed3f6..c12b1b7 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -451,11 +451,41 @@ _cairo_clip_intersect_mask (cairo_clip_t      *clip,
 
     _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE,
 			       CAIRO_CONTENT_COLOR);
+    /* The clipping operation should ideally be something like the following to
+     * avoid having to do as many passes over the data
+
+	if (clip->surface != NULL) {
+	    _cairo_pattern_init_for_surface (&pattern.surface, clip->surface);
+	} else {
+	    _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE,
+			       CAIRO_CONTENT_COLOR);
+	}
+	status = _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_IN,
+						  &pattern.base,
+						  surface,
+						  antialias,
+						  0, 0,
+						  0, 0,
+						  surface_rect.width,
+						  surface_rect.height,
+						  traps->traps,
+						  traps->num_traps);
+
+	However this operation is not accelerated by pixman
+
+	I believe the best possible operation would probably an unbounded SRC
+	operator.  Using SRC we could potentially avoid having to initialize
+	the surface which would be ideal from an efficiency point of view.
+	However, _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_SOURCE) is
+	bounded by the mask.
+
+    */
+
     surface = _cairo_surface_create_similar_solid (target,
 						   CAIRO_CONTENT_ALPHA,
 						   surface_rect.width,
 						   surface_rect.height,
-						   CAIRO_COLOR_WHITE,
+						   CAIRO_COLOR_TRANSPARENT,
 						   &pattern.base);
     if (surface->status) {
 	_cairo_pattern_fini (&pattern.base);
@@ -466,7 +496,7 @@ _cairo_clip_intersect_mask (cairo_clip_t      *clip,
 
     _cairo_traps_translate (traps, -surface_rect.x, -surface_rect.y);
 
-    status = _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_IN,
+    status = _cairo_surface_composite_trapezoids (CAIRO_OPERATOR_ADD,
 						  &pattern.base,
 						  surface,
 						  antialias,


More information about the cairo mailing list