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 "SkBlitMask.h" |
michael@0 | 10 | #include "SkColorPriv.h" |
michael@0 | 11 | #include "SkUtils.h" |
michael@0 | 12 | |
michael@0 | 13 | #define UNROLL |
michael@0 | 14 | |
michael@0 | 15 | SkBlitRow::ColorRectProc PlatformColorRectProcFactory(); |
michael@0 | 16 | |
michael@0 | 17 | static void S32_Opaque_BlitRow32(SkPMColor* SK_RESTRICT dst, |
michael@0 | 18 | const SkPMColor* SK_RESTRICT src, |
michael@0 | 19 | int count, U8CPU alpha) { |
michael@0 | 20 | SkASSERT(255 == alpha); |
michael@0 | 21 | memcpy(dst, src, count * sizeof(SkPMColor)); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | static void S32_Blend_BlitRow32(SkPMColor* SK_RESTRICT dst, |
michael@0 | 25 | const SkPMColor* SK_RESTRICT src, |
michael@0 | 26 | int count, U8CPU alpha) { |
michael@0 | 27 | SkASSERT(alpha <= 255); |
michael@0 | 28 | if (count > 0) { |
michael@0 | 29 | unsigned src_scale = SkAlpha255To256(alpha); |
michael@0 | 30 | unsigned dst_scale = 256 - src_scale; |
michael@0 | 31 | |
michael@0 | 32 | #ifdef UNROLL |
michael@0 | 33 | if (count & 1) { |
michael@0 | 34 | *dst = SkAlphaMulQ(*(src++), src_scale) + SkAlphaMulQ(*dst, dst_scale); |
michael@0 | 35 | dst += 1; |
michael@0 | 36 | count -= 1; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | const SkPMColor* SK_RESTRICT srcEnd = src + count; |
michael@0 | 40 | while (src != srcEnd) { |
michael@0 | 41 | *dst = SkAlphaMulQ(*(src++), src_scale) + SkAlphaMulQ(*dst, dst_scale); |
michael@0 | 42 | dst += 1; |
michael@0 | 43 | *dst = SkAlphaMulQ(*(src++), src_scale) + SkAlphaMulQ(*dst, dst_scale); |
michael@0 | 44 | dst += 1; |
michael@0 | 45 | } |
michael@0 | 46 | #else |
michael@0 | 47 | do { |
michael@0 | 48 | *dst = SkAlphaMulQ(*src, src_scale) + SkAlphaMulQ(*dst, dst_scale); |
michael@0 | 49 | src += 1; |
michael@0 | 50 | dst += 1; |
michael@0 | 51 | } while (--count > 0); |
michael@0 | 52 | #endif |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | static void S32A_Opaque_BlitRow32(SkPMColor* SK_RESTRICT dst, |
michael@0 | 57 | const SkPMColor* SK_RESTRICT src, |
michael@0 | 58 | int count, U8CPU alpha) { |
michael@0 | 59 | SkASSERT(255 == alpha); |
michael@0 | 60 | if (count > 0) { |
michael@0 | 61 | #ifdef UNROLL |
michael@0 | 62 | if (count & 1) { |
michael@0 | 63 | *dst = SkPMSrcOver(*(src++), *dst); |
michael@0 | 64 | dst += 1; |
michael@0 | 65 | count -= 1; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | const SkPMColor* SK_RESTRICT srcEnd = src + count; |
michael@0 | 69 | while (src != srcEnd) { |
michael@0 | 70 | *dst = SkPMSrcOver(*(src++), *dst); |
michael@0 | 71 | dst += 1; |
michael@0 | 72 | *dst = SkPMSrcOver(*(src++), *dst); |
michael@0 | 73 | dst += 1; |
michael@0 | 74 | } |
michael@0 | 75 | #else |
michael@0 | 76 | do { |
michael@0 | 77 | *dst = SkPMSrcOver(*src, *dst); |
michael@0 | 78 | src += 1; |
michael@0 | 79 | dst += 1; |
michael@0 | 80 | } while (--count > 0); |
michael@0 | 81 | #endif |
michael@0 | 82 | } |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | static void S32A_Blend_BlitRow32(SkPMColor* SK_RESTRICT dst, |
michael@0 | 86 | const SkPMColor* SK_RESTRICT src, |
michael@0 | 87 | int count, U8CPU alpha) { |
michael@0 | 88 | SkASSERT(alpha <= 255); |
michael@0 | 89 | if (count > 0) { |
michael@0 | 90 | #ifdef UNROLL |
michael@0 | 91 | if (count & 1) { |
michael@0 | 92 | *dst = SkBlendARGB32(*(src++), *dst, alpha); |
michael@0 | 93 | dst += 1; |
michael@0 | 94 | count -= 1; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | const SkPMColor* SK_RESTRICT srcEnd = src + count; |
michael@0 | 98 | while (src != srcEnd) { |
michael@0 | 99 | *dst = SkBlendARGB32(*(src++), *dst, alpha); |
michael@0 | 100 | dst += 1; |
michael@0 | 101 | *dst = SkBlendARGB32(*(src++), *dst, alpha); |
michael@0 | 102 | dst += 1; |
michael@0 | 103 | } |
michael@0 | 104 | #else |
michael@0 | 105 | do { |
michael@0 | 106 | *dst = SkBlendARGB32(*src, *dst, alpha); |
michael@0 | 107 | src += 1; |
michael@0 | 108 | dst += 1; |
michael@0 | 109 | } while (--count > 0); |
michael@0 | 110 | #endif |
michael@0 | 111 | } |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 115 | |
michael@0 | 116 | static const SkBlitRow::Proc32 gDefault_Procs32[] = { |
michael@0 | 117 | S32_Opaque_BlitRow32, |
michael@0 | 118 | S32_Blend_BlitRow32, |
michael@0 | 119 | S32A_Opaque_BlitRow32, |
michael@0 | 120 | S32A_Blend_BlitRow32 |
michael@0 | 121 | }; |
michael@0 | 122 | |
michael@0 | 123 | SkBlitRow::Proc32 SkBlitRow::Factory32(unsigned flags) { |
michael@0 | 124 | SkASSERT(flags < SK_ARRAY_COUNT(gDefault_Procs32)); |
michael@0 | 125 | // just so we don't crash |
michael@0 | 126 | flags &= kFlags32_Mask; |
michael@0 | 127 | |
michael@0 | 128 | SkBlitRow::Proc32 proc = PlatformProcs32(flags); |
michael@0 | 129 | if (NULL == proc) { |
michael@0 | 130 | proc = gDefault_Procs32[flags]; |
michael@0 | 131 | } |
michael@0 | 132 | SkASSERT(proc); |
michael@0 | 133 | return proc; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | SkBlitRow::Proc32 SkBlitRow::ColorProcFactory() { |
michael@0 | 137 | SkBlitRow::ColorProc proc = PlatformColorProc(); |
michael@0 | 138 | if (NULL == proc) { |
michael@0 | 139 | proc = Color32; |
michael@0 | 140 | } |
michael@0 | 141 | SkASSERT(proc); |
michael@0 | 142 | return proc; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | void SkBlitRow::Color32(SkPMColor* SK_RESTRICT dst, |
michael@0 | 146 | const SkPMColor* SK_RESTRICT src, |
michael@0 | 147 | int count, SkPMColor color) { |
michael@0 | 148 | if (count > 0) { |
michael@0 | 149 | if (0 == color) { |
michael@0 | 150 | if (src != dst) { |
michael@0 | 151 | memcpy(dst, src, count * sizeof(SkPMColor)); |
michael@0 | 152 | } |
michael@0 | 153 | return; |
michael@0 | 154 | } |
michael@0 | 155 | unsigned colorA = SkGetPackedA32(color); |
michael@0 | 156 | if (255 == colorA) { |
michael@0 | 157 | sk_memset32(dst, color, count); |
michael@0 | 158 | } else { |
michael@0 | 159 | unsigned scale = 256 - SkAlpha255To256(colorA); |
michael@0 | 160 | do { |
michael@0 | 161 | *dst = color + SkAlphaMulQ(*src, scale); |
michael@0 | 162 | src += 1; |
michael@0 | 163 | dst += 1; |
michael@0 | 164 | } while (--count); |
michael@0 | 165 | } |
michael@0 | 166 | } |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | template <size_t N> void assignLoop(SkPMColor* dst, SkPMColor color) { |
michael@0 | 170 | for (size_t i = 0; i < N; ++i) { |
michael@0 | 171 | *dst++ = color; |
michael@0 | 172 | } |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | static inline void assignLoop(SkPMColor dst[], SkPMColor color, int count) { |
michael@0 | 176 | while (count >= 4) { |
michael@0 | 177 | *dst++ = color; |
michael@0 | 178 | *dst++ = color; |
michael@0 | 179 | *dst++ = color; |
michael@0 | 180 | *dst++ = color; |
michael@0 | 181 | count -= 4; |
michael@0 | 182 | } |
michael@0 | 183 | if (count >= 2) { |
michael@0 | 184 | *dst++ = color; |
michael@0 | 185 | *dst++ = color; |
michael@0 | 186 | count -= 2; |
michael@0 | 187 | } |
michael@0 | 188 | if (count > 0) { |
michael@0 | 189 | *dst++ = color; |
michael@0 | 190 | } |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | void SkBlitRow::ColorRect32(SkPMColor* dst, int width, int height, |
michael@0 | 194 | size_t rowBytes, SkPMColor color) { |
michael@0 | 195 | if (width <= 0 || height <= 0 || 0 == color) { |
michael@0 | 196 | return; |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | // Just made up this value, since I saw it once in a SSE2 file. |
michael@0 | 200 | // We should consider writing some tests to find the optimimal break-point |
michael@0 | 201 | // (or query the Platform proc?) |
michael@0 | 202 | static const int MIN_WIDTH_FOR_SCANLINE_PROC = 32; |
michael@0 | 203 | |
michael@0 | 204 | bool isOpaque = (0xFF == SkGetPackedA32(color)); |
michael@0 | 205 | |
michael@0 | 206 | if (!isOpaque || width >= MIN_WIDTH_FOR_SCANLINE_PROC) { |
michael@0 | 207 | SkBlitRow::ColorProc proc = SkBlitRow::ColorProcFactory(); |
michael@0 | 208 | while (--height >= 0) { |
michael@0 | 209 | (*proc)(dst, dst, width, color); |
michael@0 | 210 | dst = (SkPMColor*) ((char*)dst + rowBytes); |
michael@0 | 211 | } |
michael@0 | 212 | } else { |
michael@0 | 213 | switch (width) { |
michael@0 | 214 | case 1: |
michael@0 | 215 | while (--height >= 0) { |
michael@0 | 216 | assignLoop<1>(dst, color); |
michael@0 | 217 | dst = (SkPMColor*) ((char*)dst + rowBytes); |
michael@0 | 218 | } |
michael@0 | 219 | break; |
michael@0 | 220 | case 2: |
michael@0 | 221 | while (--height >= 0) { |
michael@0 | 222 | assignLoop<2>(dst, color); |
michael@0 | 223 | dst = (SkPMColor*) ((char*)dst + rowBytes); |
michael@0 | 224 | } |
michael@0 | 225 | break; |
michael@0 | 226 | case 3: |
michael@0 | 227 | while (--height >= 0) { |
michael@0 | 228 | assignLoop<3>(dst, color); |
michael@0 | 229 | dst = (SkPMColor*) ((char*)dst + rowBytes); |
michael@0 | 230 | } |
michael@0 | 231 | break; |
michael@0 | 232 | default: |
michael@0 | 233 | while (--height >= 0) { |
michael@0 | 234 | assignLoop(dst, color, width); |
michael@0 | 235 | dst = (SkPMColor*) ((char*)dst + rowBytes); |
michael@0 | 236 | } |
michael@0 | 237 | break; |
michael@0 | 238 | } |
michael@0 | 239 | } |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | SkBlitRow::ColorRectProc SkBlitRow::ColorRectProcFactory() { |
michael@0 | 243 | SkBlitRow::ColorRectProc proc = PlatformColorRectProcFactory(); |
michael@0 | 244 | if (NULL == proc) { |
michael@0 | 245 | proc = ColorRect32; |
michael@0 | 246 | } |
michael@0 | 247 | SkASSERT(proc); |
michael@0 | 248 | return proc; |
michael@0 | 249 | } |