1 : /*
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
8 : *
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.
18 : *
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
26 : * SOFTWARE.
27 : */
28 : #ifdef HAVE_CONFIG_H
29 : #include <config.h>
30 : #endif
31 : #include <stdlib.h>
32 : #include <string.h>
33 : #include <math.h>
34 : #include <limits.h>
35 : #include <stdio.h>
36 : #include <stdlib.h>
37 : #include <string.h>
38 : #include "pixman-private.h"
39 :
40 : static void
41 0 : general_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
42 : {
43 0 : pixman_image_t *image = iter->image;
44 :
45 0 : if (image->type == SOLID)
46 0 : _pixman_solid_fill_iter_init (image, iter);
47 0 : else if (image->type == LINEAR)
48 0 : _pixman_linear_gradient_iter_init (image, iter);
49 0 : else if (image->type == RADIAL)
50 0 : _pixman_radial_gradient_iter_init (image, iter);
51 0 : else if (image->type == CONICAL)
52 0 : _pixman_conical_gradient_iter_init (image, iter);
53 0 : else if (image->type == BITS)
54 0 : _pixman_bits_image_src_iter_init (image, iter);
55 : else
56 : _pixman_log_error (FUNC, "Pixman bug: unknown image type\n");
57 0 : }
58 :
59 : static void
60 0 : general_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
61 : {
62 0 : if (iter->image->type == BITS)
63 : {
64 0 : _pixman_bits_image_dest_iter_init (iter->image, iter);
65 : }
66 : else
67 : {
68 : _pixman_log_error (FUNC, "Trying to write to a non-writable image");
69 : }
70 0 : }
71 :
72 : typedef struct op_info_t op_info_t;
73 : struct op_info_t
74 : {
75 : uint8_t src, dst;
76 : };
77 :
78 : #define ITER_IGNORE_BOTH \
79 : (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB | ITER_LOCALIZED_ALPHA)
80 :
81 : static const op_info_t op_flags[PIXMAN_N_OPERATORS] =
82 : {
83 : /* Src Dst */
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 */
93 : { 0, 0 }, /* ATOP */
94 : { 0, 0 }, /* ATOP_REVERSE */
95 : { 0, 0 }, /* XOR */
96 : { ITER_LOCALIZED_ALPHA, ITER_LOCALIZED_ALPHA }, /* ADD */
97 : { 0, 0 }, /* SATURATE */
98 : };
99 :
100 : #define SCANLINE_BUFFER_LENGTH 8192
101 :
102 : static void
103 0 : general_composite_rect (pixman_implementation_t *imp,
104 : pixman_op_t op,
105 : pixman_image_t * src,
106 : pixman_image_t * mask,
107 : pixman_image_t * dest,
108 : int32_t src_x,
109 : int32_t src_y,
110 : int32_t mask_x,
111 : int32_t mask_y,
112 : int32_t dest_x,
113 : int32_t dest_y,
114 : int32_t width,
115 : int32_t height)
116 : {
117 : uint64_t stack_scanline_buffer[(SCANLINE_BUFFER_LENGTH * 3 + 7) / 8];
118 0 : 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 narrow, src_flags;
124 : int Bpp;
125 : int i;
126 :
127 0 : if ((src->common.flags & FAST_PATH_NARROW_FORMAT) &&
128 0 : (!mask || mask->common.flags & FAST_PATH_NARROW_FORMAT) &&
129 0 : (dest->common.flags & FAST_PATH_NARROW_FORMAT))
130 : {
131 0 : narrow = ITER_NARROW;
132 0 : Bpp = 4;
133 : }
134 : else
135 : {
136 0 : narrow = 0;
137 0 : Bpp = 8;
138 : }
139 :
140 0 : if (width * Bpp > SCANLINE_BUFFER_LENGTH)
141 : {
142 0 : scanline_buffer = pixman_malloc_abc (width, 3, Bpp);
143 :
144 0 : if (!scanline_buffer)
145 0 : return;
146 : }
147 :
148 0 : src_buffer = scanline_buffer;
149 0 : mask_buffer = src_buffer + width * Bpp;
150 0 : dest_buffer = mask_buffer + width * Bpp;
151 :
152 : /* src iter */
153 0 : src_flags = narrow | op_flags[op].src;
154 :
155 0 : _pixman_implementation_src_iter_init (imp->toplevel, &src_iter, src,
156 : src_x, src_y, width, height,
157 : src_buffer, src_flags);
158 :
159 : /* mask iter */
160 0 : if ((src_flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) ==
161 : (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB))
162 : {
163 : /* If it doesn't matter what the source is, then it doesn't matter
164 : * what the mask is
165 : */
166 0 : mask = NULL;
167 : }
168 :
169 0 : component_alpha =
170 0 : mask &&
171 0 : mask->common.type == BITS &&
172 0 : mask->common.component_alpha &&
173 0 : PIXMAN_FORMAT_RGB (mask->bits.format);
174 :
175 0 : _pixman_implementation_src_iter_init (
176 : imp->toplevel, &mask_iter, mask, mask_x, mask_y, width, height,
177 0 : mask_buffer, narrow | (component_alpha? 0 : ITER_IGNORE_RGB));
178 :
179 : /* dest iter */
180 0 : _pixman_implementation_dest_iter_init (imp->toplevel, &dest_iter, dest,
181 : dest_x, dest_y, width, height,
182 : dest_buffer,
183 0 : narrow | op_flags[op].dst);
184 :
185 0 : if (narrow)
186 : {
187 0 : if (component_alpha)
188 0 : compose = _pixman_implementation_combine_32_ca;
189 : else
190 0 : compose = _pixman_implementation_combine_32;
191 : }
192 : else
193 : {
194 0 : if (component_alpha)
195 0 : compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64_ca;
196 : else
197 0 : compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64;
198 : }
199 :
200 0 : if (!compose)
201 0 : return;
202 :
203 0 : for (i = 0; i < height; ++i)
204 : {
205 : uint32_t *s, *m, *d;
206 :
207 0 : m = mask_iter.get_scanline (&mask_iter, NULL);
208 0 : s = src_iter.get_scanline (&src_iter, m);
209 0 : d = dest_iter.get_scanline (&dest_iter, NULL);
210 :
211 0 : compose (imp->toplevel, op, d, s, m, width);
212 :
213 0 : dest_iter.write_back (&dest_iter);
214 : }
215 :
216 0 : if (scanline_buffer != (uint8_t *) stack_scanline_buffer)
217 0 : free (scanline_buffer);
218 : }
219 :
220 : static const pixman_fast_path_t general_fast_path[] =
221 : {
222 : { PIXMAN_OP_any, PIXMAN_any, 0, PIXMAN_any, 0, PIXMAN_any, 0, general_composite_rect },
223 : { PIXMAN_OP_NONE }
224 : };
225 :
226 : static pixman_bool_t
227 0 : general_blt (pixman_implementation_t *imp,
228 : uint32_t * src_bits,
229 : uint32_t * dst_bits,
230 : int src_stride,
231 : int dst_stride,
232 : int src_bpp,
233 : int dst_bpp,
234 : int src_x,
235 : int src_y,
236 : int dst_x,
237 : int dst_y,
238 : int width,
239 : int height)
240 : {
241 : /* We can't blit unless we have sse2 or mmx */
242 :
243 0 : return FALSE;
244 : }
245 :
246 : static pixman_bool_t
247 0 : general_fill (pixman_implementation_t *imp,
248 : uint32_t * bits,
249 : int stride,
250 : int bpp,
251 : int x,
252 : int y,
253 : int width,
254 : int height,
255 : uint32_t xor)
256 : {
257 0 : return FALSE;
258 : }
259 :
260 : pixman_implementation_t *
261 4 : _pixman_implementation_create_general (void)
262 : {
263 4 : pixman_implementation_t *imp = _pixman_implementation_create (NULL, general_fast_path);
264 :
265 4 : _pixman_setup_combiner_functions_32 (imp);
266 4 : _pixman_setup_combiner_functions_64 (imp);
267 :
268 4 : imp->blt = general_blt;
269 4 : imp->fill = general_fill;
270 4 : imp->src_iter_init = general_src_iter_init;
271 4 : imp->dest_iter_init = general_dest_iter_init;
272 :
273 4 : return imp;
274 : }
275 :
|