Upload Tizen2.0 source
[framework/graphics/cairo.git] / test / clip-intersect.c
1 /*
2  * Copyright 2009 Chris Wilson
3  * Copyright 2011 Intel Corporation
4  *
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  * Chris Wilson not be used in advertising or publicity pertaining to
11  * distribution of the software without specific, written prior
12  * permission. Chris Wilson makes no representations about the
13  * suitability of this software for any purpose.  It is provided "as
14  * is" without express or implied warranty.
15  *
16  * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS, IN NO EVENT SHALL CHRIS WILSON 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.
23  *
24  * Author: Chris Wilson <chris@chris-wilson.co.uk>
25  */
26
27 #include "cairo-test.h"
28
29 #define WIDTH 20
30 #define HEIGHT 20
31
32 static void clip_mask (cairo_t *cr)
33 {
34     cairo_move_to (cr, 10, 0);
35     cairo_line_to (cr, 0, 10);
36     cairo_line_to (cr, 10, 20);
37     cairo_line_to (cr, 20, 10);
38     cairo_clip (cr);
39 }
40
41 static cairo_test_status_t
42 draw (cairo_t *cr, int width, int height)
43 {
44     cairo_set_source_rgb (cr, 1, 1, 1);
45     cairo_paint (cr);
46
47     clip_mask (cr);
48     cairo_set_source_rgb (cr, 0, 1, 0);
49     cairo_paint (cr);
50     cairo_reset_clip (cr);
51
52     cairo_set_source_rgb (cr, 1, 0, 0);
53
54     cairo_rectangle (cr, 0, 0, 4, 4);
55     cairo_clip (cr);
56     clip_mask (cr);
57     cairo_paint (cr);
58     cairo_reset_clip (cr);
59
60     cairo_rectangle (cr, 20, 0, -4, 4);
61     cairo_clip (cr);
62     clip_mask (cr);
63     cairo_paint (cr);
64     cairo_reset_clip (cr);
65
66     cairo_rectangle (cr, 20, 20, -4, -4);
67     cairo_clip (cr);
68     clip_mask (cr);
69     cairo_paint (cr);
70     cairo_reset_clip (cr);
71
72     cairo_rectangle (cr, 0, 20, 4, -4);
73     cairo_clip (cr);
74     clip_mask (cr);
75     cairo_paint (cr);
76     cairo_reset_clip (cr);
77
78     cairo_set_source_rgb (cr, 0, 0, 1);
79
80     cairo_rectangle (cr, 8, 8, 4, 4);
81     cairo_clip (cr);
82     clip_mask (cr);
83     cairo_paint (cr);
84     cairo_reset_clip (cr);
85
86     return CAIRO_TEST_SUCCESS;
87 }
88
89 CAIRO_TEST (clip_intersect,
90             "Tests intersection of a simple clip with a clip-mask",
91             "clip, paint", /* keywords */
92             NULL, /* requirements */
93             WIDTH, HEIGHT,
94             NULL, draw)