2 * Copyright 2009 Benjamin Otte
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Author: Benjamin Otte <otte@gnome.org>
27 #include "cairo-test.h"
38 static cairo_surface_t *
39 create_surface (cairo_t *target, cairo_content_t content, surface_type_t type)
41 cairo_surface_t *surface;
44 surface = cairo_surface_create_similar (cairo_get_target (target),
51 cr = cairo_create (surface);
52 cairo_surface_destroy (surface);
54 cairo_set_source_rgb (cr, 0.75, 0, 0);
60 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
64 surface = cairo_surface_reference (cairo_get_target (cr));
71 paint (cairo_t *cr, cairo_surface_t *surface)
73 cairo_set_source_surface (cr, surface, 0, 0);
78 fill (cairo_t *cr, cairo_surface_t *surface)
80 cairo_set_source_surface (cr, surface, 0, 0);
81 cairo_rectangle (cr, -SPACE, -SPACE, SIZE + 2 * SPACE, SIZE + 2 * SPACE);
86 stroke (cairo_t *cr, cairo_surface_t *surface)
88 cairo_set_source_surface (cr, surface, 0, 0);
89 cairo_set_line_width (cr, 2.0);
90 cairo_rectangle (cr, 1, 1, SIZE - 2, SIZE - 2);
95 mask (cairo_t *cr, cairo_surface_t *surface)
97 cairo_set_source_rgb (cr, 0, 0, 0.75);
98 cairo_mask_surface (cr, surface, 0, 0);
102 mask_self (cairo_t *cr, cairo_surface_t *surface)
104 cairo_set_source_surface (cr, surface, 0, 0);
105 cairo_mask_surface (cr, surface, 0, 0);
109 glyphs (cairo_t *cr, cairo_surface_t *surface)
111 cairo_set_source_surface (cr, surface, 0, 0);
112 cairo_select_font_face (cr,
114 CAIRO_FONT_SLANT_NORMAL,
115 CAIRO_FONT_WEIGHT_NORMAL);
116 cairo_set_font_size (cr, 16);
117 cairo_translate (cr, 0, SIZE);
118 cairo_show_text (cr, "C");
121 typedef void (* operation_t) (cairo_t *cr, cairo_surface_t *surface);
122 static operation_t operations[] = {
131 static cairo_test_status_t
132 draw (cairo_t *cr, int width, int height)
134 cairo_content_t contents[] = { CAIRO_CONTENT_COLOR_ALPHA, CAIRO_CONTENT_COLOR, CAIRO_CONTENT_ALPHA };
135 unsigned int content, type, ops;
137 cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
139 cairo_translate (cr, SPACE, SPACE);
141 for (type = 0; type <= PAINTED; type++) {
142 for (content = 0; content < ARRAY_LENGTH (contents); content++) {
143 cairo_surface_t *surface;
145 surface = create_surface (cr, contents[content], type);
148 for (ops = 0; ops < ARRAY_LENGTH (operations); ops++) {
150 operations[ops] (cr, surface);
152 cairo_translate (cr, 0, SIZE + SPACE);
155 cairo_translate (cr, SIZE + SPACE, 0);
157 cairo_surface_destroy (surface);
161 return CAIRO_TEST_SUCCESS;
164 CAIRO_TEST (clear_source,
165 "Check painting with cleared surfaces works as expected",
167 NULL, /* requirements */
168 (SIZE + SPACE) * 9 + SPACE, ARRAY_LENGTH (operations) * (SIZE + SPACE) + SPACE,