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>
39 #include "test-null-compositor-surface.h"
41 #include "cairo-compositor-private.h"
42 #include "cairo-default-context-private.h"
43 #include "cairo-error-private.h"
44 #include "cairo-image-surface-private.h"
45 #include "cairo-surface-backend-private.h"
46 #include "cairo-spans-compositor-private.h"
47 #include "cairo-spans-private.h"
49 typedef struct _test_compositor_surface
{
50 cairo_image_surface_t base
;
51 } test_compositor_surface_t
;
53 static const cairo_surface_backend_t test_compositor_surface_backend
;
55 static cairo_surface_t
*
56 test_compositor_surface_create (const cairo_compositor_t
*compositor
,
57 cairo_content_t content
,
61 test_compositor_surface_t
*surface
;
62 pixman_image_t
*pixman_image
;
63 pixman_format_code_t pixman_format
;
66 case CAIRO_CONTENT_ALPHA
:
67 pixman_format
= PIXMAN_a8
;
69 case CAIRO_CONTENT_COLOR
:
70 pixman_format
= PIXMAN_x8r8g8b8
;
72 case CAIRO_CONTENT_COLOR_ALPHA
:
73 pixman_format
= PIXMAN_a8r8g8b8
;
76 return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT
));
79 pixman_image
= pixman_image_create_bits (pixman_format
, width
, height
,
81 if (unlikely (pixman_image
== NULL
))
82 return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY
));
84 surface
= malloc (sizeof (test_compositor_surface_t
));
85 if (unlikely (surface
== NULL
)) {
86 pixman_image_unref (pixman_image
);
87 return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY
));
90 _cairo_surface_init (&surface
->base
.base
,
91 &test_compositor_surface_backend
,
94 _cairo_image_surface_init (&surface
->base
, pixman_image
, pixman_format
);
96 surface
->base
.compositor
= compositor
;
98 return &surface
->base
.base
;
101 static cairo_surface_t
*
102 test_compositor_surface_create_similar (void *abstract_surface
,
103 cairo_content_t content
,
107 test_compositor_surface_t
*surface
= abstract_surface
;
109 return test_compositor_surface_create (surface
->base
.compositor
,
110 content
, width
, height
);
113 static cairo_int_status_t
114 test_compositor_surface_paint (void *_surface
,
116 const cairo_pattern_t
*source
,
117 const cairo_clip_t
*clip
)
119 test_compositor_surface_t
*surface
= _surface
;
120 return _cairo_compositor_paint (surface
->base
.compositor
,
121 _surface
, op
, source
,
125 static cairo_int_status_t
126 test_compositor_surface_mask (void *_surface
,
128 const cairo_pattern_t
*source
,
129 const cairo_pattern_t
*mask
,
130 const cairo_clip_t
*clip
)
132 test_compositor_surface_t
*surface
= _surface
;
133 return _cairo_compositor_mask (surface
->base
.compositor
,
134 _surface
, op
, source
, mask
,
138 static cairo_int_status_t
139 test_compositor_surface_stroke (void *_surface
,
141 const cairo_pattern_t
*source
,
142 const cairo_path_fixed_t
*path
,
143 const cairo_stroke_style_t
*style
,
144 const cairo_matrix_t
*ctm
,
145 const cairo_matrix_t
*ctm_inverse
,
147 cairo_antialias_t antialias
,
148 const cairo_clip_t
*clip
)
150 test_compositor_surface_t
*surface
= _surface
;
151 return _cairo_compositor_stroke (surface
->base
.compositor
,
152 _surface
, op
, source
,
153 path
, style
, ctm
, ctm_inverse
,
154 tolerance
, antialias
,
158 static cairo_int_status_t
159 test_compositor_surface_fill (void *_surface
,
161 const cairo_pattern_t
*source
,
162 const cairo_path_fixed_t
*path
,
163 cairo_fill_rule_t fill_rule
,
165 cairo_antialias_t antialias
,
166 const cairo_clip_t
*clip
)
168 test_compositor_surface_t
*surface
= _surface
;
169 return _cairo_compositor_fill (surface
->base
.compositor
,
170 _surface
, op
, source
,
171 path
, fill_rule
, tolerance
, antialias
,
175 static cairo_int_status_t
176 test_compositor_surface_glyphs (void *_surface
,
178 const cairo_pattern_t
*source
,
179 cairo_glyph_t
*glyphs
,
181 cairo_scaled_font_t
*scaled_font
,
182 const cairo_clip_t
*clip
)
184 test_compositor_surface_t
*surface
= _surface
;
185 return _cairo_compositor_glyphs (surface
->base
.compositor
,
186 _surface
, op
, source
,
187 glyphs
, num_glyphs
, scaled_font
,
191 static const cairo_surface_backend_t test_compositor_surface_backend
= {
192 CAIRO_SURFACE_TYPE_IMAGE
,
193 _cairo_image_surface_finish
,
194 _cairo_default_context_create
,
196 test_compositor_surface_create_similar
,
197 NULL
, /* create similar image */
198 _cairo_image_surface_map_to_image
,
199 _cairo_image_surface_unmap_image
,
201 _cairo_image_surface_source
,
202 _cairo_image_surface_acquire_source_image
,
203 _cairo_image_surface_release_source_image
,
206 NULL
, /* copy_page */
207 NULL
, /* show_page */
209 _cairo_image_surface_get_extents
,
210 _cairo_image_surface_get_font_options
,
213 NULL
, /* mark_dirty_rectangle */
215 test_compositor_surface_paint
,
216 test_compositor_surface_mask
,
217 test_compositor_surface_stroke
,
218 test_compositor_surface_fill
,
219 NULL
, /* fill/stroke */
220 test_compositor_surface_glyphs
,
223 static cairo_int_status_t
224 acquire (void *abstract_dst
)
226 return CAIRO_STATUS_SUCCESS
;
229 static cairo_int_status_t
230 release (void *abstract_dst
)
232 return CAIRO_STATUS_SUCCESS
;
235 static cairo_int_status_t
236 set_clip_region (void *_surface
,
237 cairo_region_t
*region
)
239 return CAIRO_STATUS_SUCCESS
;
242 static cairo_surface_t
*
243 pattern_to_surface (cairo_surface_t
*dst
,
244 const cairo_pattern_t
*pattern
,
245 cairo_bool_t is_mask
,
246 const cairo_rectangle_int_t
*extents
,
247 const cairo_rectangle_int_t
*sample
,
248 int *src_x
, int *src_y
)
250 return cairo_image_surface_create (CAIRO_FORMAT_ARGB32
, 0, 0);
253 static cairo_int_status_t
254 fill_boxes (void *_dst
,
256 const cairo_color_t
*color
,
257 cairo_boxes_t
*boxes
)
259 return CAIRO_STATUS_SUCCESS
;
262 static cairo_int_status_t
263 draw_image_boxes (void *_dst
,
264 cairo_image_surface_t
*image
,
265 cairo_boxes_t
*boxes
,
268 return CAIRO_STATUS_SUCCESS
;
271 static cairo_int_status_t
272 composite (void *_dst
,
274 cairo_surface_t
*abstract_src
,
275 cairo_surface_t
*abstract_mask
,
285 return CAIRO_STATUS_SUCCESS
;
288 static cairo_int_status_t
290 cairo_surface_t
*abstract_src
,
291 cairo_surface_t
*abstract_mask
,
301 return CAIRO_STATUS_SUCCESS
;
304 static cairo_int_status_t
305 composite_boxes (void *_dst
,
307 cairo_surface_t
*abstract_src
,
308 cairo_surface_t
*abstract_mask
,
315 cairo_boxes_t
*boxes
,
316 const cairo_rectangle_int_t
*extents
)
318 return CAIRO_STATUS_SUCCESS
;
321 static cairo_int_status_t
322 composite_traps (void *_dst
,
324 cairo_surface_t
*abstract_src
,
329 const cairo_rectangle_int_t
*extents
,
330 cairo_antialias_t antialias
,
331 cairo_traps_t
*traps
)
333 return CAIRO_STATUS_SUCCESS
;
336 static cairo_int_status_t
337 check_composite_glyphs (const cairo_composite_rectangles_t
*extents
,
338 cairo_scaled_font_t
*scaled_font
,
339 cairo_glyph_t
*glyphs
,
342 return CAIRO_STATUS_SUCCESS
;
345 static cairo_int_status_t
346 composite_glyphs (void *_dst
,
348 cairo_surface_t
*_src
,
353 cairo_composite_glyphs_info_t
*info
)
355 return CAIRO_STATUS_SUCCESS
;
358 static cairo_status_t
359 spans (void *abstract_renderer
,
361 const cairo_half_open_span_t
*spans
,
364 return CAIRO_STATUS_SUCCESS
;
367 static cairo_status_t
368 finish_spans (void *abstract_renderer
)
370 return CAIRO_STATUS_SUCCESS
;
373 static cairo_int_status_t
374 span_renderer_init (cairo_abstract_span_renderer_t
*_r
,
375 const cairo_composite_rectangles_t
*composite
,
376 cairo_antialias_t antialias
,
377 cairo_bool_t needs_clip
)
379 cairo_span_renderer_t
*r
= (cairo_span_renderer_t
*)_r
;
380 r
->render_rows
= spans
;
381 r
->finish
= finish_spans
;
382 return CAIRO_STATUS_SUCCESS
;
386 span_renderer_fini (cairo_abstract_span_renderer_t
*_r
,
387 cairo_int_status_t status
)
391 static const cairo_compositor_t
*
392 no_fallback_compositor_get (void)
394 return &__cairo_no_compositor
;
397 static cairo_int_status_t
398 check_composite (const cairo_composite_rectangles_t
*extents
)
400 return CAIRO_STATUS_SUCCESS
;
403 static const cairo_compositor_t
*
404 no_traps_compositor_get (void)
406 static cairo_traps_compositor_t compositor
;
408 if (compositor
.base
.delegate
== NULL
) {
409 _cairo_traps_compositor_init (&compositor
,
410 no_fallback_compositor_get ());
412 compositor
.acquire
= acquire
;
413 compositor
.release
= release
;
414 compositor
.set_clip_region
= set_clip_region
;
415 compositor
.pattern_to_surface
= pattern_to_surface
;
416 compositor
.draw_image_boxes
= draw_image_boxes
;
417 //compositor.copy_boxes = copy_boxes;
418 compositor
.fill_boxes
= fill_boxes
;
419 compositor
.check_composite
= check_composite
;
420 compositor
.composite
= composite
;
421 compositor
.lerp
= lerp
;
422 //compositor.check_composite_boxes = check_composite_boxes;
423 compositor
.composite_boxes
= composite_boxes
;
424 //compositor.check_composite_traps = check_composite_traps;
425 compositor
.composite_traps
= composite_traps
;
426 compositor
.check_composite_glyphs
= check_composite_glyphs
;
427 compositor
.composite_glyphs
= composite_glyphs
;
430 return &compositor
.base
;
433 static const cairo_compositor_t
*
434 no_spans_compositor_get (void)
436 static cairo_spans_compositor_t compositor
;
438 if (compositor
.base
.delegate
== NULL
) {
439 _cairo_spans_compositor_init (&compositor
,
440 no_traps_compositor_get());
442 //compositor.acquire = acquire;
443 //compositor.release = release;
444 compositor
.fill_boxes
= fill_boxes
;
445 //compositor.check_composite_boxes = check_composite_boxes;
446 compositor
.composite_boxes
= composite_boxes
;
447 //compositor.check_span_renderer = check_span_renderer;
448 compositor
.renderer_init
= span_renderer_init
;
449 compositor
.renderer_fini
= span_renderer_fini
;
452 return &compositor
.base
;
456 _cairo_test_no_fallback_compositor_surface_create (cairo_content_t content
,
460 return test_compositor_surface_create (no_fallback_compositor_get(),
461 content
, width
, height
);
465 _cairo_test_no_traps_compositor_surface_create (cairo_content_t content
,
469 return test_compositor_surface_create (no_traps_compositor_get(),
470 content
, width
, height
);
474 _cairo_test_no_spans_compositor_surface_create (cairo_content_t content
,
478 return test_compositor_surface_create (no_spans_compositor_get(),
479 content
, width
, height
);