[cairo-commit] 4 commits - perf/cairo-perf.h perf/cairo-perf-micro.c perf/micro src/cairo-bentley-ottmann-rectangular.c test/a1-line-width.ref.png test/line-width.c test/Makefile.refs

Chris Wilson ickle at kemper.freedesktop.org
Sat Aug 13 01:32:30 PDT 2011


 perf/cairo-perf-micro.c                 |   11 +
 perf/cairo-perf.h                       |    3 
 perf/micro/Makefile.sources             |    3 
 perf/micro/line.c                       |  219 ++++++++++++++++++++++++++++++++
 perf/micro/many-curves.c                |   19 ++
 perf/micro/many-fills.c                 |   10 -
 perf/micro/many-strokes.c               |   10 -
 perf/micro/wide-fills.c                 |  184 ++++++++++++++++++++++++++
 perf/micro/wide-strokes.c               |  185 +++++++++++++++++++++++++++
 src/cairo-bentley-ottmann-rectangular.c |   51 +++----
 test/Makefile.refs                      |    1 
 test/a1-line-width.ref.png              |binary
 test/line-width.c                       |   38 +++++
 13 files changed, 686 insertions(+), 48 deletions(-)

New commits:
commit ee001b0b9fcafe14e0650d7b5c6f5e133f9d1e46
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Aug 12 23:26:03 2011 +0100

    bo-rect: Micro-optimisation
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-bentley-ottmann-rectangular.c b/src/cairo-bentley-ottmann-rectangular.c
index 7baec13..c7e3277 100644
--- a/src/cairo-bentley-ottmann-rectangular.c
+++ b/src/cairo-bentley-ottmann-rectangular.c
@@ -163,7 +163,7 @@ rectangle_pop_stop (sweep_line_t *sweep)
 
     tail = elements[sweep->stop_size--];
     if (sweep->stop_size == 0) {
-	elements[PQ_FIRST_ENTRY] = NULL;
+	tail = NULL;
 	return;
     }
 
