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_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
43 pixman_image_t *image = iter->image;
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);
56 _pixman_log_error (FUNC, "Pixman bug: unknown image type\n");
60 general_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
62 if (iter->image->type == BITS)
64 _pixman_bits_image_dest_iter_init (iter->image, iter);
68 _pixman_log_error (FUNC, "Trying to write to a non-writable image");
72 typedef struct op_info_t op_info_t;
78 #define ITER_IGNORE_BOTH \
79 (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB | ITER_LOCALIZED_ALPHA)
81 static const op_info_t op_flags[PIXMAN_N_OPERATORS] =
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 */
94 { 0, 0 }, /* ATOP_REVERSE */
96 { ITER_LOCALIZED_ALPHA, ITER_LOCALIZED_ALPHA }, /* ADD */
97 { 0, 0 }, /* SATURATE */
100 #define SCANLINE_BUFFER_LENGTH 8192
103 general_composite_rect (pixman_implementation_t *imp,
104 pixman_composite_info_t *info)
106 PIXMAN_COMPOSITE_ARGS (info);
107 uint64_t stack_scanline_buffer[(SCANLINE_BUFFER_LENGTH * 3 + 7) / 8];
108 uint8_t *scanline_buffer = (uint8_t *) stack_scanline_buffer;
109 uint8_t *src_buffer, *mask_buffer, *dest_buffer;
110 pixman_iter_t src_iter, mask_iter, dest_iter;
111 pixman_combine_32_func_t compose;
112 pixman_bool_t component_alpha;
113 iter_flags_t narrow, src_iter_flags;
117 if ((src_image->common.flags & FAST_PATH_NARROW_FORMAT) &&
118 (!mask_image || mask_image->common.flags & FAST_PATH_NARROW_FORMAT) &&
119 (dest_image->common.flags & FAST_PATH_NARROW_FORMAT))
121 narrow = ITER_NARROW;
130 if (width * Bpp > SCANLINE_BUFFER_LENGTH)
132 scanline_buffer = pixman_malloc_abc (width, 3, Bpp);
134 if (!scanline_buffer)
138 src_buffer = scanline_buffer;
139 mask_buffer = src_buffer + width * Bpp;
140 dest_buffer = mask_buffer + width * Bpp;
143 src_iter_flags = narrow | op_flags[op].src;
145 _pixman_implementation_src_iter_init (imp->toplevel, &src_iter, src_image,
146 src_x, src_y, width, height,
147 src_buffer, src_iter_flags, info->src_flags);
150 if ((src_iter_flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) ==
151 (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB))
153 /* If it doesn't matter what the source is, then it doesn't matter
161 mask_image->common.type == BITS &&
162 mask_image->common.component_alpha &&
163 PIXMAN_FORMAT_RGB (mask_image->bits.format);
165 _pixman_implementation_src_iter_init (
166 imp->toplevel, &mask_iter, mask_image, mask_x, mask_y, width, height,
167 mask_buffer, narrow | (component_alpha? 0 : ITER_IGNORE_RGB), info->mask_flags);
170 _pixman_implementation_dest_iter_init (
171 imp->toplevel, &dest_iter, dest_image, dest_x, dest_y, width, height,
172 dest_buffer, narrow | op_flags[op].dst, info->dest_flags);
174 compose = _pixman_implementation_lookup_combiner (
175 imp->toplevel, op, component_alpha, narrow);
180 for (i = 0; i < height; ++i)
184 m = mask_iter.get_scanline (&mask_iter, NULL);
185 s = src_iter.get_scanline (&src_iter, m);
186 d = dest_iter.get_scanline (&dest_iter, NULL);
188 compose (imp->toplevel, op, d, s, m, width);
190 dest_iter.write_back (&dest_iter);
193 if (scanline_buffer != (uint8_t *) stack_scanline_buffer)
194 free (scanline_buffer);
197 static const pixman_fast_path_t general_fast_path[] =
199 { PIXMAN_OP_any, PIXMAN_any, 0, PIXMAN_any, 0, PIXMAN_any, 0, general_composite_rect },
204 general_blt (pixman_implementation_t *imp,
218 /* We can't blit unless we have sse2 or mmx */
224 general_fill (pixman_implementation_t *imp,
237 pixman_implementation_t *
238 _pixman_implementation_create_general (void)
240 pixman_implementation_t *imp = _pixman_implementation_create (NULL, general_fast_path);
242 _pixman_setup_combiner_functions_32 (imp);
243 _pixman_setup_combiner_functions_64 (imp);
245 imp->blt = general_blt;
246 imp->fill = general_fill;
247 imp->src_iter_init = general_src_iter_init;
248 imp->dest_iter_init = general_dest_iter_init;