Sat, 03 Jan 2015 20:18:00 +0100
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 | #include "SkUtils.h" |
michael@0 | 9 | |
michael@0 | 10 | #if DSTSIZE==32 |
michael@0 | 11 | #define DSTTYPE SkPMColor |
michael@0 | 12 | #elif DSTSIZE==16 |
michael@0 | 13 | #define DSTTYPE uint16_t |
michael@0 | 14 | #else |
michael@0 | 15 | #error "need DSTSIZE to be 32 or 16" |
michael@0 | 16 | #endif |
michael@0 | 17 | |
michael@0 | 18 | #if (DSTSIZE == 32) |
michael@0 | 19 | #define BITMAPPROC_MEMSET(ptr, value, n) sk_memset32(ptr, value, n) |
michael@0 | 20 | #elif (DSTSIZE == 16) |
michael@0 | 21 | #define BITMAPPROC_MEMSET(ptr, value, n) sk_memset16(ptr, value, n) |
michael@0 | 22 | #else |
michael@0 | 23 | #error "unsupported DSTSIZE" |
michael@0 | 24 | #endif |
michael@0 | 25 | |
michael@0 | 26 | |
michael@0 | 27 | // declare functions externally to suppress warnings. |
michael@0 | 28 | void MAKENAME(_nofilter_DXDY)(const SkBitmapProcState& s, |
michael@0 | 29 | const uint32_t* SK_RESTRICT xy, |
michael@0 | 30 | int count, DSTTYPE* SK_RESTRICT colors); |
michael@0 | 31 | void MAKENAME(_nofilter_DX)(const SkBitmapProcState& s, |
michael@0 | 32 | const uint32_t* SK_RESTRICT xy, |
michael@0 | 33 | int count, DSTTYPE* SK_RESTRICT colors); |
michael@0 | 34 | void MAKENAME(_filter_DX)(const SkBitmapProcState& s, |
michael@0 | 35 | const uint32_t* SK_RESTRICT xy, |
michael@0 | 36 | int count, DSTTYPE* SK_RESTRICT colors); |
michael@0 | 37 | void MAKENAME(_filter_DXDY)(const SkBitmapProcState& s, |
michael@0 | 38 | const uint32_t* SK_RESTRICT xy, |
michael@0 | 39 | int count, DSTTYPE* SK_RESTRICT colors); |
michael@0 | 40 | |
michael@0 | 41 | void MAKENAME(_nofilter_DXDY)(const SkBitmapProcState& s, |
michael@0 | 42 | const uint32_t* SK_RESTRICT xy, |
michael@0 | 43 | int count, DSTTYPE* SK_RESTRICT colors) { |
michael@0 | 44 | SkASSERT(count > 0 && colors != NULL); |
michael@0 | 45 | SkASSERT(SkPaint::kNone_FilterLevel == s.fFilterLevel); |
michael@0 | 46 | SkDEBUGCODE(CHECKSTATE(s);) |
michael@0 | 47 | |
michael@0 | 48 | #ifdef PREAMBLE |
michael@0 | 49 | PREAMBLE(s); |
michael@0 | 50 | #endif |
michael@0 | 51 | const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels(); |
michael@0 | 52 | size_t rb = s.fBitmap->rowBytes(); |
michael@0 | 53 | |
michael@0 | 54 | uint32_t XY; |
michael@0 | 55 | SRCTYPE src; |
michael@0 | 56 | |
michael@0 | 57 | for (int i = (count >> 1); i > 0; --i) { |
michael@0 | 58 | XY = *xy++; |
michael@0 | 59 | SkASSERT((XY >> 16) < (unsigned)s.fBitmap->height() && |
michael@0 | 60 | (XY & 0xFFFF) < (unsigned)s.fBitmap->width()); |
michael@0 | 61 | src = ((const SRCTYPE*)(srcAddr + (XY >> 16) * rb))[XY & 0xFFFF]; |
michael@0 | 62 | *colors++ = RETURNDST(src); |
michael@0 | 63 | |
michael@0 | 64 | XY = *xy++; |
michael@0 | 65 | SkASSERT((XY >> 16) < (unsigned)s.fBitmap->height() && |
michael@0 | 66 | (XY & 0xFFFF) < (unsigned)s.fBitmap->width()); |
michael@0 | 67 | src = ((const SRCTYPE*)(srcAddr + (XY >> 16) * rb))[XY & 0xFFFF]; |
michael@0 | 68 | *colors++ = RETURNDST(src); |
michael@0 | 69 | } |
michael@0 | 70 | if (count & 1) { |
michael@0 | 71 | XY = *xy++; |
michael@0 | 72 | SkASSERT((XY >> 16) < (unsigned)s.fBitmap->height() && |
michael@0 | 73 | (XY & 0xFFFF) < (unsigned)s.fBitmap->width()); |
michael@0 | 74 | src = ((const SRCTYPE*)(srcAddr + (XY >> 16) * rb))[XY & 0xFFFF]; |
michael@0 | 75 | *colors++ = RETURNDST(src); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | #ifdef POSTAMBLE |
michael@0 | 79 | POSTAMBLE(s); |
michael@0 | 80 | #endif |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | void MAKENAME(_nofilter_DX)(const SkBitmapProcState& s, |
michael@0 | 84 | const uint32_t* SK_RESTRICT xy, |
michael@0 | 85 | int count, DSTTYPE* SK_RESTRICT colors) { |
michael@0 | 86 | SkASSERT(count > 0 && colors != NULL); |
michael@0 | 87 | SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)); |
michael@0 | 88 | SkASSERT(SkPaint::kNone_FilterLevel == s.fFilterLevel); |
michael@0 | 89 | SkDEBUGCODE(CHECKSTATE(s);) |
michael@0 | 90 | |
michael@0 | 91 | #ifdef PREAMBLE |
michael@0 | 92 | PREAMBLE(s); |
michael@0 | 93 | #endif |
michael@0 | 94 | const SRCTYPE* SK_RESTRICT srcAddr = (const SRCTYPE*)s.fBitmap->getPixels(); |
michael@0 | 95 | |
michael@0 | 96 | // buffer is y32, x16, x16, x16, x16, x16 |
michael@0 | 97 | // bump srcAddr to the proper row, since we're told Y never changes |
michael@0 | 98 | SkASSERT((unsigned)xy[0] < (unsigned)s.fBitmap->height()); |
michael@0 | 99 | srcAddr = (const SRCTYPE*)((const char*)srcAddr + |
michael@0 | 100 | xy[0] * s.fBitmap->rowBytes()); |
michael@0 | 101 | xy += 1; |
michael@0 | 102 | |
michael@0 | 103 | SRCTYPE src; |
michael@0 | 104 | |
michael@0 | 105 | if (1 == s.fBitmap->width()) { |
michael@0 | 106 | src = srcAddr[0]; |
michael@0 | 107 | DSTTYPE dstValue = RETURNDST(src); |
michael@0 | 108 | BITMAPPROC_MEMSET(colors, dstValue, count); |
michael@0 | 109 | } else { |
michael@0 | 110 | int i; |
michael@0 | 111 | for (i = (count >> 2); i > 0; --i) { |
michael@0 | 112 | uint32_t xx0 = *xy++; |
michael@0 | 113 | uint32_t xx1 = *xy++; |
michael@0 | 114 | SRCTYPE x0 = srcAddr[UNPACK_PRIMARY_SHORT(xx0)]; |
michael@0 | 115 | SRCTYPE x1 = srcAddr[UNPACK_SECONDARY_SHORT(xx0)]; |
michael@0 | 116 | SRCTYPE x2 = srcAddr[UNPACK_PRIMARY_SHORT(xx1)]; |
michael@0 | 117 | SRCTYPE x3 = srcAddr[UNPACK_SECONDARY_SHORT(xx1)]; |
michael@0 | 118 | |
michael@0 | 119 | *colors++ = RETURNDST(x0); |
michael@0 | 120 | *colors++ = RETURNDST(x1); |
michael@0 | 121 | *colors++ = RETURNDST(x2); |
michael@0 | 122 | *colors++ = RETURNDST(x3); |
michael@0 | 123 | } |
michael@0 | 124 | const uint16_t* SK_RESTRICT xx = (const uint16_t*)(xy); |
michael@0 | 125 | for (i = (count & 3); i > 0; --i) { |
michael@0 | 126 | SkASSERT(*xx < (unsigned)s.fBitmap->width()); |
michael@0 | 127 | src = srcAddr[*xx++]; *colors++ = RETURNDST(src); |
michael@0 | 128 | } |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | #ifdef POSTAMBLE |
michael@0 | 132 | POSTAMBLE(s); |
michael@0 | 133 | #endif |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 137 | |
michael@0 | 138 | void MAKENAME(_filter_DX)(const SkBitmapProcState& s, |
michael@0 | 139 | const uint32_t* SK_RESTRICT xy, |
michael@0 | 140 | int count, DSTTYPE* SK_RESTRICT colors) { |
michael@0 | 141 | SkASSERT(count > 0 && colors != NULL); |
michael@0 | 142 | SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel); |
michael@0 | 143 | SkDEBUGCODE(CHECKSTATE(s);) |
michael@0 | 144 | |
michael@0 | 145 | #ifdef PREAMBLE |
michael@0 | 146 | PREAMBLE(s); |
michael@0 | 147 | #endif |
michael@0 | 148 | const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels(); |
michael@0 | 149 | size_t rb = s.fBitmap->rowBytes(); |
michael@0 | 150 | unsigned subY; |
michael@0 | 151 | const SRCTYPE* SK_RESTRICT row0; |
michael@0 | 152 | const SRCTYPE* SK_RESTRICT row1; |
michael@0 | 153 | |
michael@0 | 154 | // setup row ptrs and update proc_table |
michael@0 | 155 | { |
michael@0 | 156 | uint32_t XY = *xy++; |
michael@0 | 157 | unsigned y0 = XY >> 14; |
michael@0 | 158 | row0 = (const SRCTYPE*)(srcAddr + (y0 >> 4) * rb); |
michael@0 | 159 | row1 = (const SRCTYPE*)(srcAddr + (XY & 0x3FFF) * rb); |
michael@0 | 160 | subY = y0 & 0xF; |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | do { |
michael@0 | 164 | uint32_t XX = *xy++; // x0:14 | 4 | x1:14 |
michael@0 | 165 | unsigned x0 = XX >> 14; |
michael@0 | 166 | unsigned x1 = XX & 0x3FFF; |
michael@0 | 167 | unsigned subX = x0 & 0xF; |
michael@0 | 168 | x0 >>= 4; |
michael@0 | 169 | |
michael@0 | 170 | FILTER_PROC(subX, subY, |
michael@0 | 171 | SRC_TO_FILTER(row0[x0]), |
michael@0 | 172 | SRC_TO_FILTER(row0[x1]), |
michael@0 | 173 | SRC_TO_FILTER(row1[x0]), |
michael@0 | 174 | SRC_TO_FILTER(row1[x1]), |
michael@0 | 175 | colors); |
michael@0 | 176 | colors += 1; |
michael@0 | 177 | |
michael@0 | 178 | } while (--count != 0); |
michael@0 | 179 | |
michael@0 | 180 | #ifdef POSTAMBLE |
michael@0 | 181 | POSTAMBLE(s); |
michael@0 | 182 | #endif |
michael@0 | 183 | } |
michael@0 | 184 | void MAKENAME(_filter_DXDY)(const SkBitmapProcState& s, |
michael@0 | 185 | const uint32_t* SK_RESTRICT xy, |
michael@0 | 186 | int count, DSTTYPE* SK_RESTRICT colors) { |
michael@0 | 187 | SkASSERT(count > 0 && colors != NULL); |
michael@0 | 188 | SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel); |
michael@0 | 189 | SkDEBUGCODE(CHECKSTATE(s);) |
michael@0 | 190 | |
michael@0 | 191 | #ifdef PREAMBLE |
michael@0 | 192 | PREAMBLE(s); |
michael@0 | 193 | #endif |
michael@0 | 194 | const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels(); |
michael@0 | 195 | size_t rb = s.fBitmap->rowBytes(); |
michael@0 | 196 | |
michael@0 | 197 | do { |
michael@0 | 198 | uint32_t data = *xy++; |
michael@0 | 199 | unsigned y0 = data >> 14; |
michael@0 | 200 | unsigned y1 = data & 0x3FFF; |
michael@0 | 201 | unsigned subY = y0 & 0xF; |
michael@0 | 202 | y0 >>= 4; |
michael@0 | 203 | |
michael@0 | 204 | data = *xy++; |
michael@0 | 205 | unsigned x0 = data >> 14; |
michael@0 | 206 | unsigned x1 = data & 0x3FFF; |
michael@0 | 207 | unsigned subX = x0 & 0xF; |
michael@0 | 208 | x0 >>= 4; |
michael@0 | 209 | |
michael@0 | 210 | const SRCTYPE* SK_RESTRICT row0 = (const SRCTYPE*)(srcAddr + y0 * rb); |
michael@0 | 211 | const SRCTYPE* SK_RESTRICT row1 = (const SRCTYPE*)(srcAddr + y1 * rb); |
michael@0 | 212 | |
michael@0 | 213 | FILTER_PROC(subX, subY, |
michael@0 | 214 | SRC_TO_FILTER(row0[x0]), |
michael@0 | 215 | SRC_TO_FILTER(row0[x1]), |
michael@0 | 216 | SRC_TO_FILTER(row1[x0]), |
michael@0 | 217 | SRC_TO_FILTER(row1[x1]), |
michael@0 | 218 | colors); |
michael@0 | 219 | colors += 1; |
michael@0 | 220 | } while (--count != 0); |
michael@0 | 221 | |
michael@0 | 222 | #ifdef POSTAMBLE |
michael@0 | 223 | POSTAMBLE(s); |
michael@0 | 224 | #endif |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | #undef MAKENAME |
michael@0 | 228 | #undef DSTSIZE |
michael@0 | 229 | #undef DSTTYPE |
michael@0 | 230 | #undef SRCTYPE |
michael@0 | 231 | #undef CHECKSTATE |
michael@0 | 232 | #undef RETURNDST |
michael@0 | 233 | #undef SRC_TO_FILTER |
michael@0 | 234 | #undef FILTER_TO_DST |
michael@0 | 235 | |
michael@0 | 236 | #ifdef PREAMBLE |
michael@0 | 237 | #undef PREAMBLE |
michael@0 | 238 | #endif |
michael@0 | 239 | #ifdef POSTAMBLE |
michael@0 | 240 | #undef POSTAMBLE |
michael@0 | 241 | #endif |
michael@0 | 242 | |
michael@0 | 243 | #undef FILTER_PROC_TYPE |
michael@0 | 244 | #undef GET_FILTER_TABLE |
michael@0 | 245 | #undef GET_FILTER_ROW |
michael@0 | 246 | #undef GET_FILTER_ROW_PROC |
michael@0 | 247 | #undef GET_FILTER_PROC |
michael@0 | 248 | #undef BITMAPPROC_MEMSET |