OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrClipMaskCache_DEFINED | 8 #ifndef GrClipMaskCache_DEFINED |
9 #define GrClipMaskCache_DEFINED | 9 #define GrClipMaskCache_DEFINED |
10 | 10 |
11 #include "GrContext.h" | 11 #include "GrResourceProvider.h" |
12 #include "SkClipStack.h" | 12 #include "SkClipStack.h" |
13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
14 | 14 |
15 class GrTexture; | 15 class GrTexture; |
16 | 16 |
17 /** | 17 /** |
18 * The stencil buffer stores the last clip path - providing a single entry | 18 * The stencil buffer stores the last clip path - providing a single entry |
19 * "cache". This class provides similar functionality for AA clip paths | 19 * "cache". This class provides similar functionality for AA clip paths |
20 */ | 20 */ |
21 class GrClipMaskCache : SkNoncopyable { | 21 class GrClipMaskCache : SkNoncopyable { |
22 public: | 22 public: |
23 GrClipMaskCache(); | 23 GrClipMaskCache(GrResourceProvider*); |
24 | 24 |
25 ~GrClipMaskCache() { | 25 ~GrClipMaskCache() { |
26 | |
27 while (!fStack.empty()) { | 26 while (!fStack.empty()) { |
28 GrClipStackFrame* temp = (GrClipStackFrame*) fStack.back(); | 27 GrClipStackFrame* temp = (GrClipStackFrame*) fStack.back(); |
29 temp->~GrClipStackFrame(); | 28 temp->~GrClipStackFrame(); |
30 fStack.pop_back(); | 29 fStack.pop_back(); |
31 } | 30 } |
32 } | 31 } |
33 | 32 |
34 bool canReuse(int32_t clipGenID, const SkIRect& bounds) { | 33 bool canReuse(int32_t clipGenID, const SkIRect& bounds) { |
35 | 34 |
36 SkASSERT(clipGenID != SkClipStack::kWideOpenGenID); | 35 SkASSERT(clipGenID != SkClipStack::kWideOpenGenID); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 const GrSurfaceDesc& desc, | 116 const GrSurfaceDesc& desc, |
118 const SkIRect& bound) { | 117 const SkIRect& bound) { |
119 | 118 |
120 if (fStack.empty()) { | 119 if (fStack.empty()) { |
121 SkASSERT(false); | 120 SkASSERT(false); |
122 return; | 121 return; |
123 } | 122 } |
124 | 123 |
125 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); | 124 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); |
126 | 125 |
127 back->acquireMask(fContext, clipGenID, desc, bound); | 126 back->acquireMask(fResourceProvider, clipGenID, desc, bound); |
128 } | 127 } |
129 | 128 |
130 int getLastMaskWidth() const { | 129 int getLastMaskWidth() const { |
131 | 130 |
132 if (fStack.empty()) { | 131 if (fStack.empty()) { |
133 SkASSERT(false); | 132 SkASSERT(false); |
134 return -1; | 133 return -1; |
135 } | 134 } |
136 | 135 |
137 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); | 136 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); |
(...skipping 27 matching lines...) Expand all Loading... |
165 SkASSERT(false); | 164 SkASSERT(false); |
166 bound->setEmpty(); | 165 bound->setEmpty(); |
167 return; | 166 return; |
168 } | 167 } |
169 | 168 |
170 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); | 169 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); |
171 | 170 |
172 *bound = back->fLastBound; | 171 *bound = back->fLastBound; |
173 } | 172 } |
174 | 173 |
175 void setContext(GrContext* context) { | |
176 fContext = context; | |
177 } | |
178 | |
179 GrContext* getContext() { | |
180 return fContext; | |
181 } | |
182 | |
183 // TODO: Remove this when we hold cache keys instead of refs to textures. | 174 // TODO: Remove this when we hold cache keys instead of refs to textures. |
184 void purgeResources() { | 175 void purgeResources() { |
185 SkDeque::F2BIter iter(fStack); | 176 SkDeque::F2BIter iter(fStack); |
186 for (GrClipStackFrame* frame = (GrClipStackFrame*) iter.next(); | 177 for (GrClipStackFrame* frame = (GrClipStackFrame*) iter.next(); |
187 frame != NULL; | 178 frame != NULL; |
188 frame = (GrClipStackFrame*) iter.next()) { | 179 frame = (GrClipStackFrame*) iter.next()) { |
189 frame->reset(); | 180 frame->reset(); |
190 } | 181 } |
191 } | 182 } |
192 | 183 |
193 private: | 184 private: |
194 struct GrClipStackFrame { | 185 struct GrClipStackFrame { |
195 | 186 |
196 GrClipStackFrame() { | 187 GrClipStackFrame() { |
197 this->reset(); | 188 this->reset(); |
198 } | 189 } |
199 | 190 |
200 void acquireMask(GrContext* context, | 191 void acquireMask(GrResourceProvider* resourceProvider, |
201 int32_t clipGenID, | 192 int32_t clipGenID, |
202 const GrSurfaceDesc& desc, | 193 const GrSurfaceDesc& desc, |
203 const SkIRect& bound) { | 194 const SkIRect& bound) { |
204 | 195 |
205 fLastClipGenID = clipGenID; | 196 fLastClipGenID = clipGenID; |
206 | 197 |
207 // HACK: set the last param to true to indicate that this request is
at | 198 // HACK: set the last param to true to indicate that this request is
at |
208 // flush time and therefore we require a scratch texture with no pen
ding IO operations. | 199 // flush time and therefore we require a scratch texture with no pen
ding IO operations. |
209 fLastMask.reset(context->textureProvider()->refScratchTexture( | 200 fLastMask.reset(resourceProvider->refScratchTexture( |
210 desc, GrTextureProvider::kApprox_ScratchTexMatch, /*flushing=*/t
rue)); | 201 desc, GrTextureProvider::kApprox_ScratchTexMatch, /*flushing=*/t
rue)); |
211 | 202 |
212 fLastBound = bound; | 203 fLastBound = bound; |
213 } | 204 } |
214 | 205 |
215 void reset () { | 206 void reset () { |
216 fLastClipGenID = SkClipStack::kInvalidGenID; | 207 fLastClipGenID = SkClipStack::kInvalidGenID; |
217 | 208 |
218 GrSurfaceDesc desc; | 209 GrSurfaceDesc desc; |
219 | 210 |
220 fLastMask.reset(NULL); | 211 fLastMask.reset(NULL); |
221 fLastBound.setEmpty(); | 212 fLastBound.setEmpty(); |
222 } | 213 } |
223 | 214 |
224 int32_t fLastClipGenID; | 215 int32_t fLastClipGenID; |
225 // The mask's width & height values are used by GrClipMaskManager to cor
rectly scale the | 216 // The mask's width & height values are used by GrClipMaskManager to cor
rectly scale the |
226 // texture coords for the geometry drawn with this mask. TODO: This shou
ld be a cache key | 217 // texture coords for the geometry drawn with this mask. TODO: This shou
ld be a cache key |
227 // and not a hard ref to a texture. | 218 // and not a hard ref to a texture. |
228 SkAutoTUnref<GrTexture> fLastMask; | 219 SkAutoTUnref<GrTexture> fLastMask; |
229 // fLastBound stores the bounding box of the clip mask in clip-stack spa
ce. This rect is | 220 // fLastBound stores the bounding box of the clip mask in clip-stack spa
ce. This rect is |
230 // used by GrClipMaskManager to position a rect and compute texture coor
ds for the mask. | 221 // used by GrClipMaskManager to position a rect and compute texture coor
ds for the mask. |
231 SkIRect fLastBound; | 222 SkIRect fLastBound; |
232 }; | 223 }; |
233 | 224 |
234 GrContext* fContext; | 225 SkDeque fStack; |
235 SkDeque fStack; | 226 GrResourceProvider* fResourceProvider; |
236 | 227 |
237 typedef SkNoncopyable INHERITED; | 228 typedef SkNoncopyable INHERITED; |
238 }; | 229 }; |
239 | 230 |
240 #endif // GrClipMaskCache_DEFINED | 231 #endif // GrClipMaskCache_DEFINED |
OLD | NEW |