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
37 #include "pixman-private.h"
38 #include "pixman-vmx.h"
39 #include "pixman-arm-simd.h"
40 #include "pixman-combine32.h"
41 #include "pixman-private.h"
43 #define SCANLINE_BUFFER_LENGTH 8192
46 general_composite_rect (pixman_implementation_t *imp,
60 return_if_fail (src != NULL);
61 return_if_fail (dest != NULL);
63 uint8_t stack_scanline_buffer[SCANLINE_BUFFER_LENGTH * 3];
64 const pixman_format_code_t srcFormat = src->type == BITS ? src->bits.format : 0;
65 const pixman_format_code_t maskFormat = mask && mask->type == BITS ? mask->bits.format : 0;
66 const pixman_format_code_t destFormat = dest->type == BITS ? dest->bits.format : 0;
67 const int srcWide = PIXMAN_FORMAT_16BPC(srcFormat);
68 const int maskWide = mask && PIXMAN_FORMAT_16BPC(maskFormat);
69 const int destWide = PIXMAN_FORMAT_16BPC(destFormat);
70 const int wide = srcWide || maskWide || destWide;
71 const int Bpp = wide ? 8 : 4;
72 uint8_t *scanline_buffer = stack_scanline_buffer;
73 uint8_t *src_buffer, *mask_buffer, *dest_buffer;
74 scanFetchProc fetchSrc = NULL, fetchMask = NULL, fetchDest = NULL;
75 pixman_combine_32_func_t compose;
77 source_pict_class_t srcClass, maskClass;
78 pixman_bool_t component_alpha;
83 if (width * Bpp > SCANLINE_BUFFER_LENGTH)
85 scanline_buffer = pixman_malloc_abc (width, 3, Bpp);
91 src_buffer = scanline_buffer;
92 mask_buffer = src_buffer + width * Bpp;
93 dest_buffer = mask_buffer + width * Bpp;
95 srcClass = _pixman_image_classify (src,
99 maskClass = SOURCE_IMAGE_CLASS_UNKNOWN;
102 maskClass = _pixman_image_classify (mask,
107 if (op == PIXMAN_OP_CLEAR)
110 fetchSrc = _pixman_image_get_scanline_64;
112 fetchSrc = _pixman_image_get_scanline_32;
114 if (!mask || op == PIXMAN_OP_CLEAR)
117 fetchMask = _pixman_image_get_scanline_64;
119 fetchMask = _pixman_image_get_scanline_32;
121 if (op == PIXMAN_OP_CLEAR || op == PIXMAN_OP_SRC)
124 fetchDest = _pixman_image_get_scanline_64;
126 fetchDest = _pixman_image_get_scanline_32;
129 store = _pixman_image_store_scanline_64;
131 store = _pixman_image_store_scanline_32;
133 /* Skip the store step and composite directly into the
134 * destination if the output format of the compose func matches
135 * the destination format.
138 !dest->common.alpha_map &&
139 !dest->common.write_func &&
140 (op == PIXMAN_OP_ADD || op == PIXMAN_OP_OVER) &&
141 (dest->bits.format == PIXMAN_a8r8g8b8 ||
142 dest->bits.format == PIXMAN_x8r8g8b8))
149 bits = dest->bits.bits;
150 stride = dest->bits.rowstride;
162 mask->common.type == BITS &&
163 mask->common.component_alpha &&
164 PIXMAN_FORMAT_RGB (mask->bits.format);
169 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64_ca;
171 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64;
176 compose = _pixman_implementation_combine_32_ca;
178 compose = _pixman_implementation_combine_32;
187 for (i = 0; i < height; ++i)
189 /* fill first half of scanline with source */
194 /* fetch mask before source so that fetching of
195 source can be optimized */
196 fetchMask (mask, mask_x, mask_y + i,
197 width, (void *)mask_buffer, 0, 0);
199 if (maskClass == SOURCE_IMAGE_CLASS_HORIZONTAL)
203 if (srcClass == SOURCE_IMAGE_CLASS_HORIZONTAL)
205 fetchSrc (src, src_x, src_y + i,
206 width, (void *)src_buffer, 0, 0);
211 fetchSrc (src, src_x, src_y + i,
212 width, (void *)src_buffer, (void *)mask_buffer,
218 fetchMask (mask, mask_x, mask_y + i,
219 width, (void *)mask_buffer, 0, 0);
224 /* fill dest into second half of scanline */
226 fetchDest (dest, dest_x, dest_y + i,
227 width, (void *)dest_buffer, 0, 0);
230 compose (imp->toplevel, op, (void *)dest_buffer, (void *)src_buffer, (void *)mask_buffer, width);
233 store (&(dest->bits), dest_x, dest_y + i, width,
234 (void *)dest_buffer);
239 compose (imp->toplevel, op, bits + (dest_y + i) * stride +
241 (void *)src_buffer, (void *)mask_buffer, width);
245 if (scanline_buffer != stack_scanline_buffer)
246 free (scanline_buffer);
250 general_composite (pixman_implementation_t * imp,
252 pixman_image_t * src,
253 pixman_image_t * mask,
254 pixman_image_t * dest,
264 pixman_bool_t srcRepeat = src->type == BITS && src->common.repeat == PIXMAN_REPEAT_NORMAL;
265 pixman_bool_t maskRepeat = FALSE;
266 pixman_bool_t srcTransform = src->common.transform != NULL;
267 pixman_bool_t maskTransform = FALSE;
273 if (srcRepeat && srcTransform &&
274 src->bits.width == 1 &&
275 src->bits.height == 1)
277 srcTransform = FALSE;
280 if (mask && mask->type == BITS)
282 maskRepeat = mask->common.repeat == PIXMAN_REPEAT_NORMAL;
284 maskTransform = mask->common.transform != 0;
285 if (mask->common.filter == PIXMAN_FILTER_CONVOLUTION)
286 maskTransform = TRUE;
288 if (maskRepeat && maskTransform &&
289 mask->bits.width == 1 &&
290 mask->bits.height == 1)
292 maskTransform = FALSE;
297 if (_pixman_run_fast_path (vmx_fast_paths, imp,
307 if (pixman_have_arm_neon() && _pixman_run_fast_path (arm_neon_fast_paths, imp,
317 if (pixman_have_arm_simd() && _pixman_run_fast_path (arm_simd_fast_paths, imp,
326 /* CompositeGeneral optimizes 1x1 repeating images itself */
327 if (src->type == BITS &&
328 src->bits.width == 1 && src->bits.height == 1)
333 if (mask && mask->type == BITS &&
334 mask->bits.width == 1 && mask->bits.height == 1)
339 /* if we are transforming, repeats are handled in fbFetchTransformed */
346 _pixman_walk_composite_region (imp, op, src, mask, dest, src_x, src_y,
347 mask_x, mask_y, dest_x, dest_y, width, height,
348 srcRepeat, maskRepeat, general_composite_rect);
352 general_blt (pixman_implementation_t *imp,
359 int src_x, int src_y,
360 int dst_x, int dst_y,
361 int width, int height)
363 /* We can't blit unless we have sse2 or mmx */
369 general_fill (pixman_implementation_t *imp,
382 pixman_implementation_t *
383 _pixman_implementation_create_general (pixman_implementation_t *toplevel)
385 pixman_implementation_t *imp = _pixman_implementation_create (toplevel, NULL);
387 _pixman_setup_combiner_functions_32 (imp);
388 _pixman_setup_combiner_functions_64 (imp);
390 imp->composite = general_composite;
391 imp->blt = general_blt;
392 imp->fill = general_fill;