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 2006 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 SkMask_DEFINED |
michael@0 | 11 | #define SkMask_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkRect.h" |
michael@0 | 14 | |
michael@0 | 15 | /** \class SkMask |
michael@0 | 16 | SkMask is used to describe alpha bitmaps, either 1bit, 8bit, or |
michael@0 | 17 | the 3-channel 3D format. These are passed to SkMaskFilter objects. |
michael@0 | 18 | */ |
michael@0 | 19 | struct SkMask { |
michael@0 | 20 | enum Format { |
michael@0 | 21 | kBW_Format, //!< 1bit per pixel mask (e.g. monochrome) |
michael@0 | 22 | kA8_Format, //!< 8bits per pixel mask (e.g. antialiasing) |
michael@0 | 23 | k3D_Format, //!< 3 8bit per pixl planes: alpha, mul, add |
michael@0 | 24 | kARGB32_Format, //!< SkPMColor |
michael@0 | 25 | kLCD16_Format, //!< 565 alpha for r/g/b |
michael@0 | 26 | kLCD32_Format //!< 888 alpha for r/g/b |
michael@0 | 27 | }; |
michael@0 | 28 | |
michael@0 | 29 | enum { |
michael@0 | 30 | kCountMaskFormats = kLCD32_Format + 1 |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | uint8_t* fImage; |
michael@0 | 34 | SkIRect fBounds; |
michael@0 | 35 | uint32_t fRowBytes; |
michael@0 | 36 | Format fFormat; |
michael@0 | 37 | |
michael@0 | 38 | /** Returns true if the mask is empty: i.e. it has an empty bounds. |
michael@0 | 39 | */ |
michael@0 | 40 | bool isEmpty() const { return fBounds.isEmpty(); } |
michael@0 | 41 | |
michael@0 | 42 | /** Return the byte size of the mask, assuming only 1 plane. |
michael@0 | 43 | Does not account for k3D_Format. For that, use computeTotalImageSize(). |
michael@0 | 44 | If there is an overflow of 32bits, then returns 0. |
michael@0 | 45 | */ |
michael@0 | 46 | size_t computeImageSize() const; |
michael@0 | 47 | |
michael@0 | 48 | /** Return the byte size of the mask, taking into account |
michael@0 | 49 | any extra planes (e.g. k3D_Format). |
michael@0 | 50 | If there is an overflow of 32bits, then returns 0. |
michael@0 | 51 | */ |
michael@0 | 52 | size_t computeTotalImageSize() const; |
michael@0 | 53 | |
michael@0 | 54 | /** Returns the address of the byte that holds the specified bit. |
michael@0 | 55 | Asserts that the mask is kBW_Format, and that x,y are in range. |
michael@0 | 56 | x,y are in the same coordiate space as fBounds. |
michael@0 | 57 | */ |
michael@0 | 58 | uint8_t* getAddr1(int x, int y) const { |
michael@0 | 59 | SkASSERT(kBW_Format == fFormat); |
michael@0 | 60 | SkASSERT(fBounds.contains(x, y)); |
michael@0 | 61 | SkASSERT(fImage != NULL); |
michael@0 | 62 | return fImage + ((x - fBounds.fLeft) >> 3) + (y - fBounds.fTop) * fRowBytes; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | /** Returns the address of the specified byte. |
michael@0 | 66 | Asserts that the mask is kA8_Format, and that x,y are in range. |
michael@0 | 67 | x,y are in the same coordiate space as fBounds. |
michael@0 | 68 | */ |
michael@0 | 69 | uint8_t* getAddr8(int x, int y) const { |
michael@0 | 70 | SkASSERT(kA8_Format == fFormat); |
michael@0 | 71 | SkASSERT(fBounds.contains(x, y)); |
michael@0 | 72 | SkASSERT(fImage != NULL); |
michael@0 | 73 | return fImage + x - fBounds.fLeft + (y - fBounds.fTop) * fRowBytes; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | /** |
michael@0 | 77 | * Return the address of the specified 16bit mask. In the debug build, |
michael@0 | 78 | * this asserts that the mask's format is kLCD16_Format, and that (x,y) |
michael@0 | 79 | * are contained in the mask's fBounds. |
michael@0 | 80 | */ |
michael@0 | 81 | uint16_t* getAddrLCD16(int x, int y) const { |
michael@0 | 82 | SkASSERT(kLCD16_Format == fFormat); |
michael@0 | 83 | SkASSERT(fBounds.contains(x, y)); |
michael@0 | 84 | SkASSERT(fImage != NULL); |
michael@0 | 85 | uint16_t* row = (uint16_t*)(fImage + (y - fBounds.fTop) * fRowBytes); |
michael@0 | 86 | return row + (x - fBounds.fLeft); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | /** |
michael@0 | 90 | * Return the address of the specified 32bit mask. In the debug build, |
michael@0 | 91 | * this asserts that the mask's format is kLCD32_Format, and that (x,y) |
michael@0 | 92 | * are contained in the mask's fBounds. |
michael@0 | 93 | */ |
michael@0 | 94 | uint32_t* getAddrLCD32(int x, int y) const { |
michael@0 | 95 | SkASSERT(kLCD32_Format == fFormat); |
michael@0 | 96 | SkASSERT(fBounds.contains(x, y)); |
michael@0 | 97 | SkASSERT(fImage != NULL); |
michael@0 | 98 | uint32_t* row = (uint32_t*)(fImage + (y - fBounds.fTop) * fRowBytes); |
michael@0 | 99 | return row + (x - fBounds.fLeft); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | /** |
michael@0 | 103 | * Return the address of the specified 32bit mask. In the debug build, |
michael@0 | 104 | * this asserts that the mask's format is 32bits, and that (x,y) |
michael@0 | 105 | * are contained in the mask's fBounds. |
michael@0 | 106 | */ |
michael@0 | 107 | uint32_t* getAddr32(int x, int y) const { |
michael@0 | 108 | SkASSERT(kLCD32_Format == fFormat || kARGB32_Format == fFormat); |
michael@0 | 109 | SkASSERT(fBounds.contains(x, y)); |
michael@0 | 110 | SkASSERT(fImage != NULL); |
michael@0 | 111 | uint32_t* row = (uint32_t*)(fImage + (y - fBounds.fTop) * fRowBytes); |
michael@0 | 112 | return row + (x - fBounds.fLeft); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | /** |
michael@0 | 116 | * Returns the address of the specified pixel, computing the pixel-size |
michael@0 | 117 | * at runtime based on the mask format. This will be slightly slower than |
michael@0 | 118 | * using one of the routines where the format is implied by the name |
michael@0 | 119 | * e.g. getAddr8 or getAddrLCD32. |
michael@0 | 120 | * |
michael@0 | 121 | * x,y must be contained by the mask's bounds (this is asserted in the |
michael@0 | 122 | * debug build, but not checked in the release build.) |
michael@0 | 123 | * |
michael@0 | 124 | * This should not be called with kBW_Format, as it will give unspecified |
michael@0 | 125 | * results (and assert in the debug build). |
michael@0 | 126 | */ |
michael@0 | 127 | void* getAddr(int x, int y) const; |
michael@0 | 128 | |
michael@0 | 129 | static uint8_t* AllocImage(size_t bytes); |
michael@0 | 130 | static void FreeImage(void* image); |
michael@0 | 131 | |
michael@0 | 132 | enum CreateMode { |
michael@0 | 133 | kJustComputeBounds_CreateMode, //!< compute bounds and return |
michael@0 | 134 | kJustRenderImage_CreateMode, //!< render into preallocate mask |
michael@0 | 135 | kComputeBoundsAndRenderImage_CreateMode //!< compute bounds, alloc image and render into it |
michael@0 | 136 | }; |
michael@0 | 137 | }; |
michael@0 | 138 | |
michael@0 | 139 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 140 | |
michael@0 | 141 | /** |
michael@0 | 142 | * \class SkAutoMaskImage |
michael@0 | 143 | * |
michael@0 | 144 | * Stack class used to manage the fImage buffer in a SkMask. |
michael@0 | 145 | * When this object loses scope, the buffer is freed with SkMask::FreeImage(). |
michael@0 | 146 | */ |
michael@0 | 147 | class SkAutoMaskFreeImage { |
michael@0 | 148 | public: |
michael@0 | 149 | SkAutoMaskFreeImage(uint8_t* maskImage) { |
michael@0 | 150 | fImage = maskImage; |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | ~SkAutoMaskFreeImage() { |
michael@0 | 154 | SkMask::FreeImage(fImage); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | private: |
michael@0 | 158 | uint8_t* fImage; |
michael@0 | 159 | }; |
michael@0 | 160 | #define SkAutoMaskFreeImage(...) SK_REQUIRE_LOCAL_VAR(SkAutoMaskFreeImage) |
michael@0 | 161 | |
michael@0 | 162 | #endif |