2 * Copyright © 2006 Red Hat, Inc.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Author: Carl D. Worth <cworth@cworth.org>
27 #include "cairo-perf.h"
29 /* This test case is designed to illustrate a performance bug in
30 * drawing very long lines, where most of the line is out of bounds of
31 * the destination surface, (but some portion of the line is
32 * visibile). These results are in the "long-lines-uncropped" report.
34 * For comparison, this test also renders the visible portions of the
35 * same lines, (this is the "long-lines-cropped" report).
39 LONG_LINES_CROPPED = 0x1,
40 LONG_LINES_ONCE = 0x2,
43 #define LONG_FACTOR 50.0
46 do_long_lines (cairo_t *cr, int width, int height, int loops, long_lines_crop_t crop)
49 double x, y, dx, dy, min_x, min_y, max_x, max_y;
50 double outer_width, outer_height;
54 cairo_translate (cr, width / 2, height / 2);
56 if (crop & LONG_LINES_CROPPED) {
58 outer_height = height;
59 cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); /* green */
61 outer_width = LONG_FACTOR * width;
62 outer_height = LONG_FACTOR * height;
63 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); /* red */
66 min_x = x = - outer_width / 2.0;
67 min_y = y = - outer_height / 2.0;
68 max_x = outer_width / 2.0;
69 max_y = outer_height / 2.0;
70 dx = outer_width / NUM_LINES;
71 dy = outer_height / NUM_LINES;
73 cairo_perf_timer_start ();
74 cairo_perf_set_thread_aware (cr, FALSE);
78 cairo_perf_set_thread_aware (cr, TRUE);
79 for (i = 0; i <= NUM_LINES; i++) {
80 cairo_move_to (cr, 0, 0);
81 cairo_line_to (cr, x, min_y);
82 if ((crop & LONG_LINES_ONCE) == 0)
85 cairo_move_to (cr, 0, 0);
86 cairo_line_to (cr, x, max_y);
87 if ((crop & LONG_LINES_ONCE) == 0)
90 cairo_move_to (cr, 0, 0);
91 cairo_line_to (cr, min_x, y);
92 if ((crop & LONG_LINES_ONCE) == 0)
95 cairo_move_to (cr, 0, 0);
96 cairo_line_to (cr, max_x, y);
97 if ((crop & LONG_LINES_ONCE) == 0)
103 if (crop & LONG_LINES_ONCE)
107 cairo_perf_timer_stop ();
111 return cairo_perf_timer_elapsed ();
115 long_lines_uncropped (cairo_t *cr, int width, int height, int loops)
117 return do_long_lines (cr, width, height, loops, 0);
121 long_lines_uncropped_once (cairo_t *cr, int width, int height, int loops)
123 return do_long_lines (cr, width, height, loops, LONG_LINES_ONCE);
127 long_lines_cropped (cairo_t *cr, int width, int height, int loops)
129 return do_long_lines (cr, width, height, loops, LONG_LINES_CROPPED);
133 long_lines_cropped_once (cairo_t *cr, int width, int height, int loops)
135 return do_long_lines (cr, width, height, loops, LONG_LINES_CROPPED | LONG_LINES_ONCE);
139 long_lines_enabled (cairo_perf_t *perf)
141 return cairo_perf_can_run (perf, "long-lines", NULL);
145 long_lines (cairo_perf_t *perf, cairo_t *cr, int width, int height)
147 cairo_perf_run (perf, "long-lines-uncropped", long_lines_uncropped, NULL);
148 cairo_perf_run (perf, "long-lines-uncropped-once", long_lines_uncropped_once, NULL);
149 cairo_perf_run (perf, "long-lines-cropped", long_lines_cropped, NULL);
150 cairo_perf_run (perf, "long-lines-cropped-once", long_lines_cropped_once, NULL);