1
/*
2
 * Copyright © 2006 Jeff Muizelaar <jeff@infidigm.net>
3
 * Copyright © 2006 Red Hat, Inc.
4
 *
5
 * Permission is hereby granted, free of charge, to any person
6
 * obtaining a copy of this software and associated documentation
7
 * files (the "Software"), to deal in the Software without
8
 * restriction, including without limitation the rights to use, copy,
9
 * modify, merge, publish, distribute, sublicense, and/or sell copies
10
 * of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 *
25
 * Authors: Jeff Muizelaar <jeff@infidigm.net>
26
 *          Carl Worth <cworth@cworth.org>
27
 */
28

            
29
#include "cairo-perf.h"
30

            
31
static cairo_time_t
32
do_unaligned_clip (cairo_t *cr, int width, int height, int loops)
33
{
34
    cairo_perf_timer_start ();
35

            
36
    while (loops--) {
37
	cairo_save (cr);
38

            
39
	/* First a triangular clip that obviously isn't along device-pixel
40
	 * boundaries. */
41
	cairo_move_to (cr, 50, 50);
42
	cairo_line_to (cr, 50, 90);
43
	cairo_line_to (cr, 90, 90);
44
	cairo_close_path (cr);
45
	cairo_clip (cr);
46

            
47
	/* Then a rectangular clip that would be but for the non-integer
48
	 * scaling. */
49
	cairo_scale (cr, 1.1, 1.1);
50
	cairo_rectangle (cr, 55, 55, 35, 35);
51
	cairo_clip (cr);
52

            
53
	/* And paint something to force the clip to be evaluated. */
54
	cairo_paint (cr);
55

            
56
	cairo_restore (cr);
57
    }
58
    cairo_perf_timer_stop ();
59

            
60
    return cairo_perf_timer_elapsed ();
61
}
62

            
63
cairo_bool_t
64
unaligned_clip_enabled (cairo_perf_t *perf)
65
{
66
    return cairo_perf_can_run (perf, "unaligned-clip", NULL);
67
}
68

            
69
void
70
unaligned_clip (cairo_perf_t *perf, cairo_t *cr, int width, int height)
71
{
72
    cairo_perf_run (perf, "unaligned-clip", do_unaligned_clip, NULL);
73
}