diff --git a/perf/Makefile.win32 b/perf/Makefile.win32 new file mode 100644 index 000000000..8c3b70f56 --- /dev/null +++ b/perf/Makefile.win32 @@ -0,0 +1,16 @@ +CC = cl +CFLAGS = /nologo /Zi /O2 /MD /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /I../src /I../pixman/src /I../boilerplate +LDFLAGS = ../src/cairo.lib ../pixman/src/pixman.lib ../boilerplate/boiler.lib libpng.lib zlib.lib gdi32.lib msimg32.lib user32.lib + +PERF_SOURCES = \ + cairo-perf-win32.c \ + cairo-perf.c \ + paint.c \ + tessellate.c \ + $(NULL) + +all: cairo-perf.exe + +cairo-perf.exe: $(PERF_SOURCES) + $(CC) $(CFLAGS) /Fe"$@" $^ /link $(LDFLAGS) + diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c index 976c0dcbc..6519c0bc6 100644 --- a/perf/cairo-perf.c +++ b/perf/cairo-perf.c @@ -1,3 +1,4 @@ +/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */ /* * Copyright © 2006 Mozilla Corporation * Copyright © 2006 Red Hat, Inc. @@ -142,6 +143,8 @@ main (int argc, char *argv[]) cairo_perf_ticks_t *times; stats_t stats; const char *cairo_test_target = getenv ("CAIRO_TEST_TARGET"); + double ms; + int test_number; if (getenv("CAIRO_PERF_ITERATIONS")) cairo_perf_iterations = strtol(getenv("CAIRO_PERF_ITERATIONS"), NULL, 0); @@ -154,6 +157,9 @@ main (int argc, char *argv[]) continue; if (cairo_test_target && ! strstr (cairo_test_target, target->name)) continue; + + test_number = 0; + for (j = 0; perfs[j].name; j++) { perf = &perfs[j]; for (size = perf->min_size; size <= perf->max_size; size *= 2) { @@ -176,18 +182,19 @@ main (int argc, char *argv[]) _compute_stats (times, .85 * cairo_perf_iterations, &stats); if (i==0 && j==0 && size == perf->min_size) - printf ("backend-content\ttest-size\tmean time\tstd dev.\titerations\n"); - if (perf->min_size == perf->max_size) - printf ("%s-%s\t%s\t", - target->name, _content_to_string (target->content), - perf->name); - else - printf ("%s-%s\t%s-%d\t", - target->name, _content_to_string (target->content), - perf->name, size); - printf ("%g\t%g%%\t%d\n", - stats.mean / cairo_perf_ticks_per_second (), + printf ("[ # ] %8s-%-4s %27s %9s %5s %s\n", + "backend", "content", "test-size", "mean ms", + "std dev.", "iterations"); + + printf ("[%3d] %8s-%-4s %25s-%-3d ", + test_number, target->name, _content_to_string (target->content), + perf->name, size); + + printf ("%#9.3f %#5.2f%% % 5d\n", + (stats.mean * 1000.0) / cairo_perf_ticks_per_second (), stats.std_dev * 100.0, cairo_perf_iterations); + + test_number++; } } } @@ -196,10 +203,18 @@ main (int argc, char *argv[]) } cairo_perf_t perfs[] = { - { "paint", paint, 64, 512 }, - { "paint_alpha", paint_alpha, 64, 512 }, - { "tessellate-16", tessellate_16, 100, 100}, - { "tessellate-64", tessellate_64, 100, 100}, + { "paint_over_solid", paint_over_solid, 64, 512 }, + { "paint_over_solid_alpha", paint_over_solid_alpha, 64, 512 }, + { "paint_source_solid", paint_over_solid, 64, 512 }, + { "paint_source_solid_alpha", paint_over_solid_alpha, 64, 512 }, + + { "paint_over_surf_rgb24", paint_over_solid, 64, 512 }, + { "paint_over_surf_argb32", paint_over_solid_alpha, 64, 512 }, + { "paint_source_surf_rgb24", paint_over_solid, 64, 512 }, + { "paint_source_surf_argb32", paint_over_solid_alpha, 64, 512 }, + + { "tessellate-16", tessellate_16, 100, 100}, + { "tessellate-64", tessellate_64, 100, 100}, { "tessellate-256", tessellate_256, 100, 100}, { NULL } }; diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h index 4b4071b86..f22d76273 100644 --- a/perf/cairo-perf.h +++ b/perf/cairo-perf.h @@ -63,8 +63,17 @@ typedef cairo_perf_ticks_t #define CAIRO_PERF_DECL(func) cairo_perf_ticks_t func (cairo_t *cr, int width, int height) -CAIRO_PERF_DECL (paint); -CAIRO_PERF_DECL (paint_alpha); +/* paint.c */ +CAIRO_PERF_DECL (paint_over_solid); +CAIRO_PERF_DECL (paint_over_solid_alpha); +CAIRO_PERF_DECL (paint_source_solid); +CAIRO_PERF_DECL (paint_source_solid_alpha); +CAIRO_PERF_DECL (paint_over_surface_rgb24); +CAIRO_PERF_DECL (paint_over_surface_argb32); +CAIRO_PERF_DECL (paint_source_surface_rgb24); +CAIRO_PERF_DECL (paint_source_surface_argb32); + +/* tessellate.c */ CAIRO_PERF_DECL (tessellate_16); CAIRO_PERF_DECL (tessellate_64); CAIRO_PERF_DECL (tessellate_256); diff --git a/perf/paint.c b/perf/paint.c index 2501a33cf..1556383f0 100644 --- a/perf/paint.c +++ b/perf/paint.c @@ -54,8 +54,12 @@ do_paint (cairo_t *cr, int size) return cairo_perf_timer_elapsed (); } +/* + * paint with solid color + */ + cairo_perf_ticks_t -paint (cairo_t *cr, int width, int height) +paint_over_solid (cairo_t *cr, int width, int height) { cairo_set_source_rgb (cr, 0.2, 0.6, 0.9); @@ -63,10 +67,120 @@ paint (cairo_t *cr, int width, int height) } cairo_perf_ticks_t -paint_alpha (cairo_t *cr, int width, int height) +paint_over_solid_alpha (cairo_t *cr, int width, int height) { + cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7); + + return do_paint (cr, width); +} + +cairo_perf_ticks_t +paint_source_solid (cairo_t *cr, int width, int height) +{ + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgb (cr, 0.2, 0.6, 0.9); return do_paint (cr, width); } +cairo_perf_ticks_t +paint_source_solid_alpha (cairo_t *cr, int width, int height) +{ + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7); + + return do_paint (cr, width); +} + +/* + * paint with surface + */ + + +int cached_surface_width = 0; +int cached_surface_height = 0; +cairo_content_t cached_surface_content = 0; +cairo_surface_t *cached_surface = NULL; + +void +ensure_cached_surface (cairo_t *cr, cairo_content_t content, int w, int h) +{ + cairo_surface_t *target_surface = cairo_get_target (cr); + + cairo_t *cr2; + + if (w == cached_surface_width && h == cached_surface_height && + content == cached_surface_content && + cached_surface && + cairo_surface_get_type (target_surface) == cairo_surface_get_type (cached_surface)) + { + return; + } + + if (cached_surface) + cairo_surface_destroy (cached_surface); + + cached_surface = cairo_surface_create_similar (target_surface, content, w, h); + + cached_surface_width = w; + cached_surface_height = h; + cached_surface_content = content; + + /* Fill it with something known */ + cr2 = cairo_create (cached_surface); + cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr2); + + cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE); + cairo_set_source_rgb (cr2, 0, 0, 1); + cairo_paint (cr2); + + cairo_set_source_rgba (cr2, 1, 0, 0, 0.5); + cairo_new_path (cr2); + cairo_rectangle (cr2, 0, 0, w/2.0, h/2.0); + cairo_rectangle (cr2, w/2.0, h/2.0, w/2.0, h/2.0); + cairo_fill (cr2); + cairo_destroy (cr2); +} + +cairo_perf_ticks_t +paint_over_surface_rgb24 (cairo_t *cr, int width, int height) +{ + ensure_cached_surface (cr, CAIRO_CONTENT_COLOR, width, height); + + cairo_set_source_surface (cr, cached_surface, 0, 0); + + return do_paint (cr, width); +} + +cairo_perf_ticks_t +paint_over_surface_argb32 (cairo_t *cr, int width, int height) +{ + ensure_cached_surface (cr, CAIRO_CONTENT_COLOR_ALPHA, width, height); + + cairo_set_source_surface (cr, cached_surface, 0, 0); + + return do_paint (cr, width); +} + +cairo_perf_ticks_t +paint_source_surface_rgb24 (cairo_t *cr, int width, int height) +{ + ensure_cached_surface (cr, CAIRO_CONTENT_COLOR, width, height); + + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_surface (cr, cached_surface, 0, 0); + + return do_paint (cr, width); +} + +cairo_perf_ticks_t +paint_source_surface_argb32 (cairo_t *cr, int width, int height) +{ + ensure_cached_surface (cr, CAIRO_CONTENT_COLOR_ALPHA, width, height); + + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_surface (cr, cached_surface, 0, 0); + + return do_paint (cr, width); +}