gfx/cairo/libpixman/src/pixman-noop.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: c; c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t; -*- */
michael@0 2 /*
michael@0 3 * Copyright © 2011 Red Hat, Inc.
michael@0 4 *
michael@0 5 * Permission is hereby granted, free of charge, to any person obtaining a
michael@0 6 * copy of this software and associated documentation files (the "Software"),
michael@0 7 * to deal in the Software without restriction, including without limitation
michael@0 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
michael@0 9 * and/or sell copies of the Software, and to permit persons to whom the
michael@0 10 * Software is furnished to do so, subject to the following conditions:
michael@0 11 *
michael@0 12 * The above copyright notice and this permission notice (including the next
michael@0 13 * paragraph) shall be included in all copies or substantial portions of the
michael@0 14 * Software.
michael@0 15 *
michael@0 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
michael@0 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
michael@0 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
michael@0 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
michael@0 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
michael@0 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
michael@0 22 * DEALINGS IN THE SOFTWARE.
michael@0 23 */
michael@0 24 #ifdef HAVE_CONFIG_H
michael@0 25 #include <config.h>
michael@0 26 #endif
michael@0 27 #include <string.h>
michael@0 28 #include <stdlib.h>
michael@0 29 #include "pixman-private.h"
michael@0 30 #include "pixman-combine32.h"
michael@0 31 #include "pixman-inlines.h"
michael@0 32
michael@0 33 static void
michael@0 34 noop_composite (pixman_implementation_t *imp,
michael@0 35 pixman_composite_info_t *info)
michael@0 36 {
michael@0 37 return;
michael@0 38 }
michael@0 39
michael@0 40 static void
michael@0 41 dest_write_back_direct (pixman_iter_t *iter)
michael@0 42 {
michael@0 43 iter->buffer += iter->image->bits.rowstride;
michael@0 44 }
michael@0 45
michael@0 46 static uint32_t *
michael@0 47 noop_get_scanline (pixman_iter_t *iter, const uint32_t *mask)
michael@0 48 {
michael@0 49 uint32_t *result = iter->buffer;
michael@0 50
michael@0 51 iter->buffer += iter->image->bits.rowstride;
michael@0 52
michael@0 53 return result;
michael@0 54 }
michael@0 55
michael@0 56 static uint32_t *
michael@0 57 get_scanline_null (pixman_iter_t *iter, const uint32_t *mask)
michael@0 58 {
michael@0 59 return NULL;
michael@0 60 }
michael@0 61
michael@0 62 static pixman_bool_t
michael@0 63 noop_src_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
michael@0 64 {
michael@0 65 pixman_image_t *image = iter->image;
michael@0 66
michael@0 67 #define FLAGS \
michael@0 68 (FAST_PATH_STANDARD_FLAGS | FAST_PATH_ID_TRANSFORM)
michael@0 69
michael@0 70 if (!image)
michael@0 71 {
michael@0 72 iter->get_scanline = get_scanline_null;
michael@0 73 }
michael@0 74 else if ((iter->iter_flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) ==
michael@0 75 (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB))
michael@0 76 {
michael@0 77 iter->get_scanline = _pixman_iter_get_scanline_noop;
michael@0 78 }
michael@0 79 else if (image->common.extended_format_code == PIXMAN_solid &&
michael@0 80 (iter->image->type == SOLID ||
michael@0 81 (iter->image_flags & FAST_PATH_NO_ALPHA_MAP)))
michael@0 82 {
michael@0 83 if (iter->iter_flags & ITER_NARROW)
michael@0 84 {
michael@0 85 uint32_t *buffer = iter->buffer;
michael@0 86 uint32_t *end = buffer + iter->width;
michael@0 87 uint32_t color;
michael@0 88
michael@0 89 if (image->type == SOLID)
michael@0 90 color = image->solid.color_32;
michael@0 91 else
michael@0 92 color = image->bits.fetch_pixel_32 (&image->bits, 0, 0);
michael@0 93
michael@0 94 while (buffer < end)
michael@0 95 *(buffer++) = color;
michael@0 96 }
michael@0 97 else
michael@0 98 {
michael@0 99 argb_t *buffer = (argb_t *)iter->buffer;
michael@0 100 argb_t *end = buffer + iter->width;
michael@0 101 argb_t color;
michael@0 102
michael@0 103 if (image->type == SOLID)
michael@0 104 color = image->solid.color_float;
michael@0 105 else
michael@0 106 color = image->bits.fetch_pixel_float (&image->bits, 0, 0);
michael@0 107
michael@0 108 while (buffer < end)
michael@0 109 *(buffer++) = color;
michael@0 110 }
michael@0 111
michael@0 112 iter->get_scanline = _pixman_iter_get_scanline_noop;
michael@0 113 }
michael@0 114 else if (image->common.extended_format_code == PIXMAN_a8r8g8b8 &&
michael@0 115 (iter->iter_flags & ITER_NARROW) &&
michael@0 116 (iter->image_flags & FLAGS) == FLAGS &&
michael@0 117 iter->x >= 0 && iter->y >= 0 &&
michael@0 118 iter->x + iter->width <= image->bits.width &&
michael@0 119 iter->y + iter->height <= image->bits.height)
michael@0 120 {
michael@0 121 iter->buffer =
michael@0 122 image->bits.bits + iter->y * image->bits.rowstride + iter->x;
michael@0 123
michael@0 124 iter->get_scanline = noop_get_scanline;
michael@0 125 }
michael@0 126 else
michael@0 127 {
michael@0 128 return FALSE;
michael@0 129 }
michael@0 130
michael@0 131 return TRUE;
michael@0 132 }
michael@0 133
michael@0 134 static pixman_bool_t
michael@0 135 noop_dest_iter_init (pixman_implementation_t *imp, pixman_iter_t *iter)
michael@0 136 {
michael@0 137 pixman_image_t *image = iter->image;
michael@0 138 uint32_t image_flags = iter->image_flags;
michael@0 139 uint32_t iter_flags = iter->iter_flags;
michael@0 140
michael@0 141 if ((image_flags & FAST_PATH_STD_DEST_FLAGS) == FAST_PATH_STD_DEST_FLAGS &&
michael@0 142 (iter_flags & ITER_NARROW) == ITER_NARROW &&
michael@0 143 ((image->common.extended_format_code == PIXMAN_a8r8g8b8) ||
michael@0 144 (image->common.extended_format_code == PIXMAN_x8r8g8b8 &&
michael@0 145 (iter_flags & (ITER_LOCALIZED_ALPHA)))))
michael@0 146 {
michael@0 147 iter->buffer = image->bits.bits + iter->y * image->bits.rowstride + iter->x;
michael@0 148
michael@0 149 iter->get_scanline = _pixman_iter_get_scanline_noop;
michael@0 150 iter->write_back = dest_write_back_direct;
michael@0 151
michael@0 152 return TRUE;
michael@0 153 }
michael@0 154 else
michael@0 155 {
michael@0 156 return FALSE;
michael@0 157 }
michael@0 158 }
michael@0 159
michael@0 160 static const pixman_fast_path_t noop_fast_paths[] =
michael@0 161 {
michael@0 162 { PIXMAN_OP_DST, PIXMAN_any, 0, PIXMAN_any, 0, PIXMAN_any, 0, noop_composite },
michael@0 163 { PIXMAN_OP_NONE },
michael@0 164 };
michael@0 165
michael@0 166 pixman_implementation_t *
michael@0 167 _pixman_implementation_create_noop (pixman_implementation_t *fallback)
michael@0 168 {
michael@0 169 pixman_implementation_t *imp =
michael@0 170 _pixman_implementation_create (fallback, noop_fast_paths);
michael@0 171
michael@0 172 imp->src_iter_init = noop_src_iter_init;
michael@0 173 imp->dest_iter_init = noop_dest_iter_init;
michael@0 174
michael@0 175 return imp;
michael@0 176 }

mercurial