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 #define SCANLINE_BUFFER_LENGTH 8192
113 general_composite_rect (pixman_implementation_t *imp,
115 pixman_image_t * src,
116 pixman_image_t * mask,
117 pixman_image_t * dest,
127 uint64_t stack_scanline_buffer[(SCANLINE_BUFFER_LENGTH * 3 + 7) / 8];
128 uint8_t *scanline_buffer = (uint8_t *) stack_scanline_buffer;
129 uint8_t *src_buffer, *mask_buffer, *dest_buffer;
130 pixman_iter_t src_iter, mask_iter, dest_iter;
131 pixman_combine_32_func_t compose;
132 pixman_bool_t component_alpha;
133 iter_flags_t narrow, dest_flags;
137 if ((src->common.flags & FAST_PATH_NARROW_FORMAT) &&
138 (!mask || mask->common.flags & FAST_PATH_NARROW_FORMAT) &&
139 (dest->common.flags & FAST_PATH_NARROW_FORMAT))
141 narrow = ITER_NARROW;
150 if (width * Bpp > SCANLINE_BUFFER_LENGTH)
152 scanline_buffer = pixman_malloc_abc (width, 3, Bpp);
154 if (!scanline_buffer)
158 src_buffer = scanline_buffer;
159 mask_buffer = src_buffer + width * Bpp;
160 dest_buffer = mask_buffer + width * Bpp;
162 _pixman_implementation_src_iter_init (imp->toplevel, &src_iter, src,
163 src_x, src_y, width, height,
166 _pixman_implementation_src_iter_init (imp->toplevel, &mask_iter, mask,
167 mask_x, mask_y, width, height,
168 mask_buffer, narrow);
170 if (op == PIXMAN_OP_CLEAR ||
171 op == PIXMAN_OP_SRC ||
172 op == PIXMAN_OP_DST ||
173 op == PIXMAN_OP_OVER ||
174 op == PIXMAN_OP_IN_REVERSE ||
175 op == PIXMAN_OP_OUT_REVERSE ||
178 dest_flags = narrow | ITER_LOCALIZED_ALPHA;
185 _pixman_implementation_dest_iter_init (imp->toplevel, &dest_iter, dest,
186 dest_x, dest_y, width, height,
187 dest_buffer, dest_flags);
191 mask->common.type == BITS &&
192 mask->common.component_alpha &&
193 PIXMAN_FORMAT_RGB (mask->bits.format);
198 compose = _pixman_implementation_combine_32_ca;
200 compose = _pixman_implementation_combine_32;
205 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64_ca;
207 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64;
213 for (i = 0; i < height; ++i)
217 m = mask_iter.get_scanline (&mask_iter, NULL);
218 s = src_iter.get_scanline (&src_iter, m);
219 d = dest_iter.get_scanline (&dest_iter, NULL);
221 compose (imp->toplevel, op, d, s, m, width);
223 dest_iter.write_back (&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 },
237 general_blt (pixman_implementation_t *imp,
251 /* We can't blit unless we have sse2 or mmx */
257 general_fill (pixman_implementation_t *imp,
270 pixman_implementation_t *
271 _pixman_implementation_create_general (void)
273 pixman_implementation_t *imp = _pixman_implementation_create (NULL, general_fast_path);
275 _pixman_setup_combiner_functions_32 (imp);
276 _pixman_setup_combiner_functions_64 (imp);
278 imp->blt = general_blt;
279 imp->fill = general_fill;
280 imp->src_iter_init = general_src_iter_init;
281 imp->dest_iter_init = general_dest_iter_init;