Tizen 2.0 Release
[framework/graphics/cairo.git] / test / device-offset-scale.c
1 /*
2  * Copyright © 2008 Mozilla Corporation
3  *
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without
6  * fee, provided that the above copyright notice appear in all copies
7  * and that both that copyright notice and this permission notice
8  * appear in supporting documentation, and that the name of
9  * Mozilla Corporation not be used in advertising or publicity pertaining to
10  * distribution of the software without specific, written prior
11  * permission. Mozilla Corporation makes no representations about the
12  * suitability of this software for any purpose.  It is provided "as
13  * is" without express or implied warranty.
14  *
15  * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION BE LIABLE FOR ANY SPECIAL,
18  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Authors: Michael Ventnor, Jeff Muizelaar
24  */
25
26 #include "cairo-test.h"
27
28 #define WIDTH 20
29 #define HEIGHT 20
30
31 static cairo_test_status_t
32 draw (cairo_t *cr, int width, int height)
33 {
34     cairo_surface_t *second;
35     cairo_t *second_cr;
36
37     /* fill with black so we don't need an rgb test case */
38     cairo_set_source_rgb (cr, 0, 0, 0);
39     cairo_paint (cr);
40
41     cairo_scale (cr, 0.5, 0.5);
42
43     /* draw the first rectangle */
44     cairo_set_source_rgb (cr, 0, 0, 0.4);
45     cairo_rectangle (cr, 6, 6, 10, 10);
46     cairo_fill (cr);
47
48     /* adjust the offset so that the second rectangle will fit on the surface */
49     second = cairo_image_surface_create (CAIRO_FORMAT_A8, 10, 10);
50     cairo_surface_set_device_offset (second, -6, -6);
51
52     /* draw the second rectangle:
53      * this rectangle should end up in the same place as the rectangle above
54      * independent of the device offset of the surface it is painted on*/
55     second_cr = cairo_create (second);
56     cairo_surface_destroy (second);
57     cairo_rectangle (second_cr, 6, 6, 10, 10);
58     cairo_fill (second_cr);
59
60     /* paint the second rectangle on top of the first rectangle */
61     cairo_set_source_rgb (cr, 0.5, 0.5, 0);
62     cairo_mask_surface (cr, cairo_get_target (second_cr), 0, 0);
63     cairo_destroy (second_cr);
64
65     return CAIRO_TEST_SUCCESS;
66 }
67
68 CAIRO_TEST (device_offset_scale,
69             "Test that the device-offset transform is transformed by the ctm.",
70             "device-offset", /* keywords */
71             NULL, /* requirements */
72             WIDTH, HEIGHT,
73             NULL, draw)