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 22 matching lines...) Expand all Loading... |
33 | 33 |
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 && |
44 !back->fLastMask.texture()->wasDestroyed() && | 44 !back->fLastMask->wasDestroyed() && |
45 back->fLastBound == bounds && | 45 back->fLastBound == bounds && |
46 back->fLastClipGenID == clipGenID) { | 46 back->fLastClipGenID == clipGenID) { |
47 return true; | 47 return true; |
48 } | 48 } |
49 | 49 |
50 return false; | 50 return false; |
51 } | 51 } |
52 | 52 |
53 void reset() { | 53 void reset() { |
54 if (fStack.empty()) { | 54 if (fStack.empty()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 GrTexture* getLastMask() { | 92 GrTexture* getLastMask() { |
93 | 93 |
94 if (fStack.empty()) { | 94 if (fStack.empty()) { |
95 SkASSERT(false); | 95 SkASSERT(false); |
96 return NULL; | 96 return NULL; |
97 } | 97 } |
98 | 98 |
99 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); | 99 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); |
100 | 100 |
101 return back->fLastMask.texture(); | 101 return back->fLastMask; |
102 } | 102 } |
103 | 103 |
104 const GrTexture* getLastMask() const { | 104 const GrTexture* getLastMask() const { |
105 | 105 |
106 if (fStack.empty()) { | 106 if (fStack.empty()) { |
107 SkASSERT(false); | 107 SkASSERT(false); |
108 return NULL; | 108 return NULL; |
109 } | 109 } |
110 | 110 |
111 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); | 111 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); |
112 | 112 |
113 return back->fLastMask.texture(); | 113 return back->fLastMask; |
114 } | 114 } |
115 | 115 |
116 void acquireMask(int32_t clipGenID, | 116 void acquireMask(int32_t clipGenID, |
117 const GrTextureDesc& desc, | 117 const GrTextureDesc& desc, |
118 const SkIRect& bound) { | 118 const SkIRect& bound) { |
119 | 119 |
120 if (fStack.empty()) { | 120 if (fStack.empty()) { |
121 SkASSERT(false); | 121 SkASSERT(false); |
122 return; | 122 return; |
123 } | 123 } |
124 | 124 |
125 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); | 125 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); |
126 | 126 |
127 back->acquireMask(fContext, clipGenID, desc, bound); | 127 back->acquireMask(fContext, clipGenID, desc, bound); |
128 } | 128 } |
129 | 129 |
130 int getLastMaskWidth() const { | 130 int getLastMaskWidth() const { |
131 | 131 |
132 if (fStack.empty()) { | 132 if (fStack.empty()) { |
133 SkASSERT(false); | 133 SkASSERT(false); |
134 return -1; | 134 return -1; |
135 } | 135 } |
136 | 136 |
137 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); | 137 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); |
138 | 138 |
139 if (NULL == back->fLastMask.texture()) { | 139 if (NULL == back->fLastMask) { |
140 return -1; | 140 return -1; |
141 } | 141 } |
142 | 142 |
143 return back->fLastMask.texture()->width(); | 143 return back->fLastMask->width(); |
144 } | 144 } |
145 | 145 |
146 int getLastMaskHeight() const { | 146 int getLastMaskHeight() const { |
147 | 147 |
148 if (fStack.empty()) { | 148 if (fStack.empty()) { |
149 SkASSERT(false); | 149 SkASSERT(false); |
150 return -1; | 150 return -1; |
151 } | 151 } |
152 | 152 |
153 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); | 153 GrClipStackFrame* back = (GrClipStackFrame*) fStack.back(); |
154 | 154 |
155 if (NULL == back->fLastMask.texture()) { | 155 if (NULL == back->fLastMask) { |
156 return -1; | 156 return -1; |
157 } | 157 } |
158 | 158 |
159 return back->fLastMask.texture()->height(); | 159 return back->fLastMask->height(); |
160 } | 160 } |
161 | 161 |
162 void getLastBound(SkIRect* bound) const { | 162 void getLastBound(SkIRect* bound) const { |
163 | 163 |
164 if (fStack.empty()) { | 164 if (fStack.empty()) { |
165 SkASSERT(false); | 165 SkASSERT(false); |
166 bound->setEmpty(); | 166 bound->setEmpty(); |
167 return; | 167 return; |
168 } | 168 } |
169 | 169 |
(...skipping 29 matching lines...) Expand all Loading... |
199 | 199 |
200 void acquireMask(GrContext* context, | 200 void acquireMask(GrContext* context, |
201 int32_t clipGenID, | 201 int32_t clipGenID, |
202 const GrTextureDesc& desc, | 202 const GrTextureDesc& desc, |
203 const SkIRect& bound) { | 203 const SkIRect& bound) { |
204 | 204 |
205 fLastClipGenID = clipGenID; | 205 fLastClipGenID = clipGenID; |
206 | 206 |
207 // HACK: set the last param to true to indicate that this request is
at | 207 // 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. | 208 // flush time and therefore we require a scratch texture with no pen
ding IO operations. |
209 fLastMask.set(context, desc, GrContext::kApprox_ScratchTexMatch, /*f
lushing=*/true); | 209 fLastMask.reset(context->refScratchTexture(desc, GrContext::kApprox_
ScratchTexMatch, |
| 210 /*flushing=*/true)); |
210 | 211 |
211 fLastBound = bound; | 212 fLastBound = bound; |
212 } | 213 } |
213 | 214 |
214 void reset () { | 215 void reset () { |
215 fLastClipGenID = SkClipStack::kInvalidGenID; | 216 fLastClipGenID = SkClipStack::kInvalidGenID; |
216 | 217 |
217 GrTextureDesc desc; | 218 GrTextureDesc desc; |
218 | 219 |
219 fLastMask.set(NULL, desc); | 220 fLastMask.reset(NULL); |
220 fLastBound.setEmpty(); | 221 fLastBound.setEmpty(); |
221 } | 222 } |
222 | 223 |
223 int32_t fLastClipGenID; | 224 int32_t fLastClipGenID; |
224 // The mask's width & height values are used by GrClipMaskManager to cor
rectly scale the | 225 // The mask's width & height values are used by GrClipMaskManager to cor
rectly scale the |
225 // texture coords for the geometry drawn with this mask. TODO: This shou
ld be a cache key | 226 // texture coords for the geometry drawn with this mask. TODO: This shou
ld be a cache key |
226 // and not a hard ref to a texture. | 227 // and not a hard ref to a texture. |
227 GrAutoScratchTexture fLastMask; | 228 SkAutoTUnref<GrTexture> fLastMask; |
228 // fLastBound stores the bounding box of the clip mask in clip-stack spa
ce. This rect is | 229 // fLastBound stores the bounding box of the clip mask in clip-stack spa
ce. This rect is |
229 // used by GrClipMaskManager to position a rect and compute texture coor
ds for the mask. | 230 // used by GrClipMaskManager to position a rect and compute texture coor
ds for the mask. |
230 SkIRect fLastBound; | 231 SkIRect fLastBound; |
231 }; | 232 }; |
232 | 233 |
233 GrContext* fContext; | 234 GrContext* fContext; |
234 SkDeque fStack; | 235 SkDeque fStack; |
235 | 236 |
236 typedef SkNoncopyable INHERITED; | 237 typedef SkNoncopyable INHERITED; |
237 }; | 238 }; |
238 | 239 |
239 #endif // GrClipMaskCache_DEFINED | 240 #endif // GrClipMaskCache_DEFINED |
OLD | NEW |