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 | #ifndef SkImageInfo_DEFINED |
michael@0 | 9 | #define SkImageInfo_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkMath.h" |
michael@0 | 12 | #include "SkSize.h" |
michael@0 | 13 | |
michael@0 | 14 | class SkWriteBuffer; |
michael@0 | 15 | class SkReadBuffer; |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * Describes how to interpret the alpha compoent of a pixel. |
michael@0 | 19 | */ |
michael@0 | 20 | enum SkAlphaType { |
michael@0 | 21 | /** |
michael@0 | 22 | * All pixels should be treated as opaque, regardless of the value stored |
michael@0 | 23 | * in their alpha field. Used for legacy images that wrote 0 or garbarge |
michael@0 | 24 | * in their alpha field, but intended the RGB to be treated as opaque. |
michael@0 | 25 | */ |
michael@0 | 26 | kIgnore_SkAlphaType, |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * All pixels are stored as opaque. This differs slightly from kIgnore in |
michael@0 | 30 | * that kOpaque has correct "opaque" values stored in the pixels, while |
michael@0 | 31 | * kIgnore may not, but in both cases the caller should treat the pixels |
michael@0 | 32 | * as opaque. |
michael@0 | 33 | */ |
michael@0 | 34 | kOpaque_SkAlphaType, |
michael@0 | 35 | |
michael@0 | 36 | /** |
michael@0 | 37 | * All pixels have their alpha premultiplied in their color components. |
michael@0 | 38 | * This is the natural format for the rendering target pixels. |
michael@0 | 39 | */ |
michael@0 | 40 | kPremul_SkAlphaType, |
michael@0 | 41 | |
michael@0 | 42 | /** |
michael@0 | 43 | * All pixels have their color components stored without any regard to the |
michael@0 | 44 | * alpha. e.g. this is the default configuration for PNG images. |
michael@0 | 45 | * |
michael@0 | 46 | * This alpha-type is ONLY supported for input images. Rendering cannot |
michael@0 | 47 | * generate this on output. |
michael@0 | 48 | */ |
michael@0 | 49 | kUnpremul_SkAlphaType, |
michael@0 | 50 | |
michael@0 | 51 | kLastEnum_SkAlphaType = kUnpremul_SkAlphaType |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) { |
michael@0 | 55 | SK_COMPILE_ASSERT(kIgnore_SkAlphaType < kOpaque_SkAlphaType, bad_alphatype_order); |
michael@0 | 56 | SK_COMPILE_ASSERT(kPremul_SkAlphaType > kOpaque_SkAlphaType, bad_alphatype_order); |
michael@0 | 57 | SK_COMPILE_ASSERT(kUnpremul_SkAlphaType > kOpaque_SkAlphaType, bad_alphatype_order); |
michael@0 | 58 | |
michael@0 | 59 | return (unsigned)at <= kOpaque_SkAlphaType; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | static inline bool SkAlphaTypeIsValid(unsigned value) { |
michael@0 | 63 | return value <= kLastEnum_SkAlphaType; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 67 | |
michael@0 | 68 | /** |
michael@0 | 69 | * Describes how to interpret the components of a pixel. |
michael@0 | 70 | */ |
michael@0 | 71 | enum SkColorType { |
michael@0 | 72 | kUnknown_SkColorType, |
michael@0 | 73 | kAlpha_8_SkColorType, |
michael@0 | 74 | kRGB_565_SkColorType, |
michael@0 | 75 | kARGB_4444_SkColorType, |
michael@0 | 76 | kRGBA_8888_SkColorType, |
michael@0 | 77 | kBGRA_8888_SkColorType, |
michael@0 | 78 | kIndex_8_SkColorType, |
michael@0 | 79 | |
michael@0 | 80 | kLastEnum_SkColorType = kIndex_8_SkColorType, |
michael@0 | 81 | |
michael@0 | 82 | #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
michael@0 | 83 | kPMColor_SkColorType = kBGRA_8888_SkColorType |
michael@0 | 84 | #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
michael@0 | 85 | kPMColor_SkColorType = kRGBA_8888_SkColorType |
michael@0 | 86 | #else |
michael@0 | 87 | #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" |
michael@0 | 88 | #endif |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | static int SkColorTypeBytesPerPixel(SkColorType ct) { |
michael@0 | 92 | static const uint8_t gSize[] = { |
michael@0 | 93 | 0, // Unknown |
michael@0 | 94 | 1, // Alpha_8 |
michael@0 | 95 | 2, // RGB_565 |
michael@0 | 96 | 2, // ARGB_4444 |
michael@0 | 97 | 4, // RGBA_8888 |
michael@0 | 98 | 4, // BGRA_8888 |
michael@0 | 99 | 1, // kIndex_8 |
michael@0 | 100 | }; |
michael@0 | 101 | SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1), |
michael@0 | 102 | size_mismatch_with_SkColorType_enum); |
michael@0 | 103 | |
michael@0 | 104 | SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize)); |
michael@0 | 105 | return gSize[ct]; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { |
michael@0 | 109 | return width * SkColorTypeBytesPerPixel(ct); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | static inline bool SkColorTypeIsValid(unsigned value) { |
michael@0 | 113 | return value <= kLastEnum_SkColorType; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 117 | |
michael@0 | 118 | /** |
michael@0 | 119 | * Describe an image's dimensions and pixel type. |
michael@0 | 120 | */ |
michael@0 | 121 | struct SkImageInfo { |
michael@0 | 122 | int fWidth; |
michael@0 | 123 | int fHeight; |
michael@0 | 124 | SkColorType fColorType; |
michael@0 | 125 | SkAlphaType fAlphaType; |
michael@0 | 126 | |
michael@0 | 127 | static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at) { |
michael@0 | 128 | SkImageInfo info = { |
michael@0 | 129 | width, height, ct, at |
michael@0 | 130 | }; |
michael@0 | 131 | return info; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | /** |
michael@0 | 135 | * Sets colortype to the native ARGB32 type. |
michael@0 | 136 | */ |
michael@0 | 137 | static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { |
michael@0 | 138 | SkImageInfo info = { |
michael@0 | 139 | width, height, kPMColor_SkColorType, at |
michael@0 | 140 | }; |
michael@0 | 141 | return info; |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
michael@0 | 146 | */ |
michael@0 | 147 | static SkImageInfo MakeN32Premul(int width, int height) { |
michael@0 | 148 | SkImageInfo info = { |
michael@0 | 149 | width, height, kPMColor_SkColorType, kPremul_SkAlphaType |
michael@0 | 150 | }; |
michael@0 | 151 | return info; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | /** |
michael@0 | 155 | * Sets colortype to the native ARGB32 type, and the alphatype to premul. |
michael@0 | 156 | */ |
michael@0 | 157 | static SkImageInfo MakeN32Premul(const SkISize& size) { |
michael@0 | 158 | return MakeN32Premul(size.width(), size.height()); |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | static SkImageInfo MakeA8(int width, int height) { |
michael@0 | 162 | SkImageInfo info = { |
michael@0 | 163 | width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType |
michael@0 | 164 | }; |
michael@0 | 165 | return info; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | static SkImageInfo MakeUnknown(int width, int height) { |
michael@0 | 169 | SkImageInfo info = { |
michael@0 | 170 | width, height, kUnknown_SkColorType, kIgnore_SkAlphaType |
michael@0 | 171 | }; |
michael@0 | 172 | return info; |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | int width() const { return fWidth; } |
michael@0 | 176 | int height() const { return fHeight; } |
michael@0 | 177 | SkColorType colorType() const { return fColorType; } |
michael@0 | 178 | SkAlphaType alphaType() const { return fAlphaType; } |
michael@0 | 179 | |
michael@0 | 180 | bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } |
michael@0 | 181 | |
michael@0 | 182 | bool isOpaque() const { |
michael@0 | 183 | return SkAlphaTypeIsOpaque(fAlphaType); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } |
michael@0 | 187 | |
michael@0 | 188 | int bytesPerPixel() const { |
michael@0 | 189 | return SkColorTypeBytesPerPixel(fColorType); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | uint64_t minRowBytes64() const { |
michael@0 | 193 | return sk_64_mul(fWidth, this->bytesPerPixel()); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | size_t minRowBytes() const { |
michael@0 | 197 | return (size_t)this->minRowBytes64(); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | bool operator==(const SkImageInfo& other) const { |
michael@0 | 201 | return 0 == memcmp(this, &other, sizeof(other)); |
michael@0 | 202 | } |
michael@0 | 203 | bool operator!=(const SkImageInfo& other) const { |
michael@0 | 204 | return 0 != memcmp(this, &other, sizeof(other)); |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | void unflatten(SkReadBuffer&); |
michael@0 | 208 | void flatten(SkWriteBuffer&) const; |
michael@0 | 209 | |
michael@0 | 210 | int64_t getSafeSize64(size_t rowBytes) const { |
michael@0 | 211 | if (0 == fHeight) { |
michael@0 | 212 | return 0; |
michael@0 | 213 | } |
michael@0 | 214 | return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel(); |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | size_t getSafeSize(size_t rowBytes) const { |
michael@0 | 218 | return (size_t)this->getSafeSize64(rowBytes); |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | bool validRowBytes(size_t rowBytes) const { |
michael@0 | 222 | uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel()); |
michael@0 | 223 | return rowBytes >= rb; |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | SkDEBUGCODE(void validate() const;) |
michael@0 | 227 | }; |
michael@0 | 228 | |
michael@0 | 229 | #endif |