gfx/skia/trunk/src/core/SkBitmapProcState_procs.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2011 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9 // Define NAME_WRAP(x) before including this header to perform name-wrapping
michael@0 10 // E.g. for ARM NEON, defined it as 'x ## _neon' to ensure all important
michael@0 11 // identifiers have a _neon suffix.
michael@0 12 #ifndef NAME_WRAP
michael@0 13 #error "Please define NAME_WRAP() before including this file"
michael@0 14 #endif
michael@0 15
michael@0 16 // returns expanded * 5bits
michael@0 17 static inline uint32_t Filter_565_Expanded(unsigned x, unsigned y,
michael@0 18 uint32_t a00, uint32_t a01,
michael@0 19 uint32_t a10, uint32_t a11) {
michael@0 20 SkASSERT((unsigned)x <= 0xF);
michael@0 21 SkASSERT((unsigned)y <= 0xF);
michael@0 22
michael@0 23 a00 = SkExpand_rgb_16(a00);
michael@0 24 a01 = SkExpand_rgb_16(a01);
michael@0 25 a10 = SkExpand_rgb_16(a10);
michael@0 26 a11 = SkExpand_rgb_16(a11);
michael@0 27
michael@0 28 int xy = x * y >> 3;
michael@0 29 return a00 * (32 - 2*y - 2*x + xy) +
michael@0 30 a01 * (2*x - xy) +
michael@0 31 a10 * (2*y - xy) +
michael@0 32 a11 * xy;
michael@0 33 }
michael@0 34
michael@0 35 // turn an expanded 565 * 5bits into SkPMColor
michael@0 36 // g:11 | r:10 | x:1 | b:10
michael@0 37 static inline SkPMColor SkExpanded_565_To_PMColor(uint32_t c) {
michael@0 38 unsigned r = (c >> 13) & 0xFF;
michael@0 39 unsigned g = (c >> 24);
michael@0 40 unsigned b = (c >> 2) & 0xFF;
michael@0 41 return SkPackARGB32(0xFF, r, g, b);
michael@0 42 }
michael@0 43
michael@0 44 // returns answer in SkPMColor format
michael@0 45 static inline SkPMColor Filter_4444_D32(unsigned x, unsigned y,
michael@0 46 uint32_t a00, uint32_t a01,
michael@0 47 uint32_t a10, uint32_t a11) {
michael@0 48 SkASSERT((unsigned)x <= 0xF);
michael@0 49 SkASSERT((unsigned)y <= 0xF);
michael@0 50
michael@0 51 a00 = SkExpand_4444(a00);
michael@0 52 a01 = SkExpand_4444(a01);
michael@0 53 a10 = SkExpand_4444(a10);
michael@0 54 a11 = SkExpand_4444(a11);
michael@0 55
michael@0 56 int xy = x * y >> 4;
michael@0 57 uint32_t result = a00 * (16 - y - x + xy) +
michael@0 58 a01 * (x - xy) +
michael@0 59 a10 * (y - xy) +
michael@0 60 a11 * xy;
michael@0 61
michael@0 62 return SkCompact_8888(result);
michael@0 63 }
michael@0 64
michael@0 65 static inline U8CPU Filter_8(unsigned x, unsigned y,
michael@0 66 U8CPU a00, U8CPU a01,
michael@0 67 U8CPU a10, U8CPU a11) {
michael@0 68 SkASSERT((unsigned)x <= 0xF);
michael@0 69 SkASSERT((unsigned)y <= 0xF);
michael@0 70
michael@0 71 int xy = x * y;
michael@0 72 unsigned result = a00 * (256 - 16*y - 16*x + xy) +
michael@0 73 a01 * (16*x - xy) +
michael@0 74 a10 * (16*y - xy) +
michael@0 75 a11 * xy;
michael@0 76
michael@0 77 return result >> 8;
michael@0 78 }
michael@0 79
michael@0 80 /*****************************************************************************
michael@0 81 *
michael@0 82 * D32 functions
michael@0 83 *
michael@0 84 */
michael@0 85
michael@0 86 // SRC == 8888
michael@0 87
michael@0 88 #define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst)
michael@0 89
michael@0 90 #define MAKENAME(suffix) NAME_WRAP(S32_opaque_D32 ## suffix)
michael@0 91 #define DSTSIZE 32
michael@0 92 #define SRCTYPE SkPMColor
michael@0 93 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kARGB_8888_Config); \
michael@0 94 SkASSERT(state.fAlphaScale == 256)
michael@0 95 #define RETURNDST(src) src
michael@0 96 #define SRC_TO_FILTER(src) src
michael@0 97 #include "SkBitmapProcState_sample.h"
michael@0 98
michael@0 99 #undef FILTER_PROC
michael@0 100 #define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_alpha)(x, y, a, b, c, d, dst, alphaScale)
michael@0 101
michael@0 102 #define MAKENAME(suffix) NAME_WRAP(S32_alpha_D32 ## suffix)
michael@0 103 #define DSTSIZE 32
michael@0 104 #define SRCTYPE SkPMColor
michael@0 105 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kARGB_8888_Config); \
michael@0 106 SkASSERT(state.fAlphaScale < 256)
michael@0 107 #define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale
michael@0 108 #define RETURNDST(src) SkAlphaMulQ(src, alphaScale)
michael@0 109 #define SRC_TO_FILTER(src) src
michael@0 110 #include "SkBitmapProcState_sample.h"
michael@0 111
michael@0 112 // SRC == 565
michael@0 113
michael@0 114 #undef FILTER_PROC
michael@0 115 #define FILTER_PROC(x, y, a, b, c, d, dst) \
michael@0 116 do { \
michael@0 117 uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d); \
michael@0 118 *(dst) = SkExpanded_565_To_PMColor(tmp); \
michael@0 119 } while (0)
michael@0 120
michael@0 121 #define MAKENAME(suffix) NAME_WRAP(S16_opaque_D32 ## suffix)
michael@0 122 #define DSTSIZE 32
michael@0 123 #define SRCTYPE uint16_t
michael@0 124 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kRGB_565_Config); \
michael@0 125 SkASSERT(state.fAlphaScale == 256)
michael@0 126 #define RETURNDST(src) SkPixel16ToPixel32(src)
michael@0 127 #define SRC_TO_FILTER(src) src
michael@0 128 #include "SkBitmapProcState_sample.h"
michael@0 129
michael@0 130 #undef FILTER_PROC
michael@0 131 #define FILTER_PROC(x, y, a, b, c, d, dst) \
michael@0 132 do { \
michael@0 133 uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d); \
michael@0 134 *(dst) = SkAlphaMulQ(SkExpanded_565_To_PMColor(tmp), alphaScale); \
michael@0 135 } while (0)
michael@0 136
michael@0 137 #define MAKENAME(suffix) NAME_WRAP(S16_alpha_D32 ## suffix)
michael@0 138 #define DSTSIZE 32
michael@0 139 #define SRCTYPE uint16_t
michael@0 140 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kRGB_565_Config); \
michael@0 141 SkASSERT(state.fAlphaScale < 256)
michael@0 142 #define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale
michael@0 143 #define RETURNDST(src) SkAlphaMulQ(SkPixel16ToPixel32(src), alphaScale)
michael@0 144 #define SRC_TO_FILTER(src) src
michael@0 145 #include "SkBitmapProcState_sample.h"
michael@0 146
michael@0 147 // SRC == Index8
michael@0 148
michael@0 149 #undef FILTER_PROC
michael@0 150 #define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst)
michael@0 151
michael@0 152 #define MAKENAME(suffix) NAME_WRAP(SI8_opaque_D32 ## suffix)
michael@0 153 #define DSTSIZE 32
michael@0 154 #define SRCTYPE uint8_t
michael@0 155 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kIndex8_Config); \
michael@0 156 SkASSERT(state.fAlphaScale == 256)
michael@0 157 #define PREAMBLE(state) const SkPMColor* SK_RESTRICT table = state.fBitmap->getColorTable()->lockColors()
michael@0 158 #define RETURNDST(src) table[src]
michael@0 159 #define SRC_TO_FILTER(src) table[src]
michael@0 160 #define POSTAMBLE(state) state.fBitmap->getColorTable()->unlockColors()
michael@0 161 #include "SkBitmapProcState_sample.h"
michael@0 162
michael@0 163 #undef FILTER_PROC
michael@0 164 #define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_alpha)(x, y, a, b, c, d, dst, alphaScale)
michael@0 165
michael@0 166 #define MAKENAME(suffix) NAME_WRAP(SI8_alpha_D32 ## suffix)
michael@0 167 #define DSTSIZE 32
michael@0 168 #define SRCTYPE uint8_t
michael@0 169 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kIndex8_Config); \
michael@0 170 SkASSERT(state.fAlphaScale < 256)
michael@0 171 #define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale; \
michael@0 172 const SkPMColor* SK_RESTRICT table = state.fBitmap->getColorTable()->lockColors()
michael@0 173 #define RETURNDST(src) SkAlphaMulQ(table[src], alphaScale)
michael@0 174 #define SRC_TO_FILTER(src) table[src]
michael@0 175 #define POSTAMBLE(state) state.fBitmap->getColorTable()->unlockColors()
michael@0 176 #include "SkBitmapProcState_sample.h"
michael@0 177
michael@0 178 // SRC == 4444
michael@0 179
michael@0 180 #undef FILTER_PROC
michael@0 181 #define FILTER_PROC(x, y, a, b, c, d, dst) *(dst) = Filter_4444_D32(x, y, a, b, c, d)
michael@0 182
michael@0 183 #define MAKENAME(suffix) NAME_WRAP(S4444_opaque_D32 ## suffix)
michael@0 184 #define DSTSIZE 32
michael@0 185 #define SRCTYPE SkPMColor16
michael@0 186 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kARGB_4444_Config); \
michael@0 187 SkASSERT(state.fAlphaScale == 256)
michael@0 188 #define RETURNDST(src) SkPixel4444ToPixel32(src)
michael@0 189 #define SRC_TO_FILTER(src) src
michael@0 190 #include "SkBitmapProcState_sample.h"
michael@0 191
michael@0 192 #undef FILTER_PROC
michael@0 193 #define FILTER_PROC(x, y, a, b, c, d, dst) \
michael@0 194 do { \
michael@0 195 uint32_t tmp = Filter_4444_D32(x, y, a, b, c, d); \
michael@0 196 *(dst) = SkAlphaMulQ(tmp, alphaScale); \
michael@0 197 } while (0)
michael@0 198
michael@0 199 #define MAKENAME(suffix) NAME_WRAP(S4444_alpha_D32 ## suffix)
michael@0 200 #define DSTSIZE 32
michael@0 201 #define SRCTYPE SkPMColor16
michael@0 202 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kARGB_4444_Config); \
michael@0 203 SkASSERT(state.fAlphaScale < 256)
michael@0 204 #define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale
michael@0 205 #define RETURNDST(src) SkAlphaMulQ(SkPixel4444ToPixel32(src), alphaScale)
michael@0 206 #define SRC_TO_FILTER(src) src
michael@0 207 #include "SkBitmapProcState_sample.h"
michael@0 208
michael@0 209 // SRC == A8
michael@0 210
michael@0 211 #undef FILTER_PROC
michael@0 212 #define FILTER_PROC(x, y, a, b, c, d, dst) \
michael@0 213 do { \
michael@0 214 unsigned tmp = Filter_8(x, y, a, b, c, d); \
michael@0 215 *(dst) = SkAlphaMulQ(pmColor, SkAlpha255To256(tmp)); \
michael@0 216 } while (0)
michael@0 217
michael@0 218 #define MAKENAME(suffix) NAME_WRAP(SA8_alpha_D32 ## suffix)
michael@0 219 #define DSTSIZE 32
michael@0 220 #define SRCTYPE uint8_t
michael@0 221 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kA8_Config);
michael@0 222 #define PREAMBLE(state) const SkPMColor pmColor = state.fPaintPMColor;
michael@0 223 #define RETURNDST(src) SkAlphaMulQ(pmColor, SkAlpha255To256(src))
michael@0 224 #define SRC_TO_FILTER(src) src
michael@0 225 #include "SkBitmapProcState_sample.h"
michael@0 226
michael@0 227 /*****************************************************************************
michael@0 228 *
michael@0 229 * D16 functions
michael@0 230 *
michael@0 231 */
michael@0 232
michael@0 233 // SRC == 8888
michael@0 234
michael@0 235 #undef FILTER_PROC
michael@0 236 #define FILTER_PROC(x, y, a, b, c, d, dst) \
michael@0 237 do { \
michael@0 238 SkPMColor dstColor; \
michael@0 239 NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, &dstColor); \
michael@0 240 (*dst) = SkPixel32ToPixel16(dstColor); \
michael@0 241 } while (0)
michael@0 242
michael@0 243 #define MAKENAME(suffix) NAME_WRAP(S32_D16 ## suffix)
michael@0 244 #define DSTSIZE 16
michael@0 245 #define SRCTYPE SkPMColor
michael@0 246 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kARGB_8888_Config); \
michael@0 247 SkASSERT(state.fBitmap->isOpaque())
michael@0 248 #define RETURNDST(src) SkPixel32ToPixel16(src)
michael@0 249 #define SRC_TO_FILTER(src) src
michael@0 250 #include "SkBitmapProcState_sample.h"
michael@0 251
michael@0 252 // SRC == 565
michael@0 253
michael@0 254 #undef FILTER_PROC
michael@0 255 #define FILTER_PROC(x, y, a, b, c, d, dst) \
michael@0 256 do { \
michael@0 257 uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d); \
michael@0 258 *(dst) = SkCompact_rgb_16((tmp) >> 5); \
michael@0 259 } while (0)
michael@0 260
michael@0 261 #define MAKENAME(suffix) NAME_WRAP(S16_D16 ## suffix)
michael@0 262 #define DSTSIZE 16
michael@0 263 #define SRCTYPE uint16_t
michael@0 264 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kRGB_565_Config)
michael@0 265 #define RETURNDST(src) src
michael@0 266 #define SRC_TO_FILTER(src) src
michael@0 267 #include "SkBitmapProcState_sample.h"
michael@0 268
michael@0 269 // SRC == Index8
michael@0 270
michael@0 271 #undef FILTER_PROC
michael@0 272 #define FILTER_PROC(x, y, a, b, c, d, dst) \
michael@0 273 do { \
michael@0 274 uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d); \
michael@0 275 *(dst) = SkCompact_rgb_16((tmp) >> 5); \
michael@0 276 } while (0)
michael@0 277
michael@0 278 #define MAKENAME(suffix) NAME_WRAP(SI8_D16 ## suffix)
michael@0 279 #define DSTSIZE 16
michael@0 280 #define SRCTYPE uint8_t
michael@0 281 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kIndex8_Config); \
michael@0 282 SkASSERT(state.fBitmap->isOpaque())
michael@0 283 #define PREAMBLE(state) const uint16_t* SK_RESTRICT table = state.fBitmap->getColorTable()->lock16BitCache()
michael@0 284 #define RETURNDST(src) table[src]
michael@0 285 #define SRC_TO_FILTER(src) table[src]
michael@0 286 #define POSTAMBLE(state) state.fBitmap->getColorTable()->unlock16BitCache()
michael@0 287 #include "SkBitmapProcState_sample.h"
michael@0 288
michael@0 289 ///////////////////////////////////////////////////////////////////////////////
michael@0 290
michael@0 291 #undef FILTER_PROC
michael@0 292 #define FILTER_PROC(x, y, a, b, c, d, dst) \
michael@0 293 do { \
michael@0 294 uint32_t tmp = Filter_565_Expanded(x, y, a, b, c, d); \
michael@0 295 *(dst) = SkCompact_rgb_16((tmp) >> 5); \
michael@0 296 } while (0)
michael@0 297
michael@0 298
michael@0 299 // clamp
michael@0 300
michael@0 301 #define TILEX_PROCF(fx, max) SkClampMax((fx) >> 16, max)
michael@0 302 #define TILEY_PROCF(fy, max) SkClampMax((fy) >> 16, max)
michael@0 303 #define TILEX_LOW_BITS(fx, max) (((fx) >> 12) & 0xF)
michael@0 304 #define TILEY_LOW_BITS(fy, max) (((fy) >> 12) & 0xF)
michael@0 305
michael@0 306 #define MAKENAME(suffix) NAME_WRAP(Clamp_S16_D16 ## suffix)
michael@0 307 #define SRCTYPE uint16_t
michael@0 308 #define DSTTYPE uint16_t
michael@0 309 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kRGB_565_Config)
michael@0 310 #define SRC_TO_FILTER(src) src
michael@0 311 #include "SkBitmapProcState_shaderproc.h"
michael@0 312
michael@0 313
michael@0 314 #define TILEX_PROCF(fx, max) (((fx) & 0xFFFF) * ((max) + 1) >> 16)
michael@0 315 #define TILEY_PROCF(fy, max) (((fy) & 0xFFFF) * ((max) + 1) >> 16)
michael@0 316 #define TILEX_LOW_BITS(fx, max) ((((fx) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
michael@0 317 #define TILEY_LOW_BITS(fy, max) ((((fy) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
michael@0 318
michael@0 319 #define MAKENAME(suffix) NAME_WRAP(Repeat_S16_D16 ## suffix)
michael@0 320 #define SRCTYPE uint16_t
michael@0 321 #define DSTTYPE uint16_t
michael@0 322 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kRGB_565_Config)
michael@0 323 #define SRC_TO_FILTER(src) src
michael@0 324 #include "SkBitmapProcState_shaderproc.h"
michael@0 325
michael@0 326
michael@0 327 #define TILEX_PROCF(fx, max) SkClampMax((fx) >> 16, max)
michael@0 328 #define TILEY_PROCF(fy, max) SkClampMax((fy) >> 16, max)
michael@0 329 #define TILEX_LOW_BITS(fx, max) (((fx) >> 12) & 0xF)
michael@0 330 #define TILEY_LOW_BITS(fy, max) (((fy) >> 12) & 0xF)
michael@0 331
michael@0 332 #undef FILTER_PROC
michael@0 333 #define FILTER_PROC(x, y, a, b, c, d, dst) NAME_WRAP(Filter_32_opaque)(x, y, a, b, c, d, dst)
michael@0 334 #define MAKENAME(suffix) NAME_WRAP(Clamp_SI8_opaque_D32 ## suffix)
michael@0 335 #define SRCTYPE uint8_t
michael@0 336 #define DSTTYPE uint32_t
michael@0 337 #define CHECKSTATE(state) SkASSERT(state.fBitmap->config() == SkBitmap::kIndex8_Config)
michael@0 338 #define PREAMBLE(state) const SkPMColor* SK_RESTRICT table = state.fBitmap->getColorTable()->lockColors()
michael@0 339 #define SRC_TO_FILTER(src) table[src]
michael@0 340 #define POSTAMBLE(state) state.fBitmap->getColorTable()->unlockColors()
michael@0 341 #include "SkBitmapProcState_shaderproc.h"
michael@0 342
michael@0 343 #undef NAME_WRAP

mercurial