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 pixman_image_composite_rect (pixman_implementation_t *imp,
258 pixman_image_t *mask,
259 pixman_image_t *dest,
269 FbComposeData compose_data;
270 FbComposeData *data = &compose_data;
272 return_if_fail (src != NULL);
273 return_if_fail (dest != NULL);
275 compose_data.op = op;
276 compose_data.src = src;
277 compose_data.mask = mask;
278 compose_data.dest = dest;
279 compose_data.xSrc = src_x;
280 compose_data.ySrc = src_y;
281 compose_data.xMask = mask_x;
282 compose_data.yMask = mask_y;
283 compose_data.xDest = dest_x;
284 compose_data.yDest = dest_y;
285 compose_data.width = width;
286 compose_data.height = height;
288 uint8_t stack_scanline_buffer[SCANLINE_BUFFER_LENGTH * 3];
289 const pixman_format_code_t srcFormat =
290 data->src->type == BITS ? data->src->bits.format : 0;
291 const pixman_format_code_t maskFormat =
292 data->mask && data->mask->type == BITS ? data->mask->bits.format : 0;
293 const pixman_format_code_t destFormat = data->dest->type == BITS ? data->dest->bits.format : 0;
294 const int srcWide = PIXMAN_FORMAT_16BPC(srcFormat);
295 const int maskWide = data->mask && PIXMAN_FORMAT_16BPC(maskFormat);
296 const int destWide = PIXMAN_FORMAT_16BPC(destFormat);
297 const int wide = srcWide || maskWide || destWide;
298 const int Bpp = wide ? 8 : 4;
299 uint8_t *scanline_buffer = stack_scanline_buffer;
300 uint8_t *src_buffer, *mask_buffer, *dest_buffer;
302 if (data->width * Bpp > SCANLINE_BUFFER_LENGTH)
304 scanline_buffer = pixman_malloc_abc (data->width, 3, Bpp);
306 if (!scanline_buffer)
310 src_buffer = scanline_buffer;
311 mask_buffer = src_buffer + data->width * Bpp;
312 dest_buffer = mask_buffer + data->width * Bpp;
314 pixman_composite_rect_general_internal (imp, data, src_buffer,
315 mask_buffer, dest_buffer,
318 if (scanline_buffer != stack_scanline_buffer)
319 free (scanline_buffer);
323 general_composite (pixman_implementation_t * imp,
325 pixman_image_t * src,
326 pixman_image_t * mask,
327 pixman_image_t * dest,
337 pixman_bool_t srcRepeat = src->type == BITS && src->common.repeat == PIXMAN_REPEAT_NORMAL;
338 pixman_bool_t maskRepeat = FALSE;
339 pixman_bool_t srcTransform = src->common.transform != NULL;
340 pixman_bool_t maskTransform = FALSE;
346 if (srcRepeat && srcTransform &&
347 src->bits.width == 1 &&
348 src->bits.height == 1)
350 srcTransform = FALSE;
353 if (mask && mask->type == BITS)
355 maskRepeat = mask->common.repeat == PIXMAN_REPEAT_NORMAL;
357 maskTransform = mask->common.transform != 0;
358 if (mask->common.filter == PIXMAN_FILTER_CONVOLUTION)
359 maskTransform = TRUE;
361 if (maskRepeat && maskTransform &&
362 mask->bits.width == 1 &&
363 mask->bits.height == 1)
365 maskTransform = FALSE;
370 if (_pixman_run_fast_path (vmx_fast_paths, imp,
380 if (pixman_have_arm_neon() && _pixman_run_fast_path (arm_neon_fast_paths, imp,
390 if (pixman_have_arm_simd() && _pixman_run_fast_path (arm_simd_fast_paths, imp,
399 /* CompositeGeneral optimizes 1x1 repeating images itself */
400 if (src->type == BITS &&
401 src->bits.width == 1 && src->bits.height == 1)
406 if (mask && mask->type == BITS &&
407 mask->bits.width == 1 && mask->bits.height == 1)
412 /* if we are transforming, repeats are handled in fbFetchTransformed */
419 _pixman_walk_composite_region (imp, op, src, mask, dest, src_x, src_y,
420 mask_x, mask_y, dest_x, dest_y, width, height,
421 srcRepeat, maskRepeat, pixman_image_composite_rect);
425 general_blt (pixman_implementation_t *imp,
432 int src_x, int src_y,
433 int dst_x, int dst_y,
434 int width, int height)
436 /* We can't blit unless we have sse2 or mmx */
442 general_fill (pixman_implementation_t *imp,
455 pixman_implementation_t *
456 _pixman_implementation_create_general (pixman_implementation_t *toplevel)
458 pixman_implementation_t *imp = _pixman_implementation_create (toplevel, NULL);
461 for (i = 0; i < PIXMAN_OP_LAST; ++i)
463 imp->combine_32[i] = general_combine_32;
464 imp->combine_32_ca[i] = general_combine_32_ca;
465 imp->combine_64[i] = general_combine_64;
466 imp->combine_64_ca[i] = general_combine_64_ca;
468 imp->composite = general_composite;
469 imp->blt = general_blt;
470 imp->fill = general_fill;