mmx: add add_0565_0565
[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 pixman_bool_t
31 delegate_blt (pixman_implementation_t * imp,
32               uint32_t *                src_bits,
33               uint32_t *                dst_bits,
34               int                       src_stride,
35               int                       dst_stride,
36               int                       src_bpp,
37               int                       dst_bpp,
38               int                       src_x,
39               int                       src_y,
40               int                       dest_x,
41               int                       dest_y,
42               int                       width,
43               int                       height)
44 {
45     return _pixman_implementation_blt (
46         imp->delegate, src_bits, dst_bits, src_stride, dst_stride,
47         src_bpp, dst_bpp, src_x, src_y, dest_x, dest_y,
48         width, height);
49 }
50
51 static pixman_bool_t
52 delegate_fill (pixman_implementation_t *imp,
53                uint32_t *               bits,
54                int                      stride,
55                int                      bpp,
56                int                      x,
57                int                      y,
58                int                      width,
59                int                      height,
60                uint32_t                 xor)
61 {
62     return _pixman_implementation_fill (
63         imp->delegate, bits, stride, bpp, x, y, width, height, xor);
64 }
65
66 static void
67 delegate_src_iter_init (pixman_implementation_t *imp,
68                         pixman_iter_t *          iter)
69 {
70     imp->delegate->src_iter_init (imp->delegate, iter);
71 }
72
73 static void
74 delegate_dest_iter_init (pixman_implementation_t *imp,
75                          pixman_iter_t *          iter)
76 {
77     imp->delegate->dest_iter_init (imp->delegate, iter);
78 }
79
80 pixman_implementation_t *
81 _pixman_implementation_create (pixman_implementation_t *delegate,
82                                const pixman_fast_path_t *fast_paths)
83 {
84     pixman_implementation_t *imp = malloc (sizeof (pixman_implementation_t));
85     pixman_implementation_t *d;
86     int i;
87
88     if (!imp)
89         return NULL;
90
91     assert (fast_paths);
92
93     /* Make sure the whole delegate chain has the right toplevel */
94     imp->delegate = delegate;
95     for (d = imp; d != NULL; d = d->delegate)
96         d->toplevel = imp;
97
98     /* Fill out function pointers with ones that just delegate
99      */
100     imp->blt = delegate_blt;
101     imp->fill = delegate_fill;
102     imp->src_iter_init = delegate_src_iter_init;
103     imp->dest_iter_init = delegate_dest_iter_init;
104
105     imp->fast_paths = fast_paths;
106
107     for (i = 0; i < PIXMAN_N_OPERATORS; ++i)
108     {
109         imp->combine_32[i] = NULL;
110         imp->combine_64[i] = NULL;
111         imp->combine_32_ca[i] = NULL;
112         imp->combine_64_ca[i] = NULL;
113     }
114
115     return imp;
116 }
117
118 pixman_combine_32_func_t
119 _pixman_implementation_lookup_combiner (pixman_implementation_t *imp,
120                                         pixman_op_t              op,
121                                         pixman_bool_t            component_alpha,
122                                         pixman_bool_t            narrow)
123 {
124     pixman_combine_32_func_t f;
125
126     do
127     {
128         pixman_combine_32_func_t (*combiners[]) =
129         {
130             (pixman_combine_32_func_t *)imp->combine_64,
131             (pixman_combine_32_func_t *)imp->combine_64_ca,
132             imp->combine_32,
133             imp->combine_32_ca,
134         };
135
136         f = combiners[component_alpha | (narrow << 1)][op];
137
138         imp = imp->delegate;
139     }
140     while (!f);
141
142     return f;
143 }
144
145 pixman_bool_t
146 _pixman_implementation_blt (pixman_implementation_t * imp,
147                             uint32_t *                src_bits,
148                             uint32_t *                dst_bits,
149                             int                       src_stride,
150                             int                       dst_stride,
151                             int                       src_bpp,
152                             int                       dst_bpp,
153                             int                       src_x,
154                             int                       src_y,
155                             int                       dest_x,
156                             int                       dest_y,
157                             int                       width,
158                             int                       height)
159 {
160     return (*imp->blt) (imp, src_bits, dst_bits, src_stride, dst_stride,
161                         src_bpp, dst_bpp, src_x, src_y, dest_x, dest_y,
162                         width, height);
163 }
164
165 pixman_bool_t
166 _pixman_implementation_fill (pixman_implementation_t *imp,
167                              uint32_t *               bits,
168                              int                      stride,
169                              int                      bpp,
170                              int                      x,
171                              int                      y,
172                              int                      width,
173                              int                      height,
174                              uint32_t                 xor)
175 {
176     return (*imp->fill) (imp, bits, stride, bpp, x, y, width, height, xor);
177 }
178
179 void
180 _pixman_implementation_src_iter_init (pixman_implementation_t   *imp,
181                                       pixman_iter_t             *iter,
182                                       pixman_image_t            *image,
183                                       int                        x,
184                                       int                        y,
185                                       int                        width,
186                                       int                        height,
187                                       uint8_t                   *buffer,
188                                       iter_flags_t               flags)
189 {
190     iter->image = image;
191     iter->buffer = (uint32_t *)buffer;
192     iter->x = x;
193     iter->y = y;
194     iter->width = width;
195     iter->height = height;
196     iter->flags = flags;
197
198     (*imp->src_iter_init) (imp, iter);
199 }
200
201 void
202 _pixman_implementation_dest_iter_init (pixman_implementation_t  *imp,
203                                        pixman_iter_t            *iter,
204                                        pixman_image_t           *image,
205                                        int                       x,
206                                        int                       y,
207                                        int                       width,
208                                        int                       height,
209                                        uint8_t                  *buffer,
210                                        iter_flags_t              flags)
211 {
212     iter->image = image;
213     iter->buffer = (uint32_t *)buffer;
214     iter->x = x;
215     iter->y = y;
216     iter->width = width;
217     iter->height = height;
218     iter->flags = flags;
219
220     (*imp->dest_iter_init) (imp, iter);
221 }