| 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 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 bool canReuse(int32_t clipGenID, const SkIRect& bounds) { | 34 bool canReuse(int32_t clipGenID, const SkIRect& bounds) { |
| 35 | 35 |
| 36 SkASSERT(clipGenID != SkClipStack::kWideOpenGenID); | 36 SkASSERT(clipGenID != SkClipStack::kWideOpenGenID); |
| 37 SkASSERT(clipGenID != SkClipStack::kEmptyGenID); | 37 SkASSERT(clipGenID != SkClipStack::kEmptyGenID); |
| 38 | 38 |
| 39 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); | 39 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); |
| 40 | 40 |
| 41 // We could reuse the mask if bounds is a subset of last bounds. We'd ha
ve to communicate | 41 // We could reuse the mask if bounds is a subset of last bounds. We'd ha
ve to communicate |
| 42 // an offset to the caller. | 42 // an offset to the caller. |
| 43 if (back->fLastMask.texture() && | 43 if (back->fLastMask.texture() && |
| 44 !back->fLastMask.texture()->wasDestroyed() && |
| 44 back->fLastBound == bounds && | 45 back->fLastBound == bounds && |
| 45 back->fLastClipGenID == clipGenID) { | 46 back->fLastClipGenID == clipGenID) { |
| 46 return true; | 47 return true; |
| 47 } | 48 } |
| 48 | 49 |
| 49 return false; | 50 return false; |
| 50 } | 51 } |
| 51 | 52 |
| 52 void reset() { | 53 void reset() { |
| 53 if (fStack.empty()) { | 54 if (fStack.empty()) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 173 } |
| 173 | 174 |
| 174 void setContext(GrContext* context) { | 175 void setContext(GrContext* context) { |
| 175 fContext = context; | 176 fContext = context; |
| 176 } | 177 } |
| 177 | 178 |
| 178 GrContext* getContext() { | 179 GrContext* getContext() { |
| 179 return fContext; | 180 return fContext; |
| 180 } | 181 } |
| 181 | 182 |
| 182 void releaseResources() { | 183 // TODO: Remove this when we hold cache keys instead of refs to textures. |
| 183 | 184 void purgeResources() { |
| 184 SkDeque::F2BIter iter(fStack); | 185 SkDeque::F2BIter iter(fStack); |
| 185 for (GrClipStackFrame* frame = (GrClipStackFrame*) iter.next(); | 186 for (GrClipStackFrame* frame = (GrClipStackFrame*) iter.next(); |
| 186 frame != NULL; | 187 frame != NULL; |
| 187 frame = (GrClipStackFrame*) iter.next()) { | 188 frame = (GrClipStackFrame*) iter.next()) { |
| 188 frame->reset(); | 189 frame->reset(); |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| 192 private: | 193 private: |
| 193 struct GrClipStackFrame { | 194 struct GrClipStackFrame { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 212 fLastClipGenID = SkClipStack::kInvalidGenID; | 213 fLastClipGenID = SkClipStack::kInvalidGenID; |
| 213 | 214 |
| 214 GrTextureDesc desc; | 215 GrTextureDesc desc; |
| 215 | 216 |
| 216 fLastMask.set(NULL, desc); | 217 fLastMask.set(NULL, desc); |
| 217 fLastBound.setEmpty(); | 218 fLastBound.setEmpty(); |
| 218 } | 219 } |
| 219 | 220 |
| 220 int32_t fLastClipGenID; | 221 int32_t fLastClipGenID; |
| 221 // The mask's width & height values are used by GrClipMaskManager to cor
rectly scale the | 222 // The mask's width & height values are used by GrClipMaskManager to cor
rectly scale the |
| 222 // texture coords for the geometry drawn with this mask. | 223 // texture coords for the geometry drawn with this mask. TODO: This shou
ld be a cache key |
| 224 // and not a hard ref to a texture. |
| 223 GrAutoScratchTexture fLastMask; | 225 GrAutoScratchTexture fLastMask; |
| 224 // fLastBound stores the bounding box of the clip mask in clip-stack spa
ce. This rect is | 226 // fLastBound stores the bounding box of the clip mask in clip-stack spa
ce. This rect is |
| 225 // used by GrClipMaskManager to position a rect and compute texture coor
ds for the mask. | 227 // used by GrClipMaskManager to position a rect and compute texture coor
ds for the mask. |
| 226 SkIRect fLastBound; | 228 SkIRect fLastBound; |
| 227 }; | 229 }; |
| 228 | 230 |
| 229 GrContext* fContext; | 231 GrContext* fContext; |
| 230 SkDeque fStack; | 232 SkDeque fStack; |
| 231 | 233 |
| 232 typedef SkNoncopyable INHERITED; | 234 typedef SkNoncopyable INHERITED; |
| 233 }; | 235 }; |
| 234 | 236 |
| 235 #endif // GrClipMaskCache_DEFINED | 237 #endif // GrClipMaskCache_DEFINED |
| OLD | NEW |