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 2013 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 "SkImageEncoder.h" |
michael@0 | 9 | #include "SkBitmap.h" |
michael@0 | 10 | #include "SkColorPriv.h" |
michael@0 | 11 | #include "SkStream.h" |
michael@0 | 12 | #include "SkTemplates.h" |
michael@0 | 13 | |
michael@0 | 14 | class SkARGBImageEncoder : public SkImageEncoder { |
michael@0 | 15 | protected: |
michael@0 | 16 | virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) SK_OVERRIDE; |
michael@0 | 17 | |
michael@0 | 18 | private: |
michael@0 | 19 | typedef SkImageEncoder INHERITED; |
michael@0 | 20 | }; |
michael@0 | 21 | |
michael@0 | 22 | typedef void (*ScanlineImporter)(const uint8_t* in, uint8_t* argb, int width, |
michael@0 | 23 | const SkPMColor* SK_RESTRICT ctable); |
michael@0 | 24 | |
michael@0 | 25 | static void ARGB_8888_To_ARGB(const uint8_t* in, uint8_t* argb, int width, const SkPMColor*) { |
michael@0 | 26 | const uint32_t* SK_RESTRICT src = (const uint32_t*)in; |
michael@0 | 27 | for (int i = 0; i < width; ++i) { |
michael@0 | 28 | const uint32_t c = *src++; |
michael@0 | 29 | argb[0] = SkGetPackedA32(c); |
michael@0 | 30 | argb[1] = SkGetPackedR32(c); |
michael@0 | 31 | argb[2] = SkGetPackedG32(c); |
michael@0 | 32 | argb[3] = SkGetPackedB32(c); |
michael@0 | 33 | argb += 4; |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | static void RGB_565_To_ARGB(const uint8_t* in, uint8_t* argb, int width, const SkPMColor*) { |
michael@0 | 38 | const uint16_t* SK_RESTRICT src = (const uint16_t*)in; |
michael@0 | 39 | for (int i = 0; i < width; ++i) { |
michael@0 | 40 | const uint16_t c = *src++; |
michael@0 | 41 | argb[0] = 0xFF; |
michael@0 | 42 | argb[1] = SkPacked16ToR32(c); |
michael@0 | 43 | argb[2] = SkPacked16ToG32(c); |
michael@0 | 44 | argb[3] = SkPacked16ToB32(c); |
michael@0 | 45 | argb += 4; |
michael@0 | 46 | } |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | static void ARGB_4444_To_ARGB(const uint8_t* in, uint8_t* argb, int width, const SkPMColor*) { |
michael@0 | 50 | const SkPMColor16* SK_RESTRICT src = (const SkPMColor16*)in; |
michael@0 | 51 | for (int i = 0; i < width; ++i) { |
michael@0 | 52 | const SkPMColor16 c = *src++; |
michael@0 | 53 | argb[0] = SkPacked4444ToA32(c); |
michael@0 | 54 | argb[1] = SkPacked4444ToR32(c); |
michael@0 | 55 | argb[2] = SkPacked4444ToG32(c); |
michael@0 | 56 | argb[3] = SkPacked4444ToB32(c); |
michael@0 | 57 | argb += 4; |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | static void Index8_To_ARGB(const uint8_t* in, uint8_t* argb, int width, |
michael@0 | 62 | const SkPMColor* SK_RESTRICT ctable) { |
michael@0 | 63 | const uint8_t* SK_RESTRICT src = (const uint8_t*)in; |
michael@0 | 64 | for (int i = 0; i < width; ++i) { |
michael@0 | 65 | const uint32_t c = ctable[*src++]; |
michael@0 | 66 | argb[0] = SkGetPackedA32(c); |
michael@0 | 67 | argb[1] = SkGetPackedR32(c); |
michael@0 | 68 | argb[2] = SkGetPackedG32(c); |
michael@0 | 69 | argb[3] = SkGetPackedB32(c); |
michael@0 | 70 | argb += 4; |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | static ScanlineImporter ChooseImporter(const SkBitmap::Config& config) { |
michael@0 | 75 | switch (config) { |
michael@0 | 76 | case SkBitmap::kARGB_8888_Config: |
michael@0 | 77 | return ARGB_8888_To_ARGB; |
michael@0 | 78 | case SkBitmap::kRGB_565_Config: |
michael@0 | 79 | return RGB_565_To_ARGB; |
michael@0 | 80 | case SkBitmap::kARGB_4444_Config: |
michael@0 | 81 | return ARGB_4444_To_ARGB; |
michael@0 | 82 | case SkBitmap::kIndex8_Config: |
michael@0 | 83 | return Index8_To_ARGB; |
michael@0 | 84 | default: |
michael@0 | 85 | return NULL; |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | bool SkARGBImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int) { |
michael@0 | 90 | const SkBitmap::Config config = bitmap.config(); |
michael@0 | 91 | const ScanlineImporter scanline_import = ChooseImporter(config); |
michael@0 | 92 | if (NULL == scanline_import) { |
michael@0 | 93 | return false; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | SkAutoLockPixels alp(bitmap); |
michael@0 | 97 | const uint8_t* src = (uint8_t*)bitmap.getPixels(); |
michael@0 | 98 | if (NULL == bitmap.getPixels()) { |
michael@0 | 99 | return false; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | SkAutoLockColors ctLocker; |
michael@0 | 103 | const SkPMColor* colors = ctLocker.lockColors(bitmap); |
michael@0 | 104 | |
michael@0 | 105 | const int argbStride = bitmap.width() * 4; |
michael@0 | 106 | SkAutoTDeleteArray<uint8_t> ada(new uint8_t[argbStride]); |
michael@0 | 107 | uint8_t* argb = ada.get(); |
michael@0 | 108 | for (int y = 0; y < bitmap.height(); ++y) { |
michael@0 | 109 | scanline_import(src + y * bitmap.rowBytes(), argb, bitmap.width(), colors); |
michael@0 | 110 | stream->write(argb, argbStride); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | return true; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | |
michael@0 | 117 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 118 | DEFINE_ENCODER_CREATOR(ARGBImageEncoder); |
michael@0 | 119 | /////////////////////////////////////////////////////////////////////////////// |