[cairo] [PATCH] speeding up clipping

Jeff Muizelaar jeff at infidigm.net
Mon Jun 25 22:19:16 PDT 2007


The attached patch seems to speed up clipping pretty substantially.
Unfortunately, it also seems to break unantialiased clipping on my
xserver. I haven't investigated why yet.

-Jeff

image-rgba             unaligned_clip-100    0.12 0.85% ->   0.05 1.30%:  2.34x speedup
█▍
image-rgb              unaligned_clip-100    0.12 0.44% ->   0.05 1.73%:  2.30x speedup
█▎
 xlib-rgb              unaligned_clip-100    0.45 1.63% ->   0.25 1.88%:  1.76x speedup
▊
 xlib-rgba             unaligned_clip-100    0.49 1.78% ->   0.30 0.68%:  1.63x speedup
▋
-------------- next part --------------
commit 4717f50a76d7d5db975a1750dffa4086aeb33d41
Author: Jeff Muizelaar <jeff at infidigm.net>
Date:   Mon Jun 18 01:28:38 2007 -0400

    Use ADD instead of IN for clipping.

diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index 60f2418..a47e253 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -402,11 +402,41 @@ _cairo_clip_intersect_mask (cairo_clip_t      *clip,
     if (!status)
 	_cairo_rectangle_intersect (&surface_rect, &target_rect);
 
+    /* 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,
 						   NULL);
     if (surface->status)
 	return CAIRO_STATUS_NO_MEMORY;
@@ -417,7 +447,7 @@ _cairo_clip_intersect_mask (cairo_clip_t      *clip,
     _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE,
 			       CAIRO_CONTENT_COLOR);
 
-    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