Better support for NONE repeat in nearest scaling main loop template
[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 (                                     \
122         imp, src_image, dst_image->bits.format);                        \
123                                                                         \
124     if ((flags & SKIP_ZERO_SRC) && src == 0)                            \
125         return;                                                         \
126                                                                         \
127     PIXMAN_IMAGE_GET_LINE (dst_image, dest_x, dest_y, dst_type,         \
128                            dst_stride, dst_line, dst_cnt);              \
129                                                                         \
130     pixman_composite_##name##_asm_##cputype (width, height,             \
131                                              dst_line, dst_stride,      \
132                                              src);                      \
133 }
134
135 #define PIXMAN_ARM_BIND_FAST_PATH_N_MASK_DST(flags, cputype, name,      \
136                                              mask_type, mask_cnt,       \
137                                              dst_type, dst_cnt)         \
138 void                                                                    \
139 pixman_composite_##name##_asm_##cputype (int32_t    w,                  \
140                                          int32_t    h,                  \
141                                          dst_type  *dst,                \
142                                          int32_t    dst_stride,         \
143                                          uint32_t   src,                \
144                                          int32_t    unused,             \
145                                          mask_type *mask,               \
146                                          int32_t    mask_stride);       \
147                                                                         \
148 static void                                                             \
149 cputype##_composite_##name (pixman_implementation_t *imp,               \
150                             pixman_op_t              op,                \
151                             pixman_image_t *         src_image,         \
152                             pixman_image_t *         mask_image,        \
153                             pixman_image_t *         dst_image,         \
154                             int32_t                  src_x,             \
155                             int32_t                  src_y,             \
156                             int32_t                  mask_x,            \
157                             int32_t                  mask_y,            \
158                             int32_t                  dest_x,            \
159                             int32_t                  dest_y,            \
160                             int32_t                  width,             \
161                             int32_t                  height)            \
162 {                                                                       \
163     dst_type  *dst_line;                                                \
164     mask_type *mask_line;                                               \
165     int32_t    dst_stride, mask_stride;                                 \
166     uint32_t   src;                                                     \
167                                                                         \
168     src = _pixman_image_get_solid (                                     \
169         imp, src_image, dst_image->bits.format);                        \
170                                                                         \
171     if ((flags & SKIP_ZERO_SRC) && src == 0)                            \
172         return;                                                         \
173                                                                         \
174     PIXMAN_IMAGE_GET_LINE (dst_image, dest_x, dest_y, dst_type,         \
175                            dst_stride, dst_line, dst_cnt);              \
176     PIXMAN_IMAGE_GET_LINE (mask_image, mask_x, mask_y, mask_type,       \
177                            mask_stride, mask_line, mask_cnt);           \
178                                                                         \
179     pixman_composite_##name##_asm_##cputype (width, height,             \
180                                              dst_line, dst_stride,      \
181                                              src, 0,                    \
182                                              mask_line, mask_stride);   \
183 }
184
185 #define PIXMAN_ARM_BIND_FAST_PATH_SRC_N_DST(flags, cputype, name,       \
186                                             src_type, src_cnt,          \
187                                             dst_type, dst_cnt)          \
188 void                                                                    \
189 pixman_composite_##name##_asm_##cputype (int32_t    w,                  \
190                                          int32_t    h,                  \
191                                          dst_type  *dst,                \
192                                          int32_t    dst_stride,         \
193                                          src_type  *src,                \
194                                          int32_t    src_stride,         \
195                                          uint32_t   mask);              \
196                                                                         \
197 static void                                                             \
198 cputype##_composite_##name (pixman_implementation_t *imp,               \
199                             pixman_op_t              op,                \
200                             pixman_image_t *         src_image,         \
201                             pixman_image_t *         mask_image,        \
202                             pixman_image_t *         dst_image,         \
203                             int32_t                  src_x,             \
204                             int32_t                  src_y,             \
205                             int32_t                  mask_x,            \
206                             int32_t                  mask_y,            \
207                             int32_t                  dest_x,            \
208                             int32_t                  dest_y,            \
209                             int32_t                  width,             \
210                             int32_t                  height)            \
211 {                                                                       \
212     dst_type  *dst_line;                                                \
213     src_type  *src_line;                                                \
214     int32_t    dst_stride, src_stride;                                  \
215     uint32_t   mask;                                                    \
216                                                                         \
217     mask = _pixman_image_get_solid (                                    \
218         imp, mask_image, dst_image->bits.format);                       \
219                                                                         \
220     if ((flags & SKIP_ZERO_MASK) && mask == 0)                          \
221         return;                                                         \
222                                                                         \
223     PIXMAN_IMAGE_GET_LINE (dst_image, dest_x, dest_y, dst_type,         \
224                            dst_stride, dst_line, dst_cnt);              \
225     PIXMAN_IMAGE_GET_LINE (src_image, src_x, src_y, src_type,           \
226                            src_stride, src_line, src_cnt);              \
227                                                                         \
228     pixman_composite_##name##_asm_##cputype (width, height,             \
229                                              dst_line, dst_stride,      \
230                                              src_line, src_stride,      \
231                                              mask);                     \
232 }
233
234 #define PIXMAN_ARM_BIND_FAST_PATH_SRC_MASK_DST(cputype, name,           \
235                                                src_type, src_cnt,       \
236                                                mask_type, mask_cnt,     \
237                                                dst_type, dst_cnt)       \
238 void                                                                    \
239 pixman_composite_##name##_asm_##cputype (int32_t    w,                  \
240                                          int32_t    h,                  \
241                                          dst_type  *dst,                \
242                                          int32_t    dst_stride,         \
243                                          src_type  *src,                \
244                                          int32_t    src_stride,         \
245                                          mask_type *mask,               \
246                                          int32_t    mask_stride);       \
247                                                                         \
248 static void                                                             \
249 cputype##_composite_##name (pixman_implementation_t *imp,               \
250                             pixman_op_t              op,                \
251                             pixman_image_t *         src_image,         \
252                             pixman_image_t *         mask_image,        \
253                             pixman_image_t *         dst_image,         \
254                             int32_t                  src_x,             \
255                             int32_t                  src_y,             \
256                             int32_t                  mask_x,            \
257                             int32_t                  mask_y,            \
258                             int32_t                  dest_x,            \
259                             int32_t                  dest_y,            \
260                             int32_t                  width,             \
261                             int32_t                  height)            \
262 {                                                                       \
263     dst_type  *dst_line;                                                \
264     src_type  *src_line;                                                \
265     mask_type *mask_line;                                               \
266     int32_t    dst_stride, src_stride, mask_stride;                     \
267                                                                         \
268     PIXMAN_IMAGE_GET_LINE (dst_image, dest_x, dest_y, dst_type,         \
269                            dst_stride, dst_line, dst_cnt);              \
270     PIXMAN_IMAGE_GET_LINE (src_image, src_x, src_y, src_type,           \
271                            src_stride, src_line, src_cnt);              \
272     PIXMAN_IMAGE_GET_LINE (mask_image, mask_x, mask_y, mask_type,       \
273                            mask_stride, mask_line, mask_cnt);           \
274                                                                         \
275     pixman_composite_##name##_asm_##cputype (width, height,             \
276                                              dst_line, dst_stride,      \
277                                              src_line, src_stride,      \
278                                              mask_line, mask_stride);   \
279 }
280
281 #define PIXMAN_ARM_BIND_SCALED_NEAREST_SRC_DST(cputype, name, op,             \
282                                                src_type, dst_type)            \
283 void                                                                          \
284 pixman_scaled_nearest_scanline_##name##_##op##_asm_##cputype (                \
285                                                    int32_t          w,        \
286                                                    dst_type *       dst,      \
287                                                    const src_type * src,      \
288                                                    pixman_fixed_t   vx,       \
289                                                    pixman_fixed_t   unit_x);  \
290                                                                               \
291 static force_inline void                                                      \
292 scaled_nearest_scanline_##cputype##_##name##_##op (dst_type *       pd,       \
293                                                    const src_type * ps,       \
294                                                    int32_t          w,        \
295                                                    pixman_fixed_t   vx,       \
296                                                    pixman_fixed_t   unit_x,   \
297                                                    pixman_fixed_t   max_vx,   \
298                                                    pixman_bool_t    zero_src) \
299 {                                                                             \
300     pixman_scaled_nearest_scanline_##name##_##op##_asm_##cputype (w, pd, ps,  \
301                                                                   vx, unit_x);\
302 }                                                                             \
303                                                                               \
304 FAST_NEAREST_MAINLOOP (cputype##_##name##_cover_##op,                         \
305                        scaled_nearest_scanline_##cputype##_##name##_##op,     \
306                        src_type, dst_type, COVER)                             \
307 FAST_NEAREST_MAINLOOP (cputype##_##name##_none_##op,                          \
308                        scaled_nearest_scanline_##cputype##_##name##_##op,     \
309                        src_type, dst_type, NONE)                              \
310 FAST_NEAREST_MAINLOOP (cputype##_##name##_pad_##op,                           \
311                        scaled_nearest_scanline_##cputype##_##name##_##op,     \
312                        src_type, dst_type, PAD)
313
314 /* Provide entries for the fast path table */
315 #define PIXMAN_ARM_SIMPLE_NEAREST_FAST_PATH(op,s,d,func)                      \
316     SIMPLE_NEAREST_FAST_PATH_COVER (op,s,d,func),                             \
317     SIMPLE_NEAREST_FAST_PATH_NONE (op,s,d,func),                              \
318     SIMPLE_NEAREST_FAST_PATH_PAD (op,s,d,func)
319
320 #endif