michael@0: /* michael@0: * Copyright © 2009 Red Hat, Inc. michael@0: * Copyright © 2000 SuSE, Inc. michael@0: * Copyright © 2007 Red Hat, Inc. michael@0: * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. michael@0: * 2005 Lars Knoll & Zack Rusin, Trolltech michael@0: * 2008 Aaron Plattner, NVIDIA Corporation michael@0: * michael@0: * Permission to use, copy, modify, distribute, and sell this software and its michael@0: * documentation for any purpose is hereby granted without fee, provided that michael@0: * the above copyright notice appear in all copies and that both that michael@0: * copyright notice and this permission notice appear in supporting michael@0: * documentation, and that the name of Red Hat not be used in advertising or michael@0: * publicity pertaining to distribution of the software without specific, michael@0: * written prior permission. Red Hat makes no representations about the michael@0: * suitability of this software for any purpose. It is provided "as is" michael@0: * without express or implied warranty. michael@0: * michael@0: * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS michael@0: * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND michael@0: * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY michael@0: * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES michael@0: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN michael@0: * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING michael@0: * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS michael@0: * SOFTWARE. michael@0: */ michael@0: #ifdef HAVE_CONFIG_H michael@0: #include michael@0: #endif michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include "pixman-private.h" michael@0: michael@0: static pixman_bool_t michael@0: general_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter) michael@0: { michael@0: pixman_image_t *image = iter->image; michael@0: michael@0: if (image->type == LINEAR) michael@0: _pixman_linear_gradient_iter_init (image, iter); michael@0: else if (image->type == RADIAL) michael@0: _pixman_radial_gradient_iter_init (image, iter); michael@0: else if (image->type == CONICAL) michael@0: _pixman_conical_gradient_iter_init (image, iter); michael@0: else if (image->type == BITS) michael@0: _pixman_bits_image_src_iter_init (image, iter); michael@0: else if (image->type == SOLID) michael@0: _pixman_log_error (FUNC, "Solid image not handled by noop"); michael@0: else michael@0: _pixman_log_error (FUNC, "Pixman bug: unknown image type\n"); michael@0: michael@0: return TRUE; michael@0: } michael@0: michael@0: static pixman_bool_t michael@0: general_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter) michael@0: { michael@0: if (iter->image->type == BITS) michael@0: { michael@0: _pixman_bits_image_dest_iter_init (iter->image, iter); michael@0: michael@0: return TRUE; michael@0: } michael@0: else michael@0: { michael@0: _pixman_log_error (FUNC, "Trying to write to a non-writable image"); michael@0: michael@0: return FALSE; michael@0: } michael@0: } michael@0: michael@0: typedef struct op_info_t op_info_t; michael@0: struct op_info_t michael@0: { michael@0: uint8_t src, dst; michael@0: }; michael@0: michael@0: #define ITER_IGNORE_BOTH \ michael@0: (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB | ITER_LOCALIZED_ALPHA) michael@0: michael@0: static const op_info_t op_flags[PIXMAN_N_OPERATORS] = michael@0: { michael@0: /* Src Dst */ michael@0: { ITER_IGNORE_BOTH, ITER_IGNORE_BOTH }, /* CLEAR */ michael@0: { ITER_LOCALIZED_ALPHA, ITER_IGNORE_BOTH }, /* SRC */ michael@0: { ITER_IGNORE_BOTH, ITER_LOCALIZED_ALPHA }, /* DST */ michael@0: { 0, ITER_LOCALIZED_ALPHA }, /* OVER */ michael@0: { ITER_LOCALIZED_ALPHA, 0 }, /* OVER_REVERSE */ michael@0: { ITER_LOCALIZED_ALPHA, ITER_IGNORE_RGB }, /* IN */ michael@0: { ITER_IGNORE_RGB, ITER_LOCALIZED_ALPHA }, /* IN_REVERSE */ michael@0: { ITER_LOCALIZED_ALPHA, ITER_IGNORE_RGB }, /* OUT */ michael@0: { ITER_IGNORE_RGB, ITER_LOCALIZED_ALPHA }, /* OUT_REVERSE */ michael@0: { 0, 0 }, /* ATOP */ michael@0: { 0, 0 }, /* ATOP_REVERSE */ michael@0: { 0, 0 }, /* XOR */ michael@0: { ITER_LOCALIZED_ALPHA, ITER_LOCALIZED_ALPHA }, /* ADD */ michael@0: { 0, 0 }, /* SATURATE */ michael@0: }; michael@0: michael@0: #define SCANLINE_BUFFER_LENGTH 8192 michael@0: michael@0: static void michael@0: general_composite_rect (pixman_implementation_t *imp, michael@0: pixman_composite_info_t *info) michael@0: { michael@0: PIXMAN_COMPOSITE_ARGS (info); michael@0: uint64_t stack_scanline_buffer[(SCANLINE_BUFFER_LENGTH * 3 + 7) / 8]; michael@0: uint8_t *scanline_buffer = (uint8_t *) stack_scanline_buffer; michael@0: uint8_t *src_buffer, *mask_buffer, *dest_buffer; michael@0: pixman_iter_t src_iter, mask_iter, dest_iter; michael@0: pixman_combine_32_func_t compose; michael@0: pixman_bool_t component_alpha; michael@0: iter_flags_t narrow, src_iter_flags; michael@0: iter_flags_t rgb16; michael@0: int Bpp; michael@0: int i; michael@0: michael@0: if ((src_image->common.flags & FAST_PATH_NARROW_FORMAT) && michael@0: (!mask_image || mask_image->common.flags & FAST_PATH_NARROW_FORMAT) && michael@0: (dest_image->common.flags & FAST_PATH_NARROW_FORMAT)) michael@0: { michael@0: narrow = ITER_NARROW; michael@0: Bpp = 4; michael@0: } michael@0: else michael@0: { michael@0: narrow = 0; michael@0: Bpp = 16; michael@0: } michael@0: michael@0: // XXX: This special casing is bad. Ideally, we'd keep the general code general perhaps michael@0: // by having it deal more specifically with different intermediate formats michael@0: if ( michael@0: (dest_image->common.flags & FAST_PATH_16_FORMAT && (src_image->type == LINEAR || src_image->type == RADIAL)) && michael@0: ( op == PIXMAN_OP_SRC || michael@0: (op == PIXMAN_OP_OVER && (src_image->common.flags & FAST_PATH_IS_OPAQUE)) michael@0: ) michael@0: ) { michael@0: rgb16 = ITER_16; michael@0: } else { michael@0: rgb16 = 0; michael@0: } michael@0: michael@0: michael@0: if (width * Bpp > SCANLINE_BUFFER_LENGTH) michael@0: { michael@0: scanline_buffer = pixman_malloc_abc (width, 3, Bpp); michael@0: michael@0: if (!scanline_buffer) michael@0: return; michael@0: } michael@0: michael@0: src_buffer = scanline_buffer; michael@0: mask_buffer = src_buffer + width * Bpp; michael@0: dest_buffer = mask_buffer + width * Bpp; michael@0: michael@0: if (!narrow) michael@0: { michael@0: /* To make sure there aren't any NANs in the buffers */ michael@0: memset (src_buffer, 0, width * Bpp); michael@0: memset (mask_buffer, 0, width * Bpp); michael@0: memset (dest_buffer, 0, width * Bpp); michael@0: } michael@0: michael@0: /* src iter */ michael@0: src_iter_flags = narrow | op_flags[op].src | rgb16; michael@0: michael@0: _pixman_implementation_src_iter_init (imp->toplevel, &src_iter, src_image, michael@0: src_x, src_y, width, height, michael@0: src_buffer, src_iter_flags, info->src_flags); michael@0: michael@0: /* mask iter */ michael@0: if ((src_iter_flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) == michael@0: (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) michael@0: { michael@0: /* If it doesn't matter what the source is, then it doesn't matter michael@0: * what the mask is michael@0: */ michael@0: mask_image = NULL; michael@0: } michael@0: michael@0: component_alpha = michael@0: mask_image && michael@0: mask_image->common.type == BITS && michael@0: mask_image->common.component_alpha && michael@0: PIXMAN_FORMAT_RGB (mask_image->bits.format); michael@0: michael@0: _pixman_implementation_src_iter_init ( michael@0: imp->toplevel, &mask_iter, mask_image, mask_x, mask_y, width, height, michael@0: mask_buffer, narrow | (component_alpha? 0 : ITER_IGNORE_RGB), info->mask_flags); michael@0: michael@0: /* dest iter */ michael@0: _pixman_implementation_dest_iter_init ( michael@0: imp->toplevel, &dest_iter, dest_image, dest_x, dest_y, width, height, michael@0: dest_buffer, narrow | op_flags[op].dst | rgb16, info->dest_flags); michael@0: michael@0: compose = _pixman_implementation_lookup_combiner ( michael@0: imp->toplevel, op, component_alpha, narrow, !!rgb16); michael@0: michael@0: for (i = 0; i < height; ++i) michael@0: { michael@0: uint32_t *s, *m, *d; michael@0: michael@0: m = mask_iter.get_scanline (&mask_iter, NULL); michael@0: s = src_iter.get_scanline (&src_iter, m); michael@0: d = dest_iter.get_scanline (&dest_iter, NULL); michael@0: michael@0: compose (imp->toplevel, op, d, s, m, width); michael@0: michael@0: dest_iter.write_back (&dest_iter); michael@0: } michael@0: michael@0: if (scanline_buffer != (uint8_t *) stack_scanline_buffer) michael@0: free (scanline_buffer); michael@0: } michael@0: michael@0: static const pixman_fast_path_t general_fast_path[] = michael@0: { michael@0: { PIXMAN_OP_any, PIXMAN_any, 0, PIXMAN_any, 0, PIXMAN_any, 0, general_composite_rect }, michael@0: { PIXMAN_OP_NONE } michael@0: }; michael@0: michael@0: pixman_implementation_t * michael@0: _pixman_implementation_create_general (void) michael@0: { michael@0: pixman_implementation_t *imp = _pixman_implementation_create (NULL, general_fast_path); michael@0: michael@0: _pixman_setup_combiner_functions_16 (imp); michael@0: _pixman_setup_combiner_functions_32 (imp); michael@0: _pixman_setup_combiner_functions_float (imp); michael@0: michael@0: imp->src_iter_init = general_src_iter_init; michael@0: imp->dest_iter_init = general_dest_iter_init; michael@0: michael@0: return imp; michael@0: } michael@0: