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
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.
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
38 #include "pixman-private.h"
41 general_iter_init (pixman_iter_t *iter, const pixman_iter_info_t *info)
43 pixman_image_t *image = iter->image;
48 if ((iter->iter_flags & ITER_SRC) == ITER_SRC)
49 _pixman_bits_image_src_iter_init (image, iter);
51 _pixman_bits_image_dest_iter_init (image, iter);
55 _pixman_linear_gradient_iter_init (image, iter);
59 _pixman_radial_gradient_iter_init (image, iter);
63 _pixman_conical_gradient_iter_init (image, iter);
67 _pixman_log_error (FUNC, "Solid image not handled by noop");
71 _pixman_log_error (FUNC, "Pixman bug: unknown image type\n");
76 static const pixman_iter_info_t general_iters[] =
78 { PIXMAN_any, 0, 0, general_iter_init, NULL, NULL },
82 typedef struct op_info_t op_info_t;
88 #define ITER_IGNORE_BOTH \
89 (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB | ITER_LOCALIZED_ALPHA)
91 static const op_info_t op_flags[PIXMAN_N_OPERATORS] =
94 { ITER_IGNORE_BOTH, ITER_IGNORE_BOTH }, /* CLEAR */
95 { ITER_LOCALIZED_ALPHA, ITER_IGNORE_BOTH }, /* SRC */
96 { ITER_IGNORE_BOTH, ITER_LOCALIZED_ALPHA }, /* DST */
97 { 0, ITER_LOCALIZED_ALPHA }, /* OVER */
98 { ITER_LOCALIZED_ALPHA, 0 }, /* OVER_REVERSE */
99 { ITER_LOCALIZED_ALPHA, ITER_IGNORE_RGB }, /* IN */
100 { ITER_IGNORE_RGB, ITER_LOCALIZED_ALPHA }, /* IN_REVERSE */
101 { ITER_LOCALIZED_ALPHA, ITER_IGNORE_RGB }, /* OUT */
102 { ITER_IGNORE_RGB, ITER_LOCALIZED_ALPHA }, /* OUT_REVERSE */
104 { 0, 0 }, /* ATOP_REVERSE */
106 { ITER_LOCALIZED_ALPHA, ITER_LOCALIZED_ALPHA }, /* ADD */
107 { 0, 0 }, /* SATURATE */
110 #define SCANLINE_BUFFER_LENGTH 8192
113 general_composite_rect (pixman_implementation_t *imp,
114 pixman_composite_info_t *info)
116 PIXMAN_COMPOSITE_ARGS (info);
117 uint8_t stack_scanline_buffer[3 * SCANLINE_BUFFER_LENGTH];
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 width_flag, src_iter_flags;
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))
131 width_flag = ITER_NARROW;
136 width_flag = ITER_WIDE;
140 #define ALIGN(addr) \
141 ((uint8_t *)((((uintptr_t)(addr)) + 15) & (~15)))
143 src_buffer = ALIGN (scanline_buffer);
144 mask_buffer = ALIGN (src_buffer + width * Bpp);
145 dest_buffer = ALIGN (mask_buffer + width * Bpp);
147 if (ALIGN (dest_buffer + width * Bpp) >
148 scanline_buffer + sizeof (stack_scanline_buffer))
150 scanline_buffer = pixman_malloc_ab_plus_c (width, Bpp * 3, 32 * 3);
152 if (!scanline_buffer)
155 src_buffer = ALIGN (scanline_buffer);
156 mask_buffer = ALIGN (src_buffer + width * Bpp);
157 dest_buffer = ALIGN (mask_buffer + width * Bpp);
160 if (width_flag == ITER_WIDE)
162 /* To make sure there aren't any NANs in the buffers */
163 memset (src_buffer, 0, width * Bpp);
164 memset (mask_buffer, 0, width * Bpp);
165 memset (dest_buffer, 0, width * Bpp);
169 src_iter_flags = width_flag | op_flags[op].src | ITER_SRC;
171 _pixman_implementation_iter_init (imp->toplevel, &src_iter, src_image,
172 src_x, src_y, width, height,
173 src_buffer, src_iter_flags,
177 if ((src_iter_flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) ==
178 (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB))
180 /* If it doesn't matter what the source is, then it doesn't matter
188 mask_image->common.type == BITS &&
189 mask_image->common.component_alpha &&
190 PIXMAN_FORMAT_RGB (mask_image->bits.format);
192 _pixman_implementation_iter_init (
193 imp->toplevel, &mask_iter,
194 mask_image, mask_x, mask_y, width, height, mask_buffer,
195 ITER_SRC | width_flag | (component_alpha? 0 : ITER_IGNORE_RGB),
199 _pixman_implementation_iter_init (
200 imp->toplevel, &dest_iter, dest_image, dest_x, dest_y, width, height,
201 dest_buffer, ITER_DEST | width_flag | op_flags[op].dst, info->dest_flags);
203 compose = _pixman_implementation_lookup_combiner (
204 imp->toplevel, op, component_alpha, width_flag != ITER_WIDE);
206 for (i = 0; i < height; ++i)
210 m = mask_iter.get_scanline (&mask_iter, NULL);
211 s = src_iter.get_scanline (&src_iter, m);
212 d = dest_iter.get_scanline (&dest_iter, NULL);
214 compose (imp->toplevel, op, d, s, m, width);
216 dest_iter.write_back (&dest_iter);
220 src_iter.fini (&src_iter);
222 mask_iter.fini (&mask_iter);
224 dest_iter.fini (&dest_iter);
226 if (scanline_buffer != (uint8_t *) stack_scanline_buffer)
227 free (scanline_buffer);
230 static const pixman_fast_path_t general_fast_path[] =
232 { PIXMAN_OP_any, PIXMAN_any, 0, PIXMAN_any, 0, PIXMAN_any, 0, general_composite_rect },
236 pixman_implementation_t *
237 _pixman_implementation_create_general (void)
239 pixman_implementation_t *imp = _pixman_implementation_create (NULL, general_fast_path);
241 _pixman_setup_combiner_functions_32 (imp);
242 _pixman_setup_combiner_functions_float (imp);
244 imp->iter_info = general_iters;