beta-0.89.2
[luatex.git] / source / libs / cairo / cairo-src / src / test-compositor-surface.c
blob1cc5f69212037720b3bcb48b09a80c6fea4c49f7
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
32 * Contributor(s):
33 * Chris Wilson <chris@chris-wilson.co.uk>
36 #include "cairoint.h"
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;
52 cairo_surface_t *
53 test_compositor_surface_create (const cairo_compositor_t *compositor,
54 cairo_content_t content,
55 int width,
56 int height)
58 test_compositor_surface_t *surface;
59 pixman_image_t *pixman_image;
60 pixman_format_code_t pixman_format;
62 switch (content) {
63 case CAIRO_CONTENT_ALPHA:
64 pixman_format = PIXMAN_a8;
65 break;
66 case CAIRO_CONTENT_COLOR:
67 pixman_format = PIXMAN_x8r8g8b8;
68 break;
69 case CAIRO_CONTENT_COLOR_ALPHA:
70 pixman_format = PIXMAN_a8r8g8b8;
71 break;
72 default:
73 return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT));
76 pixman_image = pixman_image_create_bits (pixman_format, width, height,
77 NULL, 0);
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,
89 NULL, /* device */
90 content);
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,
101 int width,
102 int height)
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,
112 cairo_operator_t op,
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,
119 clip);
122 static cairo_int_status_t
123 test_compositor_surface_mask (void *_surface,
124 cairo_operator_t op,
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,
132 clip);
135 static cairo_int_status_t
136 test_compositor_surface_stroke (void *_surface,
137 cairo_operator_t op,
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,
143 double tolerance,
144 cairo_antialias_t antialias,
145 const cairo_clip_t *clip)
147 test_compositor_surface_t *surface = _surface;
148 if (antialias == CAIRO_ANTIALIAS_DEFAULT)
149 antialias = CAIRO_ANTIALIAS_BEST;
150 return _cairo_compositor_stroke (surface->base.compositor,
151 _surface, op, source,
152 path, style, ctm, ctm_inverse,
153 tolerance, antialias,
154 clip);
157 static cairo_int_status_t
158 test_compositor_surface_fill (void *_surface,
159 cairo_operator_t op,
160 const cairo_pattern_t *source,
161 const cairo_path_fixed_t *path,
162 cairo_fill_rule_t fill_rule,
163 double tolerance,
164 cairo_antialias_t antialias,
165 const cairo_clip_t *clip)
167 test_compositor_surface_t *surface = _surface;
168 if (antialias == CAIRO_ANTIALIAS_DEFAULT)
169 antialias = CAIRO_ANTIALIAS_BEST;
170 return _cairo_compositor_fill (surface->base.compositor,
171 _surface, op, source,
172 path, fill_rule, tolerance, antialias,
173 clip);
176 static cairo_int_status_t
177 test_compositor_surface_glyphs (void *_surface,
178 cairo_operator_t op,
179 const cairo_pattern_t *source,
180 cairo_glyph_t *glyphs,
181 int num_glyphs,
182 cairo_scaled_font_t *scaled_font,
183 const cairo_clip_t *clip)
185 test_compositor_surface_t *surface = _surface;
186 return _cairo_compositor_glyphs (surface->base.compositor,
187 _surface, op, source,
188 glyphs, num_glyphs, scaled_font,
189 clip);
192 static const cairo_surface_backend_t test_compositor_surface_backend = {
193 CAIRO_SURFACE_TYPE_IMAGE,
194 _cairo_image_surface_finish,
195 _cairo_default_context_create,
197 test_compositor_surface_create_similar,
198 NULL, /* create similar image */
199 _cairo_image_surface_map_to_image,
200 _cairo_image_surface_unmap_image,
202 _cairo_image_surface_source,
203 _cairo_image_surface_acquire_source_image,
204 _cairo_image_surface_release_source_image,
205 _cairo_image_surface_snapshot,
207 NULL, /* copy_page */
208 NULL, /* show_page */
210 _cairo_image_surface_get_extents,
211 _cairo_image_surface_get_font_options,
213 NULL, /* flush */
214 NULL, /* mark_dirty_rectangle */
216 test_compositor_surface_paint,
217 test_compositor_surface_mask,
218 test_compositor_surface_stroke,
219 test_compositor_surface_fill,
220 NULL, /* fill/stroke */
221 test_compositor_surface_glyphs,
224 static const cairo_compositor_t *
225 get_fallback_compositor (void)
227 return &_cairo_fallback_compositor;
230 cairo_surface_t *
231 _cairo_test_fallback_compositor_surface_create (cairo_content_t content,
232 int width,
233 int height)
235 return test_compositor_surface_create (get_fallback_compositor(),
236 content, width, height);
239 cairo_surface_t *
240 _cairo_test_mask_compositor_surface_create (cairo_content_t content,
241 int width,
242 int height)
244 return test_compositor_surface_create (_cairo_image_mask_compositor_get(),
245 content, width, height);
248 cairo_surface_t *
249 _cairo_test_traps_compositor_surface_create (cairo_content_t content,
250 int width,
251 int height)
253 return test_compositor_surface_create (_cairo_image_traps_compositor_get(),
254 content, width, height);
257 cairo_surface_t *
258 _cairo_test_spans_compositor_surface_create (cairo_content_t content,
259 int width,
260 int height)
262 return test_compositor_surface_create (_cairo_image_spans_compositor_get(),
263 content, width, height);