1 : /*
2 : * Copyright © 2009 Red Hat, Inc.
3 : *
4 : * Permission to use, copy, modify, distribute, and sell this software and its
5 : * documentation for any purpose is hereby granted without fee, provided that
6 : * the above copyright notice appear in all copies and that both that
7 : * copyright notice and this permission notice appear in supporting
8 : * documentation, and that the name of Red Hat not be used in advertising or
9 : * publicity pertaining to distribution of the software without specific,
10 : * written prior permission. Red Hat makes no representations about the
11 : * suitability of this software for any purpose. It is provided "as is"
12 : * without express or implied warranty.
13 : *
14 : * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 : * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 : * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 : * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 : * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
19 : * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
20 : * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
21 : * SOFTWARE.
22 : */
23 :
24 : #ifdef HAVE_CONFIG_H
25 : #include <config.h>
26 : #endif
27 : #include <stdlib.h>
28 : #include "pixman-private.h"
29 :
30 : static void
31 0 : delegate_combine_32 (pixman_implementation_t * imp,
32 : pixman_op_t op,
33 : uint32_t * dest,
34 : const uint32_t * src,
35 : const uint32_t * mask,
36 : int width)
37 : {
38 0 : _pixman_implementation_combine_32 (imp->delegate,
39 : op, dest, src, mask, width);
40 0 : }
41 :
42 : static void
43 0 : delegate_combine_64 (pixman_implementation_t * imp,
44 : pixman_op_t op,
45 : uint64_t * dest,
46 : const uint64_t * src,
47 : const uint64_t * mask,
48 : int width)
49 : {
50 0 : _pixman_implementation_combine_64 (imp->delegate,
51 : op, dest, src, mask, width);
52 0 : }
53 :
54 : static void
55 0 : delegate_combine_32_ca (pixman_implementation_t * imp,
56 : pixman_op_t op,
57 : uint32_t * dest,
58 : const uint32_t * src,
59 : const uint32_t * mask,
60 : int width)
61 : {
62 0 : _pixman_implementation_combine_32_ca (imp->delegate,
63 : op, dest, src, mask, width);
64 0 : }
65 :
66 : static void
67 0 : delegate_combine_64_ca (pixman_implementation_t * imp,
68 : pixman_op_t op,
69 : uint64_t * dest,
70 : const uint64_t * src,
71 : const uint64_t * mask,
72 : int width)
73 : {
74 0 : _pixman_implementation_combine_64_ca (imp->delegate,
75 : op, dest, src, mask, width);
76 0 : }
77 :
78 : static pixman_bool_t
79 0 : delegate_blt (pixman_implementation_t * imp,
80 : uint32_t * src_bits,
81 : uint32_t * dst_bits,
82 : int src_stride,
83 : int dst_stride,
84 : int src_bpp,
85 : int dst_bpp,
86 : int src_x,
87 : int src_y,
88 : int dst_x,
89 : int dst_y,
90 : int width,
91 : int height)
92 : {
93 0 : return _pixman_implementation_blt (
94 : imp->delegate, src_bits, dst_bits, src_stride, dst_stride,
95 : src_bpp, dst_bpp, src_x, src_y, dst_x, dst_y,
96 : width, height);
97 : }
98 :
99 : static pixman_bool_t
100 0 : delegate_fill (pixman_implementation_t *imp,
101 : uint32_t * bits,
102 : int stride,
103 : int bpp,
104 : int x,
105 : int y,
106 : int width,
107 : int height,
108 : uint32_t xor)
109 : {
110 0 : return _pixman_implementation_fill (
111 : imp->delegate, bits, stride, bpp, x, y, width, height, xor);
112 : }
113 :
114 : static void
115 0 : delegate_src_iter_init (pixman_implementation_t *imp,
116 : pixman_iter_t * iter)
117 : {
118 0 : imp->delegate->src_iter_init (imp->delegate, iter);
119 0 : }
120 :
121 : static void
122 0 : delegate_dest_iter_init (pixman_implementation_t *imp,
123 : pixman_iter_t * iter)
124 : {
125 0 : imp->delegate->dest_iter_init (imp->delegate, iter);
126 0 : }
127 :
128 : pixman_implementation_t *
129 16 : _pixman_implementation_create (pixman_implementation_t *delegate,
130 : const pixman_fast_path_t *fast_paths)
131 : {
132 16 : pixman_implementation_t *imp = malloc (sizeof (pixman_implementation_t));
133 : pixman_implementation_t *d;
134 : int i;
135 :
136 16 : if (!imp)
137 0 : return NULL;
138 :
139 16 : assert (fast_paths);
140 :
141 : /* Make sure the whole delegate chain has the right toplevel */
142 16 : imp->delegate = delegate;
143 56 : for (d = imp; d != NULL; d = d->delegate)
144 40 : d->toplevel = imp;
145 :
146 : /* Fill out function pointers with ones that just delegate
147 : */
148 16 : imp->blt = delegate_blt;
149 16 : imp->fill = delegate_fill;
150 16 : imp->src_iter_init = delegate_src_iter_init;
151 16 : imp->dest_iter_init = delegate_dest_iter_init;
152 :
153 1024 : for (i = 0; i < PIXMAN_N_OPERATORS; ++i)
154 : {
155 1008 : imp->combine_32[i] = delegate_combine_32;
156 1008 : imp->combine_64[i] = delegate_combine_64;
157 1008 : imp->combine_32_ca[i] = delegate_combine_32_ca;
158 1008 : imp->combine_64_ca[i] = delegate_combine_64_ca;
159 : }
160 :
161 16 : imp->fast_paths = fast_paths;
162 :
163 16 : return imp;
164 : }
165 :
166 : void
167 0 : _pixman_implementation_combine_32 (pixman_implementation_t * imp,
168 : pixman_op_t op,
169 : uint32_t * dest,
170 : const uint32_t * src,
171 : const uint32_t * mask,
172 : int width)
173 : {
174 0 : (*imp->combine_32[op]) (imp, op, dest, src, mask, width);
175 0 : }
176 :
177 : void
178 0 : _pixman_implementation_combine_64 (pixman_implementation_t * imp,
179 : pixman_op_t op,
180 : uint64_t * dest,
181 : const uint64_t * src,
182 : const uint64_t * mask,
183 : int width)
184 : {
185 0 : (*imp->combine_64[op]) (imp, op, dest, src, mask, width);
186 0 : }
187 :
188 : void
189 0 : _pixman_implementation_combine_32_ca (pixman_implementation_t * imp,
190 : pixman_op_t op,
191 : uint32_t * dest,
192 : const uint32_t * src,
193 : const uint32_t * mask,
194 : int width)
195 : {
196 0 : (*imp->combine_32_ca[op]) (imp, op, dest, src, mask, width);
197 0 : }
198 :
199 : void
200 0 : _pixman_implementation_combine_64_ca (pixman_implementation_t * imp,
201 : pixman_op_t op,
202 : uint64_t * dest,
203 : const uint64_t * src,
204 : const uint64_t * mask,
205 : int width)
206 : {
207 0 : (*imp->combine_64_ca[op]) (imp, op, dest, src, mask, width);
208 0 : }
209 :
210 : pixman_bool_t
211 0 : _pixman_implementation_blt (pixman_implementation_t * imp,
212 : uint32_t * src_bits,
213 : uint32_t * dst_bits,
214 : int src_stride,
215 : int dst_stride,
216 : int src_bpp,
217 : int dst_bpp,
218 : int src_x,
219 : int src_y,
220 : int dst_x,
221 : int dst_y,
222 : int width,
223 : int height)
224 : {
225 0 : return (*imp->blt) (imp, src_bits, dst_bits, src_stride, dst_stride,
226 : src_bpp, dst_bpp, src_x, src_y, dst_x, dst_y,
227 : width, height);
228 : }
229 :
230 : pixman_bool_t
231 17 : _pixman_implementation_fill (pixman_implementation_t *imp,
232 : uint32_t * bits,
233 : int stride,
234 : int bpp,
235 : int x,
236 : int y,
237 : int width,
238 : int height,
239 : uint32_t xor)
240 : {
241 17 : return (*imp->fill) (imp, bits, stride, bpp, x, y, width, height, xor);
242 : }
243 :
244 : static uint32_t *
245 0 : get_scanline_null (pixman_iter_t *iter, const uint32_t *mask)
246 : {
247 0 : return NULL;
248 : }
249 :
250 : void
251 0 : _pixman_implementation_src_iter_init (pixman_implementation_t *imp,
252 : pixman_iter_t *iter,
253 : pixman_image_t *image,
254 : int x,
255 : int y,
256 : int width,
257 : int height,
258 : uint8_t *buffer,
259 : iter_flags_t flags)
260 : {
261 0 : iter->image = image;
262 0 : iter->buffer = (uint32_t *)buffer;
263 0 : iter->x = x;
264 0 : iter->y = y;
265 0 : iter->width = width;
266 0 : iter->height = height;
267 0 : iter->flags = flags;
268 :
269 0 : if (!image)
270 : {
271 0 : iter->get_scanline = get_scanline_null;
272 : }
273 0 : else if ((flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) ==
274 : (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB))
275 : {
276 0 : iter->get_scanline = _pixman_iter_get_scanline_noop;
277 : }
278 : else
279 : {
280 0 : (*imp->src_iter_init) (imp, iter);
281 : }
282 0 : }
283 :
284 : void
285 0 : _pixman_implementation_dest_iter_init (pixman_implementation_t *imp,
286 : pixman_iter_t *iter,
287 : pixman_image_t *image,
288 : int x,
289 : int y,
290 : int width,
291 : int height,
292 : uint8_t *buffer,
293 : iter_flags_t flags)
294 : {
295 0 : iter->image = image;
296 0 : iter->buffer = (uint32_t *)buffer;
297 0 : iter->x = x;
298 0 : iter->y = y;
299 0 : iter->width = width;
300 0 : iter->height = height;
301 0 : iter->flags = flags;
302 :
303 0 : (*imp->dest_iter_init) (imp, iter);
304 0 : }
|