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.
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
8 #ifndef GrClipMaskCache_DEFINED
9 #define GrClipMaskCache_DEFINED
11 #include "GrContext.h"
12 #include "SkClipStack.h"
13 #include "SkTypes.h"
15 class GrTexture;
17 /**
18 * The stencil buffer stores the last clip path - providing a single entry
19 * "cache". This class provides similar functionality for AA clip paths
20 */
21 class GrClipMaskCache : public SkNoncopyable {
22 public:
23 GrClipMaskCache();
25 ~GrClipMaskCache() {
27 while (!fStack.empty()) {
28 GrClipStackFrame* temp = (GrClipStackFrame*) fStack.back();
29 temp->~GrClipStackFrame();
30 fStack.pop_back();
31 }
32 }
34 bool canReuse(int32_t clipGenID, const SkIRect& bounds) {
36 SkASSERT(clipGenID != SkClipStack::kWideOpenGenID);
37 SkASSERT(clipGenID != SkClipStack::kEmptyGenID);
39 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
41 // We could reuse the mask if bounds is a subset of last bounds. We'd have to communicate
42 // an offset to the caller.
43 if (back->fLastMask.texture() &&
44 back->fLastBound == bounds &&
45 back->fLastClipGenID == clipGenID) {
46 return true;
47 }
49 return false;
50 }
52 void reset() {
53 if (fStack.empty()) {
54 // SkASSERT(false);
55 return;
56 }
58 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
60 back->reset();
61 }
63 /**
64 * After a "push" the clip state is entirely open. Currently, the
65 * entire clip stack will be re-rendered into a new clip mask.
66 * TODO: can we take advantage of the nested nature of the clips to
67 * reduce the mask creation cost?
68 */
69 void push();
71 void pop() {
72 //SkASSERT(!fStack.empty());
74 if (!fStack.empty()) {
75 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
77 back->~GrClipStackFrame();
78 fStack.pop_back();
79 }
80 }
82 int32_t getLastClipGenID() const {
84 if (fStack.empty()) {
85 return SkClipStack::kInvalidGenID;
86 }
88 return ((GrClipStackFrame*) fStack.back())->fLastClipGenID;
89 }
91 GrTexture* getLastMask() {
93 if (fStack.empty()) {
94 SkASSERT(false);
95 return NULL;
96 }
98 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
100 return back->fLastMask.texture();
101 }
103 const GrTexture* getLastMask() const {
105 if (fStack.empty()) {
106 SkASSERT(false);
107 return NULL;
108 }
110 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
112 return back->fLastMask.texture();
113 }
115 void acquireMask(int32_t clipGenID,
116 const GrTextureDesc& desc,
117 const SkIRect& bound) {
119 if (fStack.empty()) {
120 SkASSERT(false);
121 return;
122 }
124 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
126 back->acquireMask(fContext, clipGenID, desc, bound);
127 }
129 int getLastMaskWidth() const {
131 if (fStack.empty()) {
132 SkASSERT(false);
133 return -1;
134 }
136 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
138 if (NULL == back->fLastMask.texture()) {
139 return -1;
140 }
142 return back->fLastMask.texture()->width();
143 }
145 int getLastMaskHeight() const {
147 if (fStack.empty()) {
148 SkASSERT(false);
149 return -1;
150 }
152 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
154 if (NULL == back->fLastMask.texture()) {
155 return -1;
156 }
158 return back->fLastMask.texture()->height();
159 }
161 void getLastBound(SkIRect* bound) const {
163 if (fStack.empty()) {
164 SkASSERT(false);
165 bound->setEmpty();
166 return;
167 }
169 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back();
171 *bound = back->fLastBound;
172 }
174 void setContext(GrContext* context) {
175 fContext = context;
176 }
178 GrContext* getContext() {
179 return fContext;
180 }
182 void releaseResources() {
184 SkDeque::F2BIter iter(fStack);
185 for (GrClipStackFrame* frame = (GrClipStackFrame*) iter.next();
186 frame != NULL;
187 frame = (GrClipStackFrame*) iter.next()) {
188 frame->reset();
189 }
190 }
192 private:
193 struct GrClipStackFrame {
195 GrClipStackFrame() {
196 this->reset();
197 }
199 void acquireMask(GrContext* context,
200 int32_t clipGenID,
201 const GrTextureDesc& desc,
202 const SkIRect& bound) {
204 fLastClipGenID = clipGenID;
206 fLastMask.set(context, desc);
208 fLastBound = bound;
209 }
211 void reset () {
212 fLastClipGenID = SkClipStack::kInvalidGenID;
214 GrTextureDesc desc;
216 fLastMask.set(NULL, desc);
217 fLastBound.setEmpty();
218 }
220 int32_t fLastClipGenID;
221 // The mask's width & height values are used by GrClipMaskManager to correctly scale the
222 // texture coords for the geometry drawn with this mask.
223 GrAutoScratchTexture fLastMask;
224 // fLastBound stores the bounding box of the clip mask in clip-stack space. This rect is
225 // used by GrClipMaskManager to position a rect and compute texture coords for the mask.
226 SkIRect fLastBound;
227 };
229 GrContext* fContext;
230 SkDeque fStack;
232 typedef SkNoncopyable INHERITED;
233 };
235 #endif // GrClipMaskCache_DEFINED