2 * Copyright © 2006 Red Hat, Inc.
3 * Copyright © 2009 Chris Wilson
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of
10 * Red Hat, Inc. not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. Red Hat, Inc. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as
14 * is" without express or implied warranty.
16 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
19 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
22 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Author: Carl D. Worth <cworth@cworth.org>
25 * Chris Wilson <chris@chris-wilson.co.uk>
28 #include "cairo-perf.h"
31 do_glyphs (double font_size,
32 cairo_antialias_t antialias,
33 cairo_t *cr, int width, int height, int loops)
35 const char text[] = "the jay, pig, fox, zebra and my wolves quack";
36 cairo_scaled_font_t *scaled_font;
37 cairo_glyph_t *glyphs = NULL, *glyphs_copy;
38 cairo_text_extents_t extents;
39 cairo_font_options_t *options;
40 cairo_status_t status;
44 options = cairo_font_options_create ();
45 cairo_font_options_set_antialias (options, antialias);
46 cairo_set_font_options (cr, options);
47 cairo_font_options_destroy (options);
49 cairo_select_font_face (cr,
51 CAIRO_FONT_SLANT_NORMAL,
52 CAIRO_FONT_WEIGHT_NORMAL);
53 cairo_set_font_size (cr, font_size);
54 scaled_font = cairo_get_scaled_font (cr);
55 status = cairo_scaled_font_text_to_glyphs (scaled_font, 0., 0.,
63 glyphs_copy = cairo_glyph_allocate (num_glyphs);
64 if (glyphs_copy == NULL) {
65 cairo_glyph_free (glyphs);
69 cairo_scaled_font_glyph_extents (scaled_font,
73 cairo_perf_timer_start ();
80 for (n = 0; n < num_glyphs; n++) {
81 glyphs_copy[n] = glyphs[n];
82 glyphs_copy[n].x += x;
83 glyphs_copy[n].y += y;
85 cairo_show_glyphs (cr, glyphs_copy, num_glyphs);
93 cairo_perf_timer_stop ();
95 cairo_glyph_free (glyphs);
96 cairo_glyph_free (glyphs_copy);
98 return cairo_perf_timer_elapsed ();
102 count_glyphs (double font_size,
103 cairo_antialias_t antialias,
104 cairo_t *cr, int width, int height)
106 const char text[] = "the jay, pig, fox, zebra and my wolves quack";
107 cairo_scaled_font_t *scaled_font;
108 cairo_glyph_t *glyphs = NULL;
109 cairo_text_extents_t extents;
110 cairo_font_options_t *options;
111 cairo_status_t status;
113 int glyphs_per_line, lines_per_loop;
115 options = cairo_font_options_create ();
116 cairo_font_options_set_antialias (options, antialias);
117 cairo_set_font_options (cr, options);
118 cairo_font_options_destroy (options);
120 cairo_select_font_face (cr,
122 CAIRO_FONT_SLANT_NORMAL,
123 CAIRO_FONT_WEIGHT_NORMAL);
124 cairo_set_font_size (cr, font_size);
125 scaled_font = cairo_get_scaled_font (cr);
126 status = cairo_scaled_font_text_to_glyphs (scaled_font, 0., 0.,
128 &glyphs, &num_glyphs,
134 cairo_scaled_font_glyph_extents (scaled_font,
137 cairo_glyph_free (glyphs);
139 glyphs_per_line = num_glyphs * width / extents.width + 1;
140 lines_per_loop = height / extents.height + 1;
141 return glyphs_per_line * lines_per_loop / 1000.; /* kiloglyphs */
144 #define DECL(name,size, aa) \
145 static cairo_time_t \
146 do_glyphs##name (cairo_t *cr, int width, int height, int loops) \
148 return do_glyphs (size, aa, cr, width, height, loops); \
152 count_glyphs##name (cairo_t *cr, int width, int height) \
154 return count_glyphs (size, aa, cr, width, height); \
157 DECL(8, 8, CAIRO_ANTIALIAS_GRAY)
158 DECL(10, 10, CAIRO_ANTIALIAS_GRAY)
159 DECL(12, 12, CAIRO_ANTIALIAS_GRAY)
160 DECL(16, 16, CAIRO_ANTIALIAS_GRAY)
161 DECL(20, 20, CAIRO_ANTIALIAS_GRAY)
162 DECL(24, 24, CAIRO_ANTIALIAS_GRAY)
163 DECL(32, 32, CAIRO_ANTIALIAS_GRAY)
164 DECL(40, 40, CAIRO_ANTIALIAS_GRAY)
165 DECL(48, 48, CAIRO_ANTIALIAS_GRAY)
167 DECL(8ca, 8, CAIRO_ANTIALIAS_SUBPIXEL)
168 DECL(48ca, 48, CAIRO_ANTIALIAS_SUBPIXEL)
170 DECL(8mono, 8, CAIRO_ANTIALIAS_NONE)
171 DECL(48mono, 48, CAIRO_ANTIALIAS_NONE)
174 glyphs_enabled (cairo_perf_t *perf)
176 return cairo_perf_can_run (perf, "glyphs", NULL);
180 glyphs (cairo_perf_t *perf, cairo_t *cr, int width, int height)
182 cairo_perf_cover_sources_and_operators (perf, "glyphs8mono", do_glyphs8mono, count_glyphs8mono);
183 cairo_perf_cover_sources_and_operators (perf, "glyphs8", do_glyphs8, count_glyphs8);
184 cairo_perf_cover_sources_and_operators (perf, "glyphs8ca", do_glyphs8ca, count_glyphs8ca);
186 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
187 cairo_set_source_rgb (cr, 0, 0, 0);
189 cairo_perf_run (perf, "glyphs8", do_glyphs8, count_glyphs8);
190 cairo_perf_run (perf, "glyphs10", do_glyphs10, count_glyphs10);
191 cairo_perf_run (perf, "glyphs12", do_glyphs12, count_glyphs12);
192 cairo_perf_run (perf, "glyphs16", do_glyphs16, count_glyphs16);
193 cairo_perf_run (perf, "glyphs20", do_glyphs20, count_glyphs20);
194 cairo_perf_run (perf, "glyphs24", do_glyphs24, count_glyphs24);
195 cairo_perf_run (perf, "glyphs32", do_glyphs32, count_glyphs32);
196 cairo_perf_run (perf, "glyphs40", do_glyphs40, count_glyphs40);
197 cairo_perf_run (perf, "glyphs48", do_glyphs48, count_glyphs48);
199 cairo_perf_cover_sources_and_operators (perf, "glyphs48mono", do_glyphs48mono, count_glyphs48mono);
200 cairo_perf_cover_sources_and_operators (perf, "glyphs48", do_glyphs48, count_glyphs48);
201 cairo_perf_cover_sources_and_operators (perf, "glyphs48ca", do_glyphs48ca, count_glyphs48ca);