diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-08-14 19:53:17 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-08-26 23:51:42 +0100 |
commit | 6bfb77a33c3614cafdcd6206de5c71321c5fc1e5 (patch) | |
tree | 53ebe59c31603eb17c3dceec47031c6066feca7d /perf | |
parent | 54b2935c3842e77888faef06bbf247f99bd9de8c (diff) |
[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.
Diffstat (limited to 'perf')
-rw-r--r-- | perf/spiral.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/perf/spiral.c b/perf/spiral.c index bd81c7e6..0e17e933 100644 --- a/perf/spiral.c +++ b/perf/spiral.c @@ -107,6 +107,61 @@ draw_spiral (cairo_t *cr, } 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) { return draw_spiral (cr, @@ -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); } |