1 /* cairo - a vector graphics library with display and print output
3 * Copyright © 2011 Intel Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it either under the terms of the GNU Lesser General Public
7 * License version 2.1 as published by the Free Software Foundation
8 * (the "LGPL") or, at your option, under the terms of the Mozilla
9 * Public License Version 1.1 (the "MPL"). If you do not alter this
10 * notice, a recipient may use your version of this file under either
11 * the MPL or the LGPL.
13 * You should have received a copy of the LGPL along with this library
14 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
16 * You should have received a copy of the MPL along with this library
17 * in the file COPYING-MPL-1.1
19 * The contents of this file are subject to the Mozilla Public License
20 * Version 1.1 (the "License"); you may not use this file except in
21 * compliance with the License. You may obtain a copy of the License at
22 * http://www.mozilla.org/MPL/
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26 * the specific language governing rights and limitations.
28 * The Original Code is the cairo graphics library.
30 * The Initial Developer of the Original Code is Intel Corporation
33 * Chris Wilson <chris@chris-wilson.co.uk>
38 #include "test-compositor-surface-private.h"
40 #include "cairo-compositor-private.h"
41 #include "cairo-default-context-private.h"
42 #include "cairo-error-private.h"
43 #include "cairo-image-surface-private.h"
44 #include "cairo-surface-backend-private.h"
46 typedef struct _test_compositor_surface {
47 cairo_image_surface_t base;
48 } test_compositor_surface_t;
50 static const cairo_surface_backend_t test_compositor_surface_backend;
53 test_compositor_surface_create (const cairo_compositor_t *compositor,
54 cairo_content_t content,
58 test_compositor_surface_t *surface;
59 pixman_image_t *pixman_image;
60 pixman_format_code_t pixman_format;
63 case CAIRO_CONTENT_ALPHA:
64 pixman_format = PIXMAN_a8;
66 case CAIRO_CONTENT_COLOR:
67 pixman_format = PIXMAN_x8r8g8b8;
69 case CAIRO_CONTENT_COLOR_ALPHA:
70 pixman_format = PIXMAN_a8r8g8b8;
73 return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT));
76 pixman_image = pixman_image_create_bits (pixman_format, width, height,
78 if (unlikely (pixman_image == NULL))
79 return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
81 surface = malloc (sizeof (test_compositor_surface_t));
82 if (unlikely (surface == NULL)) {
83 pixman_image_unref (pixman_image);
84 return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
87 _cairo_surface_init (&surface->base.base,
88 &test_compositor_surface_backend,
91 _cairo_image_surface_init (&surface->base, pixman_image, pixman_format);
93 surface->base.compositor = compositor;
95 return &surface->base.base;
98 static cairo_surface_t *
99 test_compositor_surface_create_similar (void *abstract_surface,
100 cairo_content_t content,
104 test_compositor_surface_t *surface = abstract_surface;
106 return test_compositor_surface_create (surface->base.compositor,
107 content, width, height);
110 static cairo_int_status_t
111 test_compositor_surface_paint (void *_surface,
113 const cairo_pattern_t *source,
114 const cairo_clip_t *clip)
116 test_compositor_surface_t *surface = _surface;
117 return _cairo_compositor_paint (surface->base.compositor,
118 _surface, op, source,
122 static cairo_int_status_t
123 test_compositor_surface_mask (void *_surface,
125 const cairo_pattern_t *source,
126 const cairo_pattern_t *mask,
127 const cairo_clip_t *clip)
129 test_compositor_surface_t *surface = _surface;
130 return _cairo_compositor_mask (surface->base.compositor,
131 _surface, op, source, mask,
135 static cairo_int_status_t
136 test_compositor_surface_stroke (void *_surface,
138 const cairo_pattern_t *source,
139 const cairo_path_fixed_t *path,
140 const cairo_stroke_style_t *style,
141 const cairo_matrix_t *ctm,
142 const cairo_matrix_t *ctm_inverse,
144 cairo_antialias_t antialias,
145 const cairo_clip_t *clip)
147 test_compositor_surface_t *surface = _surface;
148 return _cairo_compositor_stroke (surface->base.compositor,
149 _surface, op, source,
150 path, style, ctm, ctm_inverse,
151 tolerance, antialias,
155 static cairo_int_status_t
156 test_compositor_surface_fill (void *_surface,
158 const cairo_pattern_t *source,
159 const cairo_path_fixed_t *path,
160 cairo_fill_rule_t fill_rule,
162 cairo_antialias_t antialias,
163 const cairo_clip_t *clip)
165 test_compositor_surface_t *surface = _surface;
166 return _cairo_compositor_fill (surface->base.compositor,
167 _surface, op, source,
168 path, fill_rule, tolerance, antialias,
172 static cairo_int_status_t
173 test_compositor_surface_glyphs (void *_surface,
175 const cairo_pattern_t *source,
176 cairo_glyph_t *glyphs,
178 cairo_scaled_font_t *scaled_font,
179 const cairo_clip_t *clip)
181 test_compositor_surface_t *surface = _surface;
182 return _cairo_compositor_glyphs (surface->base.compositor,
183 _surface, op, source,
184 glyphs, num_glyphs, scaled_font,
188 static const cairo_surface_backend_t test_compositor_surface_backend = {
189 CAIRO_SURFACE_TYPE_IMAGE,
190 _cairo_image_surface_finish,
191 _cairo_default_context_create,
193 test_compositor_surface_create_similar,
194 NULL, /* create similar image */
195 _cairo_image_surface_map_to_image,
196 _cairo_image_surface_unmap_image,
198 _cairo_image_surface_source,
199 _cairo_image_surface_acquire_source_image,
200 _cairo_image_surface_release_source_image,
201 _cairo_image_surface_snapshot,
203 NULL, /* copy_page */
204 NULL, /* show_page */
206 _cairo_image_surface_get_extents,
207 _cairo_image_surface_get_font_options,
210 NULL, /* mark_dirty_rectangle */
212 test_compositor_surface_paint,
213 test_compositor_surface_mask,
214 test_compositor_surface_stroke,
215 test_compositor_surface_fill,
216 NULL, /* fill/stroke */
217 test_compositor_surface_glyphs,
220 static const cairo_compositor_t *
221 get_fallback_compositor (void)
223 return &_cairo_fallback_compositor;
227 _cairo_test_fallback_compositor_surface_create (cairo_content_t content,
231 return test_compositor_surface_create (get_fallback_compositor(),
232 content, width, height);
236 _cairo_test_mask_compositor_surface_create (cairo_content_t content,
240 return test_compositor_surface_create (_cairo_image_mask_compositor_get(),
241 content, width, height);
245 _cairo_test_traps_compositor_surface_create (cairo_content_t content,
249 return test_compositor_surface_create (_cairo_image_traps_compositor_get(),
250 content, width, height);
254 _cairo_test_spans_compositor_surface_create (cairo_content_t content,
258 return test_compositor_surface_create (_cairo_image_spans_compositor_get(),
259 content, width, height);