From 6bfb77a33c3614cafdcd6206de5c71321c5fc1e5 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 14 Aug 2009 19:53:17 +0100 Subject: [perf] Add spiral strokes Use cairo_stroke() to perform the equivalent of spiral-rect-(pix|non)align-evenodd-fill. A useful comparison of stroking versus filling, as we can assume the composition costs are similar. --- perf/spiral.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'perf') diff --git a/perf/spiral.c b/perf/spiral.c index bd81c7e6..0e17e933 100644 --- a/perf/spiral.c +++ b/perf/spiral.c @@ -106,6 +106,61 @@ draw_spiral (cairo_t *cr, return cairo_perf_timer_elapsed (); } +static cairo_perf_ticks_t +draw_spiral_stroke (cairo_t *cr, + align_t align, + int width, int height, int loops) +{ + const int step = 3; + int side = width < height ? width : height; + + cairo_save (cr); + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_paint (cr); + + cairo_translate (cr, 1, 1); + cairo_set_source_rgb (cr, 1, 0, 0); + cairo_set_line_width (cr, 4.); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); + + cairo_new_path (cr); + switch (align) { + case PIXALIGN: cairo_move_to (cr, 0,0); break; + case NONALIGN: cairo_move_to (cr, 0.1415926, 0.7182818); break; + } + while (side >= step) { + cairo_rel_line_to (cr, 0, side); + side -= step; + if (side <= 0) + break; + + cairo_rel_line_to (cr, side, 0); + side -= step; + if (side <= 0) + break; + + cairo_rel_line_to (cr, 0, -side); + side -= step; + if (side <= 0) + break; + + cairo_rel_line_to (cr, -side, 0); + side -= step; + if (side <= 0) + break; + } + + cairo_perf_timer_start (); + while (loops--) + cairo_stroke_preserve (cr); + cairo_perf_timer_stop (); + + cairo_restore (cr); + + return cairo_perf_timer_elapsed (); +} + static cairo_perf_ticks_t draw_spiral_eo_pa_re (cairo_t *cr, int width, int height, int loops) { @@ -186,6 +241,22 @@ draw_spiral_nz_na_di (cairo_t *cr, int width, int height, int loops) width, height, loops); } +static cairo_perf_ticks_t +draw_spiral_stroke_pa (cairo_t *cr, int width, int height, int loops) +{ + return draw_spiral_stroke (cr, + PIXALIGN, + width, height, loops); +} + +static cairo_perf_ticks_t +draw_spiral_stroke_na (cairo_t *cr, int width, int height, int loops) +{ + return draw_spiral_stroke (cr, + NONALIGN, + width, height, loops); +} + void spiral (cairo_perf_t *perf, cairo_t *cr, int width, int height) { @@ -200,4 +271,6 @@ spiral (cairo_perf_t *perf, cairo_t *cr, int width, int height) cairo_perf_run (perf, "spiral-rect-nonalign-nonzero-fill", draw_spiral_nz_na_re); cairo_perf_run (perf, "spiral-rect-pixalign-evenodd-fill", draw_spiral_eo_pa_re); cairo_perf_run (perf, "spiral-rect-pixalign-nonzero-fill", draw_spiral_nz_pa_re); + cairo_perf_run (perf, "spiral-nonalign-stroke", draw_spiral_stroke_na); + cairo_perf_run (perf, "spiral-pixalign-stroke", draw_spiral_stroke_pa); } -- cgit v1.2.3