28f16ec84d013daf89862ea15f4ea40c56566c43
[platform/core/graphics/cairo.git] / test / clip-twice-rectangle.c
1 /*\r
2  * Copyright © 2010 Mozilla Corporation\r
3  * Copyright © 2010 Intel Corporation\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person\r
6  * obtaining a copy of this software and associated documentation\r
7  * files (the "Software"), to deal in the Software without\r
8  * restriction, including without limitation the rights to use, copy,\r
9  * modify, merge, publish, distribute, sublicense, and/or sell copies\r
10  * of the Software, and to permit persons to whom the Software is\r
11  * furnished to do so, subject to the following conditions:\r
12  *\r
13  * The above copyright notice and this permission notice shall be\r
14  * included in all copies or substantial portions of the Software.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
23  * SOFTWARE.\r
24  *\r
25  * Author: Chris Wilson <chris@chris-wilson.co.uk>\r
26  */\r
27 \r
28 #include "cairo-test.h"\r
29 \r
30 static cairo_test_status_t\r
31 draw (cairo_t *cr, int width, int height)\r
32 {\r
33     cairo_surface_t *mask;\r
34     cairo_t *cr2;\r
35 \r
36     cairo_set_source_rgb (cr, 0, 1, 0);\r
37     cairo_paint (cr);\r
38 \r
39     /* clip twice, note that the intersection is smaller then the extents */\r
40     cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);\r
41     cairo_rectangle (cr, 10, 10, 80, 80);\r
42     cairo_rectangle (cr, 20, 20, 60, 60);\r
43     cairo_clip (cr);\r
44 \r
45     cairo_rectangle (cr, 0, 40, 40, 30);\r
46     cairo_clip (cr);\r
47 \r
48     /* and exercise the bug found by Jeff Muizelaar */\r
49     mask = cairo_surface_create_similar (cairo_get_target (cr),\r
50                                          CAIRO_CONTENT_ALPHA,\r
51                                          width-20, height-20);\r
52     cr2 = cairo_create (mask);\r
53     cairo_surface_destroy (mask);\r
54 \r
55     cairo_set_source_rgba (cr2, 1, 1, 1, 1);\r
56     cairo_paint (cr2);\r
57 \r
58     cairo_set_source_rgb (cr, 1, 0, 0);\r
59     cairo_mask_surface (cr, cairo_get_target (cr2), 0, 0);\r
60     cairo_destroy (cr2);\r
61 \r
62     return CAIRO_TEST_SUCCESS;\r
63 }\r
64 \r
65 CAIRO_TEST (clip_twice_rectangle,\r
66             "Tests clipping twice using rectangles",\r
67             "clip", /* keywords */\r
68             NULL, /* requirements */\r
69             100, 100,\r
70             NULL, draw)\r