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 2013 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 | #include "GrBlend.h" |
michael@0 | 10 | |
michael@0 | 11 | static inline GrBlendCoeff swap_coeff_src_dst(GrBlendCoeff coeff) { |
michael@0 | 12 | switch (coeff) { |
michael@0 | 13 | case kDC_GrBlendCoeff: |
michael@0 | 14 | return kSC_GrBlendCoeff; |
michael@0 | 15 | case kIDC_GrBlendCoeff: |
michael@0 | 16 | return kISC_GrBlendCoeff; |
michael@0 | 17 | case kDA_GrBlendCoeff: |
michael@0 | 18 | return kSA_GrBlendCoeff; |
michael@0 | 19 | case kIDA_GrBlendCoeff: |
michael@0 | 20 | return kISA_GrBlendCoeff; |
michael@0 | 21 | case kSC_GrBlendCoeff: |
michael@0 | 22 | return kDC_GrBlendCoeff; |
michael@0 | 23 | case kISC_GrBlendCoeff: |
michael@0 | 24 | return kIDC_GrBlendCoeff; |
michael@0 | 25 | case kSA_GrBlendCoeff: |
michael@0 | 26 | return kDA_GrBlendCoeff; |
michael@0 | 27 | case kISA_GrBlendCoeff: |
michael@0 | 28 | return kIDA_GrBlendCoeff; |
michael@0 | 29 | default: |
michael@0 | 30 | return coeff; |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | static inline unsigned saturated_add(unsigned a, unsigned b) { |
michael@0 | 35 | SkASSERT(a <= 255); |
michael@0 | 36 | SkASSERT(b <= 255); |
michael@0 | 37 | unsigned sum = a + b; |
michael@0 | 38 | if (sum > 255) { |
michael@0 | 39 | sum = 255; |
michael@0 | 40 | } |
michael@0 | 41 | return sum; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | static GrColor add_colors(GrColor src, GrColor dst) { |
michael@0 | 45 | unsigned r = saturated_add(GrColorUnpackR(src), GrColorUnpackR(dst)); |
michael@0 | 46 | unsigned g = saturated_add(GrColorUnpackG(src), GrColorUnpackG(dst)); |
michael@0 | 47 | unsigned b = saturated_add(GrColorUnpackB(src), GrColorUnpackB(dst)); |
michael@0 | 48 | unsigned a = saturated_add(GrColorUnpackA(src), GrColorUnpackA(dst)); |
michael@0 | 49 | return GrColorPackRGBA(r, g, b, a); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | static inline bool valid_color(uint32_t compFlags) { |
michael@0 | 53 | return (kRGBA_GrColorComponentFlags & compFlags) == kRGBA_GrColorComponentFlags; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | static GrColor simplify_blend_term(GrBlendCoeff* srcCoeff, |
michael@0 | 57 | GrColor srcColor, uint32_t srcCompFlags, |
michael@0 | 58 | GrColor dstColor, uint32_t dstCompFlags, |
michael@0 | 59 | GrColor constantColor) { |
michael@0 | 60 | |
michael@0 | 61 | SkASSERT(!GrBlendCoeffRefsSrc(*srcCoeff)); |
michael@0 | 62 | SkASSERT(NULL != srcCoeff); |
michael@0 | 63 | |
michael@0 | 64 | // Check whether srcCoeff can be reduced to kOne or kZero based on known color inputs. |
michael@0 | 65 | // We could pick out the coeff r,g,b,a values here and use them to compute the blend term color, |
michael@0 | 66 | // if possible, below but that is not implemented now. |
michael@0 | 67 | switch (*srcCoeff) { |
michael@0 | 68 | case kIDC_GrBlendCoeff: |
michael@0 | 69 | dstColor = ~dstColor; // fallthrough |
michael@0 | 70 | case kDC_GrBlendCoeff: |
michael@0 | 71 | if (valid_color(dstCompFlags)) { |
michael@0 | 72 | if (0xffffffff == dstColor) { |
michael@0 | 73 | *srcCoeff = kOne_GrBlendCoeff; |
michael@0 | 74 | } else if (0 == dstColor) { |
michael@0 | 75 | *srcCoeff = kZero_GrBlendCoeff; |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | break; |
michael@0 | 79 | |
michael@0 | 80 | case kIDA_GrBlendCoeff: |
michael@0 | 81 | dstColor = ~dstColor; // fallthrough |
michael@0 | 82 | case kDA_GrBlendCoeff: |
michael@0 | 83 | if (kA_GrColorComponentFlag & dstCompFlags) { |
michael@0 | 84 | if (0xff == GrColorUnpackA(dstColor)) { |
michael@0 | 85 | *srcCoeff = kOne_GrBlendCoeff; |
michael@0 | 86 | } else if (0 == GrColorUnpackA(dstColor)) { |
michael@0 | 87 | *srcCoeff = kZero_GrBlendCoeff; |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | break; |
michael@0 | 91 | |
michael@0 | 92 | case kIConstC_GrBlendCoeff: |
michael@0 | 93 | constantColor = ~constantColor; // fallthrough |
michael@0 | 94 | case kConstC_GrBlendCoeff: |
michael@0 | 95 | if (0xffffffff == constantColor) { |
michael@0 | 96 | *srcCoeff = kOne_GrBlendCoeff; |
michael@0 | 97 | } else if (0 == constantColor) { |
michael@0 | 98 | *srcCoeff = kZero_GrBlendCoeff; |
michael@0 | 99 | } |
michael@0 | 100 | break; |
michael@0 | 101 | |
michael@0 | 102 | case kIConstA_GrBlendCoeff: |
michael@0 | 103 | constantColor = ~constantColor; // fallthrough |
michael@0 | 104 | case kConstA_GrBlendCoeff: |
michael@0 | 105 | if (0xff == GrColorUnpackA(constantColor)) { |
michael@0 | 106 | *srcCoeff = kOne_GrBlendCoeff; |
michael@0 | 107 | } else if (0 == GrColorUnpackA(constantColor)) { |
michael@0 | 108 | *srcCoeff = kZero_GrBlendCoeff; |
michael@0 | 109 | } |
michael@0 | 110 | break; |
michael@0 | 111 | |
michael@0 | 112 | default: |
michael@0 | 113 | break; |
michael@0 | 114 | } |
michael@0 | 115 | // We may have invalidated these above and shouldn't read them again. |
michael@0 | 116 | SkDEBUGCODE(dstColor = constantColor = GrColor_ILLEGAL;) |
michael@0 | 117 | |
michael@0 | 118 | if (kZero_GrBlendCoeff == *srcCoeff || (valid_color(srcCompFlags) && 0 == srcColor)) { |
michael@0 | 119 | *srcCoeff = kZero_GrBlendCoeff; |
michael@0 | 120 | return 0; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | if (kOne_GrBlendCoeff == *srcCoeff && valid_color(srcCompFlags)) { |
michael@0 | 124 | return srcColor; |
michael@0 | 125 | } else { |
michael@0 | 126 | return GrColor_ILLEGAL; |
michael@0 | 127 | } |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | GrColor GrSimplifyBlend(GrBlendCoeff* srcCoeff, |
michael@0 | 131 | GrBlendCoeff* dstCoeff, |
michael@0 | 132 | GrColor srcColor, uint32_t srcCompFlags, |
michael@0 | 133 | GrColor dstColor, uint32_t dstCompFlags, |
michael@0 | 134 | GrColor constantColor) { |
michael@0 | 135 | GrColor srcTermColor = simplify_blend_term(srcCoeff, |
michael@0 | 136 | srcColor, srcCompFlags, |
michael@0 | 137 | dstColor, dstCompFlags, |
michael@0 | 138 | constantColor); |
michael@0 | 139 | |
michael@0 | 140 | // We call the same function to simplify the dst blend coeff. We trick it out by swapping the |
michael@0 | 141 | // src and dst. |
michael@0 | 142 | GrBlendCoeff spoofedCoeff = swap_coeff_src_dst(*dstCoeff); |
michael@0 | 143 | GrColor dstTermColor = simplify_blend_term(&spoofedCoeff, |
michael@0 | 144 | dstColor, dstCompFlags, |
michael@0 | 145 | srcColor, srcCompFlags, |
michael@0 | 146 | constantColor); |
michael@0 | 147 | *dstCoeff = swap_coeff_src_dst(spoofedCoeff); |
michael@0 | 148 | |
michael@0 | 149 | if (GrColor_ILLEGAL != srcTermColor && GrColor_ILLEGAL != dstTermColor) { |
michael@0 | 150 | return add_colors(srcTermColor, dstTermColor); |
michael@0 | 151 | } else { |
michael@0 | 152 | return GrColor_ILLEGAL; |
michael@0 | 153 | } |
michael@0 | 154 | } |