In pixman-general.c rename image_parameters to {src, mask, dest}_image
[profile/ivi/pixman.git] / pixman / pixman-general.c
1 /*
2  * Copyright © 2009 Red Hat, Inc.
3  * Copyright © 2000 SuSE, Inc.
4  * Copyright © 2007 Red Hat, Inc.
5  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
6  *             2005 Lars Knoll & Zack Rusin, Trolltech
7  *             2008 Aaron Plattner, NVIDIA Corporation
8  *
9  * Permission to use, copy, modify, distribute, and sell this software and its
10  * documentation for any purpose is hereby granted without fee, provided that
11  * the above copyright notice appear in all copies and that both that
12  * copyright notice and this permission notice appear in supporting
13  * documentation, and that the name of Red Hat not be used in advertising or
14  * publicity pertaining to distribution of the software without specific,
15  * written prior permission.  Red Hat makes no representations about the
16  * suitability of this software for any purpose.  It is provided "as is"
17  * without express or implied warranty.
18  *
19  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
20  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
23  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
24  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
25  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
26  * SOFTWARE.
27  */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include <stdlib.h>
32 #include <string.h>
33 #include <math.h>
34 #include <limits.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include "pixman-private.h"
39
40 static void
41 general_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
42 {
43     pixman_image_t *image = iter->image;
44
45     if (image->type == SOLID)
46         _pixman_solid_fill_iter_init (image, iter);
47     else if (image->type == LINEAR)
48         _pixman_linear_gradient_iter_init (image, iter);
49     else if (image->type == RADIAL)
50         _pixman_radial_gradient_iter_init (image, iter);
51     else if (image->type == CONICAL)
52         _pixman_conical_gradient_iter_init (image, iter);
53     else if (image->type == BITS)
54         _pixman_bits_image_src_iter_init (image, iter);
55     else
56         _pixman_log_error (FUNC, "Pixman bug: unknown image type\n");
57 }
58
59 static void
60 general_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
61 {
62     if (iter->image->type == BITS)
63     {
64         _pixman_bits_image_dest_iter_init (iter->image, iter);
65     }
66     else
67     {
68         _pixman_log_error (FUNC, "Trying to write to a non-writable image");
69     }
70 }
71
72 typedef struct op_info_t op_info_t;
73 struct op_info_t
74 {
75     uint8_t src, dst;
76 };
77
78 #define ITER_IGNORE_BOTH                                                \
79     (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB | ITER_LOCALIZED_ALPHA)
80
81 static const op_info_t op_flags[PIXMAN_N_OPERATORS] =
82 {
83     /* Src                   Dst                   */
84     { ITER_IGNORE_BOTH,      ITER_IGNORE_BOTH      }, /* CLEAR */
85     { ITER_LOCALIZED_ALPHA,  ITER_IGNORE_BOTH      }, /* SRC */
86     { ITER_IGNORE_BOTH,      ITER_LOCALIZED_ALPHA  }, /* DST */
87     { 0,                     ITER_LOCALIZED_ALPHA  }, /* OVER */
88     { ITER_LOCALIZED_ALPHA,  0                     }, /* OVER_REVERSE */
89     { ITER_LOCALIZED_ALPHA,  ITER_IGNORE_RGB       }, /* IN */
90     { ITER_IGNORE_RGB,       ITER_LOCALIZED_ALPHA  }, /* IN_REVERSE */
91     { ITER_LOCALIZED_ALPHA,  ITER_IGNORE_RGB       }, /* OUT */
92     { ITER_IGNORE_RGB,       ITER_LOCALIZED_ALPHA  }, /* OUT_REVERSE */
93     { 0,                     0                     }, /* ATOP */
94     { 0,                     0                     }, /* ATOP_REVERSE */
95     { 0,                     0                     }, /* XOR */
96     { ITER_LOCALIZED_ALPHA,  ITER_LOCALIZED_ALPHA  }, /* ADD */
97     { 0,                     0                     }, /* SATURATE */
98 };
99
100 #define SCANLINE_BUFFER_LENGTH 8192
101
102 static void
103 general_composite_rect  (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 *         dest_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     uint64_t stack_scanline_buffer[(SCANLINE_BUFFER_LENGTH * 3 + 7) / 8];
118     uint8_t *scanline_buffer = (uint8_t *) stack_scanline_buffer;
119     uint8_t *src_buffer, *mask_buffer, *dest_buffer;
120     pixman_iter_t src_iter, mask_iter, dest_iter;
121     pixman_combine_32_func_t compose;
122     pixman_bool_t component_alpha;
123     iter_flags_t narrow, src_flags;
124     int Bpp;
125     int i;
126
127     if ((src_image->common.flags & FAST_PATH_NARROW_FORMAT)                 &&
128         (!mask_image || mask_image->common.flags & FAST_PATH_NARROW_FORMAT) &&
129         (dest_image->common.flags & FAST_PATH_NARROW_FORMAT))
130     {
131         narrow = ITER_NARROW;
132         Bpp = 4;
133     }
134     else
135     {
136         narrow = 0;
137         Bpp = 8;
138     }
139
140     if (width * Bpp > SCANLINE_BUFFER_LENGTH)
141     {
142         scanline_buffer = pixman_malloc_abc (width, 3, Bpp);
143
144         if (!scanline_buffer)
145             return;
146     }
147
148     src_buffer = scanline_buffer;
149     mask_buffer = src_buffer + width * Bpp;
150     dest_buffer = mask_buffer + width * Bpp;
151
152     /* src iter */
153     src_flags = narrow | op_flags[op].src;
154
155     _pixman_implementation_src_iter_init (imp->toplevel, &src_iter, src_image,
156                                           src_x, src_y, width, height,
157                                           src_buffer, src_flags);
158
159     /* mask iter */
160     if ((src_flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) ==
161         (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB))
162     {
163         /* If it doesn't matter what the source is, then it doesn't matter
164          * what the mask is
165          */
166         mask_image = NULL;
167     }
168
169     component_alpha =
170         mask_image                            &&
171         mask_image->common.type == BITS       &&
172         mask_image->common.component_alpha    &&
173         PIXMAN_FORMAT_RGB (mask_image->bits.format);
174
175     _pixman_implementation_src_iter_init (
176         imp->toplevel, &mask_iter, mask_image, mask_x, mask_y, width, height,
177         mask_buffer, narrow | (component_alpha? 0 : ITER_IGNORE_RGB));
178
179     /* dest iter */
180     _pixman_implementation_dest_iter_init (
181         imp->toplevel, &dest_iter, dest_image, dest_x, dest_y, width, height,
182         dest_buffer, narrow | op_flags[op].dst);
183
184     if (narrow)
185     {
186         if (component_alpha)
187             compose = _pixman_implementation_combine_32_ca;
188         else
189             compose = _pixman_implementation_combine_32;
190     }
191     else
192     {
193         if (component_alpha)
194             compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64_ca;
195         else
196             compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64;
197     }
198
199     if (!compose)
200         return;
201
202     for (i = 0; i < height; ++i)
203     {
204         uint32_t *s, *m, *d;
205
206         m = mask_iter.get_scanline (&mask_iter, NULL);
207         s = src_iter.get_scanline (&src_iter, m);
208         d = dest_iter.get_scanline (&dest_iter, NULL);
209
210         compose (imp->toplevel, op, d, s, m, width);
211
212         dest_iter.write_back (&dest_iter);
213     }
214
215     if (scanline_buffer != (uint8_t *) stack_scanline_buffer)
216         free (scanline_buffer);
217 }
218
219 static const pixman_fast_path_t general_fast_path[] =
220 {
221     { PIXMAN_OP_any, PIXMAN_any, 0, PIXMAN_any, 0, PIXMAN_any, 0, general_composite_rect },
222     { PIXMAN_OP_NONE }
223 };
224
225 static pixman_bool_t
226 general_blt (pixman_implementation_t *imp,
227              uint32_t *               src_bits,
228              uint32_t *               dst_bits,
229              int                      src_stride,
230              int                      dst_stride,
231              int                      src_bpp,
232              int                      dst_bpp,
233              int                      src_x,
234              int                      src_y,
235              int                      dest_x,
236              int                      dest_y,
237              int                      width,
238              int                      height)
239 {
240     /* We can't blit unless we have sse2 or mmx */
241
242     return FALSE;
243 }
244
245 static pixman_bool_t
246 general_fill (pixman_implementation_t *imp,
247               uint32_t *               bits,
248               int                      stride,
249               int                      bpp,
250               int                      x,
251               int                      y,
252               int                      width,
253               int                      height,
254               uint32_t xor)
255 {
256     return FALSE;
257 }
258
259 pixman_implementation_t *
260 _pixman_implementation_create_general (void)
261 {
262     pixman_implementation_t *imp = _pixman_implementation_create (NULL, general_fast_path);
263
264     _pixman_setup_combiner_functions_32 (imp);
265     _pixman_setup_combiner_functions_64 (imp);
266
267     imp->blt = general_blt;
268     imp->fill = general_fill;
269     imp->src_iter_init = general_src_iter_init;
270     imp->dest_iter_init = general_dest_iter_init;
271
272     return imp;
273 }
274