Opensource Compliance Issue.
[platform/core/graphics/cairo.git] / test / mask-transformed-similar.c
1 /*
2  * Copyright 2008 Kai-Uwe Behrmann
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  * Kai-Uwe Behrmann not be used in advertising or publicity pertaining to
10  * distribution of the software without specific, written prior
11  * permission. Kai-Uwe Behrmann 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  * KAI_UWE BEHRMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL KAI_UWE BEHRMANN 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  * Author: Kai-Uwe Behrmann <ku.b@gmx.de>
24  *         Chris Wilson <chris@chris-wilson.co.uk>
25  */
26
27 #include "cairo-test.h"
28
29 static const char png_filename[] = "romedalen.png";
30
31 static cairo_surface_t *
32 create_mask (cairo_t *dst, int width, int height)
33 {
34     cairo_surface_t *mask;
35     cairo_t *cr;
36
37     mask = cairo_surface_create_similar (cairo_get_target (dst),
38                                          CAIRO_CONTENT_ALPHA,
39                                          width, height);
40     cr = cairo_create (mask);
41     cairo_surface_destroy (mask);
42
43     cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
44     cairo_rectangle (cr, width/4, height/4, width/2, height/2);
45     cairo_fill (cr);
46
47     mask = cairo_surface_reference (cairo_get_target (cr));
48     cairo_destroy (cr);
49
50     return mask;
51 }
52
53 static cairo_test_status_t
54 draw (cairo_t *cr, int width, int height)
55 {
56     const cairo_test_context_t *ctx = cairo_test_get_context (cr);
57     cairo_surface_t *image, *mask;
58
59     image = cairo_test_create_surface_from_png (ctx, png_filename);
60     mask = create_mask (cr, 40, 40);
61
62     /* opaque background */
63     cairo_paint (cr);
64
65     /* center */
66     cairo_translate (cr,
67                      (width - cairo_image_surface_get_width (image)) / 2.,
68                      (height - cairo_image_surface_get_height (image)) / 2.);
69
70     /* rotate 30 degree around the center */
71     cairo_translate (cr, width/2., height/2.);
72     cairo_rotate (cr, -30 * 2 * M_PI / 360);
73     cairo_translate (cr, -width/2., -height/2.);
74
75     /* place the image on our surface */
76     cairo_set_source_surface (cr, image, 0, 0);
77
78     /* reset the drawing matrix */
79     cairo_identity_matrix (cr);
80
81     /* fill nicely */
82     cairo_scale (cr, width / 40., height / 40.);
83
84     /* apply the mask */
85     cairo_mask_surface (cr, mask, 0, 0);
86
87     cairo_surface_destroy (mask);
88     cairo_surface_destroy (image);
89
90     return CAIRO_TEST_SUCCESS;
91 }
92
93 CAIRO_TEST (mask_transformed_similar,
94             "Test that cairo_mask() is affected properly by the CTM and not the image",
95             "mask", /* keywords */
96             NULL, /* requirements */
97             80, 80,
98             NULL, draw)