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 | #include "SkTransparentShader.h" |
michael@0 | 11 | #include "SkColorPriv.h" |
michael@0 | 12 | #include "SkString.h" |
michael@0 | 13 | |
michael@0 | 14 | bool SkTransparentShader::setContext(const SkBitmap& device, |
michael@0 | 15 | const SkPaint& paint, |
michael@0 | 16 | const SkMatrix& matrix) { |
michael@0 | 17 | fDevice = &device; |
michael@0 | 18 | fAlpha = paint.getAlpha(); |
michael@0 | 19 | |
michael@0 | 20 | return this->INHERITED::setContext(device, paint, matrix); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | uint32_t SkTransparentShader::getFlags() { |
michael@0 | 24 | uint32_t flags = this->INHERITED::getFlags(); |
michael@0 | 25 | |
michael@0 | 26 | switch (fDevice->colorType()) { |
michael@0 | 27 | case kRGB_565_SkColorType: |
michael@0 | 28 | flags |= kHasSpan16_Flag; |
michael@0 | 29 | if (fAlpha == 255) |
michael@0 | 30 | flags |= kOpaqueAlpha_Flag; |
michael@0 | 31 | break; |
michael@0 | 32 | case kPMColor_SkColorType: |
michael@0 | 33 | if (fAlpha == 255 && fDevice->isOpaque()) |
michael@0 | 34 | flags |= kOpaqueAlpha_Flag; |
michael@0 | 35 | break; |
michael@0 | 36 | default: |
michael@0 | 37 | break; |
michael@0 | 38 | } |
michael@0 | 39 | return flags; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | void SkTransparentShader::shadeSpan(int x, int y, SkPMColor span[], int count) { |
michael@0 | 43 | unsigned scale = SkAlpha255To256(fAlpha); |
michael@0 | 44 | |
michael@0 | 45 | switch (fDevice->colorType()) { |
michael@0 | 46 | case kPMColor_SkColorType: |
michael@0 | 47 | if (scale == 256) { |
michael@0 | 48 | SkPMColor* src = fDevice->getAddr32(x, y); |
michael@0 | 49 | if (src != span) { |
michael@0 | 50 | memcpy(span, src, count * sizeof(SkPMColor)); |
michael@0 | 51 | } |
michael@0 | 52 | } else { |
michael@0 | 53 | const SkPMColor* src = fDevice->getAddr32(x, y); |
michael@0 | 54 | for (int i = count - 1; i >= 0; --i) { |
michael@0 | 55 | span[i] = SkAlphaMulQ(src[i], scale); |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | break; |
michael@0 | 59 | case kRGB_565_SkColorType: { |
michael@0 | 60 | const uint16_t* src = fDevice->getAddr16(x, y); |
michael@0 | 61 | if (scale == 256) { |
michael@0 | 62 | for (int i = count - 1; i >= 0; --i) { |
michael@0 | 63 | span[i] = SkPixel16ToPixel32(src[i]); |
michael@0 | 64 | } |
michael@0 | 65 | } else { |
michael@0 | 66 | unsigned alpha = fAlpha; |
michael@0 | 67 | for (int i = count - 1; i >= 0; --i) { |
michael@0 | 68 | uint16_t c = src[i]; |
michael@0 | 69 | unsigned r = SkPacked16ToR32(c); |
michael@0 | 70 | unsigned g = SkPacked16ToG32(c); |
michael@0 | 71 | unsigned b = SkPacked16ToB32(c); |
michael@0 | 72 | |
michael@0 | 73 | span[i] = SkPackARGB32( alpha, |
michael@0 | 74 | SkAlphaMul(r, scale), |
michael@0 | 75 | SkAlphaMul(g, scale), |
michael@0 | 76 | SkAlphaMul(b, scale)); |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | break; |
michael@0 | 80 | } |
michael@0 | 81 | case kAlpha_8_SkColorType: { |
michael@0 | 82 | const uint8_t* src = fDevice->getAddr8(x, y); |
michael@0 | 83 | if (scale == 256) { |
michael@0 | 84 | for (int i = count - 1; i >= 0; --i) { |
michael@0 | 85 | span[i] = SkPackARGB32(src[i], 0, 0, 0); |
michael@0 | 86 | } |
michael@0 | 87 | } else { |
michael@0 | 88 | for (int i = count - 1; i >= 0; --i) { |
michael@0 | 89 | span[i] = SkPackARGB32(SkAlphaMul(src[i], scale), 0, 0, 0); |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | break; |
michael@0 | 93 | } |
michael@0 | 94 | default: |
michael@0 | 95 | SkDEBUGFAIL("colorType not supported as a destination device"); |
michael@0 | 96 | break; |
michael@0 | 97 | } |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | void SkTransparentShader::shadeSpan16(int x, int y, uint16_t span[], int count) { |
michael@0 | 101 | SkASSERT(fDevice->colorType() == kRGB_565_SkColorType); |
michael@0 | 102 | |
michael@0 | 103 | uint16_t* src = fDevice->getAddr16(x, y); |
michael@0 | 104 | if (src != span) { |
michael@0 | 105 | memcpy(span, src, count << 1); |
michael@0 | 106 | } |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | #ifndef SK_IGNORE_TO_STRING |
michael@0 | 110 | void SkTransparentShader::toString(SkString* str) const { |
michael@0 | 111 | str->append("SkTransparentShader: ("); |
michael@0 | 112 | |
michael@0 | 113 | this->INHERITED::toString(str); |
michael@0 | 114 | |
michael@0 | 115 | str->append(")"); |
michael@0 | 116 | } |
michael@0 | 117 | #endif |