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 ();
74 cairo_perf_set_thread_aware (cr, FALSE);
78 cairo_perf_set_thread_aware (cr, TRUE);
83 for (n = 0; n < num_glyphs; n++) {
84 glyphs_copy[n] = glyphs[n];
85 glyphs_copy[n].x += x;
86 glyphs_copy[n].y += y;
88 cairo_show_glyphs (cr, glyphs_copy, num_glyphs);
96 cairo_perf_timer_stop ();
98 cairo_glyph_free (glyphs);
99 cairo_glyph_free (glyphs_copy);
101 return cairo_perf_timer_elapsed ();
105 count_glyphs (double font_size,
106 cairo_antialias_t antialias,
107 cairo_t *cr, int width, int height)
109 const char text[] = "the jay, pig, fox, zebra and my wolves quack";
110 cairo_scaled_font_t *scaled_font;
111 cairo_glyph_t *glyphs = NULL;
112 cairo_text_extents_t extents;
113 cairo_font_options_t *options;
114 cairo_status_t status;
116 int glyphs_per_line, lines_per_loop;
118 options = cairo_font_options_create ();
119 cairo_font_options_set_antialias (options, antialias);
120 cairo_set_font_options (cr, options);
121 cairo_font_options_destroy (options);
123 cairo_select_font_face (cr,
125 CAIRO_FONT_SLANT_NORMAL,
126 CAIRO_FONT_WEIGHT_NORMAL);
127 cairo_set_font_size (cr, font_size);
128 scaled_font = cairo_get_scaled_font (cr);
129 status = cairo_scaled_font_text_to_glyphs (scaled_font, 0., 0.,
131 &glyphs, &num_glyphs,
137 cairo_scaled_font_glyph_extents (scaled_font,
140 cairo_glyph_free (glyphs);
142 glyphs_per_line = num_glyphs * width / extents.width + 1;
143 lines_per_loop = height / extents.height + 1;
144 return glyphs_per_line * lines_per_loop / 1000.; /* kiloglyphs */
147 #define DECL(name,size, aa) \
148 static cairo_time_t \
149 do_glyphs##name (cairo_t *cr, int width, int height, int loops) \
151 return do_glyphs (size, aa, cr, width, height, loops); \
155 count_glyphs##name (cairo_t *cr, int width, int height) \
157 return count_glyphs (size, aa, cr, width, height); \
160 DECL(8, 8, CAIRO_ANTIALIAS_GRAY)
161 DECL(10, 10, CAIRO_ANTIALIAS_GRAY)
162 DECL(12, 12, CAIRO_ANTIALIAS_GRAY)
163 DECL(16, 16, CAIRO_ANTIALIAS_GRAY)
164 DECL(20, 20, CAIRO_ANTIALIAS_GRAY)
165 DECL(24, 24, CAIRO_ANTIALIAS_GRAY)
166 DECL(32, 32, CAIRO_ANTIALIAS_GRAY)
167 DECL(40, 40, CAIRO_ANTIALIAS_GRAY)
168 DECL(48, 48, CAIRO_ANTIALIAS_GRAY)
170 DECL(8ca, 8, CAIRO_ANTIALIAS_SUBPIXEL)
171 DECL(48ca, 48, CAIRO_ANTIALIAS_SUBPIXEL)
173 DECL(8mono, 8, CAIRO_ANTIALIAS_NONE)
174 DECL(48mono, 48, CAIRO_ANTIALIAS_NONE)
177 glyphs_enabled (cairo_perf_t *perf)
179 return cairo_perf_can_run (perf, "glyphs", NULL);
183 glyphs (cairo_perf_t *perf, cairo_t *cr, int width, int height)
185 cairo_perf_cover_sources_and_operators (perf, "glyphs8mono", do_glyphs8mono, count_glyphs8mono);
186 cairo_perf_cover_sources_and_operators (perf, "glyphs8", do_glyphs8, count_glyphs8);
187 cairo_perf_cover_sources_and_operators (perf, "glyphs8ca", do_glyphs8ca, count_glyphs8ca);
189 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
190 cairo_set_source_rgb (cr, 0, 0, 0);
192 cairo_perf_run (perf, "glyphs8", do_glyphs8, count_glyphs8);
193 cairo_perf_run (perf, "glyphs10", do_glyphs10, count_glyphs10);
194 cairo_perf_run (perf, "glyphs12", do_glyphs12, count_glyphs12);
195 cairo_perf_run (perf, "glyphs16", do_glyphs16, count_glyphs16);
196 cairo_perf_run (perf, "glyphs20", do_glyphs20, count_glyphs20);
197 cairo_perf_run (perf, "glyphs24", do_glyphs24, count_glyphs24);
198 cairo_perf_run (perf, "glyphs32", do_glyphs32, count_glyphs32);
199 cairo_perf_run (perf, "glyphs40", do_glyphs40, count_glyphs40);
200 cairo_perf_run (perf, "glyphs48", do_glyphs48, count_glyphs48);
202 cairo_perf_cover_sources_and_operators (perf, "glyphs48mono", do_glyphs48mono, count_glyphs48mono);
203 cairo_perf_cover_sources_and_operators (perf, "glyphs48", do_glyphs48, count_glyphs48);
204 cairo_perf_cover_sources_and_operators (perf, "glyphs48ca", do_glyphs48ca, count_glyphs48ca);