in class/System.Windows/System.Windows/:
[moon.git] / cairo / src / test-fallback-surface.c
blob883941df014aaf7cedcdd63edfe9923bf61d4cfb
1 /* cairo - a vector graphics library with display and print output
3 * Copyright © 2005 Red Hat, Inc
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 Red Hat, Inc.
32 * Contributor(s):
33 * Carl Worth <cworth@cworth.org>
36 /* This isn't a "real" surface, but just something to be used by the
37 * test suite to test a mythical backend that uses nothing but
38 * fallbacks.
40 * The defining feature of this backend is that it has as many %NULL
41 * backend function entries as possible. The ones that aren't %NULL are
42 * simply those that must be implemented to have working fallbacks.
43 * (Except for create_similar---fallbacks would work fine without
44 * that---I implemented it here in order to create as many surfaces as
45 * possible of type test_fallback_surface_t during the test suite
46 * run).
48 * It's possible that this code might serve as a good starting point
49 * for someone working on bringing up a new backend, starting with the
50 * minimal all-fallbacks approach and working up gradually from
51 * there.
54 #include "cairoint.h"
56 #include "test-fallback-surface.h"
58 typedef struct _test_fallback_surface {
59 cairo_surface_t base;
61 /* This is a cairo_image_surface to hold the actual contents. */
62 cairo_surface_t *backing;
63 } test_fallback_surface_t;
65 static const cairo_surface_backend_t test_fallback_surface_backend;
67 slim_hidden_proto (_cairo_test_fallback_surface_create);
69 cairo_surface_t *
70 _cairo_test_fallback_surface_create (cairo_content_t content,
71 int width,
72 int height)
74 test_fallback_surface_t *surface;
75 cairo_surface_t *backing;
77 backing = _cairo_image_surface_create_with_content (content, width, height);
78 if (cairo_surface_status (backing))
79 return backing;
81 surface = malloc (sizeof (test_fallback_surface_t));
82 if (surface == NULL) {
83 cairo_surface_destroy (backing);
84 return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
87 _cairo_surface_init (&surface->base, &test_fallback_surface_backend,
88 content);
90 surface->backing = backing;
92 return &surface->base;
94 slim_hidden_def (_cairo_test_fallback_surface_create);
96 static cairo_surface_t *
97 _test_fallback_surface_create_similar (void *abstract_surface,
98 cairo_content_t content,
99 int width,
100 int height)
102 assert (CAIRO_CONTENT_VALID (content));
104 return _cairo_test_fallback_surface_create (content,
105 width, height);
108 static cairo_status_t
109 _test_fallback_surface_finish (void *abstract_surface)
111 test_fallback_surface_t *surface = abstract_surface;
113 cairo_surface_destroy (surface->backing);
115 return CAIRO_STATUS_SUCCESS;
118 static cairo_status_t
119 _test_fallback_surface_acquire_source_image (void *abstract_surface,
120 cairo_image_surface_t **image_out,
121 void **image_extra)
123 test_fallback_surface_t *surface = abstract_surface;
125 return _cairo_surface_acquire_source_image (surface->backing,
126 image_out, image_extra);
129 static void
130 _test_fallback_surface_release_source_image (void *abstract_surface,
131 cairo_image_surface_t *image,
132 void *image_extra)
134 test_fallback_surface_t *surface = abstract_surface;
136 _cairo_surface_release_source_image (surface->backing,
137 image, image_extra);
140 static cairo_status_t
141 _test_fallback_surface_acquire_dest_image (void *abstract_surface,
142 cairo_rectangle_int_t *interest_rect,
143 cairo_image_surface_t **image_out,
144 cairo_rectangle_int_t *image_rect_out,
145 void **image_extra)
147 test_fallback_surface_t *surface = abstract_surface;
149 return _cairo_surface_acquire_dest_image (surface->backing,
150 interest_rect,
151 image_out,
152 image_rect_out,
153 image_extra);
156 static void
157 _test_fallback_surface_release_dest_image (void *abstract_surface,
158 cairo_rectangle_int_t *interest_rect,
159 cairo_image_surface_t *image,
160 cairo_rectangle_int_t *image_rect,
161 void *image_extra)
163 test_fallback_surface_t *surface = abstract_surface;
165 _cairo_surface_release_dest_image (surface->backing,
166 interest_rect,
167 image,
168 image_rect,
169 image_extra);
172 static cairo_status_t
173 _test_fallback_surface_clone_similar (void *abstract_surface,
174 cairo_surface_t *src,
175 int src_x,
176 int src_y,
177 int width,
178 int height,
179 int *clone_offset_x,
180 int *clone_offset_y,
181 cairo_surface_t **clone_out)
183 test_fallback_surface_t *surface = abstract_surface;
185 if (src->backend == surface->base.backend) {
186 *clone_offset_x = 0;
187 *clone_offset_y = 0;
188 *clone_out = cairo_surface_reference (src);
190 return CAIRO_STATUS_SUCCESS;
193 return CAIRO_INT_STATUS_UNSUPPORTED;
196 static cairo_int_status_t
197 _test_fallback_surface_get_extents (void *abstract_surface,
198 cairo_rectangle_int_t *rectangle)
200 test_fallback_surface_t *surface = abstract_surface;
202 return _cairo_surface_get_extents (surface->backing, rectangle);
205 static const cairo_surface_backend_t test_fallback_surface_backend = {
206 CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
207 _test_fallback_surface_create_similar,
208 _test_fallback_surface_finish,
209 _test_fallback_surface_acquire_source_image,
210 _test_fallback_surface_release_source_image,
211 _test_fallback_surface_acquire_dest_image,
212 _test_fallback_surface_release_dest_image,
213 _test_fallback_surface_clone_similar,
214 NULL, /* composite */
215 NULL, /* fill_rectangles */
216 NULL, /* composite_trapezoids */
217 NULL, /* copy_page */
218 NULL, /* show_page */
219 NULL, /* set_clip_region */
220 NULL, /* intersect_clip_path */
221 _test_fallback_surface_get_extents,
222 NULL, /* old_show_glyphs */
223 NULL, /* get_font_options */
224 NULL, /* flush */
225 NULL, /* mark_dirty_rectangle */
226 NULL, /* scaled_font_fini */
227 NULL, /* scaled_glyph_fini */
228 NULL, /* paint */
229 NULL, /* mask */
230 NULL, /* stroke */
231 NULL, /* fill */
232 NULL, /* show_glyphs */
233 NULL /* snapshot */