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 | * Copyright 2011 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "SkBlitRow.h" |
michael@0 | 9 | #include "SkColorPriv.h" |
michael@0 | 10 | #include "SkDither.h" |
michael@0 | 11 | #include "SkMathPriv.h" |
michael@0 | 12 | |
michael@0 | 13 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 14 | |
michael@0 | 15 | static void S32_D565_Opaque(uint16_t* SK_RESTRICT dst, |
michael@0 | 16 | const SkPMColor* SK_RESTRICT src, int count, |
michael@0 | 17 | U8CPU alpha, int /*x*/, int /*y*/) { |
michael@0 | 18 | SkASSERT(255 == alpha); |
michael@0 | 19 | |
michael@0 | 20 | if (count > 0) { |
michael@0 | 21 | do { |
michael@0 | 22 | SkPMColor c = *src++; |
michael@0 | 23 | SkPMColorAssert(c); |
michael@0 | 24 | *dst++ = SkPixel32ToPixel16_ToU16(c); |
michael@0 | 25 | } while (--count != 0); |
michael@0 | 26 | } |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | static void S32_D565_Blend(uint16_t* SK_RESTRICT dst, |
michael@0 | 30 | const SkPMColor* SK_RESTRICT src, int count, |
michael@0 | 31 | U8CPU alpha, int /*x*/, int /*y*/) { |
michael@0 | 32 | SkASSERT(255 > alpha); |
michael@0 | 33 | |
michael@0 | 34 | if (count > 0) { |
michael@0 | 35 | int scale = SkAlpha255To256(alpha); |
michael@0 | 36 | do { |
michael@0 | 37 | SkPMColor c = *src++; |
michael@0 | 38 | SkPMColorAssert(c); |
michael@0 | 39 | uint16_t d = *dst; |
michael@0 | 40 | *dst++ = SkPackRGB16( |
michael@0 | 41 | SkAlphaBlend(SkPacked32ToR16(c), SkGetPackedR16(d), scale), |
michael@0 | 42 | SkAlphaBlend(SkPacked32ToG16(c), SkGetPackedG16(d), scale), |
michael@0 | 43 | SkAlphaBlend(SkPacked32ToB16(c), SkGetPackedB16(d), scale)); |
michael@0 | 44 | } while (--count != 0); |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | static void S32A_D565_Opaque(uint16_t* SK_RESTRICT dst, |
michael@0 | 49 | const SkPMColor* SK_RESTRICT src, int count, |
michael@0 | 50 | U8CPU alpha, int /*x*/, int /*y*/) { |
michael@0 | 51 | SkASSERT(255 == alpha); |
michael@0 | 52 | |
michael@0 | 53 | if (count > 0) { |
michael@0 | 54 | do { |
michael@0 | 55 | SkPMColor c = *src++; |
michael@0 | 56 | SkPMColorAssert(c); |
michael@0 | 57 | // if (__builtin_expect(c!=0, 1)) |
michael@0 | 58 | if (c) { |
michael@0 | 59 | *dst = SkSrcOver32To16(c, *dst); |
michael@0 | 60 | } |
michael@0 | 61 | dst += 1; |
michael@0 | 62 | } while (--count != 0); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | static void S32A_D565_Blend(uint16_t* SK_RESTRICT dst, |
michael@0 | 67 | const SkPMColor* SK_RESTRICT src, int count, |
michael@0 | 68 | U8CPU alpha, int /*x*/, int /*y*/) { |
michael@0 | 69 | SkASSERT(255 > alpha); |
michael@0 | 70 | |
michael@0 | 71 | if (count > 0) { |
michael@0 | 72 | do { |
michael@0 | 73 | SkPMColor sc = *src++; |
michael@0 | 74 | SkPMColorAssert(sc); |
michael@0 | 75 | if (sc) { |
michael@0 | 76 | uint16_t dc = *dst; |
michael@0 | 77 | unsigned dst_scale = 255 - SkMulDiv255Round(SkGetPackedA32(sc), alpha); |
michael@0 | 78 | unsigned dr = SkMulS16(SkPacked32ToR16(sc), alpha) + SkMulS16(SkGetPackedR16(dc), dst_scale); |
michael@0 | 79 | unsigned dg = SkMulS16(SkPacked32ToG16(sc), alpha) + SkMulS16(SkGetPackedG16(dc), dst_scale); |
michael@0 | 80 | unsigned db = SkMulS16(SkPacked32ToB16(sc), alpha) + SkMulS16(SkGetPackedB16(dc), dst_scale); |
michael@0 | 81 | *dst = SkPackRGB16(SkDiv255Round(dr), SkDiv255Round(dg), SkDiv255Round(db)); |
michael@0 | 82 | } |
michael@0 | 83 | dst += 1; |
michael@0 | 84 | } while (--count != 0); |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | ///////////////////////////////////////////////////////////////////////////// |
michael@0 | 89 | |
michael@0 | 90 | static void S32_D565_Opaque_Dither(uint16_t* SK_RESTRICT dst, |
michael@0 | 91 | const SkPMColor* SK_RESTRICT src, |
michael@0 | 92 | int count, U8CPU alpha, int x, int y) { |
michael@0 | 93 | SkASSERT(255 == alpha); |
michael@0 | 94 | |
michael@0 | 95 | if (count > 0) { |
michael@0 | 96 | DITHER_565_SCAN(y); |
michael@0 | 97 | do { |
michael@0 | 98 | SkPMColor c = *src++; |
michael@0 | 99 | SkPMColorAssert(c); |
michael@0 | 100 | |
michael@0 | 101 | unsigned dither = DITHER_VALUE(x); |
michael@0 | 102 | *dst++ = SkDitherRGB32To565(c, dither); |
michael@0 | 103 | DITHER_INC_X(x); |
michael@0 | 104 | } while (--count != 0); |
michael@0 | 105 | } |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | static void S32_D565_Blend_Dither(uint16_t* SK_RESTRICT dst, |
michael@0 | 109 | const SkPMColor* SK_RESTRICT src, |
michael@0 | 110 | int count, U8CPU alpha, int x, int y) { |
michael@0 | 111 | SkASSERT(255 > alpha); |
michael@0 | 112 | |
michael@0 | 113 | if (count > 0) { |
michael@0 | 114 | int scale = SkAlpha255To256(alpha); |
michael@0 | 115 | DITHER_565_SCAN(y); |
michael@0 | 116 | do { |
michael@0 | 117 | SkPMColor c = *src++; |
michael@0 | 118 | SkPMColorAssert(c); |
michael@0 | 119 | |
michael@0 | 120 | int dither = DITHER_VALUE(x); |
michael@0 | 121 | int sr = SkGetPackedR32(c); |
michael@0 | 122 | int sg = SkGetPackedG32(c); |
michael@0 | 123 | int sb = SkGetPackedB32(c); |
michael@0 | 124 | sr = SkDITHER_R32To565(sr, dither); |
michael@0 | 125 | sg = SkDITHER_G32To565(sg, dither); |
michael@0 | 126 | sb = SkDITHER_B32To565(sb, dither); |
michael@0 | 127 | |
michael@0 | 128 | uint16_t d = *dst; |
michael@0 | 129 | *dst++ = SkPackRGB16(SkAlphaBlend(sr, SkGetPackedR16(d), scale), |
michael@0 | 130 | SkAlphaBlend(sg, SkGetPackedG16(d), scale), |
michael@0 | 131 | SkAlphaBlend(sb, SkGetPackedB16(d), scale)); |
michael@0 | 132 | DITHER_INC_X(x); |
michael@0 | 133 | } while (--count != 0); |
michael@0 | 134 | } |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | static void S32A_D565_Opaque_Dither(uint16_t* SK_RESTRICT dst, |
michael@0 | 138 | const SkPMColor* SK_RESTRICT src, |
michael@0 | 139 | int count, U8CPU alpha, int x, int y) { |
michael@0 | 140 | SkASSERT(255 == alpha); |
michael@0 | 141 | |
michael@0 | 142 | if (count > 0) { |
michael@0 | 143 | DITHER_565_SCAN(y); |
michael@0 | 144 | do { |
michael@0 | 145 | SkPMColor c = *src++; |
michael@0 | 146 | SkPMColorAssert(c); |
michael@0 | 147 | if (c) { |
michael@0 | 148 | unsigned a = SkGetPackedA32(c); |
michael@0 | 149 | |
michael@0 | 150 | int d = SkAlphaMul(DITHER_VALUE(x), SkAlpha255To256(a)); |
michael@0 | 151 | |
michael@0 | 152 | unsigned sr = SkGetPackedR32(c); |
michael@0 | 153 | unsigned sg = SkGetPackedG32(c); |
michael@0 | 154 | unsigned sb = SkGetPackedB32(c); |
michael@0 | 155 | sr = SkDITHER_R32_FOR_565(sr, d); |
michael@0 | 156 | sg = SkDITHER_G32_FOR_565(sg, d); |
michael@0 | 157 | sb = SkDITHER_B32_FOR_565(sb, d); |
michael@0 | 158 | |
michael@0 | 159 | uint32_t src_expanded = (sg << 24) | (sr << 13) | (sb << 2); |
michael@0 | 160 | uint32_t dst_expanded = SkExpand_rgb_16(*dst); |
michael@0 | 161 | dst_expanded = dst_expanded * (SkAlpha255To256(255 - a) >> 3); |
michael@0 | 162 | // now src and dst expanded are in g:11 r:10 x:1 b:10 |
michael@0 | 163 | *dst = SkCompact_rgb_16((src_expanded + dst_expanded) >> 5); |
michael@0 | 164 | } |
michael@0 | 165 | dst += 1; |
michael@0 | 166 | DITHER_INC_X(x); |
michael@0 | 167 | } while (--count != 0); |
michael@0 | 168 | } |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | static void S32A_D565_Blend_Dither(uint16_t* SK_RESTRICT dst, |
michael@0 | 172 | const SkPMColor* SK_RESTRICT src, |
michael@0 | 173 | int count, U8CPU alpha, int x, int y) { |
michael@0 | 174 | SkASSERT(255 > alpha); |
michael@0 | 175 | |
michael@0 | 176 | if (count > 0) { |
michael@0 | 177 | int src_scale = SkAlpha255To256(alpha); |
michael@0 | 178 | DITHER_565_SCAN(y); |
michael@0 | 179 | do { |
michael@0 | 180 | SkPMColor c = *src++; |
michael@0 | 181 | SkPMColorAssert(c); |
michael@0 | 182 | if (c) |
michael@0 | 183 | { |
michael@0 | 184 | unsigned d = *dst; |
michael@0 | 185 | int sa = SkGetPackedA32(c); |
michael@0 | 186 | int dst_scale = SkAlpha255To256(255 - SkAlphaMul(sa, src_scale)); |
michael@0 | 187 | int dither = DITHER_VALUE(x); |
michael@0 | 188 | |
michael@0 | 189 | int sr = SkGetPackedR32(c); |
michael@0 | 190 | int sg = SkGetPackedG32(c); |
michael@0 | 191 | int sb = SkGetPackedB32(c); |
michael@0 | 192 | sr = SkDITHER_R32To565(sr, dither); |
michael@0 | 193 | sg = SkDITHER_G32To565(sg, dither); |
michael@0 | 194 | sb = SkDITHER_B32To565(sb, dither); |
michael@0 | 195 | |
michael@0 | 196 | int dr = (sr * src_scale + SkGetPackedR16(d) * dst_scale) >> 8; |
michael@0 | 197 | int dg = (sg * src_scale + SkGetPackedG16(d) * dst_scale) >> 8; |
michael@0 | 198 | int db = (sb * src_scale + SkGetPackedB16(d) * dst_scale) >> 8; |
michael@0 | 199 | |
michael@0 | 200 | *dst = SkPackRGB16(dr, dg, db); |
michael@0 | 201 | } |
michael@0 | 202 | dst += 1; |
michael@0 | 203 | DITHER_INC_X(x); |
michael@0 | 204 | } while (--count != 0); |
michael@0 | 205 | } |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 209 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 210 | |
michael@0 | 211 | static const SkBlitRow::Proc gDefault_565_Procs[] = { |
michael@0 | 212 | // no dither |
michael@0 | 213 | S32_D565_Opaque, |
michael@0 | 214 | S32_D565_Blend, |
michael@0 | 215 | |
michael@0 | 216 | S32A_D565_Opaque, |
michael@0 | 217 | S32A_D565_Blend, |
michael@0 | 218 | |
michael@0 | 219 | // dither |
michael@0 | 220 | S32_D565_Opaque_Dither, |
michael@0 | 221 | S32_D565_Blend_Dither, |
michael@0 | 222 | |
michael@0 | 223 | S32A_D565_Opaque_Dither, |
michael@0 | 224 | S32A_D565_Blend_Dither |
michael@0 | 225 | }; |
michael@0 | 226 | |
michael@0 | 227 | SkBlitRow::Proc SkBlitRow::Factory(unsigned flags, SkBitmap::Config config) { |
michael@0 | 228 | SkASSERT(flags < SK_ARRAY_COUNT(gDefault_565_Procs)); |
michael@0 | 229 | // just so we don't crash |
michael@0 | 230 | flags &= kFlags16_Mask; |
michael@0 | 231 | |
michael@0 | 232 | SkBlitRow::Proc proc = NULL; |
michael@0 | 233 | |
michael@0 | 234 | switch (config) { |
michael@0 | 235 | case SkBitmap::kRGB_565_Config: |
michael@0 | 236 | proc = PlatformProcs565(flags); |
michael@0 | 237 | if (NULL == proc) { |
michael@0 | 238 | proc = gDefault_565_Procs[flags]; |
michael@0 | 239 | } |
michael@0 | 240 | break; |
michael@0 | 241 | default: |
michael@0 | 242 | break; |
michael@0 | 243 | } |
michael@0 | 244 | return proc; |
michael@0 | 245 | } |