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 2012 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 GrClipMaskManager_DEFINED |
michael@0 | 9 | #define GrClipMaskManager_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "GrClipMaskCache.h" |
michael@0 | 12 | #include "GrContext.h" |
michael@0 | 13 | #include "GrDrawState.h" |
michael@0 | 14 | #include "GrReducedClip.h" |
michael@0 | 15 | #include "GrStencil.h" |
michael@0 | 16 | #include "GrTexture.h" |
michael@0 | 17 | |
michael@0 | 18 | #include "SkClipStack.h" |
michael@0 | 19 | #include "SkDeque.h" |
michael@0 | 20 | #include "SkPath.h" |
michael@0 | 21 | #include "SkRefCnt.h" |
michael@0 | 22 | #include "SkTLList.h" |
michael@0 | 23 | #include "SkTypes.h" |
michael@0 | 24 | |
michael@0 | 25 | class GrGpu; |
michael@0 | 26 | class GrPathRenderer; |
michael@0 | 27 | class GrPathRendererChain; |
michael@0 | 28 | class GrTexture; |
michael@0 | 29 | class SkPath; |
michael@0 | 30 | |
michael@0 | 31 | /** |
michael@0 | 32 | * The clip mask creator handles the generation of the clip mask. If anti |
michael@0 | 33 | * aliasing is requested it will (in the future) generate a single channel |
michael@0 | 34 | * (8bit) mask. If no anti aliasing is requested it will generate a 1-bit |
michael@0 | 35 | * mask in the stencil buffer. In the non anti-aliasing case, if the clip |
michael@0 | 36 | * mask can be represented as a rectangle then scissoring is used. In all |
michael@0 | 37 | * cases scissoring is used to bound the range of the clip mask. |
michael@0 | 38 | */ |
michael@0 | 39 | class GrClipMaskManager : public SkNoncopyable { |
michael@0 | 40 | public: |
michael@0 | 41 | GrClipMaskManager() |
michael@0 | 42 | : fGpu(NULL) |
michael@0 | 43 | , fCurrClipMaskType(kNone_ClipMaskType) { |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * Creates a clip mask if necessary as a stencil buffer or alpha texture |
michael@0 | 48 | * and sets the GrGpu's scissor and stencil state. If the return is false |
michael@0 | 49 | * then the draw can be skipped. The AutoRestoreEffects is initialized by |
michael@0 | 50 | * the manager when it must install additional effects to implement the |
michael@0 | 51 | * clip. devBounds is optional but can help optimize clipping. |
michael@0 | 52 | */ |
michael@0 | 53 | bool setupClipping(const GrClipData* clipDataIn, GrDrawState::AutoRestoreEffects*, |
michael@0 | 54 | const SkRect* devBounds); |
michael@0 | 55 | |
michael@0 | 56 | void releaseResources(); |
michael@0 | 57 | |
michael@0 | 58 | bool isClipInStencil() const { |
michael@0 | 59 | return kStencil_ClipMaskType == fCurrClipMaskType; |
michael@0 | 60 | } |
michael@0 | 61 | bool isClipInAlpha() const { |
michael@0 | 62 | return kAlpha_ClipMaskType == fCurrClipMaskType; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | void invalidateStencilMask() { |
michael@0 | 66 | if (kStencil_ClipMaskType == fCurrClipMaskType) { |
michael@0 | 67 | fCurrClipMaskType = kNone_ClipMaskType; |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | GrContext* getContext() { |
michael@0 | 72 | return fAACache.getContext(); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | void setGpu(GrGpu* gpu); |
michael@0 | 76 | |
michael@0 | 77 | void adjustPathStencilParams(GrStencilSettings* settings); |
michael@0 | 78 | private: |
michael@0 | 79 | /** |
michael@0 | 80 | * Informs the helper function adjustStencilParams() about how the stencil |
michael@0 | 81 | * buffer clip is being used. |
michael@0 | 82 | */ |
michael@0 | 83 | enum StencilClipMode { |
michael@0 | 84 | // Draw to the clip bit of the stencil buffer |
michael@0 | 85 | kModifyClip_StencilClipMode, |
michael@0 | 86 | // Clip against the existing representation of the clip in the high bit |
michael@0 | 87 | // of the stencil buffer. |
michael@0 | 88 | kRespectClip_StencilClipMode, |
michael@0 | 89 | // Neither writing to nor clipping against the clip bit. |
michael@0 | 90 | kIgnoreClip_StencilClipMode, |
michael@0 | 91 | }; |
michael@0 | 92 | |
michael@0 | 93 | GrGpu* fGpu; |
michael@0 | 94 | |
michael@0 | 95 | /** |
michael@0 | 96 | * We may represent the clip as a mask in the stencil buffer or as an alpha |
michael@0 | 97 | * texture. It may be neither because the scissor rect suffices or we |
michael@0 | 98 | * haven't yet examined the clip. |
michael@0 | 99 | */ |
michael@0 | 100 | enum ClipMaskType { |
michael@0 | 101 | kNone_ClipMaskType, |
michael@0 | 102 | kStencil_ClipMaskType, |
michael@0 | 103 | kAlpha_ClipMaskType, |
michael@0 | 104 | } fCurrClipMaskType; |
michael@0 | 105 | |
michael@0 | 106 | GrClipMaskCache fAACache; // cache for the AA path |
michael@0 | 107 | |
michael@0 | 108 | // Attempts to install a series of coverage effects to implement the clip. Return indicates |
michael@0 | 109 | // whether the element list was successfully converted to effects. |
michael@0 | 110 | bool installClipEffects(const GrReducedClip::ElementList&, |
michael@0 | 111 | GrDrawState::AutoRestoreEffects*, |
michael@0 | 112 | const SkVector& clipOffset, |
michael@0 | 113 | const SkRect* devBounds); |
michael@0 | 114 | |
michael@0 | 115 | // Draws the clip into the stencil buffer |
michael@0 | 116 | bool createStencilClipMask(int32_t elementsGenID, |
michael@0 | 117 | GrReducedClip::InitialState initialState, |
michael@0 | 118 | const GrReducedClip::ElementList& elements, |
michael@0 | 119 | const SkIRect& clipSpaceIBounds, |
michael@0 | 120 | const SkIPoint& clipSpaceToStencilOffset); |
michael@0 | 121 | // Creates an alpha mask of the clip. The mask is a rasterization of elements through the |
michael@0 | 122 | // rect specified by clipSpaceIBounds. |
michael@0 | 123 | GrTexture* createAlphaClipMask(int32_t elementsGenID, |
michael@0 | 124 | GrReducedClip::InitialState initialState, |
michael@0 | 125 | const GrReducedClip::ElementList& elements, |
michael@0 | 126 | const SkIRect& clipSpaceIBounds); |
michael@0 | 127 | // Similar to createAlphaClipMask but it rasterizes in SW and uploads to the result texture. |
michael@0 | 128 | GrTexture* createSoftwareClipMask(int32_t elementsGenID, |
michael@0 | 129 | GrReducedClip::InitialState initialState, |
michael@0 | 130 | const GrReducedClip::ElementList& elements, |
michael@0 | 131 | const SkIRect& clipSpaceIBounds); |
michael@0 | 132 | |
michael@0 | 133 | // Gets a texture to use for the clip mask. If true is returned then a cached mask was found |
michael@0 | 134 | // that already contains the rasterization of the clip stack, otherwise an uninitialized texture |
michael@0 | 135 | // is returned. 'willUpload' is set when the alpha mask needs to be uploaded from the CPU. |
michael@0 | 136 | bool getMaskTexture(int32_t elementsGenID, |
michael@0 | 137 | const SkIRect& clipSpaceIBounds, |
michael@0 | 138 | GrTexture** result, |
michael@0 | 139 | bool willUpload); |
michael@0 | 140 | |
michael@0 | 141 | bool useSWOnlyPath(const GrReducedClip::ElementList& elements); |
michael@0 | 142 | |
michael@0 | 143 | // Draws a clip element into the target alpha mask. The caller should have already setup the |
michael@0 | 144 | // desired blend operation. Optionally if the caller already selected a path renderer it can |
michael@0 | 145 | // be passed. Otherwise the function will select one if the element is a path. |
michael@0 | 146 | bool drawElement(GrTexture* target, const SkClipStack::Element*, GrPathRenderer* = NULL); |
michael@0 | 147 | |
michael@0 | 148 | // Determines whether it is possible to draw the element to both the stencil buffer and the |
michael@0 | 149 | // alpha mask simultaneously. If so and the element is a path a compatible path renderer is |
michael@0 | 150 | // also returned. |
michael@0 | 151 | bool canStencilAndDrawElement(GrTexture* target, const SkClipStack::Element*, GrPathRenderer**); |
michael@0 | 152 | |
michael@0 | 153 | void mergeMask(GrTexture* dstMask, |
michael@0 | 154 | GrTexture* srcMask, |
michael@0 | 155 | SkRegion::Op op, |
michael@0 | 156 | const SkIRect& dstBound, |
michael@0 | 157 | const SkIRect& srcBound); |
michael@0 | 158 | |
michael@0 | 159 | void getTemp(int width, int height, GrAutoScratchTexture* temp); |
michael@0 | 160 | |
michael@0 | 161 | void setupCache(const SkClipStack& clip, |
michael@0 | 162 | const SkIRect& bounds); |
michael@0 | 163 | |
michael@0 | 164 | /** |
michael@0 | 165 | * Called prior to return control back the GrGpu in setupClipping. It |
michael@0 | 166 | * updates the GrGpu with stencil settings that account stencil-based |
michael@0 | 167 | * clipping. |
michael@0 | 168 | */ |
michael@0 | 169 | void setGpuStencil(); |
michael@0 | 170 | |
michael@0 | 171 | /** |
michael@0 | 172 | * Adjusts the stencil settings to account for interaction with stencil |
michael@0 | 173 | * clipping. |
michael@0 | 174 | */ |
michael@0 | 175 | void adjustStencilParams(GrStencilSettings* settings, |
michael@0 | 176 | StencilClipMode mode, |
michael@0 | 177 | int stencilBitCnt); |
michael@0 | 178 | |
michael@0 | 179 | typedef SkNoncopyable INHERITED; |
michael@0 | 180 | }; |
michael@0 | 181 | |
michael@0 | 182 | #endif // GrClipMaskManager_DEFINED |