1 /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
3 * Copyright © 2004,2006 Red Hat, Inc.
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.
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.
24 * Author: Carl D. Worth <cworth@cworth.org>
27 #include "../cairo-version.h"
29 #include "cairo-boilerplate-private.h"
31 #include <cairo-types-private.h>
33 #include <test-compositor-surface.h>
34 #include <test-null-compositor-surface.h>
35 #if CAIRO_HAS_TEST_PAGINATED_SURFACE
36 #include <test-paginated-surface.h>
39 static cairo_surface_t *
40 _cairo_boilerplate_test_base_compositor_create_surface (const char *name,
41 cairo_content_t content,
46 cairo_boilerplate_mode_t mode,
50 return _cairo_test_base_compositor_surface_create (content, ceil (width), ceil (height));
54 static cairo_surface_t *
55 _cairo_boilerplate_test_fallback_compositor_create_surface (const char *name,
56 cairo_content_t content,
61 cairo_boilerplate_mode_t mode,
65 return _cairo_test_fallback_compositor_surface_create (content, ceil (width), ceil (height));
68 static cairo_surface_t *
69 _cairo_boilerplate_test_mask_compositor_create_surface (const char *name,
70 cairo_content_t content,
75 cairo_boilerplate_mode_t mode,
79 return _cairo_test_mask_compositor_surface_create (content, ceil (width), ceil (height));
83 static cairo_surface_t *
84 _cairo_boilerplate_test_traps_compositor_create_surface (const char *name,
85 cairo_content_t content,
90 cairo_boilerplate_mode_t mode,
94 return _cairo_test_traps_compositor_surface_create (content, ceil (width), ceil (height));
97 static cairo_surface_t *
98 _cairo_boilerplate_test_spans_compositor_create_surface (const char *name,
99 cairo_content_t content,
104 cairo_boilerplate_mode_t mode,
108 return _cairo_test_spans_compositor_surface_create (content, ceil (width), ceil (height));
111 static cairo_surface_t *
112 _cairo_boilerplate_test_no_fallback_compositor_create_surface (const char *name,
113 cairo_content_t content,
118 cairo_boilerplate_mode_t mode,
121 if (mode == CAIRO_BOILERPLATE_MODE_TEST)
125 return _cairo_test_no_fallback_compositor_surface_create (content, ceil (width), ceil (height));
128 static cairo_surface_t *
129 _cairo_boilerplate_test_no_traps_compositor_create_surface (const char *name,
130 cairo_content_t content,
135 cairo_boilerplate_mode_t mode,
138 if (mode == CAIRO_BOILERPLATE_MODE_TEST)
142 return _cairo_test_no_traps_compositor_surface_create (content, ceil (width), ceil (height));
145 static cairo_surface_t *
146 _cairo_boilerplate_test_no_spans_compositor_create_surface (const char *name,
147 cairo_content_t content,
152 cairo_boilerplate_mode_t mode,
155 if (mode == CAIRO_BOILERPLATE_MODE_TEST)
159 return _cairo_test_no_spans_compositor_surface_create (content, ceil (width), ceil (height));
162 #if CAIRO_HAS_TEST_PAGINATED_SURFACE
163 static const cairo_user_data_key_t test_paginated_closure_key;
166 cairo_surface_t *target;
167 } test_paginated_closure_t;
169 static cairo_surface_t *
170 _cairo_boilerplate_test_paginated_create_surface (const char *name,
171 cairo_content_t content,
176 cairo_boilerplate_mode_t mode,
179 test_paginated_closure_t *tpc;
180 cairo_format_t format;
181 cairo_surface_t *surface;
182 cairo_status_t status;
184 *closure = tpc = xmalloc (sizeof (test_paginated_closure_t));
186 format = cairo_boilerplate_format_from_content (content);
187 tpc->target = cairo_image_surface_create (format,
188 ceil (width), ceil (height));
190 surface = _cairo_test_paginated_surface_create (tpc->target);
191 if (cairo_surface_status (surface))
194 status = cairo_surface_set_user_data (surface,
195 &test_paginated_closure_key,
197 if (status == CAIRO_STATUS_SUCCESS)
200 cairo_surface_destroy (surface);
201 surface = cairo_boilerplate_surface_create_in_error (status);
203 cairo_surface_destroy (tpc->target);
210 /* The only reason we go through all these machinations to write a PNG
211 * image is to _really ensure_ that the data actually landed in our
212 * buffer through the paginated surface to the test_paginated_surface.
214 * If we didn't implement this function then the default
215 * cairo_surface_write_to_png would result in the paginated_surface's
216 * acquire_source_image function replaying the recording-surface to an
217 * intermediate image surface. And in that case the
218 * test_paginated_surface would not be involved and wouldn't be
221 static cairo_status_t
222 _cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface,
223 const char *filename)
225 test_paginated_closure_t *tpc;
226 cairo_status_t status;
228 /* show page first. the automatic show_page is too late for us */
229 cairo_surface_show_page (surface);
230 status = cairo_surface_status (surface);
234 tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key);
235 return cairo_surface_write_to_png (tpc->target, filename);
238 static cairo_surface_t *
239 _cairo_boilerplate_test_paginated_get_image_surface (cairo_surface_t *surface,
244 test_paginated_closure_t *tpc;
245 cairo_status_t status;
247 /* XXX separate finish as per PDF */
249 return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
251 /* show page first. the automatic show_page is too late for us */
252 cairo_surface_show_page (surface);
253 status = cairo_surface_status (surface);
255 return cairo_boilerplate_surface_create_in_error (status);
257 tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key);
258 return _cairo_boilerplate_get_image_surface (tpc->target, 0, width, height);
262 _cairo_boilerplate_test_paginated_cleanup (void *closure)
264 test_paginated_closure_t *tpc = closure;
266 cairo_surface_destroy (tpc->target);
271 static const cairo_boilerplate_target_t targets[] = {
273 "test-base", "base", NULL, NULL,
274 CAIRO_SURFACE_TYPE_IMAGE,
275 CAIRO_CONTENT_COLOR_ALPHA, 0,
276 "_cairo_test_base_compositor_surface_create",
277 _cairo_boilerplate_test_base_compositor_create_surface,
278 cairo_surface_create_similar,
280 _cairo_boilerplate_get_image_surface,
281 cairo_surface_write_to_png,
282 NULL, NULL, NULL, TRUE, FALSE, FALSE
285 "test-base", "base", NULL, NULL,
286 CAIRO_SURFACE_TYPE_IMAGE,
287 CAIRO_CONTENT_COLOR, 0,
288 "_cairo_test_base_compositor_surface_create",
289 _cairo_boilerplate_test_base_compositor_create_surface,
290 cairo_surface_create_similar,
292 _cairo_boilerplate_get_image_surface,
293 cairo_surface_write_to_png,
294 NULL, NULL, NULL, FALSE, FALSE, FALSE
298 "test-fallback", "image", NULL, NULL,
299 CAIRO_SURFACE_TYPE_IMAGE,
300 CAIRO_CONTENT_COLOR_ALPHA, 0,
301 "_cairo_test_fallback_compositor_surface_create",
302 _cairo_boilerplate_test_fallback_compositor_create_surface,
303 cairo_surface_create_similar,
305 _cairo_boilerplate_get_image_surface,
306 cairo_surface_write_to_png,
307 NULL, NULL, NULL, FALSE, FALSE, FALSE
310 "test-fallback", "image", NULL, NULL,
311 CAIRO_SURFACE_TYPE_IMAGE,
312 CAIRO_CONTENT_COLOR, 0,
313 "_cairo_test_fallback_compositor_surface_create",
314 _cairo_boilerplate_test_fallback_compositor_create_surface,
315 cairo_surface_create_similar,
317 _cairo_boilerplate_get_image_surface,
318 cairo_surface_write_to_png,
319 NULL, NULL, NULL, FALSE, FALSE, FALSE
323 "test-mask", "mask", NULL, NULL,
324 CAIRO_SURFACE_TYPE_IMAGE,
325 CAIRO_CONTENT_COLOR_ALPHA, 0,
326 "_cairo_test_mask_compositor_surface_create",
327 _cairo_boilerplate_test_mask_compositor_create_surface,
328 cairo_surface_create_similar,
330 _cairo_boilerplate_get_image_surface,
331 cairo_surface_write_to_png,
332 NULL, NULL, NULL, TRUE, FALSE, FALSE
335 "test-mask", "mask", NULL, NULL,
336 CAIRO_SURFACE_TYPE_IMAGE,
337 CAIRO_CONTENT_COLOR, 0,
338 "_cairo_test_mask_compositor_surface_create",
339 _cairo_boilerplate_test_mask_compositor_create_surface,
340 cairo_surface_create_similar,
342 _cairo_boilerplate_get_image_surface,
343 cairo_surface_write_to_png,
344 NULL, NULL, NULL, FALSE, FALSE, FALSE
348 "test-traps", "traps", NULL, NULL,
349 CAIRO_SURFACE_TYPE_IMAGE,
350 CAIRO_CONTENT_COLOR_ALPHA, 0,
351 "_cairo_test_traps_compositor_surface_create",
352 _cairo_boilerplate_test_traps_compositor_create_surface,
353 cairo_surface_create_similar,
355 _cairo_boilerplate_get_image_surface,
356 cairo_surface_write_to_png,
357 NULL, NULL, NULL, TRUE, FALSE, FALSE
360 "test-traps", "traps", NULL, NULL,
361 CAIRO_SURFACE_TYPE_IMAGE,
362 CAIRO_CONTENT_COLOR, 0,
363 "_cairo_test_traps_compositor_surface_create",
364 _cairo_boilerplate_test_traps_compositor_create_surface,
365 cairo_surface_create_similar,
367 _cairo_boilerplate_get_image_surface,
368 cairo_surface_write_to_png,
369 NULL, NULL, NULL, FALSE, FALSE, FALSE
373 "test-spans", "spans", NULL, NULL,
374 CAIRO_SURFACE_TYPE_IMAGE,
375 CAIRO_CONTENT_COLOR_ALPHA, 0,
376 "_cairo_test_spans_compositor_surface_create",
377 _cairo_boilerplate_test_spans_compositor_create_surface,
378 cairo_surface_create_similar,
380 _cairo_boilerplate_get_image_surface,
381 cairo_surface_write_to_png,
382 NULL, NULL, NULL, TRUE, FALSE, FALSE
385 "test-spans", "spans", NULL, NULL,
386 CAIRO_SURFACE_TYPE_IMAGE,
387 CAIRO_CONTENT_COLOR, 0,
388 "_cairo_test_spans_compositor_surface_create",
389 _cairo_boilerplate_test_spans_compositor_create_surface,
390 cairo_surface_create_similar,
392 _cairo_boilerplate_get_image_surface,
393 cairo_surface_write_to_png,
394 NULL, NULL, NULL, FALSE, FALSE, FALSE
398 "no-fallback", "image", NULL, NULL,
399 CAIRO_SURFACE_TYPE_IMAGE,
400 CAIRO_CONTENT_COLOR_ALPHA, 0,
401 "_cairo_test_no_fallback_compositor_surface_create",
402 _cairo_boilerplate_test_no_fallback_compositor_create_surface,
403 cairo_surface_create_similar,
405 _cairo_boilerplate_get_image_surface,
406 cairo_surface_write_to_png,
407 NULL, NULL, NULL, FALSE, FALSE, FALSE
410 "no-traps", "traps", NULL, NULL,
411 CAIRO_SURFACE_TYPE_IMAGE,
412 CAIRO_CONTENT_COLOR_ALPHA, 0,
413 "_cairo_test_no_traps_compositor_surface_create",
414 _cairo_boilerplate_test_no_traps_compositor_create_surface,
415 cairo_surface_create_similar,
417 _cairo_boilerplate_get_image_surface,
418 cairo_surface_write_to_png,
419 NULL, NULL, NULL, TRUE, FALSE, FALSE
422 "no-spans", "spans", NULL, NULL,
423 CAIRO_SURFACE_TYPE_IMAGE,
424 CAIRO_CONTENT_COLOR_ALPHA, 0,
425 "_cairo_test_no_spans_compositor_surface_create",
426 _cairo_boilerplate_test_no_spans_compositor_create_surface,
427 cairo_surface_create_similar,
429 _cairo_boilerplate_get_image_surface,
430 cairo_surface_write_to_png,
431 NULL, NULL, NULL, TRUE, FALSE, FALSE
433 #if CAIRO_HAS_TEST_PAGINATED_SURFACE
435 "test-paginated", "image", NULL, NULL,
436 CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED,
437 CAIRO_CONTENT_COLOR_ALPHA, 0,
438 "_cairo_test_paginated_surface_create",
439 _cairo_boilerplate_test_paginated_create_surface,
440 cairo_surface_create_similar,
442 _cairo_boilerplate_test_paginated_get_image_surface,
443 _cairo_boilerplate_test_paginated_surface_write_to_png,
444 _cairo_boilerplate_test_paginated_cleanup,
445 NULL, NULL, FALSE, TRUE, FALSE
448 "test-paginated", "image", NULL, NULL,
449 CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED,
450 CAIRO_CONTENT_COLOR, 0,
451 "_cairo_test_paginated_surface_create",
452 _cairo_boilerplate_test_paginated_create_surface,
453 cairo_surface_create_similar,
455 _cairo_boilerplate_test_paginated_get_image_surface,
456 _cairo_boilerplate_test_paginated_surface_write_to_png,
457 _cairo_boilerplate_test_paginated_cleanup,
458 NULL, NULL, FALSE, TRUE, FALSE
462 CAIRO_BOILERPLATE (test, targets)