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"
45 general_combine_32 (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.combineU[op];
51 f (dest, src, mask, width);
55 general_combine_32_ca (pixman_implementation_t *imp, pixman_op_t op,
56 uint32_t *dest, const uint32_t *src, const uint32_t *mask,
59 CombineFunc32 f = pixman_composeFunctions.combineC[op];
61 f (dest, src, mask, width);
65 general_combine_64 (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.combineU[op];
71 f (dest, src, mask, width);
75 general_combine_64_ca (pixman_implementation_t *imp, pixman_op_t op,
76 uint64_t *dest, const uint64_t *src, const uint64_t *mask,
79 CombineFunc64 f = pixman_composeFunctions64.combineC[op];
81 f (dest, src, mask, width);
85 pixman_composite_rect_general_internal (pixman_implementation_t *imp,
86 const FbComposeData *data,
87 void *src_buffer, void *mask_buffer,
88 void *dest_buffer, const int wide)
92 scanFetchProc fetchSrc = NULL, fetchMask = NULL, fetchDest = NULL;
95 source_pict_class_t srcClass, maskClass;
96 pixman_bool_t component_alpha;
98 srcClass = _pixman_image_classify (data->src,
99 data->xSrc, data->ySrc,
100 data->width, data->height);
102 maskClass = SOURCE_IMAGE_CLASS_UNKNOWN;
105 maskClass = _pixman_image_classify (data->mask,
106 data->xSrc, data->ySrc,
107 data->width, data->height);
110 if (data->op == PIXMAN_OP_CLEAR)
113 fetchSrc = _pixman_image_get_scanline_64;
115 fetchSrc = _pixman_image_get_scanline_32;
117 if (!data->mask || data->op == PIXMAN_OP_CLEAR)
120 fetchMask = _pixman_image_get_scanline_64;
122 fetchMask = _pixman_image_get_scanline_32;
124 if (data->op == PIXMAN_OP_CLEAR || data->op == PIXMAN_OP_SRC)
127 fetchDest = _pixman_image_get_scanline_64;
129 fetchDest = _pixman_image_get_scanline_32;
132 store = _pixman_image_store_scanline_64;
134 store = _pixman_image_store_scanline_32;
136 // Skip the store step and composite directly into the
137 // destination if the output format of the compose func matches
138 // the destination format.
140 !data->dest->common.alpha_map &&
141 !data->dest->common.write_func &&
142 (data->op == PIXMAN_OP_ADD || data->op == PIXMAN_OP_OVER) &&
143 (data->dest->bits.format == PIXMAN_a8r8g8b8 ||
144 data->dest->bits.format == PIXMAN_x8r8g8b8))
151 bits = data->dest->bits.bits;
152 stride = data->dest->bits.rowstride;
164 data->mask->common.type == BITS &&
165 data->mask->common.component_alpha &&
166 PIXMAN_FORMAT_RGB (data->mask->bits.format);
169 pixman_combine_32_func_t compose;
174 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64_ca;
176 compose = (pixman_combine_32_func_t)_pixman_implementation_combine_64;
181 compose = _pixman_implementation_combine_32_ca;
183 compose = _pixman_implementation_combine_32;
192 for (i = 0; i < data->height; ++i)
194 /* fill first half of scanline with source */
199 /* fetch mask before source so that fetching of
200 source can be optimized */
201 fetchMask (data->mask, data->xMask, data->yMask + i,
202 data->width, mask_buffer, 0, 0);
204 if (maskClass == SOURCE_IMAGE_CLASS_HORIZONTAL)
208 if (srcClass == SOURCE_IMAGE_CLASS_HORIZONTAL)
210 fetchSrc (data->src, data->xSrc, data->ySrc + i,
211 data->width, src_buffer, 0, 0);
216 fetchSrc (data->src, data->xSrc, data->ySrc + i,
217 data->width, src_buffer, mask_buffer,
223 fetchMask (data->mask, data->xMask, data->yMask + i,
224 data->width, mask_buffer, 0, 0);
229 /* fill dest into second half of scanline */
231 fetchDest (data->dest, data->xDest, data->yDest + i,
232 data->width, dest_buffer, 0, 0);
235 compose (imp, data->op, dest_buffer, src_buffer, mask_buffer, data->width);
238 store (&(data->dest->bits), data->xDest, data->yDest + i, data->width,
244 compose (imp, data->op, bits + (data->yDest + i) * stride +
246 src_buffer, mask_buffer, data->width);
252 #define SCANLINE_BUFFER_LENGTH 8192
255 general_composite_rect (pixman_implementation_t *imp,
256 const FbComposeData *data)
258 uint8_t stack_scanline_buffer[SCANLINE_BUFFER_LENGTH * 3];
259 const pixman_format_code_t srcFormat =
260 data->src->type == BITS ? data->src->bits.format : 0;
261 const pixman_format_code_t maskFormat =
262 data->mask && data->mask->type == BITS ? data->mask->bits.format : 0;
263 const pixman_format_code_t destFormat = data->dest->type == BITS ? data->dest->bits.format : 0;
264 const int srcWide = PIXMAN_FORMAT_16BPC(srcFormat);
265 const int maskWide = data->mask && PIXMAN_FORMAT_16BPC(maskFormat);
266 const int destWide = PIXMAN_FORMAT_16BPC(destFormat);
267 const int wide = srcWide || maskWide || destWide;
268 const int Bpp = wide ? 8 : 4;
269 uint8_t *scanline_buffer = stack_scanline_buffer;
270 uint8_t *src_buffer, *mask_buffer, *dest_buffer;
272 if (data->width * Bpp > SCANLINE_BUFFER_LENGTH)
274 scanline_buffer = pixman_malloc_abc (data->width, 3, Bpp);
276 if (!scanline_buffer)
280 src_buffer = scanline_buffer;
281 mask_buffer = src_buffer + data->width * Bpp;
282 dest_buffer = mask_buffer + data->width * Bpp;
284 pixman_composite_rect_general_internal (imp, data, src_buffer,
285 mask_buffer, dest_buffer,
288 if (scanline_buffer != stack_scanline_buffer)
289 free (scanline_buffer);
293 pixman_image_composite_rect (pixman_implementation_t *imp,
296 pixman_image_t *mask,
297 pixman_image_t *dest,
307 FbComposeData compose_data;
309 return_if_fail (src != NULL);
310 return_if_fail (dest != NULL);
312 compose_data.op = op;
313 compose_data.src = src;
314 compose_data.mask = mask;
315 compose_data.dest = dest;
316 compose_data.xSrc = src_x;
317 compose_data.ySrc = src_y;
318 compose_data.xMask = mask_x;
319 compose_data.yMask = mask_y;
320 compose_data.xDest = dest_x;
321 compose_data.yDest = dest_y;
322 compose_data.width = width;
323 compose_data.height = height;
325 general_composite_rect (imp, &compose_data);
329 general_composite (pixman_implementation_t * imp,
331 pixman_image_t * src,
332 pixman_image_t * mask,
333 pixman_image_t * dest,
343 pixman_bool_t srcRepeat = src->type == BITS && src->common.repeat == PIXMAN_REPEAT_NORMAL;
344 pixman_bool_t maskRepeat = FALSE;
345 pixman_bool_t srcTransform = src->common.transform != NULL;
346 pixman_bool_t maskTransform = FALSE;
352 if (srcRepeat && srcTransform &&
353 src->bits.width == 1 &&
354 src->bits.height == 1)
356 srcTransform = FALSE;
359 if (mask && mask->type == BITS)
361 maskRepeat = mask->common.repeat == PIXMAN_REPEAT_NORMAL;
363 maskTransform = mask->common.transform != 0;
364 if (mask->common.filter == PIXMAN_FILTER_CONVOLUTION)
365 maskTransform = TRUE;
367 if (maskRepeat && maskTransform &&
368 mask->bits.width == 1 &&
369 mask->bits.height == 1)
371 maskTransform = FALSE;
376 if (_pixman_run_fast_path (vmx_fast_paths, imp,
386 if (pixman_have_arm_neon() && _pixman_run_fast_path (arm_neon_fast_paths, imp,
396 if (pixman_have_arm_simd() && _pixman_run_fast_path (arm_simd_fast_paths, imp,
405 /* CompositeGeneral optimizes 1x1 repeating images itself */
406 if (src->type == BITS &&
407 src->bits.width == 1 && src->bits.height == 1)
412 if (mask && mask->type == BITS &&
413 mask->bits.width == 1 && mask->bits.height == 1)
418 /* if we are transforming, repeats are handled in fbFetchTransformed */
425 _pixman_walk_composite_region (imp, op, src, mask, dest, src_x, src_y,
426 mask_x, mask_y, dest_x, dest_y, width, height,
427 srcRepeat, maskRepeat, pixman_image_composite_rect);
431 general_blt (pixman_implementation_t *imp,
438 int src_x, int src_y,
439 int dst_x, int dst_y,
440 int width, int height)
442 /* We can't blit unless we have sse2 or mmx */
448 general_fill (pixman_implementation_t *imp,
461 pixman_implementation_t *
462 _pixman_implementation_create_general (pixman_implementation_t *toplevel)
464 pixman_implementation_t *imp = _pixman_implementation_create (toplevel, NULL);
467 for (i = 0; i < PIXMAN_OP_LAST; ++i)
469 imp->combine_32[i] = general_combine_32;
470 imp->combine_32_ca[i] = general_combine_32_ca;
471 imp->combine_64[i] = general_combine_64;
472 imp->combine_64_ca[i] = general_combine_64_ca;
474 imp->composite = general_composite;
475 imp->blt = general_blt;
476 imp->fill = general_fill;