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 2006 The Android Open Source Project |
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 | |
michael@0 | 10 | |
michael@0 | 11 | #ifndef NOFILTER_BITMAP_SHADER_PREAMBLE |
michael@0 | 12 | #define NOFILTER_BITMAP_SHADER_PREAMBLE(bitmap, rb) |
michael@0 | 13 | #endif |
michael@0 | 14 | #ifndef NOFILTER_BITMAP_SHADER_POSTAMBLE |
michael@0 | 15 | #define NOFILTER_BITMAP_SHADER_POSTAMBLE(bitmap) |
michael@0 | 16 | #endif |
michael@0 | 17 | #ifndef NOFILTER_BITMAP_SHADER_PREAMBLE16 |
michael@0 | 18 | #define NOFILTER_BITMAP_SHADER_PREAMBLE16(bitmap, rb) |
michael@0 | 19 | #endif |
michael@0 | 20 | #ifndef NOFILTER_BITMAP_SHADER_POSTAMBLE16 |
michael@0 | 21 | #define NOFILTER_BITMAP_SHADER_POSTAMBLE16(bitmap) |
michael@0 | 22 | #endif |
michael@0 | 23 | |
michael@0 | 24 | class NOFILTER_BITMAP_SHADER_CLASS : public HasSpan16_Sampler_BitmapShader { |
michael@0 | 25 | public: |
michael@0 | 26 | NOFILTER_BITMAP_SHADER_CLASS(const SkBitmap& src) |
michael@0 | 27 | : HasSpan16_Sampler_BitmapShader(src, false, |
michael@0 | 28 | NOFILTER_BITMAP_SHADER_TILEMODE, |
michael@0 | 29 | NOFILTER_BITMAP_SHADER_TILEMODE) |
michael@0 | 30 | { |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | virtual bool setContext(const SkBitmap& device, const SkPaint& paint, const SkMatrix& matrix) |
michael@0 | 34 | { |
michael@0 | 35 | if (!this->INHERITED::setContext(device, paint, matrix)) |
michael@0 | 36 | return false; |
michael@0 | 37 | |
michael@0 | 38 | #ifdef NOFILTER_BITMAP_SHADER_USE_UNITINVERSE |
michael@0 | 39 | this->computeUnitInverse(); |
michael@0 | 40 | #endif |
michael@0 | 41 | return true; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) |
michael@0 | 45 | { |
michael@0 | 46 | SkASSERT(count > 0); |
michael@0 | 47 | |
michael@0 | 48 | #ifdef NOFILTER_BITMAP_SHADER_SPRITEPROC32 |
michael@0 | 49 | if ((this->getTotalInverse().getType() & ~SkMatrix::kTranslate_Mask) == 0) |
michael@0 | 50 | { |
michael@0 | 51 | NOFILTER_BITMAP_SHADER_SPRITEPROC32(this, x, y, dstC, count); |
michael@0 | 52 | return; |
michael@0 | 53 | } |
michael@0 | 54 | #endif |
michael@0 | 55 | |
michael@0 | 56 | unsigned scale = SkAlpha255To256(this->getPaintAlpha()); |
michael@0 | 57 | #ifdef NOFILTER_BITMAP_SHADER_USE_UNITINVERSE |
michael@0 | 58 | const SkMatrix& inv = this->getUnitInverse(); |
michael@0 | 59 | SkMatrix::MapPtProc invProc = this->getUnitInverseProc(); |
michael@0 | 60 | #else |
michael@0 | 61 | const SkMatrix& inv = this->getTotalInverse(); |
michael@0 | 62 | SkMatrix::MapPtProc invProc = this->getInverseMapPtProc(); |
michael@0 | 63 | #endif |
michael@0 | 64 | const SkBitmap& srcBitmap = this->getSrcBitmap(); |
michael@0 | 65 | unsigned srcMaxX = srcBitmap.width() - 1; |
michael@0 | 66 | unsigned srcMaxY = srcBitmap.height() - 1; |
michael@0 | 67 | unsigned srcRB = srcBitmap.rowBytes(); |
michael@0 | 68 | SkFixed fx, fy, dx, dy; |
michael@0 | 69 | |
michael@0 | 70 | const NOFILTER_BITMAP_SHADER_TYPE* srcPixels = (const NOFILTER_BITMAP_SHADER_TYPE*)srcBitmap.getPixels(); |
michael@0 | 71 | NOFILTER_BITMAP_SHADER_PREAMBLE(srcBitmap, srcRB); |
michael@0 | 72 | |
michael@0 | 73 | if (this->getInverseClass() == kPerspective_MatrixClass) |
michael@0 | 74 | { |
michael@0 | 75 | SkPerspIter iter(inv, SkIntToScalar(x) + SK_ScalarHalf, |
michael@0 | 76 | SkIntToScalar(y) + SK_ScalarHalf, count); |
michael@0 | 77 | while ((count = iter.next()) != 0) |
michael@0 | 78 | { |
michael@0 | 79 | const SkFixed* srcXY = iter.getXY(); |
michael@0 | 80 | |
michael@0 | 81 | /* Do I need this? |
michael@0 | 82 | #ifndef NOFILTER_BITMAP_SHADER_USE_UNITINVERSE |
michael@0 | 83 | fx >>= level; |
michael@0 | 84 | fy >>= level; |
michael@0 | 85 | #endif |
michael@0 | 86 | */ |
michael@0 | 87 | if (256 == scale) |
michael@0 | 88 | { |
michael@0 | 89 | while (--count >= 0) |
michael@0 | 90 | { |
michael@0 | 91 | fx = *srcXY++; |
michael@0 | 92 | fy = *srcXY++; |
michael@0 | 93 | unsigned x = NOFILTER_BITMAP_SHADER_TILEPROC(fx, srcMaxX); |
michael@0 | 94 | unsigned y = NOFILTER_BITMAP_SHADER_TILEPROC(fy, srcMaxY); |
michael@0 | 95 | *dstC++ = NOFILTER_BITMAP_SHADER_SAMPLE_XY(srcPixels, x, y, srcRB); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | else |
michael@0 | 99 | { |
michael@0 | 100 | while (--count >= 0) |
michael@0 | 101 | { |
michael@0 | 102 | fx = *srcXY++; |
michael@0 | 103 | fy = *srcXY++; |
michael@0 | 104 | unsigned x = NOFILTER_BITMAP_SHADER_TILEPROC(fx, srcMaxX); |
michael@0 | 105 | unsigned y = NOFILTER_BITMAP_SHADER_TILEPROC(fy, srcMaxY); |
michael@0 | 106 | uint32_t c = NOFILTER_BITMAP_SHADER_SAMPLE_XY(srcPixels, x, y, srcRB); |
michael@0 | 107 | *dstC++ = SkAlphaMulQ(c, scale); |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | } |
michael@0 | 111 | return; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | // now init fx, fy, dx, dy |
michael@0 | 115 | { |
michael@0 | 116 | SkPoint srcPt; |
michael@0 | 117 | invProc(inv, SkIntToScalar(x) + SK_ScalarHalf, |
michael@0 | 118 | SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
michael@0 | 119 | |
michael@0 | 120 | fx = SkScalarToFixed(srcPt.fX); |
michael@0 | 121 | fy = SkScalarToFixed(srcPt.fY); |
michael@0 | 122 | |
michael@0 | 123 | if (this->getInverseClass() == kFixedStepInX_MatrixClass) |
michael@0 | 124 | (void)inv.fixedStepInX(SkIntToScalar(y), &dx, &dy); |
michael@0 | 125 | else |
michael@0 | 126 | { |
michael@0 | 127 | dx = SkScalarToFixed(inv.getScaleX()); |
michael@0 | 128 | dy = SkScalarToFixed(inv.getSkewY()); |
michael@0 | 129 | } |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | #ifndef NOFILTER_BITMAP_SHADER_USE_UNITINVERSE |
michael@0 | 133 | { int level = this->getMipLevel() >> 16; |
michael@0 | 134 | fx >>= level; |
michael@0 | 135 | fy >>= level; |
michael@0 | 136 | dx >>= level; |
michael@0 | 137 | dy >>= level; |
michael@0 | 138 | } |
michael@0 | 139 | #endif |
michael@0 | 140 | |
michael@0 | 141 | if (dy == 0) |
michael@0 | 142 | { |
michael@0 | 143 | int y_index = NOFILTER_BITMAP_SHADER_TILEPROC(fy, srcMaxY); |
michael@0 | 144 | // SkDEBUGF(("fy = %g, srcMaxY = %d, y_index = %d\n", SkFixedToFloat(fy), srcMaxY, y_index)); |
michael@0 | 145 | srcPixels = (const NOFILTER_BITMAP_SHADER_TYPE*)((const char*)srcPixels + y_index * srcRB); |
michael@0 | 146 | if (scale == 256) |
michael@0 | 147 | while (--count >= 0) |
michael@0 | 148 | { |
michael@0 | 149 | unsigned x = NOFILTER_BITMAP_SHADER_TILEPROC(fx, srcMaxX); |
michael@0 | 150 | fx += dx; |
michael@0 | 151 | *dstC++ = NOFILTER_BITMAP_SHADER_SAMPLE_X(srcPixels, x); |
michael@0 | 152 | } |
michael@0 | 153 | else |
michael@0 | 154 | while (--count >= 0) |
michael@0 | 155 | { |
michael@0 | 156 | unsigned x = NOFILTER_BITMAP_SHADER_TILEPROC(fx, srcMaxX); |
michael@0 | 157 | SkPMColor c = NOFILTER_BITMAP_SHADER_SAMPLE_X(srcPixels, x); |
michael@0 | 158 | fx += dx; |
michael@0 | 159 | *dstC++ = SkAlphaMulQ(c, scale); |
michael@0 | 160 | } |
michael@0 | 161 | } |
michael@0 | 162 | else // dy != 0 |
michael@0 | 163 | { |
michael@0 | 164 | if (scale == 256) |
michael@0 | 165 | while (--count >= 0) |
michael@0 | 166 | { |
michael@0 | 167 | unsigned x = NOFILTER_BITMAP_SHADER_TILEPROC(fx, srcMaxX); |
michael@0 | 168 | unsigned y = NOFILTER_BITMAP_SHADER_TILEPROC(fy, srcMaxY); |
michael@0 | 169 | fx += dx; |
michael@0 | 170 | fy += dy; |
michael@0 | 171 | *dstC++ = NOFILTER_BITMAP_SHADER_SAMPLE_XY(srcPixels, x, y, srcRB); |
michael@0 | 172 | } |
michael@0 | 173 | else |
michael@0 | 174 | while (--count >= 0) |
michael@0 | 175 | { |
michael@0 | 176 | unsigned x = NOFILTER_BITMAP_SHADER_TILEPROC(fx, srcMaxX); |
michael@0 | 177 | unsigned y = NOFILTER_BITMAP_SHADER_TILEPROC(fy, srcMaxY); |
michael@0 | 178 | SkPMColor c = NOFILTER_BITMAP_SHADER_SAMPLE_XY(srcPixels, x, y, srcRB); |
michael@0 | 179 | fx += dx; |
michael@0 | 180 | fy += dy; |
michael@0 | 181 | *dstC++ = SkAlphaMulQ(c, scale); |
michael@0 | 182 | } |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | NOFILTER_BITMAP_SHADER_POSTAMBLE(srcBitmap); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) |
michael@0 | 189 | { |
michael@0 | 190 | SkASSERT(count > 0); |
michael@0 | 191 | SkASSERT(this->getFlags() & SkShader::kHasSpan16_Flag); |
michael@0 | 192 | |
michael@0 | 193 | #ifdef NOFILTER_BITMAP_SHADER_SPRITEPROC16 |
michael@0 | 194 | if ((this->getTotalInverse().getType() & ~SkMatrix::kTranslate_Mask) == 0) |
michael@0 | 195 | { |
michael@0 | 196 | NOFILTER_BITMAP_SHADER_SPRITEPROC16(this, x, y, dstC, count); |
michael@0 | 197 | return; |
michael@0 | 198 | } |
michael@0 | 199 | #endif |
michael@0 | 200 | |
michael@0 | 201 | #ifdef NOFILTER_BITMAP_SHADER_USE_UNITINVERSE |
michael@0 | 202 | const SkMatrix& inv = this->getUnitInverse(); |
michael@0 | 203 | SkMatrix::MapPtProc invProc = this->getUnitInverseProc(); |
michael@0 | 204 | #else |
michael@0 | 205 | const SkMatrix& inv = this->getTotalInverse(); |
michael@0 | 206 | SkMatrix::MapPtProc invProc = this->getInverseMapPtProc(); |
michael@0 | 207 | #endif |
michael@0 | 208 | const SkBitmap& srcBitmap = this->getSrcBitmap(); |
michael@0 | 209 | unsigned srcMaxX = srcBitmap.width() - 1; |
michael@0 | 210 | unsigned srcMaxY = srcBitmap.height() - 1; |
michael@0 | 211 | unsigned srcRB = srcBitmap.rowBytes(); |
michael@0 | 212 | SkFixed fx, fy, dx, dy; |
michael@0 | 213 | |
michael@0 | 214 | const NOFILTER_BITMAP_SHADER_TYPE* srcPixels = (const NOFILTER_BITMAP_SHADER_TYPE*)srcBitmap.getPixels(); |
michael@0 | 215 | NOFILTER_BITMAP_SHADER_PREAMBLE16(srcBitmap, srcRB); |
michael@0 | 216 | |
michael@0 | 217 | if (this->getInverseClass() == kPerspective_MatrixClass) |
michael@0 | 218 | { |
michael@0 | 219 | SkPerspIter iter(inv, SkIntToScalar(x) + SK_ScalarHalf, |
michael@0 | 220 | SkIntToScalar(y) + SK_ScalarHalf, count); |
michael@0 | 221 | while ((count = iter.next()) != 0) |
michael@0 | 222 | { |
michael@0 | 223 | const SkFixed* srcXY = iter.getXY(); |
michael@0 | 224 | |
michael@0 | 225 | while (--count >= 0) |
michael@0 | 226 | { |
michael@0 | 227 | fx = *srcXY++; |
michael@0 | 228 | fy = *srcXY++; |
michael@0 | 229 | unsigned x = NOFILTER_BITMAP_SHADER_TILEPROC(fx, srcMaxX); |
michael@0 | 230 | unsigned y = NOFILTER_BITMAP_SHADER_TILEPROC(fy, srcMaxY); |
michael@0 | 231 | *dstC++ = NOFILTER_BITMAP_SHADER_SAMPLE_XY16(srcPixels, x, y, srcRB); |
michael@0 | 232 | } |
michael@0 | 233 | } |
michael@0 | 234 | return; |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | // now init fx, fy, dx, dy |
michael@0 | 238 | { |
michael@0 | 239 | SkPoint srcPt; |
michael@0 | 240 | invProc(inv, SkIntToScalar(x) + SK_ScalarHalf, |
michael@0 | 241 | SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
michael@0 | 242 | |
michael@0 | 243 | fx = SkScalarToFixed(srcPt.fX); |
michael@0 | 244 | fy = SkScalarToFixed(srcPt.fY); |
michael@0 | 245 | |
michael@0 | 246 | if (this->getInverseClass() == kFixedStepInX_MatrixClass) |
michael@0 | 247 | (void)inv.fixedStepInX(SkIntToScalar(y), &dx, &dy); |
michael@0 | 248 | else |
michael@0 | 249 | { |
michael@0 | 250 | dx = SkScalarToFixed(inv.getScaleX()); |
michael@0 | 251 | dy = SkScalarToFixed(inv.getSkewY()); |
michael@0 | 252 | } |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | #ifndef NOFILTER_BITMAP_SHADER_USE_UNITINVERSE |
michael@0 | 256 | { int level = this->getMipLevel() >> 16; |
michael@0 | 257 | fx >>= level; |
michael@0 | 258 | fy >>= level; |
michael@0 | 259 | dx >>= level; |
michael@0 | 260 | dy >>= level; |
michael@0 | 261 | } |
michael@0 | 262 | #endif |
michael@0 | 263 | |
michael@0 | 264 | if (dy == 0) |
michael@0 | 265 | { |
michael@0 | 266 | srcPixels = (const NOFILTER_BITMAP_SHADER_TYPE*)((const char*)srcPixels + NOFILTER_BITMAP_SHADER_TILEPROC(fy, srcMaxY) * srcRB); |
michael@0 | 267 | do { |
michael@0 | 268 | unsigned x = NOFILTER_BITMAP_SHADER_TILEPROC(fx, srcMaxX); |
michael@0 | 269 | fx += dx; |
michael@0 | 270 | *dstC++ = NOFILTER_BITMAP_SHADER_SAMPLE_X16(srcPixels, x); |
michael@0 | 271 | } while (--count != 0); |
michael@0 | 272 | } |
michael@0 | 273 | else // dy != 0 |
michael@0 | 274 | { |
michael@0 | 275 | do { |
michael@0 | 276 | unsigned x = NOFILTER_BITMAP_SHADER_TILEPROC(fx, srcMaxX); |
michael@0 | 277 | unsigned y = NOFILTER_BITMAP_SHADER_TILEPROC(fy, srcMaxY); |
michael@0 | 278 | fx += dx; |
michael@0 | 279 | fy += dy; |
michael@0 | 280 | *dstC++ = NOFILTER_BITMAP_SHADER_SAMPLE_XY16(srcPixels, x, y, srcRB); |
michael@0 | 281 | } while (--count != 0); |
michael@0 | 282 | } |
michael@0 | 283 | |
michael@0 | 284 | NOFILTER_BITMAP_SHADER_POSTAMBLE16(srcBitmap); |
michael@0 | 285 | } |
michael@0 | 286 | private: |
michael@0 | 287 | typedef HasSpan16_Sampler_BitmapShader INHERITED; |
michael@0 | 288 | }; |
michael@0 | 289 | |
michael@0 | 290 | #undef NOFILTER_BITMAP_SHADER_CLASS |
michael@0 | 291 | #undef NOFILTER_BITMAP_SHADER_TYPE |
michael@0 | 292 | #undef NOFILTER_BITMAP_SHADER_PREAMBLE |
michael@0 | 293 | #undef NOFILTER_BITMAP_SHADER_POSTAMBLE |
michael@0 | 294 | #undef NOFILTER_BITMAP_SHADER_SAMPLE_X //(x) |
michael@0 | 295 | #undef NOFILTER_BITMAP_SHADER_SAMPLE_XY //(x, y, rowBytes) |
michael@0 | 296 | #undef NOFILTER_BITMAP_SHADER_TILEMODE |
michael@0 | 297 | #undef NOFILTER_BITMAP_SHADER_TILEPROC |
michael@0 | 298 | |
michael@0 | 299 | #undef NOFILTER_BITMAP_SHADER_PREAMBLE16 |
michael@0 | 300 | #undef NOFILTER_BITMAP_SHADER_POSTAMBLE16 |
michael@0 | 301 | #undef NOFILTER_BITMAP_SHADER_SAMPLE_X16 //(x) |
michael@0 | 302 | #undef NOFILTER_BITMAP_SHADER_SAMPLE_XY16 //(x, y, rowBytes) |
michael@0 | 303 | |
michael@0 | 304 | #undef NOFILTER_BITMAP_SHADER_USE_UNITINVERSE |
michael@0 | 305 | #undef NOFILTER_BITMAP_SHADER_SPRITEPROC16 |
michael@0 | 306 | #undef NOFILTER_BITMAP_SHADER_SPRITEPROC32 |