OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrLayerCache_DEFINED | 8 #ifndef GrLayerCache_DEFINED |
9 #define GrLayerCache_DEFINED | 9 #define GrLayerCache_DEFINED |
10 | 10 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 const SkMatrix& ctm, | 151 const SkMatrix& ctm, |
152 const int* key, | 152 const int* key, |
153 int keySize, | 153 int keySize, |
154 const SkPaint* paint) | 154 const SkPaint* paint) |
155 : fKey(pictureID, ctm, key, keySize, true) | 155 : fKey(pictureID, ctm, key, keySize, true) |
156 , fStart(start) | 156 , fStart(start) |
157 , fStop(stop) | 157 , fStop(stop) |
158 , fSrcIR(srcIR) | 158 , fSrcIR(srcIR) |
159 , fDstIR(dstIR) | 159 , fDstIR(dstIR) |
160 , fOffset(SkIPoint::Make(0, 0)) | 160 , fOffset(SkIPoint::Make(0, 0)) |
161 , fPaint(paint ? new SkPaint(*paint) : NULL) | 161 , fPaint(paint ? new SkPaint(*paint) : nullptr) |
162 , fFilter(NULL) | 162 , fFilter(nullptr) |
163 , fTexture(NULL) | 163 , fTexture(nullptr) |
164 , fRect(SkIRect::MakeEmpty()) | 164 , fRect(SkIRect::MakeEmpty()) |
165 , fPlot(NULL) | 165 , fPlot(nullptr) |
166 , fUses(0) | 166 , fUses(0) |
167 , fLocked(false) { | 167 , fLocked(false) { |
168 SkASSERT(SK_InvalidGenID != pictureID); | 168 SkASSERT(SK_InvalidGenID != pictureID); |
169 | 169 |
170 if (fPaint) { | 170 if (fPaint) { |
171 if (fPaint->getImageFilter()) { | 171 if (fPaint->getImageFilter()) { |
172 fFilter = SkSafeRef(fPaint->getImageFilter()); | 172 fFilter = SkSafeRef(fPaint->getImageFilter()); |
173 fPaint->setImageFilter(NULL); | 173 fPaint->setImageFilter(nullptr); |
174 } | 174 } |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 ~GrCachedLayer() { | 178 ~GrCachedLayer() { |
179 SkSafeUnref(fTexture); | 179 SkSafeUnref(fTexture); |
180 SkSafeUnref(fFilter); | 180 SkSafeUnref(fFilter); |
181 delete fPaint; | 181 delete fPaint; |
182 } | 182 } |
183 | 183 |
(...skipping 16 matching lines...) Expand all Loading... |
200 } | 200 } |
201 GrTexture* texture() { return fTexture; } | 201 GrTexture* texture() { return fTexture; } |
202 const SkPaint* paint() const { return fPaint; } | 202 const SkPaint* paint() const { return fPaint; } |
203 const SkImageFilter* filter() const { return fFilter; } | 203 const SkImageFilter* filter() const { return fFilter; } |
204 const SkIRect& rect() const { return fRect; } | 204 const SkIRect& rect() const { return fRect; } |
205 | 205 |
206 void setOffset(const SkIPoint& offset) { fOffset = offset; } | 206 void setOffset(const SkIPoint& offset) { fOffset = offset; } |
207 const SkIPoint& offset() const { return fOffset; } | 207 const SkIPoint& offset() const { return fOffset; } |
208 | 208 |
209 void setPlot(GrPlot* plot) { | 209 void setPlot(GrPlot* plot) { |
210 SkASSERT(NULL == plot || NULL == fPlot); | 210 SkASSERT(nullptr == plot || nullptr == fPlot); |
211 fPlot = plot; | 211 fPlot = plot; |
212 } | 212 } |
213 GrPlot* plot() { return fPlot; } | 213 GrPlot* plot() { return fPlot; } |
214 | 214 |
215 bool isAtlased() const { return SkToBool(fPlot); } | 215 bool isAtlased() const { return SkToBool(fPlot); } |
216 | 216 |
217 void setLocked(bool locked) { fLocked = locked; } | 217 void setLocked(bool locked) { fLocked = locked; } |
218 bool locked() const { return fLocked; } | 218 bool locked() const { return fLocked; } |
219 | 219 |
220 SkDEBUGCODE(const GrPlot* plot() const { return fPlot; }) | 220 SkDEBUGCODE(const GrPlot* plot() const { return fPlot; }) |
221 SkDEBUGCODE(void validate(const GrTexture* backingTexture) const;) | 221 SkDEBUGCODE(void validate(const GrTexture* backingTexture) const;) |
222 | 222 |
223 private: | 223 private: |
224 const Key fKey; | 224 const Key fKey; |
225 | 225 |
226 // The "saveLayer" operation index of the cached layer | 226 // The "saveLayer" operation index of the cached layer |
227 const int fStart; | 227 const int fStart; |
228 // The final "restore" operation index of the cached layer | 228 // The final "restore" operation index of the cached layer |
229 const int fStop; | 229 const int fStop; |
230 | 230 |
231 // The layer's src rect (i.e., the portion of the source scene required | 231 // The layer's src rect (i.e., the portion of the source scene required |
232 // for filtering). | 232 // for filtering). |
233 const SkIRect fSrcIR; | 233 const SkIRect fSrcIR; |
234 // The layer's dest rect (i.e., where it will land in device space) | 234 // The layer's dest rect (i.e., where it will land in device space) |
235 const SkIRect fDstIR; | 235 const SkIRect fDstIR; |
236 // Offset sometimes required by image filters | 236 // Offset sometimes required by image filters |
237 SkIPoint fOffset; | 237 SkIPoint fOffset; |
238 | 238 |
239 // The paint used when dropping the layer down into the owning canvas. | 239 // The paint used when dropping the layer down into the owning canvas. |
240 // Can be NULL. This class makes a copy for itself. | 240 // Can be nullptr. This class makes a copy for itself. |
241 SkPaint* fPaint; | 241 SkPaint* fPaint; |
242 | 242 |
243 // The imagefilter that needs to be applied to the layer prior to it being | 243 // The imagefilter that needs to be applied to the layer prior to it being |
244 // composited with the rest of the scene. | 244 // composited with the rest of the scene. |
245 const SkImageFilter* fFilter; | 245 const SkImageFilter* fFilter; |
246 | 246 |
247 // fTexture is a ref on the atlasing texture for atlased layers and a | 247 // fTexture is a ref on the atlasing texture for atlased layers and a |
248 // ref on a GrTexture for non-atlased textures. | 248 // ref on a GrTexture for non-atlased textures. |
249 GrTexture* fTexture; | 249 GrTexture* fTexture; |
250 | 250 |
251 // For both atlased and non-atlased layers 'fRect' contains the bound of | 251 // For both atlased and non-atlased layers 'fRect' contains the bound of |
252 // the layer in whichever texture it resides. It is empty when 'fTexture' | 252 // the layer in whichever texture it resides. It is empty when 'fTexture' |
253 // is NULL. | 253 // is nullptr. |
254 SkIRect fRect; | 254 SkIRect fRect; |
255 | 255 |
256 // For atlased layers, fPlot stores the atlas plot in which the layer rests. | 256 // For atlased layers, fPlot stores the atlas plot in which the layer rests. |
257 // It is always NULL for non-atlased layers. | 257 // It is always nullptr for non-atlased layers. |
258 GrPlot* fPlot; | 258 GrPlot* fPlot; |
259 | 259 |
260 // The number of actively hoisted layers using this cached image (e.g., | 260 // The number of actively hoisted layers using this cached image (e.g., |
261 // extant GrHoistedLayers pointing at this object). This object will | 261 // extant GrHoistedLayers pointing at this object). This object will |
262 // be unlocked when the use count reaches 0. | 262 // be unlocked when the use count reaches 0. |
263 int fUses; | 263 int fUses; |
264 | 264 |
265 // For non-atlased layers 'fLocked' should always match "fTexture". | 265 // For non-atlased layers 'fLocked' should always match "fTexture". |
266 // (i.e., if there is a texture it is locked). | 266 // (i.e., if there is a texture it is locked). |
267 // For atlased layers, 'fLocked' is true if the layer is in a plot and | 267 // For atlased layers, 'fLocked' is true if the layer is in a plot and |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 SkASSERT(fPlotLocks[plotIdx] > 0); | 402 SkASSERT(fPlotLocks[plotIdx] > 0); |
403 --fPlotLocks[plotIdx]; | 403 --fPlotLocks[plotIdx]; |
404 } | 404 } |
405 | 405 |
406 // for testing | 406 // for testing |
407 friend class TestingAccess; | 407 friend class TestingAccess; |
408 int numLayers() const { return fLayerHash.count(); } | 408 int numLayers() const { return fLayerHash.count(); } |
409 }; | 409 }; |
410 | 410 |
411 #endif | 411 #endif |
OLD | NEW |