2 * Copyright © 2009 Red Hat, Inc.
3 * Copyright © 2000 SuSE, Inc.
4 * Copyright © 2007 Red Hat, Inc.
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Red Hat not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. Red Hat makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
21 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
22 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
31 #include "pixman-private.h"
35 general_combine_32 (pixman_implementation_t *imp, pixman_op_t op,
36 uint32_t *dest, const uint32_t *src, const uint32_t *mask,
39 CombineFunc32 f = pixman_composeFunctions.combineU[op];
41 f (dest, src, mask, width);
45 general_combine_32_ca (pixman_implementation_t *imp, pixman_op_t op,
46 uint32_t *dest, const uint32_t *src, const uint32_t *mask,
49 CombineFunc32 f = pixman_composeFunctions.combineC[op];
51 f (dest, src, mask, width);
55 general_combine_64 (pixman_implementation_t *imp, pixman_op_t op,
56 uint64_t *dest, const uint64_t *src, const uint64_t *mask,
59 CombineFunc64 f = pixman_composeFunctions64.combineU[op];
61 f (dest, src, mask, width);
65 general_combine_64_ca (pixman_implementation_t *imp, pixman_op_t op,
66 uint64_t *dest, const uint64_t *src, const uint64_t *mask,
69 CombineFunc64 f = pixman_composeFunctions64.combineC[op];
71 f (dest, src, mask, width);
76 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
77 * 2005 Lars Knoll & Zack Rusin, Trolltech
78 * 2008 Aaron Plattner, NVIDIA Corporation
80 * Permission to use, copy, modify, distribute, and sell this software and its
81 * documentation for any purpose is hereby granted without fee, provided that
82 * the above copyright notice appear in all copies and that both that
83 * copyright notice and this permission notice appear in supporting
84 * documentation, and that the name of Keith Packard not be used in
85 * advertising or publicity pertaining to distribution of the software without
86 * specific, written prior permission. Keith Packard makes no
87 * representations about the suitability of this software for any purpose. It
88 * is provided "as is" without express or implied warranty.
90 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
91 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
92 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
93 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
94 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
95 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
96 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
105 pixman_composite_rect_general_internal (const FbComposeData *data,
106 void *src_buffer, void *mask_buffer,
107 void *dest_buffer, const int wide)
111 scanFetchProc fetchSrc = NULL, fetchMask = NULL, fetchDest = NULL;
114 source_pict_class_t srcClass, maskClass;
115 pixman_bool_t component_alpha;
117 srcClass = _pixman_image_classify (data->src,
118 data->xSrc, data->ySrc,
119 data->width, data->height);
121 maskClass = SOURCE_IMAGE_CLASS_UNKNOWN;
124 maskClass = _pixman_image_classify (data->mask,
125 data->xSrc, data->ySrc,
126 data->width, data->height);
129 if (data->op == PIXMAN_OP_CLEAR)
132 fetchSrc = _pixman_image_get_scanline_64;
134 fetchSrc = _pixman_image_get_scanline_32;
136 if (!data->mask || data->op == PIXMAN_OP_CLEAR)
139 fetchMask = _pixman_image_get_scanline_64;
141 fetchMask = _pixman_image_get_scanline_32;
143 if (data->op == PIXMAN_OP_CLEAR || data->op == PIXMAN_OP_SRC)
146 fetchDest = _pixman_image_get_scanline_64;
148 fetchDest = _pixman_image_get_scanline_32;
151 store = _pixman_image_store_scanline_64;
153 store = _pixman_image_store_scanline_32;
155 // Skip the store step and composite directly into the
156 // destination if the output format of the compose func matches
157 // the destination format.
159 !data->dest->common.alpha_map &&
160 !data->dest->common.write_func &&
161 (data->op == PIXMAN_OP_ADD || data->op == PIXMAN_OP_OVER) &&
162 (data->dest->bits.format == PIXMAN_a8r8g8b8 ||
163 data->dest->bits.format == PIXMAN_x8r8g8b8))
170 bits = data->dest->bits.bits;
171 stride = data->dest->bits.rowstride;
183 data->mask->common.type == BITS &&
184 data->mask->common.component_alpha &&
185 PIXMAN_FORMAT_RGB (data->mask->bits.format);
188 CombineFunc32 compose;
193 compose = (CombineFunc32)pixman_composeFunctions64.combineC[data->op];
195 compose = (CombineFunc32)pixman_composeFunctions64.combineU[data->op];
200 compose = pixman_composeFunctions.combineC[data->op];
202 compose = pixman_composeFunctions.combineU[data->op];
211 for (i = 0; i < data->height; ++i)
213 /* fill first half of scanline with source */
218 /* fetch mask before source so that fetching of
219 source can be optimized */
220 fetchMask (data->mask, data->xMask, data->yMask + i,
221 data->width, mask_buffer, 0, 0);
223 if (maskClass == SOURCE_IMAGE_CLASS_HORIZONTAL)
227 if (srcClass == SOURCE_IMAGE_CLASS_HORIZONTAL)
229 fetchSrc (data->src, data->xSrc, data->ySrc + i,
230 data->width, src_buffer, 0, 0);
235 fetchSrc (data->src, data->xSrc, data->ySrc + i,
236 data->width, src_buffer, mask_buffer,
242 fetchMask (data->mask, data->xMask, data->yMask + i,
243 data->width, mask_buffer, 0, 0);
248 /* fill dest into second half of scanline */
250 fetchDest (data->dest, data->xDest, data->yDest + i,
251 data->width, dest_buffer, 0, 0);
254 compose (dest_buffer, src_buffer, mask_buffer, data->width);
257 store (&(data->dest->bits), data->xDest, data->yDest + i, data->width,
263 compose (bits + (data->yDest + i) * stride +
265 src_buffer, mask_buffer, data->width);
271 #define SCANLINE_BUFFER_LENGTH 8192
274 general_composite_rect (const FbComposeData *data)
276 uint8_t stack_scanline_buffer[SCANLINE_BUFFER_LENGTH * 3];
277 const pixman_format_code_t srcFormat =
278 data->src->type == BITS ? data->src->bits.format : 0;
279 const pixman_format_code_t maskFormat =
280 data->mask && data->mask->type == BITS ? data->mask->bits.format : 0;
281 const pixman_format_code_t destFormat = data->dest->type == BITS ? data->dest->bits.format : 0;
282 const int srcWide = PIXMAN_FORMAT_16BPC(srcFormat);
283 const int maskWide = data->mask && PIXMAN_FORMAT_16BPC(maskFormat);
284 const int destWide = PIXMAN_FORMAT_16BPC(destFormat);
285 const int wide = srcWide || maskWide || destWide;
286 const int Bpp = wide ? 8 : 4;
287 uint8_t *scanline_buffer = stack_scanline_buffer;
288 uint8_t *src_buffer, *mask_buffer, *dest_buffer;
290 if (data->width * Bpp > SCANLINE_BUFFER_LENGTH)
292 scanline_buffer = pixman_malloc_abc (data->width, 3, Bpp);
294 if (!scanline_buffer)
298 src_buffer = scanline_buffer;
299 mask_buffer = src_buffer + data->width * Bpp;
300 dest_buffer = mask_buffer + data->width * Bpp;
302 pixman_composite_rect_general_internal (data, src_buffer,
303 mask_buffer, dest_buffer,
306 if (scanline_buffer != stack_scanline_buffer)
307 free (scanline_buffer);
313 #include "pixman-private.h"
314 #include "pixman-mmx.h"
315 #include "pixman-vmx.h"
316 #include "pixman-sse2.h"
317 #include "pixman-arm-simd.h"
318 #include "pixman-combine32.h"
321 pixman_image_composite_rect (pixman_implementation_t *imp,
324 pixman_image_t *mask,
325 pixman_image_t *dest,
335 FbComposeData compose_data;
337 return_if_fail (src != NULL);
338 return_if_fail (dest != NULL);
340 compose_data.op = op;
341 compose_data.src = src;
342 compose_data.mask = mask;
343 compose_data.dest = dest;
344 compose_data.xSrc = src_x;
345 compose_data.ySrc = src_y;
346 compose_data.xMask = mask_x;
347 compose_data.yMask = mask_y;
348 compose_data.xDest = dest_x;
349 compose_data.yDest = dest_y;
350 compose_data.width = width;
351 compose_data.height = height;
353 general_composite_rect (&compose_data);
356 #if defined(USE_SSE2) && defined(__GNUC__) && !defined(__x86_64__) && !defined(__amd64__)
359 * Work around GCC bug causing crashes in Mozilla with SSE2
361 * When using SSE2 intrinsics, gcc assumes that the stack is 16 byte
362 * aligned. Unfortunately some code, such as Mozilla and Mono contain
363 * code that aligns the stack to 4 bytes.
365 * The __force_align_arg_pointer__ makes gcc generate a prologue that
366 * realigns the stack pointer to 16 bytes.
368 * On x86-64 this is not necessary because the standard ABI already
369 * calls for a 16 byte aligned stack.
371 * See https://bugs.freedesktop.org/show_bug.cgi?id=15693
374 __attribute__((__force_align_arg_pointer__))
377 general_composite (pixman_implementation_t * imp,
379 pixman_image_t * src,
380 pixman_image_t * mask,
381 pixman_image_t * dest,
391 pixman_bool_t srcRepeat = src->type == BITS && src->common.repeat == PIXMAN_REPEAT_NORMAL;
392 pixman_bool_t maskRepeat = FALSE;
393 pixman_bool_t srcTransform = src->common.transform != NULL;
394 pixman_bool_t maskTransform = FALSE;
405 fbComposeSetupSSE2();
408 if (srcRepeat && srcTransform &&
409 src->bits.width == 1 &&
410 src->bits.height == 1)
412 srcTransform = FALSE;
415 if (mask && mask->type == BITS)
417 maskRepeat = mask->common.repeat == PIXMAN_REPEAT_NORMAL;
419 maskTransform = mask->common.transform != 0;
420 if (mask->common.filter == PIXMAN_FILTER_CONVOLUTION)
421 maskTransform = TRUE;
423 if (maskRepeat && maskTransform &&
424 mask->bits.width == 1 &&
425 mask->bits.height == 1)
427 maskTransform = FALSE;
432 if (_pixman_run_fast_path (mmx_fast_paths, imp,
442 if (_pixman_run_fast_path (vmx_fast_paths, imp,
452 if (pixman_have_arm_neon() && _pixman_run_fast_path (arm_neon_fast_paths, imp,
462 if (pixman_have_arm_simd() && _pixman_run_fast_path (arm_simd_fast_paths, imp,
471 if (pixman_have_arm_simd() && _pixman_run_fast_path (c_fast_paths, imp,
479 /* CompositeGeneral optimizes 1x1 repeating images itself */
480 if (src->type == BITS &&
481 src->bits.width == 1 && src->bits.height == 1)
486 if (mask && mask->type == BITS &&
487 mask->bits.width == 1 && mask->bits.height == 1)
492 /* if we are transforming, repeats are handled in fbFetchTransformed */
499 _pixman_walk_composite_region (imp, op, src, mask, dest, src_x, src_y,
500 mask_x, mask_y, dest_x, dest_y, width, height,
501 srcRepeat, maskRepeat, pixman_image_composite_rect);
504 pixman_implementation_t *
505 _pixman_implementation_create_general (pixman_implementation_t *toplevel)
507 pixman_implementation_t *imp = _pixman_implementation_create (toplevel, NULL);
510 imp->composite = general_composite;
512 for (i = 0; i < PIXMAN_OP_LAST; ++i)
514 imp->combine_32[i] = general_combine_32;
515 imp->combine_32_ca[i] = general_combine_32_ca;
516 imp->combine_64[i] = general_combine_64;
517 imp->combine_64_ca[i] = general_combine_64_ca;