Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/* cairo - a vector graphics library with display and print output
2
 *
3
 * Copyright © 2011 Intel Corporation
4
 *
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.
12
 *
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
18
 *
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/
23
 *
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.
27
 *
28
 * The Original Code is the cairo graphics library.
29
 *
30
 * The Initial Developer of the Original Code is Intel Corporation
31
 *
32
 * Contributor(s):
33
 *	Chris Wilson 
34
 */
35
 
36
#include "cairoint.h"
37
 
38
#include "test-compositor-surface-private.h"
39
 
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"
45
 
46
typedef struct _test_compositor_surface {
47
    cairo_image_surface_t base;
48
} test_compositor_surface_t;
49
 
50
static const cairo_surface_backend_t test_compositor_surface_backend;
51
 
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)
57
{
58
    test_compositor_surface_t *surface;
59
    pixman_image_t *pixman_image;
60
    pixman_format_code_t pixman_format;
61
 
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));
74
    }
75
 
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));
80
 
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));
85
    }
86
 
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);
92
 
93
    surface->base.compositor = compositor;
94
 
95
    return &surface->base.base;
96
}
97
 
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)
103
{
104
    test_compositor_surface_t *surface = abstract_surface;
105
 
106
    return test_compositor_surface_create (surface->base.compositor,
107
					   content, width, height);
108
}
109
 
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)
115
{
116
    test_compositor_surface_t *surface = _surface;
117
    return _cairo_compositor_paint (surface->base.compositor,
118
				    _surface, op, source,
119
				    clip);
120
}
121
 
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)
128
{
129
    test_compositor_surface_t *surface = _surface;
130
    return _cairo_compositor_mask (surface->base.compositor,
131
				   _surface, op, source, mask,
132
				    clip);
133
}
134
 
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)
146
{
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);
155
}
156
 
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)
166
{
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);
174
}
175
 
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)
184
{
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);
190
}
191
 
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,
196
 
197
    test_compositor_surface_create_similar,
198
    NULL, /* create similar image */
199
    _cairo_image_surface_map_to_image,
200
    _cairo_image_surface_unmap_image,
201
 
202
    _cairo_image_surface_source,
203
    _cairo_image_surface_acquire_source_image,
204
    _cairo_image_surface_release_source_image,
205
    _cairo_image_surface_snapshot,
206
 
207
    NULL, /* copy_page */
208
    NULL, /* show_page */
209
 
210
    _cairo_image_surface_get_extents,
211
    _cairo_image_surface_get_font_options,
212
 
213
    NULL, /* flush */
214
    NULL, /* mark_dirty_rectangle */
215
 
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,
222
};
223
 
224
static const cairo_compositor_t *
225
get_fallback_compositor (void)
226
{
227
    return &_cairo_fallback_compositor;
228
}
229
 
230
cairo_surface_t *
231
_cairo_test_fallback_compositor_surface_create (cairo_content_t	content,
232
						int		width,
233
						int		height)
234
{
235
    return test_compositor_surface_create (get_fallback_compositor(),
236
					   content, width, height);
237
}
238
 
239
cairo_surface_t *
240
_cairo_test_mask_compositor_surface_create (cairo_content_t	content,
241
						int		width,
242
						int		height)
243
{
244
    return test_compositor_surface_create (_cairo_image_mask_compositor_get(),
245
					   content, width, height);
246
}
247
 
248
cairo_surface_t *
249
_cairo_test_traps_compositor_surface_create (cairo_content_t	content,
250
					     int		width,
251
					     int		height)
252
{
253
    return test_compositor_surface_create (_cairo_image_traps_compositor_get(),
254
					   content, width, height);
255
}
256
 
257
cairo_surface_t *
258
_cairo_test_spans_compositor_surface_create (cairo_content_t	content,
259
					     int		width,
260
					     int		height)
261
{
262
    return test_compositor_surface_create (_cairo_image_spans_compositor_get(),
263
					   content, width, height);
264
}