ARM: added flags parameter to some asm fast path wrapper macros
[profile/ivi/pixman.git] / pixman / pixman-arm-common.h
1 /*
2  * Copyright © 2010 Nokia Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Author:  Siarhei Siamashka (siarhei.siamashka@nokia.com)
24  */
25
26 #ifndef PIXMAN_ARM_COMMON_H
27 #define PIXMAN_ARM_COMMON_H
28
29 #include "pixman-fast-path.h"
30
31 /* Define some macros which can expand into proxy functions between
32  * ARM assembly optimized functions and the rest of pixman fast path API.
33  *
34  * All the low level ARM assembly functions have to use ARM EABI
35  * calling convention and take up to 8 arguments:
36  *    width, height, dst, dst_stride, src, src_stride, mask, mask_stride
37  *
38  * The arguments are ordered with the most important coming first (the
39  * first 4 arguments are passed to function in registers, the rest are
40  * on stack). The last arguments are optional, for example if the
41  * function is not using mask, then 'mask' and 'mask_stride' can be
42  * omitted when doing a function call.
43  *
44  * Arguments 'src' and 'mask' contain either a pointer to the top left
45  * pixel of the composited rectangle or a pixel color value depending
46  * on the function type. In the case of just a color value (solid source
47  * or mask), the corresponding stride argument is unused.
48  */
49
50 #define SKIP_ZERO_SRC  1
51 #define SKIP_ZERO_MASK 2
52
53 #define PIXMAN_ARM_BIND_FAST_PATH_SRC_DST(cputype, name,                \
54                                           src_type, src_cnt,            \
55                                           dst_type, dst_cnt)            \
56 void                                                                    \
57 pixman_composite_##name##_asm_##cputype (int32_t   w,                   \
58                                          int32_t   h,                   \
59                                          dst_type *dst,                 \
60                                          int32_t   dst_stride,          \
61                                          src_type *src,                 \
62                                          int32_t   src_stride);         \
63                                                                         \
64 static void                                                             \
65 cputype##_composite_##name (pixman_implementation_t *imp,               \
66                             pixman_op_t              op,                \
67                             pixman_image_t *         src_image,         \
68                             pixman_image_t *         mask_image,        \
69                             pixman_image_t *         dst_image,         \
70                             int32_t                  src_x,             \
71                             int32_t                  src_y,             \
72                             int32_t                  mask_x,            \
73                             int32_t                  mask_y,            \
74                             int32_t                  dest_x,            \
75                             int32_t                  dest_y,            \
76                             int32_t                  width,             \
77                             int32_t                  height)            \
78 {                                                                       \
79     dst_type *dst_line;                                                 \
80     src_type *src_line;                                                 \
81     int32_t dst_stride, src_stride;                                     \
82                                                                         \
83     PIXMAN_IMAGE_GET_LINE (src_image, src_x, src_y, src_type,           \
84                            src_stride, src_line, src_cnt);              \
85     PIXMAN_IMAGE_GET_LINE (dst_image, dest_x, dest_y, dst_type,         \
86                            dst_stride, dst_line, dst_cnt);              \
87                                                                         \
88     pixman_composite_##name##_asm_##cputype (width, height,             \
89                                              dst_line, dst_stride,      \
90                                              src_line, src_stride);     \
91 }
92
93 #define PIXMAN_ARM_BIND_FAST_PATH_N_DST(flags, cputype, name,           \
94                                         dst_type, dst_cnt)              \
95 void                                                                    \
96 pixman_composite_##name##_asm_##cputype (int32_t    w,                  \
97                                          int32_t    h,                  \
98                                          dst_type  *dst,                \
99                                          int32_t    dst_stride,         \
100                                          uint32_t   src);               \
101                                                                         \
102 static void                                                             \
103 cputype##_composite_##name (pixman_implementation_t *imp,               \
104                             pixman_op_t              op,                \
105                             pixman_image_t *         src_image,         \
106                             pixman_image_t *         mask_image,        \
107                             pixman_image_t *         dst_image,         \
108                             int32_t                  src_x,             \
109                             int32_t                  src_y,             \
110                             int32_t                  mask_x,            \
111                             int32_t                  mask_y,            \
112                             int32_t                  dest_x,            \
113                             int32_t                  dest_y,            \
114                             int32_t                  width,             \
115                             int32_t                  height)            \
116 {                                                                       \
117     dst_type  *dst_line;                                                \
118     int32_t    dst_stride;                                              \
119     uint32_t   src;                                                     \
120                                                                         \
121     src = _pixman_image_get_solid (src_image, dst_image->bits.format);  \
122                                                                         \
123     if ((flags & SKIP_ZERO_SRC) && src == 0)                            \
124         return;                                                         \
125                                                                         \
126     PIXMAN_IMAGE_GET_LINE (dst_image, dest_x, dest_y, dst_type,         \
127                            dst_stride, dst_line, dst_cnt);              \
128                                                                         \
129     pixman_composite_##name##_asm_##cputype (width, height,             \
130                                              dst_line, dst_stride,      \
131                                              src);                      \
132 }
133
134 #define PIXMAN_ARM_BIND_FAST_PATH_N_MASK_DST(flags, cputype, name,      \
135                                              mask_type, mask_cnt,       \
136                                              dst_type, dst_cnt)         \
137 void                                                                    \
138 pixman_composite_##name##_asm_##cputype (int32_t    w,                  \
139                                          int32_t    h,                  \
140                                          dst_type  *dst,                \
141                                          int32_t    dst_stride,         \
142                                          uint32_t   src,                \
143                                          int32_t    unused,             \
144                                          mask_type *mask,               \
145                                          int32_t    mask_stride);       \
146                                                                         \
147 static void                                                             \
148 cputype##_composite_##name (pixman_implementation_t *imp,               \
149                             pixman_op_t              op,                \
150                             pixman_image_t *         src_image,         \
151                             pixman_image_t *         mask_image,        \
152                             pixman_image_t *         dst_image,         \
153                             int32_t                  src_x,             \
154                             int32_t                  src_y,             \
155                             int32_t                  mask_x,            \
156                             int32_t                  mask_y,            \
157                             int32_t                  dest_x,            \
158                             int32_t                  dest_y,            \
159                             int32_t                  width,             \
160                             int32_t                  height)            \
161 {                                                                       \
162     dst_type  *dst_line;                                                \
163     mask_type *mask_line;                                               \
164     int32_t    dst_stride, mask_stride;                                 \
165     uint32_t   src;                                                     \
166                                                                         \
167     src = _pixman_image_get_solid (src_image, dst_image->bits.format);  \
168                                                                         \
169     if ((flags & SKIP_ZERO_SRC) && src == 0)                            \
170         return;                                                         \
171                                                                         \
172     PIXMAN_IMAGE_GET_LINE (dst_image, dest_x, dest_y, dst_type,         \
173                            dst_stride, dst_line, dst_cnt);              \
174     PIXMAN_IMAGE_GET_LINE (mask_image, mask_x, mask_y, mask_type,       \
175                            mask_stride, mask_line, mask_cnt);           \
176                                                                         \
177     pixman_composite_##name##_asm_##cputype (width, height,             \
178                                              dst_line, dst_stride,      \
179                                              src, 0,                    \
180                                              mask_line, mask_stride);   \
181 }
182
183 #define PIXMAN_ARM_BIND_FAST_PATH_SRC_N_DST(flags, cputype, name,       \
184                                             src_type, src_cnt,          \
185                                             dst_type, dst_cnt)          \
186 void                                                                    \
187 pixman_composite_##name##_asm_##cputype (int32_t    w,                  \
188                                          int32_t    h,                  \
189                                          dst_type  *dst,                \
190                                          int32_t    dst_stride,         \
191                                          src_type  *src,                \
192                                          int32_t    src_stride,         \
193                                          uint32_t   mask);              \
194                                                                         \
195 static void                                                             \
196 cputype##_composite_##name (pixman_implementation_t *imp,               \
197                             pixman_op_t              op,                \
198                             pixman_image_t *         src_image,         \
199                             pixman_image_t *         mask_image,        \
200                             pixman_image_t *         dst_image,         \
201                             int32_t                  src_x,             \
202                             int32_t                  src_y,             \
203                             int32_t                  mask_x,            \
204                             int32_t                  mask_y,            \
205                             int32_t                  dest_x,            \
206                             int32_t                  dest_y,            \
207                             int32_t                  width,             \
208                             int32_t                  height)            \
209 {                                                                       \
210     dst_type  *dst_line;                                                \
211     src_type  *src_line;                                                \
212     int32_t    dst_stride, src_stride;                                  \
213     uint32_t   mask;                                                    \
214                                                                         \
215     mask = _pixman_image_get_solid (mask_image, dst_image->bits.format);\
216                                                                         \
217     if ((flags & SKIP_ZERO_MASK) && mask == 0)                          \
218         return;                                                         \
219                                                                         \
220     PIXMAN_IMAGE_GET_LINE (dst_image, dest_x, dest_y, dst_type,         \
221                            dst_stride, dst_line, dst_cnt);              \
222     PIXMAN_IMAGE_GET_LINE (src_image, src_x, src_y, src_type,           \
223                            src_stride, src_line, src_cnt);              \
224                                                                         \
225     pixman_composite_##name##_asm_##cputype (width, height,             \
226                                              dst_line, dst_stride,      \
227                                              src_line, src_stride,      \
228                                              mask);                     \
229 }
230
231 #define PIXMAN_ARM_BIND_FAST_PATH_SRC_MASK_DST(cputype, name,           \
232                                                src_type, src_cnt,       \
233                                                mask_type, mask_cnt,     \
234                                                dst_type, dst_cnt)       \
235 void                                                                    \
236 pixman_composite_##name##_asm_##cputype (int32_t    w,                  \
237                                          int32_t    h,                  \
238                                          dst_type  *dst,                \
239                                          int32_t    dst_stride,         \
240                                          src_type  *src,                \
241                                          int32_t    src_stride,         \
242                                          mask_type *mask,               \
243                                          int32_t    mask_stride);       \
244                                                                         \
245 static void                                                             \
246 cputype##_composite_##name (pixman_implementation_t *imp,               \
247                             pixman_op_t              op,                \
248                             pixman_image_t *         src_image,         \
249                             pixman_image_t *         mask_image,        \
250                             pixman_image_t *         dst_image,         \
251                             int32_t                  src_x,             \
252                             int32_t                  src_y,             \
253                             int32_t                  mask_x,            \
254                             int32_t                  mask_y,            \
255                             int32_t                  dest_x,            \
256                             int32_t                  dest_y,            \
257                             int32_t                  width,             \
258                             int32_t                  height)            \
259 {                                                                       \
260     dst_type  *dst_line;                                                \
261     src_type  *src_line;                                                \
262     mask_type *mask_line;                                               \
263     int32_t    dst_stride, src_stride, mask_stride;                     \
264                                                                         \
265     PIXMAN_IMAGE_GET_LINE (dst_image, dest_x, dest_y, dst_type,         \
266                            dst_stride, dst_line, dst_cnt);              \
267     PIXMAN_IMAGE_GET_LINE (src_image, src_x, src_y, src_type,           \
268                            src_stride, src_line, src_cnt);              \
269     PIXMAN_IMAGE_GET_LINE (mask_image, mask_x, mask_y, mask_type,       \
270                            mask_stride, mask_line, mask_cnt);           \
271                                                                         \
272     pixman_composite_##name##_asm_##cputype (width, height,             \
273                                              dst_line, dst_stride,      \
274                                              src_line, src_stride,      \
275                                              mask_line, mask_stride);   \
276 }
277
278 #define PIXMAN_ARM_BIND_SCALED_NEAREST_SRC_DST(cputype, name, op,             \
279                                                src_type, dst_type)            \
280 void                                                                          \
281 pixman_scaled_nearest_scanline_##name##_##op##_asm_##cputype (                \
282                                                        int32_t        w,      \
283                                                        dst_type *     dst,    \
284                                                        src_type *     src,    \
285                                                        pixman_fixed_t vx,     \
286                                                        pixman_fixed_t unit_x);\
287                                                                               \
288 static force_inline void                                                      \
289 scaled_nearest_scanline_##cputype##_##name##_##op (dst_type *       pd,       \
290                                                    src_type *       ps,       \
291                                                    int32_t          w,        \
292                                                    pixman_fixed_t   vx,       \
293                                                    pixman_fixed_t   unit_x,   \
294                                                    pixman_fixed_t   max_vx)   \
295 {                                                                             \
296     pixman_scaled_nearest_scanline_##name##_##op##_asm_##cputype (w, pd, ps,  \
297                                                                   vx, unit_x);\
298 }                                                                             \
299                                                                               \
300 FAST_NEAREST_MAINLOOP (cputype##_##name##_cover_##op,                         \
301                        scaled_nearest_scanline_##cputype##_##name##_##op,     \
302                        src_type, dst_type, COVER)                             \
303 FAST_NEAREST_MAINLOOP (cputype##_##name##_none_##op,                          \
304                        scaled_nearest_scanline_##cputype##_##name##_##op,     \
305                        src_type, dst_type, NONE)                              \
306 FAST_NEAREST_MAINLOOP (cputype##_##name##_pad_##op,                           \
307                        scaled_nearest_scanline_##cputype##_##name##_##op,     \
308                        src_type, dst_type, PAD)
309
310 /* Provide entries for the fast path table */
311 #define PIXMAN_ARM_SIMPLE_NEAREST_FAST_PATH(op,s,d,func)                      \
312     SIMPLE_NEAREST_FAST_PATH_COVER (op,s,d,func),                             \
313     SIMPLE_NEAREST_FAST_PATH_NONE (op,s,d,func),                              \
314     SIMPLE_NEAREST_FAST_PATH_PAD (op,s,d,func)
315
316 #endif