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 src_get_scanline_null (pixman_iter_t *iter, const uint32_t *mask)
49 src_iter_init (pixman_implementation_t *imp,
51 pixman_image_t *image,
52 int x, int y, int width, int height,
53 uint8_t *buffer, iter_flags_t flags)
59 iter->buffer = (uint32_t *)buffer;
63 iter->get_scanline = src_get_scanline_null;
65 else if (image->type == SOLID)
67 _pixman_solid_fill_iter_init (
68 image, iter, x, y, width, height, buffer, flags);
70 else if (image->type == LINEAR)
72 _pixman_linear_gradient_iter_init (
73 image, iter, x, y, width, height, buffer, flags);
75 else if (image->type == RADIAL)
77 _pixman_radial_gradient_iter_init (
78 image, iter, x, y, width, height, buffer, flags);
80 else if (image->type == CONICAL)
82 _pixman_conical_gradient_iter_init (
83 image, iter, x, y, width, height, buffer, flags);
85 else if (image->type == BITS)
87 _pixman_bits_image_src_iter_init (
88 image, iter, x, y, width, height, buffer, flags);
92 _pixman_log_error (FUNC, "Pixman bug: unknown image type\n");
97 dest_iter_init (pixman_implementation_t *imp,
99 pixman_image_t *image,
100 int x, int y, int width, int height,
101 uint8_t *buffer, iter_flags_t flags)
107 iter->buffer = (uint32_t *)buffer;
109 if (image->type == BITS)
111 _pixman_bits_image_dest_iter_init (
112 image, iter, x, y, width, height, buffer, flags);
116 _pixman_log_error (FUNC, "Trying to write to a non-writable image");
120 #define SCANLINE_BUFFER_LENGTH 8192
123 general_composite_rect (pixman_implementation_t *imp,
125 pixman_image_t * src,
126 pixman_image_t * mask,
127 pixman_image_t * dest,
137 uint64_t stack_scanline_buffer[(SCANLINE_BUFFER_LENGTH * 3 + 7) / 8];
138 uint8_t *scanline_buffer = (uint8_t *) stack_scanline_buffer;
139 uint8_t *src_buffer, *mask_buffer, *dest_buffer;
140 pixman_iter_t src_iter, mask_iter, dest_iter;
141 pixman_combine_32_func_t compose;
142 pixman_bool_t component_alpha;
147 if ((src->common.flags & FAST_PATH_NARROW_FORMAT) &&
148 (!mask || mask->common.flags & FAST_PATH_NARROW_FORMAT) &&
149 (dest->common.flags & FAST_PATH_NARROW_FORMAT))
151 narrow = ITER_NARROW;
160 if (width * Bpp > SCANLINE_BUFFER_LENGTH)
162 scanline_buffer = pixman_malloc_abc (width, 3, Bpp);
164 if (!scanline_buffer)
168 src_buffer = scanline_buffer;
169 mask_buffer = src_buffer + width * Bpp;
170 dest_buffer = mask_buffer + width * Bpp;
172 src_iter_init (imp->toplevel, &src_iter, src,
173 src_x, src_y, width, height,
176 src_iter_init (imp->toplevel, &mask_iter, mask,
177 mask_x, mask_y, width, height,
178 mask_buffer, narrow);
180 dest_iter_init (imp->toplevel, &dest_iter, dest,
181 dest_x, dest_y, width, height,
182 dest_buffer, narrow);
186 mask->common.type == BITS &&
187 mask->common.component_alpha &&
188 PIXMAN_FORMAT_RGB (mask->bits.format);
193 compose = _pixman_implementation_combine_32_ca;
195 compose = _pixman_implementation_combine_32;
200 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64_ca;
202 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64;
208 for (i = 0; i < height; ++i)
212 m = mask_iter.get_scanline (&mask_iter, NULL);
213 s = src_iter.get_scanline (&src_iter, m);
214 d = dest_iter.get_scanline (&dest_iter, NULL);
216 compose (imp->toplevel, op, d, s, m, width);
218 dest_iter.write_back (&dest_iter);
221 if (scanline_buffer != (uint8_t *) stack_scanline_buffer)
222 free (scanline_buffer);
225 static const pixman_fast_path_t general_fast_path[] =
227 { PIXMAN_OP_any, PIXMAN_any, 0, PIXMAN_any, 0, PIXMAN_any, 0, general_composite_rect },
232 general_blt (pixman_implementation_t *imp,
246 /* We can't blit unless we have sse2 or mmx */
252 general_fill (pixman_implementation_t *imp,
265 pixman_implementation_t *
266 _pixman_implementation_create_general (void)
268 pixman_implementation_t *imp = _pixman_implementation_create (NULL, general_fast_path);
270 _pixman_setup_combiner_functions_32 (imp);
271 _pixman_setup_combiner_functions_64 (imp);
273 imp->blt = general_blt;
274 imp->fill = general_fill;