2 * Copyright 2008 Kai-Uwe Behrmann
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.
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.
23 * Author: Kai-Uwe Behrmann <ku.b@gmx.de>
24 * Chris Wilson <chris@chris-wilson.co.uk>
27 #include "cairo-test.h"
29 static const char png_filename[] = "romedalen.png";
31 static cairo_surface_t *
32 create_mask (cairo_t *dst, int width, int height)
34 cairo_surface_t *mask;
37 mask = cairo_surface_create_similar (cairo_get_target (dst),
40 cr = cairo_create (mask);
41 cairo_surface_destroy (mask);
43 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
44 cairo_rectangle (cr, width/4, height/4, width/2, height/2);
47 mask = cairo_surface_reference (cairo_get_target (cr));
53 static cairo_test_status_t
54 draw (cairo_t *cr, int width, int height)
56 const cairo_test_context_t *ctx = cairo_test_get_context (cr);
57 cairo_surface_t *image, *mask;
59 image = cairo_test_create_surface_from_png (ctx, png_filename);
60 mask = create_mask (cr, 40, 40);
62 /* opaque background */
67 (width - cairo_image_surface_get_width (image)) / 2.,
68 (height - cairo_image_surface_get_height (image)) / 2.);
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.);
75 /* place the image on our surface */
76 cairo_set_source_surface (cr, image, 0, 0);
78 /* reset the drawing matrix */
79 cairo_identity_matrix (cr);
82 cairo_scale (cr, width / 40., height / 40.);
85 cairo_mask_surface (cr, mask, 0, 0);
87 cairo_surface_destroy (mask);
88 cairo_surface_destroy (image);
90 return CAIRO_TEST_SUCCESS;
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 */