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 2008 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 | #ifndef SkDither_DEFINED |
michael@0 | 11 | #define SkDither_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkColorPriv.h" |
michael@0 | 14 | |
michael@0 | 15 | #define SK_DitherValueMax4444 15 |
michael@0 | 16 | #define SK_DitherValueMax565 7 |
michael@0 | 17 | |
michael@0 | 18 | /* need to use macros for bit-counts for each component, and then |
michael@0 | 19 | move these into SkColorPriv.h |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | #define SkDITHER_R32_FOR_565_MACRO(r, d) (r + d - (r >> 5)) |
michael@0 | 23 | #define SkDITHER_G32_FOR_565_MACRO(g, d) (g + (d >> 1) - (g >> 6)) |
michael@0 | 24 | #define SkDITHER_B32_FOR_565_MACRO(b, d) (b + d - (b >> 5)) |
michael@0 | 25 | |
michael@0 | 26 | #define SkDITHER_A32_FOR_4444_MACRO(a, d) (a + 15 - (a >> 4)) |
michael@0 | 27 | #define SkDITHER_R32_FOR_4444_MACRO(r, d) (r + d - (r >> 4)) |
michael@0 | 28 | #define SkDITHER_G32_FOR_4444_MACRO(g, d) (g + d - (g >> 4)) |
michael@0 | 29 | #define SkDITHER_B32_FOR_4444_MACRO(b, d) (b + d - (b >> 4)) |
michael@0 | 30 | |
michael@0 | 31 | #ifdef SK_DEBUG |
michael@0 | 32 | inline unsigned SkDITHER_R32_FOR_565(unsigned r, unsigned d) |
michael@0 | 33 | { |
michael@0 | 34 | SkASSERT(d <= SK_DitherValueMax565); |
michael@0 | 35 | SkA32Assert(r); |
michael@0 | 36 | r = SkDITHER_R32_FOR_565_MACRO(r, d); |
michael@0 | 37 | SkA32Assert(r); |
michael@0 | 38 | return r; |
michael@0 | 39 | } |
michael@0 | 40 | inline unsigned SkDITHER_G32_FOR_565(unsigned g, unsigned d) |
michael@0 | 41 | { |
michael@0 | 42 | SkASSERT(d <= SK_DitherValueMax565); |
michael@0 | 43 | SkG32Assert(g); |
michael@0 | 44 | g = SkDITHER_G32_FOR_565_MACRO(g, d); |
michael@0 | 45 | SkG32Assert(g); |
michael@0 | 46 | return g; |
michael@0 | 47 | } |
michael@0 | 48 | inline unsigned SkDITHER_B32_FOR_565(unsigned b, unsigned d) |
michael@0 | 49 | { |
michael@0 | 50 | SkASSERT(d <= SK_DitherValueMax565); |
michael@0 | 51 | SkB32Assert(b); |
michael@0 | 52 | b = SkDITHER_B32_FOR_565_MACRO(b, d); |
michael@0 | 53 | SkB32Assert(b); |
michael@0 | 54 | return b; |
michael@0 | 55 | } |
michael@0 | 56 | #else |
michael@0 | 57 | #define SkDITHER_R32_FOR_565(r, d) SkDITHER_R32_FOR_565_MACRO(r, d) |
michael@0 | 58 | #define SkDITHER_G32_FOR_565(g, d) SkDITHER_G32_FOR_565_MACRO(g, d) |
michael@0 | 59 | #define SkDITHER_B32_FOR_565(b, d) SkDITHER_B32_FOR_565_MACRO(b, d) |
michael@0 | 60 | #endif |
michael@0 | 61 | |
michael@0 | 62 | #define SkDITHER_R32To565(r, d) SkR32ToR16(SkDITHER_R32_FOR_565(r, d)) |
michael@0 | 63 | #define SkDITHER_G32To565(g, d) SkG32ToG16(SkDITHER_G32_FOR_565(g, d)) |
michael@0 | 64 | #define SkDITHER_B32To565(b, d) SkB32ToB16(SkDITHER_B32_FOR_565(b, d)) |
michael@0 | 65 | |
michael@0 | 66 | #define SkDITHER_A32To4444(a, d) SkA32To4444(SkDITHER_A32_FOR_4444_MACRO(a, d)) |
michael@0 | 67 | #define SkDITHER_R32To4444(r, d) SkR32To4444(SkDITHER_R32_FOR_4444_MACRO(r, d)) |
michael@0 | 68 | #define SkDITHER_G32To4444(g, d) SkG32To4444(SkDITHER_G32_FOR_4444_MACRO(g, d)) |
michael@0 | 69 | #define SkDITHER_B32To4444(b, d) SkB32To4444(SkDITHER_B32_FOR_4444_MACRO(b, d)) |
michael@0 | 70 | |
michael@0 | 71 | static inline SkPMColor SkDitherARGB32For565(SkPMColor c, unsigned dither) |
michael@0 | 72 | { |
michael@0 | 73 | SkASSERT(dither <= SK_DitherValueMax565); |
michael@0 | 74 | |
michael@0 | 75 | unsigned sa = SkGetPackedA32(c); |
michael@0 | 76 | dither = SkAlphaMul(dither, SkAlpha255To256(sa)); |
michael@0 | 77 | |
michael@0 | 78 | unsigned sr = SkGetPackedR32(c); |
michael@0 | 79 | unsigned sg = SkGetPackedG32(c); |
michael@0 | 80 | unsigned sb = SkGetPackedB32(c); |
michael@0 | 81 | sr = SkDITHER_R32_FOR_565(sr, dither); |
michael@0 | 82 | sg = SkDITHER_G32_FOR_565(sg, dither); |
michael@0 | 83 | sb = SkDITHER_B32_FOR_565(sb, dither); |
michael@0 | 84 | |
michael@0 | 85 | return SkPackARGB32(sa, sr, sg, sb); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | static inline SkPMColor SkDitherRGB32For565(SkPMColor c, unsigned dither) |
michael@0 | 89 | { |
michael@0 | 90 | SkASSERT(dither <= SK_DitherValueMax565); |
michael@0 | 91 | |
michael@0 | 92 | unsigned sr = SkGetPackedR32(c); |
michael@0 | 93 | unsigned sg = SkGetPackedG32(c); |
michael@0 | 94 | unsigned sb = SkGetPackedB32(c); |
michael@0 | 95 | sr = SkDITHER_R32_FOR_565(sr, dither); |
michael@0 | 96 | sg = SkDITHER_G32_FOR_565(sg, dither); |
michael@0 | 97 | sb = SkDITHER_B32_FOR_565(sb, dither); |
michael@0 | 98 | |
michael@0 | 99 | return SkPackARGB32(0xFF, sr, sg, sb); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | static inline uint16_t SkDitherRGBTo565(U8CPU r, U8CPU g, U8CPU b, |
michael@0 | 103 | unsigned dither) |
michael@0 | 104 | { |
michael@0 | 105 | SkASSERT(dither <= SK_DitherValueMax565); |
michael@0 | 106 | r = SkDITHER_R32To565(r, dither); |
michael@0 | 107 | g = SkDITHER_G32To565(g, dither); |
michael@0 | 108 | b = SkDITHER_B32To565(b, dither); |
michael@0 | 109 | return SkPackRGB16(r, g, b); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | static inline uint16_t SkDitherRGB32To565(SkPMColor c, unsigned dither) |
michael@0 | 113 | { |
michael@0 | 114 | SkASSERT(dither <= SK_DitherValueMax565); |
michael@0 | 115 | |
michael@0 | 116 | unsigned sr = SkGetPackedR32(c); |
michael@0 | 117 | unsigned sg = SkGetPackedG32(c); |
michael@0 | 118 | unsigned sb = SkGetPackedB32(c); |
michael@0 | 119 | sr = SkDITHER_R32To565(sr, dither); |
michael@0 | 120 | sg = SkDITHER_G32To565(sg, dither); |
michael@0 | 121 | sb = SkDITHER_B32To565(sb, dither); |
michael@0 | 122 | |
michael@0 | 123 | return SkPackRGB16(sr, sg, sb); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | static inline uint16_t SkDitherARGB32To565(U8CPU sa, SkPMColor c, unsigned dither) |
michael@0 | 127 | { |
michael@0 | 128 | SkASSERT(dither <= SK_DitherValueMax565); |
michael@0 | 129 | dither = SkAlphaMul(dither, SkAlpha255To256(sa)); |
michael@0 | 130 | |
michael@0 | 131 | unsigned sr = SkGetPackedR32(c); |
michael@0 | 132 | unsigned sg = SkGetPackedG32(c); |
michael@0 | 133 | unsigned sb = SkGetPackedB32(c); |
michael@0 | 134 | sr = SkDITHER_R32To565(sr, dither); |
michael@0 | 135 | sg = SkDITHER_G32To565(sg, dither); |
michael@0 | 136 | sb = SkDITHER_B32To565(sb, dither); |
michael@0 | 137 | |
michael@0 | 138 | return SkPackRGB16(sr, sg, sb); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | ///////////////////////// 4444 |
michael@0 | 142 | |
michael@0 | 143 | static inline SkPMColor16 SkDitherARGB32To4444(U8CPU a, U8CPU r, U8CPU g, |
michael@0 | 144 | U8CPU b, unsigned dither) |
michael@0 | 145 | { |
michael@0 | 146 | dither = SkAlphaMul(dither, SkAlpha255To256(a)); |
michael@0 | 147 | |
michael@0 | 148 | a = SkDITHER_A32To4444(a, dither); |
michael@0 | 149 | r = SkDITHER_R32To4444(r, dither); |
michael@0 | 150 | g = SkDITHER_G32To4444(g, dither); |
michael@0 | 151 | b = SkDITHER_B32To4444(b, dither); |
michael@0 | 152 | |
michael@0 | 153 | return SkPackARGB4444(a, r, g, b); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | static inline SkPMColor16 SkDitherARGB32To4444(SkPMColor c, unsigned dither) |
michael@0 | 157 | { |
michael@0 | 158 | unsigned a = SkGetPackedA32(c); |
michael@0 | 159 | unsigned r = SkGetPackedR32(c); |
michael@0 | 160 | unsigned g = SkGetPackedG32(c); |
michael@0 | 161 | unsigned b = SkGetPackedB32(c); |
michael@0 | 162 | |
michael@0 | 163 | dither = SkAlphaMul(dither, SkAlpha255To256(a)); |
michael@0 | 164 | |
michael@0 | 165 | a = SkDITHER_A32To4444(a, dither); |
michael@0 | 166 | r = SkDITHER_R32To4444(r, dither); |
michael@0 | 167 | g = SkDITHER_G32To4444(g, dither); |
michael@0 | 168 | b = SkDITHER_B32To4444(b, dither); |
michael@0 | 169 | |
michael@0 | 170 | return SkPackARGB4444(a, r, g, b); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | // TODO: need dither routines for 565 -> 4444 |
michael@0 | 174 | |
michael@0 | 175 | // this toggles between a 4x4 and a 1x4 array |
michael@0 | 176 | //#define ENABLE_DITHER_MATRIX_4X4 |
michael@0 | 177 | |
michael@0 | 178 | #ifdef ENABLE_DITHER_MATRIX_4X4 |
michael@0 | 179 | extern const uint8_t gDitherMatrix_4Bit_4X4[4][4]; |
michael@0 | 180 | extern const uint8_t gDitherMatrix_3Bit_4X4[4][4]; |
michael@0 | 181 | |
michael@0 | 182 | #define DITHER_4444_SCAN(y) const uint8_t* dither_scan = gDitherMatrix_4Bit_4X4[(y) & 3] |
michael@0 | 183 | #define DITHER_565_SCAN(y) const uint8_t* dither_scan = gDitherMatrix_3Bit_4X4[(y) & 3] |
michael@0 | 184 | |
michael@0 | 185 | #define DITHER_VALUE(x) dither_scan[(x) & 3] |
michael@0 | 186 | #else |
michael@0 | 187 | extern const uint16_t gDitherMatrix_4Bit_16[4]; |
michael@0 | 188 | extern const uint16_t gDitherMatrix_3Bit_16[4]; |
michael@0 | 189 | |
michael@0 | 190 | #define DITHER_4444_SCAN(y) const uint16_t dither_scan = gDitherMatrix_4Bit_16[(y) & 3] |
michael@0 | 191 | #define DITHER_565_SCAN(y) const uint16_t dither_scan = gDitherMatrix_3Bit_16[(y) & 3] |
michael@0 | 192 | |
michael@0 | 193 | #define DITHER_VALUE(x) ((dither_scan >> (((x) & 3) << 2)) & 0xF) |
michael@0 | 194 | #endif |
michael@0 | 195 | |
michael@0 | 196 | #define DITHER_INC_X(x) ++(x) |
michael@0 | 197 | |
michael@0 | 198 | #endif |