Upload Tizen2.0 source
[framework/graphics/cairo.git] / test / paint-source-alpha.c
1 /*
2  * Copyright © 2005 Red Hat, Inc.
3  * Copyright © 2006 Red Hat, Inc.
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  * Red Hat, Inc. not be used in advertising or publicity pertaining to
11  * distribution of the software without specific, written prior
12  * permission. Red Hat, Inc. 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  * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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: Carl D. Worth <cworth@cworth.org>
25  */
26
27 #include "cairo-test.h"
28
29 static cairo_test_status_t
30 draw (cairo_t *cr, int width, int height)
31 {
32     cairo_surface_t *surface;
33     uint32_t data[16] = {
34         0x80808080, 0x80808080,         0x80800000, 0x80800000,
35         0x80808080, 0x80808080,         0x80800000, 0x80800000,
36
37         0x80008000, 0x80008000,         0x80000080, 0x80000080,
38         0x80008000, 0x80008000,         0x80000080, 0x80000080
39     };
40
41     surface = cairo_image_surface_create_for_data ((unsigned char *) data,
42                                                    CAIRO_FORMAT_ARGB32, 4, 4, 16);
43
44     cairo_test_paint_checkered (cr);
45
46     cairo_scale (cr, 4, 4);
47
48     cairo_set_source_surface (cr, surface, 2 , 2);
49     cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
50     cairo_paint (cr);
51
52     cairo_surface_finish (surface); /* data will go out of scope */
53     cairo_surface_destroy (surface);
54
55     return CAIRO_TEST_SUCCESS;
56 }
57
58 CAIRO_TEST (paint_source_alpha,
59             "Simple test of cairo_paint with a source surface with non-opaque alpha",
60             "paint, alpha", /* keywords */
61             NULL, /* requirements */
62             32, 32,
63             NULL, draw)