Reject trapezoids where top (botttom) is above (below) the edges
[profile/ivi/pixman.git] / pixman / pixman-implementation.c
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 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     _pixman_implementation_combine_32 (imp->delegate,
39                                        op, dest, src, mask, width);
40 }
41
42 static void
43 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     _pixman_implementation_combine_64 (imp->delegate,
51                                        op, dest, src, mask, width);
52 }
53
54 static void
55 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     _pixman_implementation_combine_32_ca (imp->delegate,
63                                           op, dest, src, mask, width);
64 }
65
66 static void
67 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     _pixman_implementation_combine_64_ca (imp->delegate,
75                                           op, dest, src, mask, width);
76 }
77
78 static pixman_bool_t
79 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                       dest_x,
89               int                       dest_y,
90               int                       width,
91               int                       height)
92 {
93     return _pixman_implementation_blt (
94         imp->delegate, src_bits, dst_bits, src_stride, dst_stride,
95         src_bpp, dst_bpp, src_x, src_y, dest_x, dest_y,
96         width, height);
97 }
98
99 static pixman_bool_t
100 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     return _pixman_implementation_fill (
111         imp->delegate, bits, stride, bpp, x, y, width, height, xor);
112 }
113
114 static void
115 delegate_src_iter_init (pixman_implementation_t *imp,
116                         pixman_iter_t *          iter)
117 {
118     imp->delegate->src_iter_init (imp->delegate, iter);
119 }
120
121 static void
122 delegate_dest_iter_init (pixman_implementation_t *imp,
123                          pixman_iter_t *          iter)
124 {
125     imp->delegate->dest_iter_init (imp->delegate, iter);
126 }
127
128 pixman_implementation_t *
129 _pixman_implementation_create (pixman_implementation_t *delegate,
130                                const pixman_fast_path_t *fast_paths)
131 {
132     pixman_implementation_t *imp = malloc (sizeof (pixman_implementation_t));
133     pixman_implementation_t *d;
134     int i;
135
136     if (!imp)
137         return NULL;
138
139     assert (fast_paths);
140
141     /* Make sure the whole delegate chain has the right toplevel */
142     imp->delegate = delegate;
143     for (d = imp; d != NULL; d = d->delegate)
144         d->toplevel = imp;
145
146     /* Fill out function pointers with ones that just delegate
147      */
148     imp->blt = delegate_blt;
149     imp->fill = delegate_fill;
150     imp->src_iter_init = delegate_src_iter_init;
151     imp->dest_iter_init = delegate_dest_iter_init;
152
153     for (i = 0; i < PIXMAN_N_OPERATORS; ++i)
154     {
155         imp->combine_32[i] = delegate_combine_32;
156         imp->combine_64[i] = delegate_combine_64;
157         imp->combine_32_ca[i] = delegate_combine_32_ca;
158         imp->combine_64_ca[i] = delegate_combine_64_ca;
159     }
160
161     imp->fast_paths = fast_paths;
162
163     return imp;
164 }
165
166 void
167 _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     (*imp->combine_32[op]) (imp, op, dest, src, mask, width);
175 }
176
177 void
178 _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     (*imp->combine_64[op]) (imp, op, dest, src, mask, width);
186 }
187
188 void
189 _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     (*imp->combine_32_ca[op]) (imp, op, dest, src, mask, width);
197 }
198
199 void
200 _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     (*imp->combine_64_ca[op]) (imp, op, dest, src, mask, width);
208 }
209
210 pixman_bool_t
211 _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                       dest_x,
221                             int                       dest_y,
222                             int                       width,
223                             int                       height)
224 {
225     return (*imp->blt) (imp, src_bits, dst_bits, src_stride, dst_stride,
226                         src_bpp, dst_bpp, src_x, src_y, dest_x, dest_y,
227                         width, height);
228 }
229
230 pixman_bool_t
231 _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     return (*imp->fill) (imp, bits, stride, bpp, x, y, width, height, xor);
242 }
243
244 void
245 _pixman_implementation_src_iter_init (pixman_implementation_t   *imp,
246                                       pixman_iter_t             *iter,
247                                       pixman_image_t            *image,
248                                       int                        x,
249                                       int                        y,
250                                       int                        width,
251                                       int                        height,
252                                       uint8_t                   *buffer,
253                                       iter_flags_t               flags)
254 {
255     iter->image = image;
256     iter->buffer = (uint32_t *)buffer;
257     iter->x = x;
258     iter->y = y;
259     iter->width = width;
260     iter->height = height;
261     iter->flags = flags;
262
263     (*imp->src_iter_init) (imp, iter);
264 }
265
266 void
267 _pixman_implementation_dest_iter_init (pixman_implementation_t  *imp,
268                                        pixman_iter_t            *iter,
269                                        pixman_image_t           *image,
270                                        int                       x,
271                                        int                       y,
272                                        int                       width,
273                                        int                       height,
274                                        uint8_t                  *buffer,
275                                        iter_flags_t              flags)
276 {
277     iter->image = image;
278     iter->buffer = (uint32_t *)buffer;
279     iter->x = x;
280     iter->y = y;
281     iter->width = width;
282     iter->height = height;
283     iter->flags = flags;
284
285     (*imp->dest_iter_init) (imp, iter);
286 }