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-mmx.h"
39 #include "pixman-vmx.h"
40 #include "pixman-sse2.h"
41 #include "pixman-arm-simd.h"
42 #include "pixman-combine32.h"
43 #include "pixman-private.h"
47 general_combine_32 (pixman_implementation_t *imp, pixman_op_t op,
48 uint32_t *dest, const uint32_t *src, const uint32_t *mask,
51 CombineFunc32 f = pixman_composeFunctions.combineU[op];
53 f (dest, src, mask, width);
57 general_combine_32_ca (pixman_implementation_t *imp, pixman_op_t op,
58 uint32_t *dest, const uint32_t *src, const uint32_t *mask,
61 CombineFunc32 f = pixman_composeFunctions.combineC[op];
63 f (dest, src, mask, width);
67 general_combine_64 (pixman_implementation_t *imp, pixman_op_t op,
68 uint64_t *dest, const uint64_t *src, const uint64_t *mask,
71 CombineFunc64 f = pixman_composeFunctions64.combineU[op];
73 f (dest, src, mask, width);
77 general_combine_64_ca (pixman_implementation_t *imp, pixman_op_t op,
78 uint64_t *dest, const uint64_t *src, const uint64_t *mask,
81 CombineFunc64 f = pixman_composeFunctions64.combineC[op];
83 f (dest, src, mask, width);
87 pixman_composite_rect_general_internal (pixman_implementation_t *imp,
88 const FbComposeData *data,
89 void *src_buffer, void *mask_buffer,
90 void *dest_buffer, const int wide)
94 scanFetchProc fetchSrc = NULL, fetchMask = NULL, fetchDest = NULL;
97 source_pict_class_t srcClass, maskClass;
98 pixman_bool_t component_alpha;
100 srcClass = _pixman_image_classify (data->src,
101 data->xSrc, data->ySrc,
102 data->width, data->height);
104 maskClass = SOURCE_IMAGE_CLASS_UNKNOWN;
107 maskClass = _pixman_image_classify (data->mask,
108 data->xSrc, data->ySrc,
109 data->width, data->height);
112 if (data->op == PIXMAN_OP_CLEAR)
115 fetchSrc = _pixman_image_get_scanline_64;
117 fetchSrc = _pixman_image_get_scanline_32;
119 if (!data->mask || data->op == PIXMAN_OP_CLEAR)
122 fetchMask = _pixman_image_get_scanline_64;
124 fetchMask = _pixman_image_get_scanline_32;
126 if (data->op == PIXMAN_OP_CLEAR || data->op == PIXMAN_OP_SRC)
129 fetchDest = _pixman_image_get_scanline_64;
131 fetchDest = _pixman_image_get_scanline_32;
134 store = _pixman_image_store_scanline_64;
136 store = _pixman_image_store_scanline_32;
138 // Skip the store step and composite directly into the
139 // destination if the output format of the compose func matches
140 // the destination format.
142 !data->dest->common.alpha_map &&
143 !data->dest->common.write_func &&
144 (data->op == PIXMAN_OP_ADD || data->op == PIXMAN_OP_OVER) &&
145 (data->dest->bits.format == PIXMAN_a8r8g8b8 ||
146 data->dest->bits.format == PIXMAN_x8r8g8b8))
153 bits = data->dest->bits.bits;
154 stride = data->dest->bits.rowstride;
166 data->mask->common.type == BITS &&
167 data->mask->common.component_alpha &&
168 PIXMAN_FORMAT_RGB (data->mask->bits.format);
171 pixman_combine_32_func_t compose;
176 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64_ca;
178 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64;
183 compose = _pixman_implementation_combine_32_ca;
185 compose = _pixman_implementation_combine_32;
194 for (i = 0; i < data->height; ++i)
196 /* fill first half of scanline with source */
201 /* fetch mask before source so that fetching of
202 source can be optimized */
203 fetchMask (data->mask, data->xMask, data->yMask + i,
204 data->width, mask_buffer, 0, 0);
206 if (maskClass == SOURCE_IMAGE_CLASS_HORIZONTAL)
210 if (srcClass == SOURCE_IMAGE_CLASS_HORIZONTAL)
212 fetchSrc (data->src, data->xSrc, data->ySrc + i,
213 data->width, src_buffer, 0, 0);
218 fetchSrc (data->src, data->xSrc, data->ySrc + i,
219 data->width, src_buffer, mask_buffer,
225 fetchMask (data->mask, data->xMask, data->yMask + i,
226 data->width, mask_buffer, 0, 0);
231 /* fill dest into second half of scanline */
233 fetchDest (data->dest, data->xDest, data->yDest + i,
234 data->width, dest_buffer, 0, 0);
237 compose (imp, data->op, dest_buffer, src_buffer, mask_buffer, data->width);
240 store (&(data->dest->bits), data->xDest, data->yDest + i, data->width,
246 compose (imp, data->op, bits + (data->yDest + i) * stride +
248 src_buffer, mask_buffer, data->width);
254 #define SCANLINE_BUFFER_LENGTH 8192
257 general_composite_rect (pixman_implementation_t *imp,
258 const FbComposeData *data)
260 uint8_t stack_scanline_buffer[SCANLINE_BUFFER_LENGTH * 3];
261 const pixman_format_code_t srcFormat =
262 data->src->type == BITS ? data->src->bits.format : 0;
263 const pixman_format_code_t maskFormat =
264 data->mask && data->mask->type == BITS ? data->mask->bits.format : 0;
265 const pixman_format_code_t destFormat = data->dest->type == BITS ? data->dest->bits.format : 0;
266 const int srcWide = PIXMAN_FORMAT_16BPC(srcFormat);
267 const int maskWide = data->mask && PIXMAN_FORMAT_16BPC(maskFormat);
268 const int destWide = PIXMAN_FORMAT_16BPC(destFormat);
269 const int wide = srcWide || maskWide || destWide;
270 const int Bpp = wide ? 8 : 4;
271 uint8_t *scanline_buffer = stack_scanline_buffer;
272 uint8_t *src_buffer, *mask_buffer, *dest_buffer;
274 if (data->width * Bpp > SCANLINE_BUFFER_LENGTH)
276 scanline_buffer = pixman_malloc_abc (data->width, 3, Bpp);
278 if (!scanline_buffer)
282 src_buffer = scanline_buffer;
283 mask_buffer = src_buffer + data->width * Bpp;
284 dest_buffer = mask_buffer + data->width * Bpp;
286 pixman_composite_rect_general_internal (imp, data, src_buffer,
287 mask_buffer, dest_buffer,
290 if (scanline_buffer != stack_scanline_buffer)
291 free (scanline_buffer);
295 pixman_image_composite_rect (pixman_implementation_t *imp,
298 pixman_image_t *mask,
299 pixman_image_t *dest,
309 FbComposeData compose_data;
311 return_if_fail (src != NULL);
312 return_if_fail (dest != NULL);
314 compose_data.op = op;
315 compose_data.src = src;
316 compose_data.mask = mask;
317 compose_data.dest = dest;
318 compose_data.xSrc = src_x;
319 compose_data.ySrc = src_y;
320 compose_data.xMask = mask_x;
321 compose_data.yMask = mask_y;
322 compose_data.xDest = dest_x;
323 compose_data.yDest = dest_y;
324 compose_data.width = width;
325 compose_data.height = height;
327 general_composite_rect (imp, &compose_data);
330 #if defined(USE_SSE2) && defined(__GNUC__) && !defined(__x86_64__) && !defined(__amd64__)
333 * Work around GCC bug causing crashes in Mozilla with SSE2
335 * When using SSE2 intrinsics, gcc assumes that the stack is 16 byte
336 * aligned. Unfortunately some code, such as Mozilla and Mono contain
337 * code that aligns the stack to 4 bytes.
339 * The __force_align_arg_pointer__ makes gcc generate a prologue that
340 * realigns the stack pointer to 16 bytes.
342 * On x86-64 this is not necessary because the standard ABI already
343 * calls for a 16 byte aligned stack.
345 * See https://bugs.freedesktop.org/show_bug.cgi?id=15693
348 __attribute__((__force_align_arg_pointer__))
351 general_composite (pixman_implementation_t * imp,
353 pixman_image_t * src,
354 pixman_image_t * mask,
355 pixman_image_t * dest,
365 pixman_bool_t srcRepeat = src->type == BITS && src->common.repeat == PIXMAN_REPEAT_NORMAL;
366 pixman_bool_t maskRepeat = FALSE;
367 pixman_bool_t srcTransform = src->common.transform != NULL;
368 pixman_bool_t maskTransform = FALSE;
374 if (srcRepeat && srcTransform &&
375 src->bits.width == 1 &&
376 src->bits.height == 1)
378 srcTransform = FALSE;
381 if (mask && mask->type == BITS)
383 maskRepeat = mask->common.repeat == PIXMAN_REPEAT_NORMAL;
385 maskTransform = mask->common.transform != 0;
386 if (mask->common.filter == PIXMAN_FILTER_CONVOLUTION)
387 maskTransform = TRUE;
389 if (maskRepeat && maskTransform &&
390 mask->bits.width == 1 &&
391 mask->bits.height == 1)
393 maskTransform = FALSE;
398 if (_pixman_run_fast_path (vmx_fast_paths, imp,
408 if (pixman_have_arm_neon() && _pixman_run_fast_path (arm_neon_fast_paths, imp,
418 if (pixman_have_arm_simd() && _pixman_run_fast_path (arm_simd_fast_paths, imp,
427 if (pixman_have_arm_simd() && _pixman_run_fast_path (c_fast_paths, imp,
435 /* CompositeGeneral optimizes 1x1 repeating images itself */
436 if (src->type == BITS &&
437 src->bits.width == 1 && src->bits.height == 1)
442 if (mask && mask->type == BITS &&
443 mask->bits.width == 1 && mask->bits.height == 1)
448 /* if we are transforming, repeats are handled in fbFetchTransformed */
455 _pixman_walk_composite_region (imp, op, src, mask, dest, src_x, src_y,
456 mask_x, mask_y, dest_x, dest_y, width, height,
457 srcRepeat, maskRepeat, pixman_image_composite_rect);
460 pixman_implementation_t *
461 _pixman_implementation_create_general (pixman_implementation_t *toplevel)
463 pixman_implementation_t *imp = _pixman_implementation_create (toplevel, NULL);
466 imp->composite = general_composite;
468 for (i = 0; i < PIXMAN_OP_LAST; ++i)
470 imp->combine_32[i] = general_combine_32;
471 imp->combine_32_ca[i] = general_combine_32_ca;
472 imp->combine_64[i] = general_combine_64;
473 imp->combine_64_ca[i] = general_combine_64_ca;