diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-05-28 18:05:26 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-06-02 15:13:46 +0100 |
commit | 4aca84ddb22bc178cbc9b132b9ce06af3f4b300b (patch) | |
tree | 8f20580b5cb400d6cb191433cfd86a047134643c | |
parent | 55f4e0e4e8c7df59bfc9e6ffea8daa065276e42f (diff) | |
download | cairo-4aca84ddb22bc178cbc9b132b9ce06af3f4b300b.tar.gz |
[perf] Add a pure glyphs performance metric
Use the new API Behdad exposed in 1.8 to precompute a glyph string using
Cairo and then benchmark cairo_show_glyphs(). This is then equivalent to
the text benchmark but without the extra step of converting to glyphs on
every call to cairo_show_text() i.e. it shows the underlying glyph
rendering performance.
-rw-r--r-- | perf/Makefile.am | 1 | ||||
-rw-r--r-- | perf/cairo-perf.c | 1 | ||||
-rw-r--r-- | perf/cairo-perf.h | 1 | ||||
-rw-r--r-- | perf/glyphs.c | 97 |
4 files changed, 100 insertions, 0 deletions
diff --git a/perf/Makefile.am b/perf/Makefile.am index 08f9cc007..d33e51116 100644 --- a/perf/Makefile.am +++ b/perf/Makefile.am @@ -40,6 +40,7 @@ cairo_perf_SOURCES = \ subimage_copy.c \ tessellate.c \ text.c \ + glyphs.c \ twin.c \ unaligned-clip.c \ world-map.c \ diff --git a/perf/cairo-perf.c b/perf/cairo-perf.c index 64136e0a9..085a0c045 100644 --- a/perf/cairo-perf.c +++ b/perf/cairo-perf.c @@ -456,6 +456,7 @@ const cairo_perf_case_t perf_cases[] = { { fill, 64, 512}, { stroke, 64, 512}, { text, 64, 512}, + { glyphs, 64, 512}, { tessellate, 100, 100}, { subimage_copy, 16, 512}, { pattern_create_radial, 16, 16}, diff --git a/perf/cairo-perf.h b/perf/cairo-perf.h index 7e792ad87..0a3606b27 100644 --- a/perf/cairo-perf.h +++ b/perf/cairo-perf.h @@ -170,6 +170,7 @@ CAIRO_PERF_DECL (stroke); CAIRO_PERF_DECL (subimage_copy); CAIRO_PERF_DECL (tessellate); CAIRO_PERF_DECL (text); +CAIRO_PERF_DECL (glyphs); CAIRO_PERF_DECL (pattern_create_radial); CAIRO_PERF_DECL (zrusin); CAIRO_PERF_DECL (world_map); diff --git a/perf/glyphs.c b/perf/glyphs.c new file mode 100644 index 000000000..fdd4d97a9 --- /dev/null +++ b/perf/glyphs.c @@ -0,0 +1,97 @@ +/* + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2009 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Red Hat, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Red Hat, Inc. makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Carl D. Worth <cworth@cworth.org> + * Chris Wilson <chris@chris-wilson.co.uk> + */ + +#include "cairo-perf.h" + +static cairo_perf_ticks_t +do_glyphs (cairo_t *cr, int width, int height) +{ + const char text[] = "the jay, pig, fox, zebra and my wolves quack"; + cairo_scaled_font_t *scaled_font; + cairo_glyph_t *glyphs = NULL, *glyphs_copy; + cairo_text_extents_t extents; + cairo_status_t status; + double x, y; + int num_glyphs, n; + + cairo_set_font_size (cr, 9); + scaled_font = cairo_get_scaled_font (cr); + status = cairo_scaled_font_text_to_glyphs (scaled_font, 0., 0., + text, -1, + &glyphs, &num_glyphs, + NULL, NULL, + NULL); + if (status) + return 0; + + glyphs_copy = cairo_glyph_allocate (num_glyphs); + if (glyphs_copy == NULL) { + cairo_glyph_free (glyphs); + return 0; + } + + cairo_scaled_font_glyph_extents (scaled_font, + glyphs, num_glyphs, + &extents); + y = 0; + + cairo_perf_timer_start (); + + do { + x = 0; + do { + for (n = 0; n < num_glyphs; n++) { + glyphs_copy[n] = glyphs[n]; + glyphs_copy[n].x += x; + glyphs_copy[n].y += y; + } + cairo_show_glyphs (cr, glyphs_copy, num_glyphs); + if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) + goto out; + + x += extents.width; + } while (x < width); + y += extents.height; + } while (y < height); +out: + + cairo_perf_timer_stop (); + + cairo_glyph_free (glyphs); + cairo_glyph_free (glyphs_copy); + + return cairo_perf_timer_elapsed (); +} + +void +glyphs (cairo_perf_t *perf, cairo_t *cr, int width, int height) +{ + if (! cairo_perf_can_run (perf, "glyphs")) + return; + + cairo_perf_cover_sources_and_operators (perf, "glyphs", do_glyphs); +} |