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"
39 #include "pixman-combine32.h"
40 #include "pixman-private.h"
43 general_src_iter_init (pixman_implementation_t *imp,
45 pixman_image_t *image,
46 int x, int y, int width, int height,
47 uint8_t *buffer, iter_flags_t flags)
53 iter->buffer = (uint32_t *)buffer;
55 if (image->type == SOLID)
57 _pixman_solid_fill_iter_init (
58 image, iter, x, y, width, height, buffer, flags);
60 else if (image->type == LINEAR)
62 _pixman_linear_gradient_iter_init (
63 image, iter, x, y, width, height, buffer, flags);
65 else if (image->type == RADIAL)
67 _pixman_radial_gradient_iter_init (
68 image, iter, x, y, width, height, buffer, flags);
70 else if (image->type == CONICAL)
72 _pixman_conical_gradient_iter_init (
73 image, iter, x, y, width, height, buffer, flags);
75 else if (image->type == BITS)
77 _pixman_bits_image_src_iter_init (
78 image, iter, x, y, width, height, buffer, flags);
82 _pixman_log_error (FUNC, "Pixman bug: unknown image type\n");
87 general_dest_iter_init (pixman_implementation_t *imp,
89 pixman_image_t *image,
90 int x, int y, int width, int height,
91 uint8_t *buffer, iter_flags_t flags)
97 iter->buffer = (uint32_t *)buffer;
99 if (image->type == BITS)
101 _pixman_bits_image_dest_iter_init (
102 image, iter, x, y, width, height, buffer, flags);
106 _pixman_log_error (FUNC, "Trying to write to a non-writable image");
110 typedef struct op_info_t op_info_t;
116 #define ITER_IGNORE_BOTH \
117 (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB | ITER_LOCALIZED_ALPHA)
119 static const op_info_t op_flags[PIXMAN_N_OPERATORS] =
122 { ITER_IGNORE_BOTH, ITER_IGNORE_BOTH }, /* CLEAR */
123 { ITER_LOCALIZED_ALPHA, ITER_IGNORE_BOTH }, /* SRC */
124 { ITER_IGNORE_BOTH, ITER_LOCALIZED_ALPHA }, /* DST */
125 { 0, ITER_LOCALIZED_ALPHA }, /* OVER */
126 { ITER_LOCALIZED_ALPHA, 0 }, /* OVER_REVERSE */
127 { ITER_LOCALIZED_ALPHA, ITER_IGNORE_RGB }, /* IN */
128 { ITER_IGNORE_RGB, ITER_LOCALIZED_ALPHA }, /* IN_REVERSE */
129 { ITER_LOCALIZED_ALPHA, ITER_IGNORE_RGB }, /* OUT */
130 { ITER_IGNORE_RGB, ITER_LOCALIZED_ALPHA }, /* OUT_REVERSE */
132 { 0, 0 }, /* ATOP_REVERSE */
134 { ITER_LOCALIZED_ALPHA, ITER_LOCALIZED_ALPHA }, /* ADD */
135 { 0, 0 }, /* SATURATE */
138 #define SCANLINE_BUFFER_LENGTH 8192
141 general_composite_rect (pixman_implementation_t *imp,
143 pixman_image_t * src,
144 pixman_image_t * mask,
145 pixman_image_t * dest,
155 uint64_t stack_scanline_buffer[(SCANLINE_BUFFER_LENGTH * 3 + 7) / 8];
156 uint8_t *scanline_buffer = (uint8_t *) stack_scanline_buffer;
157 uint8_t *src_buffer, *mask_buffer, *dest_buffer;
158 pixman_iter_t src_iter, mask_iter, dest_iter;
159 pixman_combine_32_func_t compose;
160 pixman_bool_t component_alpha;
161 iter_flags_t narrow, src_flags;
165 if ((src->common.flags & FAST_PATH_NARROW_FORMAT) &&
166 (!mask || mask->common.flags & FAST_PATH_NARROW_FORMAT) &&
167 (dest->common.flags & FAST_PATH_NARROW_FORMAT))
169 narrow = ITER_NARROW;
178 if (width * Bpp > SCANLINE_BUFFER_LENGTH)
180 scanline_buffer = pixman_malloc_abc (width, 3, Bpp);
182 if (!scanline_buffer)
186 src_buffer = scanline_buffer;
187 mask_buffer = src_buffer + width * Bpp;
188 dest_buffer = mask_buffer + width * Bpp;
191 src_flags = narrow | op_flags[op].src;
193 _pixman_implementation_src_iter_init (imp->toplevel, &src_iter, src,
194 src_x, src_y, width, height,
195 src_buffer, src_flags);
198 if ((src_flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) ==
199 (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB))
201 /* If it doesn't matter what the source is, then it doesn't matter
209 mask->common.type == BITS &&
210 mask->common.component_alpha &&
211 PIXMAN_FORMAT_RGB (mask->bits.format);
213 _pixman_implementation_src_iter_init (
214 imp->toplevel, &mask_iter, mask, mask_x, mask_y, width, height,
215 mask_buffer, narrow | (component_alpha? 0 : ITER_IGNORE_RGB));
218 _pixman_implementation_dest_iter_init (imp->toplevel, &dest_iter, dest,
219 dest_x, dest_y, width, height,
221 narrow | op_flags[op].dst);
226 compose = _pixman_implementation_combine_32_ca;
228 compose = _pixman_implementation_combine_32;
233 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64_ca;
235 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64;
241 for (i = 0; i < height; ++i)
245 m = mask_iter.get_scanline (&mask_iter, NULL);
246 s = src_iter.get_scanline (&src_iter, m);
247 d = dest_iter.get_scanline (&dest_iter, NULL);
249 compose (imp->toplevel, op, d, s, m, width);
251 dest_iter.write_back (&dest_iter);
254 if (scanline_buffer != (uint8_t *) stack_scanline_buffer)
255 free (scanline_buffer);
258 static const pixman_fast_path_t general_fast_path[] =
260 { PIXMAN_OP_any, PIXMAN_any, 0, PIXMAN_any, 0, PIXMAN_any, 0, general_composite_rect },
265 general_blt (pixman_implementation_t *imp,
279 /* We can't blit unless we have sse2 or mmx */
285 general_fill (pixman_implementation_t *imp,
298 pixman_implementation_t *
299 _pixman_implementation_create_general (void)
301 pixman_implementation_t *imp = _pixman_implementation_create (NULL, general_fast_path);
303 _pixman_setup_combiner_functions_32 (imp);
304 _pixman_setup_combiner_functions_64 (imp);
306 imp->blt = general_blt;
307 imp->fill = general_fill;
308 imp->src_iter_init = general_src_iter_init;
309 imp->dest_iter_init = general_dest_iter_init;