pixman-implementation.c revision a450e446
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
30static void
31delegate_composite (pixman_implementation_t * imp,
32                    pixman_op_t               op,
33                    pixman_image_t *          src,
34                    pixman_image_t *          mask,
35                    pixman_image_t *          dest,
36                    int32_t                   src_x,
37                    int32_t                   src_y,
38                    int32_t                   mask_x,
39                    int32_t                   mask_y,
40                    int32_t                   dest_x,
41                    int32_t                   dest_y,
42                    int32_t                   width,
43                    int32_t                   height)
44{
45    _pixman_implementation_composite (imp->delegate,
46                                      op,
47                                      src, mask, dest,
48                                      src_x, src_y,
49                                      mask_x, mask_y,
50                                      dest_x, dest_y,
51                                      width, height);
52}
53
54static void
55delegate_combine_32 (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    _pixman_implementation_combine_32 (imp->delegate,
63                                       op, dest, src, mask, width);
64}
65
66static void
67delegate_combine_64 (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    _pixman_implementation_combine_64 (imp->delegate,
75                                       op, dest, src, mask, width);
76}
77
78static void
79delegate_combine_32_ca (pixman_implementation_t * imp,
80                        pixman_op_t               op,
81                        uint32_t *                dest,
82                        const uint32_t *          src,
83                        const uint32_t *          mask,
84                        int                       width)
85{
86    _pixman_implementation_combine_32_ca (imp->delegate,
87                                          op, dest, src, mask, width);
88}
89
90static void
91delegate_combine_64_ca (pixman_implementation_t * imp,
92                        pixman_op_t               op,
93                        uint64_t *                dest,
94                        const uint64_t *          src,
95                        const uint64_t *          mask,
96                        int                       width)
97{
98    _pixman_implementation_combine_64_ca (imp->delegate,
99                                          op, dest, src, mask, width);
100}
101
102static pixman_bool_t
103delegate_blt (pixman_implementation_t * imp,
104              uint32_t *                src_bits,
105              uint32_t *                dst_bits,
106              int                       src_stride,
107              int                       dst_stride,
108              int                       src_bpp,
109              int                       dst_bpp,
110              int                       src_x,
111              int                       src_y,
112              int                       dst_x,
113              int                       dst_y,
114              int                       width,
115              int                       height)
116{
117    return _pixman_implementation_blt (
118	imp->delegate, src_bits, dst_bits, src_stride, dst_stride,
119	src_bpp, dst_bpp, src_x, src_y, dst_x, dst_y,
120	width, height);
121}
122
123static pixman_bool_t
124delegate_fill (pixman_implementation_t *imp,
125               uint32_t *               bits,
126               int                      stride,
127               int                      bpp,
128               int                      x,
129               int                      y,
130               int                      width,
131               int                      height,
132               uint32_t                 xor)
133{
134    return _pixman_implementation_fill (
135	imp->delegate, bits, stride, bpp, x, y, width, height, xor);
136}
137
138pixman_implementation_t *
139_pixman_implementation_create (pixman_implementation_t *delegate)
140{
141    pixman_implementation_t *imp = malloc (sizeof (pixman_implementation_t));
142    pixman_implementation_t *d;
143    int i;
144
145    if (!imp)
146	return NULL;
147
148    /* Make sure the whole delegate chain has the right toplevel */
149    imp->delegate = delegate;
150    for (d = imp; d != NULL; d = d->delegate)
151	d->toplevel = imp;
152
153    /* Fill out function pointers with ones that just delegate
154     */
155    imp->composite = delegate_composite;
156    imp->blt = delegate_blt;
157    imp->fill = delegate_fill;
158
159    for (i = 0; i < PIXMAN_OP_LAST; ++i)
160    {
161	imp->combine_32[i] = delegate_combine_32;
162	imp->combine_64[i] = delegate_combine_64;
163	imp->combine_32_ca[i] = delegate_combine_32_ca;
164	imp->combine_64_ca[i] = delegate_combine_64_ca;
165    }
166
167    return imp;
168}
169
170void
171_pixman_implementation_combine_32 (pixman_implementation_t * imp,
172                                   pixman_op_t               op,
173                                   uint32_t *                dest,
174                                   const uint32_t *          src,
175                                   const uint32_t *          mask,
176                                   int                       width)
177{
178    (*imp->combine_32[op]) (imp, op, dest, src, mask, width);
179}
180
181void
182_pixman_implementation_combine_64 (pixman_implementation_t * imp,
183                                   pixman_op_t               op,
184                                   uint64_t *                dest,
185                                   const uint64_t *          src,
186                                   const uint64_t *          mask,
187                                   int                       width)
188{
189    (*imp->combine_64[op]) (imp, op, dest, src, mask, width);
190}
191
192void
193_pixman_implementation_combine_32_ca (pixman_implementation_t * imp,
194                                      pixman_op_t               op,
195                                      uint32_t *                dest,
196                                      const uint32_t *          src,
197                                      const uint32_t *          mask,
198                                      int                       width)
199{
200    (*imp->combine_32_ca[op]) (imp, op, dest, src, mask, width);
201}
202
203void
204_pixman_implementation_combine_64_ca (pixman_implementation_t * imp,
205                                      pixman_op_t               op,
206                                      uint64_t *                dest,
207                                      const uint64_t *          src,
208                                      const uint64_t *          mask,
209                                      int                       width)
210{
211    (*imp->combine_64_ca[op]) (imp, op, dest, src, mask, width);
212}
213
214void
215_pixman_implementation_composite (pixman_implementation_t * imp,
216                                  pixman_op_t               op,
217                                  pixman_image_t *          src,
218                                  pixman_image_t *          mask,
219                                  pixman_image_t *          dest,
220                                  int32_t                   src_x,
221                                  int32_t                   src_y,
222                                  int32_t                   mask_x,
223                                  int32_t                   mask_y,
224                                  int32_t                   dest_x,
225                                  int32_t                   dest_y,
226                                  int32_t                   width,
227                                  int32_t                   height)
228{
229    (*imp->composite) (imp, op,
230		       src, mask, dest,
231		       src_x, src_y, mask_x, mask_y, dest_x, dest_y,
232		       width, height);
233}
234
235pixman_bool_t
236_pixman_implementation_blt (pixman_implementation_t * imp,
237                            uint32_t *                src_bits,
238                            uint32_t *                dst_bits,
239                            int                       src_stride,
240                            int                       dst_stride,
241                            int                       src_bpp,
242                            int                       dst_bpp,
243                            int                       src_x,
244                            int                       src_y,
245                            int                       dst_x,
246                            int                       dst_y,
247                            int                       width,
248                            int                       height)
249{
250    return (*imp->blt) (imp, src_bits, dst_bits, src_stride, dst_stride,
251			src_bpp, dst_bpp, src_x, src_y, dst_x, dst_y,
252			width, height);
253}
254
255pixman_bool_t
256_pixman_implementation_fill (pixman_implementation_t *imp,
257                             uint32_t *               bits,
258                             int                      stride,
259                             int                      bpp,
260                             int                      x,
261                             int                      y,
262                             int                      width,
263                             int                      height,
264                             uint32_t                 xor)
265{
266    return (*imp->fill) (imp, bits, stride, bpp, x, y, width, height, xor);
267}
268
269