@@ -326,11 +326,10 @@ edge_start_or_continue_box (sweep_line_t *sweep_line,
 static edge_t *
 merge_sorted_edges (edge_t *head_a, edge_t *head_b)
 {
-    edge_t *head, **next, *prev;
+    edge_t *head, *prev;
     int32_t x;
 
     prev = head_a->prev;
-    next = &head;
     if (head_a->x <= head_b->x) {
 	head = head_a;
     } else {
@@ -343,12 +342,11 @@ merge_sorted_edges (edge_t *head_a, edge_t *head_b)
 	x = head_b->x;
 	while (head_a != NULL && head_a->x <= x) {
 	    prev = head_a;
-	    next = &head_a->next;
 	    head_a = head_a->next;
 	}
 
 	head_b->prev = prev;
-	*next = head_b;
+	prev->next = head_b;
 	if (head_a == NULL)
 	    return head;
 
@@ -356,12 +354,11 @@ start_with_b:
 	x = head_a->x;
 	while (head_b != NULL && head_b->x <= x) {
 	    prev = head_b;
-	    next = &head_b->next;
 	    head_b = head_b->next;
 	}
 
 	head_a->prev = prev;
-	*next = head_a;
+	prev->next = head_a;
 	if (head_b == NULL)
 	    return head;
     } while (1);
@@ -429,7 +426,7 @@ merge_unsorted_edges (edge_t *head, edge_t *unsorted)
 static void
 active_edges_insert (sweep_line_t *sweep)
 {
-    edge_t *edge, *prev;
+    edge_t *prev;
     int x;
 
     x = sweep->insert_x;
@@ -476,36 +473,32 @@ active_edges_to_traps (sweep_line_t *sweep)
 	    right = left->next;
 
 	    /* Check if there is a co-linear edge with an existing trap */
-	    if (left->right == NULL) {
-		while (unlikely (right->x == left->x)) {
-		    winding += right->dir;
-		    if (right->right != NULL) {
-			/* continuation on left */
-			left->top = right->top;
-			left->right = right->right;
-			right->right = NULL;
-			winding -= right->dir;
-			break;
-		    }
-
-		    right = right->next;
-		}
-
-		if (winding == 0) {
-		    pos = right;
-		    continue;
+	    while (right->x == left->x) {
+		if (right->right != NULL) {
+		    assert (left->right == NULL);
+		    /* continuation on left */
+		    left->top = right->top;
+		    left->right = right->right;
+		    right->right = NULL;
 		}
+		winding += right->dir;
+		right = right->next;
 	    }
 
-	    /* Greedily search for the closing edge, so that we generate the
-	     * maximal span width with the minimal number of trapezoids.
-	     */
+	    if (winding == 0) {
+		pos = right;
+		continue;
+	    }
 
 	    do {
 		/* End all subsumed traps */
 		if (unlikely (right->right != NULL))
 		    edge_end_box (sweep, right, top);
 
+		/* Greedily search for the closing edge, so that we generate
+		 * the * maximal span width with the minimal number of
+		 * boxes.
+		 */
 		winding += right->dir;
 		if (winding == 0 && right->x != right->next->x)
 		    break;
commit 2e545672ba14fb49455ce501ded21efd18df1a65
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Aug 12 23:49:12 2011 +0100

    perf/micro: diagonal lines
    
    The ideal benchmark for spans?...
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/perf/cairo-perf-micro.c b/perf/cairo-perf-micro.c
index 55ca0e8..0f5f64e 100644
--- a/perf/cairo-perf-micro.c
+++ b/perf/cairo-perf-micro.c
@@ -544,7 +544,8 @@ const cairo_perf_case_t perf_cases[] = {
     { text,   64, 512},
     { glyphs, 64, 512},
     { mask,   64, 512},
-    { curve,  64, 512},
+    { line,  32, 512},
+    { curve,  32, 512},
     { disjoint,   64, 512},
     { hatching,   64, 512},
     { tessellate, 100, 100},
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 5da6ee0..b52bdfa 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -217,5 +217,6 @@ CAIRO_PERF_DECL (many_fills);
 CAIRO_PERF_DECL (wide_fills);
 CAIRO_PERF_DECL (many_curves);
 CAIRO_PERF_DECL (curve);
+CAIRO_PERF_DECL (line);
 
 #endif
diff --git a/perf/micro/Makefile.sources b/perf/micro/Makefile.sources
index 1fe8be1..0c2bca0 100644
--- a/perf/micro/Makefile.sources
+++ b/perf/micro/Makefile.sources
@@ -6,6 +6,7 @@ libcairo_perf_micro_sources = \
 	fill.c			\
 	hatching.c		\
 	hash-table.c		\
+	line.c			\
 	long-lines.c		\
 	mosaic.c		\
 	paint.c			\
diff --git a/perf/micro/line.c b/perf/micro/line.c
new file mode 100644
index 0000000..6249d9c
--- /dev/null
+++ b/perf/micro/line.c
@@ -0,0 +1,219 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-perf.h"
+
+static cairo_perf_ticks_t
+horizontal (cairo_t *cr, int width, int height, int loops)
+{
+    double h = height/2 + .5;
+
+    cairo_move_to (cr, 0, h);
+    cairo_line_to (cr, width, h);
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_stroke_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+horizontal_hair (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 1.);
+    return horizontal (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
+horizontal_wide (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 5.);
+    return horizontal (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
+nearly_horizontal (cairo_t *cr, int width, int height, int loops)
+{
+    double h = height/2;
+
+    cairo_move_to (cr, 0, h);
+    cairo_line_to (cr, width, h+1);
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_stroke_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+nearly_horizontal_hair (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 1.);
+    return nearly_horizontal (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
+nearly_horizontal_wide (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 5.);
+    return nearly_horizontal (cr, width, height, loops);
+}
+
+
+static cairo_perf_ticks_t
+vertical (cairo_t *cr, int width, int height, int loops)
+{
+    double w = width/2 + .5;
+
+    cairo_move_to (cr, w, 0);
+    cairo_line_to (cr, w, height);
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_stroke_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+vertical_hair (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 1.);
+    return vertical (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
+vertical_wide (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 5.);
+    return vertical (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
+nearly_vertical (cairo_t *cr, int width, int height, int loops)
+{
+    double w = width/2;
+
+    cairo_move_to (cr, w, 0);
+    cairo_line_to (cr, w+1, height);
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_stroke_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+nearly_vertical_hair (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 1.);
+    return nearly_vertical (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
+nearly_vertical_wide (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 5.);
+    return nearly_vertical (cr, width, height, loops);
+}
+
+
+static cairo_perf_ticks_t
+diagonal (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_move_to (cr, 0, 0);
+    cairo_line_to (cr, width, height);
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_stroke_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+diagonal_hair (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 1.);
+    return diagonal (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
+diagonal_wide (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 5.);
+    return diagonal (cr, width, height, loops);
+}
+
+void
+line (cairo_perf_t *perf, cairo_t *cr, int width, int height)
+{
+    if (! cairo_perf_can_run (perf, "line", NULL))
+	return;
+
+    cairo_set_source_rgb (cr, 1., 1., 1.);
+
+    cairo_perf_run (perf, "line-hh", horizontal_hair, NULL);
+    cairo_perf_run (perf, "line-hw", horizontal_wide, NULL);
+    cairo_perf_run (perf, "line-nhh", nearly_horizontal_hair, NULL);
+    cairo_perf_run (perf, "line-nhw", nearly_horizontal_wide, NULL);
+
+    cairo_perf_run (perf, "line-vh", vertical_hair, NULL);
+    cairo_perf_run (perf, "line-vw", vertical_wide, NULL);
+    cairo_perf_run (perf, "line-nvh", nearly_vertical_hair, NULL);
+    cairo_perf_run (perf, "line-nvw", nearly_vertical_wide, NULL);
+
+    cairo_perf_run (perf, "line-dh", diagonal_hair, NULL);
+    cairo_perf_run (perf, "line-dw", diagonal_wide, NULL);
+}
commit e9d41054f954e84b317ca756edb4cd58dcad6362
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Aug 12 21:58:55 2011 +0100

    perf/micro: Test wide vs hairline strokes
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/perf/cairo-perf-micro.c b/perf/cairo-perf-micro.c
index 1107139..55ca0e8 100644
--- a/perf/cairo-perf-micro.c
+++ b/perf/cairo-perf-micro.c
@@ -565,9 +565,11 @@ const cairo_perf_case_t perf_cases[] = {
     { dragon, 1024, 1024 },
     { pythagoras_tree, 768, 768 },
     { intersections, 512, 512 },
-    { many_strokes, 64, 512 },
-    { many_fills, 64, 512 },
-    { many_curves, 64, 512 },
+    { many_strokes, 32, 512 },
+    { wide_strokes, 32, 512 },
+    { many_fills, 32, 512 },
+    { wide_fills, 32, 512 },
+    { many_curves, 32, 512 },
     { spiral, 512, 512 },
     { wave, 500, 500 },
     { NULL }
diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h
index 3921222..5da6ee0 100644
--- a/perf/cairo-perf.h
+++ b/perf/cairo-perf.h
@@ -212,7 +212,9 @@ CAIRO_PERF_DECL (intersections);
 CAIRO_PERF_DECL (spiral);
 CAIRO_PERF_DECL (wave);
 CAIRO_PERF_DECL (many_strokes);
+CAIRO_PERF_DECL (wide_strokes);
 CAIRO_PERF_DECL (many_fills);
+CAIRO_PERF_DECL (wide_fills);
 CAIRO_PERF_DECL (many_curves);
 CAIRO_PERF_DECL (curve);
 
diff --git a/perf/micro/Makefile.sources b/perf/micro/Makefile.sources
index 5de4d43..1fe8be1 100644
--- a/perf/micro/Makefile.sources
+++ b/perf/micro/Makefile.sources
@@ -29,7 +29,9 @@ libcairo_perf_micro_sources = \
 	pythagoras-tree.c	\
 	intersections.c		\
 	many-strokes.c		\
+	wide-strokes.c		\
 	many-fills.c		\
+	wide-fills.c		\
 	many-curves.c		\
 	curve.c			\
 	spiral.c		\
diff --git a/perf/micro/many-curves.c b/perf/micro/many-curves.c
index aec92bf..b44fd13 100644
--- a/perf/micro/many-curves.c
+++ b/perf/micro/many-curves.c
@@ -55,8 +55,6 @@ do_many_curves_stroked (cairo_t *cr, int width, int height, int loops)
 	cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
     }
 
-    cairo_set_line_width (cr, 2.);
-
     cairo_perf_timer_start ();
 
     while (loops--)
@@ -70,6 +68,20 @@ do_many_curves_stroked (cairo_t *cr, int width, int height, int loops)
 }
 
 static cairo_perf_ticks_t
+do_many_curves_hair_stroked (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 1.);
+    return do_many_curves_stroked (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
+do_many_curves_wide_stroked (cairo_t *cr, int width, int height, int loops)
+{
+    cairo_set_line_width (cr, 5.);
+    return do_many_curves_stroked (cr, width, height, loops);
+}
+
+static cairo_perf_ticks_t
 do_many_curves_filled (cairo_t *cr, int width, int height, int loops)
 {
     int count;
@@ -114,6 +126,7 @@ many_curves (cairo_perf_t *perf, cairo_t *cr, int width, int height)
 
     cairo_set_source_rgb (cr, 1., 1., 1.);
 
-    cairo_perf_run (perf, "many-curves-stroked", do_many_curves_stroked, NULL);
+    cairo_perf_run (perf, "many-curves-hair-stroked", do_many_curves_hair_stroked, NULL);
+    cairo_perf_run (perf, "many-curves-wide-stroked", do_many_curves_wide_stroked, NULL);
     cairo_perf_run (perf, "many-curves-filled", do_many_curves_filled, NULL);
 }
diff --git a/perf/micro/many-fills.c b/perf/micro/many-fills.c
index 8c012aa..c52e1bf 100644
--- a/perf/micro/many-fills.c
+++ b/perf/micro/many-fills.c
@@ -54,7 +54,7 @@ do_many_fills_ha (cairo_t *cr, int width, int height, int loops)
     for (count = 0; count < 1000; count++) {
 	double y = floor (uniform_random (0, height));
 	double x = floor (uniform_random (0, width));
-	cairo_rectangle (cr, x, y, ceil (uniform_random (0, width)) - x, 2);
+	cairo_rectangle (cr, x, y, ceil (uniform_random (0, width)) - x, 1);
     }
 
     cairo_perf_timer_start ();
@@ -78,7 +78,7 @@ do_many_fills_h (cairo_t *cr, int width, int height, int loops)
     for (count = 0; count < 1000; count++) {
 	double y = uniform_random (0, height);
 	double x = uniform_random (0, width);
-	cairo_rectangle (cr, x, y, uniform_random (0, width) - x, 2);
+	cairo_rectangle (cr, x, y, uniform_random (0, width) - x, 1);
     }
 
     cairo_perf_timer_start ();
@@ -102,7 +102,7 @@ do_many_fills_va (cairo_t *cr, int width, int height, int loops)
     for (count = 0; count < 1000; count++) {
 	double x = floor (uniform_random (0, width));
 	double y = floor (uniform_random (0, height));
-	cairo_rectangle (cr, x, y, 2, ceil (uniform_random (0, height) - y));
+	cairo_rectangle (cr, x, y, 1, ceil (uniform_random (0, height) - y));
     }
 
     cairo_perf_timer_start ();
@@ -126,7 +126,7 @@ do_many_fills_v (cairo_t *cr, int width, int height, int loops)
     for (count = 0; count < 1000; count++) {
 	double x = uniform_random (0, width);
 	double y = uniform_random (0, height);
-	cairo_rectangle (cr, x, y, 2, uniform_random (0, height) - y);
+	cairo_rectangle (cr, x, y, 1, uniform_random (0, height) - y);
     }
 
     cairo_perf_timer_start ();
@@ -154,7 +154,7 @@ do_many_fills (cairo_t *cr, int width, int height, int loops)
 			 uniform_random (0, width),
 			 uniform_random (0, height));
 	cairo_rotate (cr, uniform_random (-M_PI,M_PI));
-	cairo_rectangle (cr, 0, 0, uniform_random (0, width), 2);
+	cairo_rectangle (cr, 0, 0, uniform_random (0, width), 1);
 	cairo_restore (cr);
     }
 
diff --git a/perf/micro/many-strokes.c b/perf/micro/many-strokes.c
index f5b3a8c..8ef1876 100644
--- a/perf/micro/many-strokes.c
+++ b/perf/micro/many-strokes.c
@@ -50,7 +50,7 @@ do_many_strokes_ha (cairo_t *cr, int width, int height, int loops)
 	cairo_line_to (cr, ceil (uniform_random (0, width)), h);
     }
 
-    cairo_set_line_width (cr, 2.);
+    cairo_set_line_width (cr, 1.);
 
     cairo_perf_timer_start ();
 
@@ -76,7 +76,7 @@ do_many_strokes_h (cairo_t *cr, int width, int height, int loops)
 	cairo_line_to (cr, uniform_random (0, width), h);
     }
 
-    cairo_set_line_width (cr, 2.);
+    cairo_set_line_width (cr, 1.);
 
     cairo_perf_timer_start ();
 
@@ -102,7 +102,7 @@ do_many_strokes_va (cairo_t *cr, int width, int height, int loops)
 	cairo_line_to (cr, v, ceil (uniform_random (0, height)));
     }
 
-    cairo_set_line_width (cr, 2.);
+    cairo_set_line_width (cr, 1.);
 
     cairo_perf_timer_start ();
 
@@ -128,7 +128,7 @@ do_many_strokes_v (cairo_t *cr, int width, int height, int loops)
 	cairo_line_to (cr, v, uniform_random (0, height));
     }
 
-    cairo_set_line_width (cr, 2.);
+    cairo_set_line_width (cr, 1.);
 
     cairo_perf_timer_start ();
 
@@ -155,7 +155,7 @@ do_many_strokes (cairo_t *cr, int width, int height, int loops)
 		       uniform_random (0, height));
     }
 
-    cairo_set_line_width (cr, 2.);
+    cairo_set_line_width (cr, 1.);
 
     cairo_perf_timer_start ();
 
diff --git a/perf/micro/wide-fills.c b/perf/micro/wide-fills.c
new file mode 100644
index 0000000..a4adc48
--- /dev/null
+++ b/perf/micro/wide-fills.c
@@ -0,0 +1,184 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+
+/* This is a variant on wide strokes where we precompute
+ * a simplified stroke-to-path.
+ * When we have a real stroke-to-path, it would useful to compare the cost
+ * of stroking vs filling the "identical" paths.
+ */
+
+#include "cairo-perf.h"
+
+static uint32_t state;
+
+static double
+uniform_random (double minval, double maxval)
+{
+    static uint32_t const poly = 0x9a795537U;
+    uint32_t n = 32;
+    while (n-->0)
+	state = 2*state < state ? (2*state ^ poly) : 2*state;
+    return minval + state * (maxval - minval) / 4294967296.0;
+}
+
+static cairo_perf_ticks_t
+do_wide_fills_ha (cairo_t *cr, int width, int height, int loops)
+{
+    int count;
+
+    state = 0xc0ffee;
+    for (count = 0; count < 1000; count++) {
+	double y = floor (uniform_random (0, height));
+	double x = floor (uniform_random (0, width));
+	cairo_rectangle (cr, x, y, ceil (uniform_random (0, width)) - x, 5);
+    }
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_fill_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_fills_h (cairo_t *cr, int width, int height, int loops)
+{
+    int count;
+
+    state = 0xc0ffee;
+    for (count = 0; count < 1000; count++) {
+	double y = uniform_random (0, height);
+	double x = uniform_random (0, width);
+	cairo_rectangle (cr, x, y, uniform_random (0, width) - x, 5);
+    }
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_fill_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_fills_va (cairo_t *cr, int width, int height, int loops)
+{
+    int count;
+
+    state = 0xc0ffee;
+    for (count = 0; count < 1000; count++) {
+	double x = floor (uniform_random (0, width));
+	double y = floor (uniform_random (0, height));
+	cairo_rectangle (cr, x, y, 5, ceil (uniform_random (0, height) - y));
+    }
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_fill_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_fills_v (cairo_t *cr, int width, int height, int loops)
+{
+    int count;
+
+    state = 0xc0ffee;
+    for (count = 0; count < 1000; count++) {
+	double x = uniform_random (0, width);
+	double y = uniform_random (0, height);
+	cairo_rectangle (cr, x, y, 5, uniform_random (0, height) - y);
+    }
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_fill_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_fills (cairo_t *cr, int width, int height, int loops)
+{
+    int count;
+
+    /* lots and lots of overlapping stroke-like fills */
+    state = 0xc0ffee;
+    for (count = 0; count < 1000; count++) {
+	cairo_save (cr);
+	cairo_translate (cr,
+			 uniform_random (0, width),
+			 uniform_random (0, height));
+	cairo_rotate (cr, uniform_random (-M_PI,M_PI));
+	cairo_rectangle (cr, 0, 0, uniform_random (0, width), 5);
+	cairo_restore (cr);
+    }
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_fill_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+void
+wide_fills (cairo_perf_t *perf, cairo_t *cr, int width, int height)
+{
+    if (! cairo_perf_can_run (perf, "wide-fills", NULL))
+	return;
+
+    cairo_perf_run (perf, "wide-fills-halign", do_wide_fills_ha, NULL);
+    cairo_perf_run (perf, "wide-fills-valign", do_wide_fills_va, NULL);
+    cairo_perf_run (perf, "wide-fills-horizontal", do_wide_fills_h, NULL);
+    cairo_perf_run (perf, "wide-fills-vertical", do_wide_fills_v, NULL);
+    cairo_perf_run (perf, "wide-fills-random", do_wide_fills, NULL);
+}
diff --git a/perf/micro/wide-strokes.c b/perf/micro/wide-strokes.c
new file mode 100644
index 0000000..450d6a9
--- /dev/null
+++ b/perf/micro/wide-strokes.c
@@ -0,0 +1,185 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-perf.h"
+
+static uint32_t state;
+
+static double
+uniform_random (double minval, double maxval)
+{
+    static uint32_t const poly = 0x9a795537U;
+    uint32_t n = 32;
+    while (n-->0)
+	state = 2*state < state ? (2*state ^ poly) : 2*state;
+    return minval + state * (maxval - minval) / 4294967296.0;
+}
+
+static cairo_perf_ticks_t
+do_wide_strokes_ha (cairo_t *cr, int width, int height, int loops)
+{
+    int count;
+
+    state = 0xc0ffee;
+    for (count = 0; count < 1000; count++) {
+	double h = floor (uniform_random (0, height));
+	cairo_move_to (cr, floor (uniform_random (0, width)), h);
+	cairo_line_to (cr, ceil (uniform_random (0, width)), h);
+    }
+
+    cairo_set_line_width (cr, 5.);
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_stroke_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_strokes_h (cairo_t *cr, int width, int height, int loops)
+{
+    int count;
+
+    state = 0xc0ffee;
+    for (count = 0; count < 1000; count++) {
+	double h = uniform_random (0, height);
+	cairo_move_to (cr, uniform_random (0, width), h);
+	cairo_line_to (cr, uniform_random (0, width), h);
+    }
+
+    cairo_set_line_width (cr, 5.);
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_stroke_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_strokes_va (cairo_t *cr, int width, int height, int loops)
+{
+    int count;
+
+    state = 0xc0ffee;
+    for (count = 0; count < 1000; count++) {
+	double v = floor (uniform_random (0, width));
+	cairo_move_to (cr, v, floor (uniform_random (0, height)));
+	cairo_line_to (cr, v, ceil (uniform_random (0, height)));
+    }
+
+    cairo_set_line_width (cr, 5.);
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_stroke_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_strokes_v (cairo_t *cr, int width, int height, int loops)
+{
+    int count;
+
+    state = 0xc0ffee;
+    for (count = 0; count < 1000; count++) {
+	double v = uniform_random (0, width);
+	cairo_move_to (cr, v, uniform_random (0, height));
+	cairo_line_to (cr, v, uniform_random (0, height));
+    }
+
+    cairo_set_line_width (cr, 5.);
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_stroke_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+static cairo_perf_ticks_t
+do_wide_strokes (cairo_t *cr, int width, int height, int loops)
+{
+    int count;
+
+    /* lots and lots of overlapping strokes */
+    state = 0xc0ffee;
+    for (count = 0; count < 1000; count++) {
+	cairo_line_to (cr,
+		       uniform_random (0, width),
+		       uniform_random (0, height));
+    }
+
+    cairo_set_line_width (cr, 5.);
+
+    cairo_perf_timer_start ();
+
+    while (loops--)
+	cairo_stroke_preserve (cr);
+
+    cairo_perf_timer_stop ();
+
+    cairo_new_path (cr);
+
+    return cairo_perf_timer_elapsed ();
+}
+
+void
+wide_strokes (cairo_perf_t *perf, cairo_t *cr, int width, int height)
+{
+    if (! cairo_perf_can_run (perf, "wide-strokes", NULL))
+	return;
+
+    cairo_set_source_rgb (cr, 1., 1., 1.);
+
+    cairo_perf_run (perf, "wide-strokes-halign", do_wide_strokes_ha, NULL);
+    cairo_perf_run (perf, "wide-strokes-valign", do_wide_strokes_va, NULL);
+    cairo_perf_run (perf, "wide-strokes-horizontal", do_wide_strokes_h, NULL);
+    cairo_perf_run (perf, "wide-strokes-vertical", do_wide_strokes_v, NULL);
+    cairo_perf_run (perf, "wide-strokes-random", do_wide_strokes, NULL);
+}
commit ccbd7281b25f4b25a4c324aa815b94d7de76ac90
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sat Aug 13 09:22:15 2011 +0100

    test/line-width: Add a non-antialiased variant
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/test/Makefile.refs b/test/Makefile.refs
index bbf64dd..5a73386 100644
--- a/test/Makefile.refs
+++ b/test/Makefile.refs
@@ -11,6 +11,7 @@ REFERENCE_IMAGES = \
 	a1-clip-stroke.ref.png \
 	a1-image-sample.gl.xfail.png \
 	a1-image-sample.ref.png \
+	a1-line-width.ref.png \
 	a1-mask-sample.ref.png \
 	a1-mask.ref.png \
 	a1-rasterisation-rectangles.quartz.xfail.png \
diff --git a/test/a1-line-width.ref.png b/test/a1-line-width.ref.png
new file mode 100644
index 0000000..35d9cad
Binary files /dev/null and b/test/a1-line-width.ref.png differ
diff --git a/test/line-width.c b/test/line-width.c
index e612a93..66924f1 100644
--- a/test/line-width.c
+++ b/test/line-width.c
@@ -31,7 +31,7 @@
 #define IMAGE_HEIGHT ((LINES+4)*LINES)/2 + 2
 
 static cairo_test_status_t
-draw (cairo_t *cr, int width, int height)
+draw_a8 (cairo_t *cr, int width, int height)
 {
     int i;
 
@@ -56,9 +56,43 @@ draw (cairo_t *cr, int width, int height)
     return CAIRO_TEST_SUCCESS;
 }
 
+static cairo_test_status_t
+draw_a1 (cairo_t *cr, int width, int height)
+{
+    int i;
+
+    /* We draw in black, so paint white first. */
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+
+    cairo_set_source_rgb (cr, 0, 0, 0);
+    cairo_translate (cr, 2, 2);
+
+    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+
+    for (i=0; i < LINES; i++) {
+	cairo_set_line_width (cr, i+1);
+	cairo_move_to (cr, 0, 0);
+	cairo_rel_line_to (cr, LINE_LENGTH, 0);
+	cairo_stroke (cr);
+	cairo_move_to (cr, LINE_LENGTH + 2, 0.5);
+	cairo_rel_line_to (cr, LINE_LENGTH, 0);
+	cairo_stroke (cr);
+	cairo_translate (cr, 0, i+3);
+    }
+
+    return CAIRO_TEST_SUCCESS;
+}
+
 CAIRO_TEST (line_width,
 	    "Tests cairo_set_line_width",
 	    "stroke", /* keywords */
 	    NULL, /* requirements */
 	    IMAGE_WIDTH, IMAGE_HEIGHT,
-	    NULL, draw)
+	    NULL, draw_a8)
+CAIRO_TEST (a1_line_width,
+	    "Tests cairo_set_line_width",
+	    "stroke", /* keywords */
+	    NULL, /* requirements */
+	    IMAGE_WIDTH, IMAGE_HEIGHT,
+	    NULL, draw_a1)


More information about the cairo-commit mailing list