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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 const unsigned* fKey; | 137 const unsigned* fKey; |
138 const int fKeySize; | 138 const int fKeySize; |
139 bool fFreeKey; | 139 bool fFreeKey; |
140 }; | 140 }; |
141 | 141 |
142 static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; } | 142 static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; } |
143 static uint32_t Hash(const Key& key) { return key.hash(); } | 143 static uint32_t Hash(const Key& key) { return key.hash(); } |
144 | 144 |
145 // GrCachedLayer proper | 145 // GrCachedLayer proper |
146 GrCachedLayer(uint32_t pictureID, unsigned start, unsigned stop, | 146 GrCachedLayer(uint32_t pictureID, unsigned start, unsigned stop, |
147 const SkIRect& bounds, const SkMatrix& ctm, | 147 const SkIRect& srcIR, const SkIRect& dstIR, |
| 148 const SkMatrix& ctm, |
148 const unsigned* key, int keySize, | 149 const unsigned* key, int keySize, |
149 const SkPaint* paint) | 150 const SkPaint* paint) |
150 : fKey(pictureID, ctm, key, keySize, true) | 151 : fKey(pictureID, ctm, key, keySize, true) |
151 , fStart(start) | 152 , fStart(start) |
152 , fStop(stop) | 153 , fStop(stop) |
153 , fBounds(bounds) | 154 , fSrcIR(srcIR) |
| 155 , fDstIR(dstIR) |
| 156 , fOffset(SkIPoint::Make(0, 0)) |
154 , fPaint(paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL) | 157 , fPaint(paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL) |
155 , fFilter(NULL) | 158 , fFilter(NULL) |
156 , fTexture(NULL) | 159 , fTexture(NULL) |
157 , fRect(SkIRect::MakeEmpty()) | 160 , fRect(SkIRect::MakeEmpty()) |
158 , fPlot(NULL) | 161 , fPlot(NULL) |
159 , fUses(0) | 162 , fUses(0) |
160 , fLocked(false) { | 163 , fLocked(false) { |
161 SkASSERT(SK_InvalidGenID != pictureID); | 164 SkASSERT(SK_InvalidGenID != pictureID); |
162 | 165 |
163 if (fPaint) { | 166 if (fPaint) { |
164 fFilter = SkSafeRef(fPaint->getImageFilter()); | 167 if (fPaint->getImageFilter() && fPaint->getImageFilter()->canFilterI
mageGPU()) { |
165 fPaint->setImageFilter(NULL); | 168 fFilter = SkSafeRef(fPaint->getImageFilter()); |
| 169 fPaint->setImageFilter(NULL); |
| 170 } |
166 } | 171 } |
167 } | 172 } |
168 | 173 |
169 ~GrCachedLayer() { | 174 ~GrCachedLayer() { |
170 SkSafeUnref(fTexture); | 175 SkSafeUnref(fTexture); |
171 SkSafeUnref(fFilter); | 176 SkSafeUnref(fFilter); |
172 SkDELETE(fPaint); | 177 SkDELETE(fPaint); |
173 } | 178 } |
174 | 179 |
175 uint32_t pictureID() const { return fKey.pictureID(); } | 180 uint32_t pictureID() const { return fKey.pictureID(); } |
176 // TODO: remove these when GrCachedLayer & ReplacementInfo fuse | 181 // TODO: remove these when GrCachedLayer & ReplacementInfo fuse |
177 const unsigned* key() const { return fKey.key(); } | 182 const unsigned* key() const { return fKey.key(); } |
178 int keySize() const { return fKey.keySize(); } | 183 int keySize() const { return fKey.keySize(); } |
179 | 184 |
180 unsigned start() const { return fStart; } | 185 unsigned start() const { return fStart; } |
181 // TODO: make bound debug only | 186 // TODO: make bound debug only |
182 const SkIRect& bound() const { return fBounds; } | 187 const SkIRect& srcIR() const { return fSrcIR; } |
| 188 const SkIRect& dstIR() const { return fDstIR; } |
183 unsigned stop() const { return fStop; } | 189 unsigned stop() const { return fStop; } |
184 void setTexture(GrTexture* texture, const SkIRect& rect) { | 190 void setTexture(GrTexture* texture, const SkIRect& rect) { |
185 SkRefCnt_SafeAssign(fTexture, texture); | 191 SkRefCnt_SafeAssign(fTexture, texture); |
186 fRect = rect; | 192 fRect = rect; |
187 } | 193 } |
188 GrTexture* texture() { return fTexture; } | 194 GrTexture* texture() { return fTexture; } |
189 const SkPaint* paint() const { return fPaint; } | 195 const SkPaint* paint() const { return fPaint; } |
190 const SkImageFilter* filter() const { return fFilter; } | 196 const SkImageFilter* filter() const { return fFilter; } |
191 const SkIRect& rect() const { return fRect; } | 197 const SkIRect& rect() const { return fRect; } |
192 | 198 |
| 199 void setOffset(const SkIPoint& offset) { fOffset = offset; } |
| 200 const SkIPoint& offset() const { return fOffset; } |
| 201 |
193 void setPlot(GrPlot* plot) { | 202 void setPlot(GrPlot* plot) { |
194 SkASSERT(NULL == plot || NULL == fPlot); | 203 SkASSERT(NULL == plot || NULL == fPlot); |
195 fPlot = plot; | 204 fPlot = plot; |
196 } | 205 } |
197 GrPlot* plot() { return fPlot; } | 206 GrPlot* plot() { return fPlot; } |
198 | 207 |
199 bool isAtlased() const { return SkToBool(fPlot); } | 208 bool isAtlased() const { return SkToBool(fPlot); } |
200 | 209 |
201 void setLocked(bool locked) { fLocked = locked; } | 210 void setLocked(bool locked) { fLocked = locked; } |
202 bool locked() const { return fLocked; } | 211 bool locked() const { return fLocked; } |
203 | 212 |
204 SkDEBUGCODE(const GrPlot* plot() const { return fPlot; }) | 213 SkDEBUGCODE(const GrPlot* plot() const { return fPlot; }) |
205 SkDEBUGCODE(void validate(const GrTexture* backingTexture) const;) | 214 SkDEBUGCODE(void validate(const GrTexture* backingTexture) const;) |
206 | 215 |
207 private: | 216 private: |
208 const Key fKey; | 217 const Key fKey; |
209 | 218 |
210 // The "saveLayer" operation index of the cached layer | 219 // The "saveLayer" operation index of the cached layer |
211 const unsigned fStart; | 220 const unsigned fStart; |
212 // The final "restore" operation index of the cached layer | 221 // The final "restore" operation index of the cached layer |
213 const unsigned fStop; | 222 const unsigned fStop; |
214 | 223 |
215 const SkIRect fBounds; | 224 // The layer's src rect (i.e., the portion of the source scene required |
| 225 // for filtering). |
| 226 const SkIRect fSrcIR; |
| 227 // The layer's dest rect (i.e., where it will land in device space) |
| 228 const SkIRect fDstIR; |
| 229 // Offset sometimes required by image filters |
| 230 SkIPoint fOffset; |
216 | 231 |
217 // The paint used when dropping the layer down into the owning canvas. | 232 // The paint used when dropping the layer down into the owning canvas. |
218 // Can be NULL. This class makes a copy for itself. | 233 // Can be NULL. This class makes a copy for itself. |
219 SkPaint* fPaint; | 234 SkPaint* fPaint; |
220 | 235 |
221 // The imagefilter that needs to be applied to the layer prior to it being | 236 // The imagefilter that needs to be applied to the layer prior to it being |
222 // composited with the rest of the scene. | 237 // composited with the rest of the scene. |
223 const SkImageFilter* fFilter; | 238 const SkImageFilter* fFilter; |
224 | 239 |
225 // fTexture is a ref on the atlasing texture for atlased layers and a | 240 // fTexture is a ref on the atlasing texture for atlased layers and a |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 ~GrLayerCache(); | 284 ~GrLayerCache(); |
270 | 285 |
271 // As a cache, the GrLayerCache can be ordered to free up all its cached | 286 // As a cache, the GrLayerCache can be ordered to free up all its cached |
272 // elements by the GrContext | 287 // elements by the GrContext |
273 void freeAll(); | 288 void freeAll(); |
274 | 289 |
275 GrCachedLayer* findLayer(uint32_t pictureID, const SkMatrix& ctm, | 290 GrCachedLayer* findLayer(uint32_t pictureID, const SkMatrix& ctm, |
276 const unsigned* key, int keySize); | 291 const unsigned* key, int keySize); |
277 GrCachedLayer* findLayerOrCreate(uint32_t pictureID, | 292 GrCachedLayer* findLayerOrCreate(uint32_t pictureID, |
278 int start, int stop, | 293 int start, int stop, |
279 const SkIRect& bounds, | 294 const SkIRect& srcIR, |
| 295 const SkIRect& dstIR, |
280 const SkMatrix& initialMat, | 296 const SkMatrix& initialMat, |
281 const unsigned* key, int keySize, | 297 const unsigned* key, int keySize, |
282 const SkPaint* paint); | 298 const SkPaint* paint); |
283 | 299 |
284 // Attempt to place 'layer' in the atlas. Return true on success; false on f
ailure. | 300 // Attempt to place 'layer' in the atlas. Return true on success; false on f
ailure. |
285 // When true is returned, 'needsRendering' will indicate if the layer must b
e (re)drawn. | 301 // When true is returned, 'needsRendering' will indicate if the layer must b
e (re)drawn. |
286 // Additionally, the GPU resources will be locked. | 302 // Additionally, the GPU resources will be locked. |
287 bool tryToAtlas(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* needs
Rendering); | 303 bool tryToAtlas(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* needs
Rendering); |
288 | 304 |
289 // Attempt to lock the GPU resources required for a layer. Return true on su
ccess; | 305 // Attempt to lock the GPU resources required for a layer. Return true on su
ccess; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 // count for that plot. Similarly, once a rendering is complete all the | 369 // count for that plot. Similarly, once a rendering is complete all the |
354 // layers used in it decrement the lock count for the used plots. | 370 // layers used in it decrement the lock count for the used plots. |
355 // Plots with a 0 lock count are open for recycling/purging. | 371 // Plots with a 0 lock count are open for recycling/purging. |
356 int fPlotLocks[kNumPlotsX * kNumPlotsY]; | 372 int fPlotLocks[kNumPlotsX * kNumPlotsY]; |
357 | 373 |
358 // Inform the cache that layer's cached image is not currently required | 374 // Inform the cache that layer's cached image is not currently required |
359 void unlock(GrCachedLayer* layer); | 375 void unlock(GrCachedLayer* layer); |
360 | 376 |
361 void initAtlas(); | 377 void initAtlas(); |
362 GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop, | 378 GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop, |
363 const SkIRect& bounds, const SkMatrix& initialMat
, | 379 const SkIRect& srcIR, const SkIRect& dstIR, |
| 380 const SkMatrix& initialMat, |
364 const unsigned* key, int keySize, | 381 const unsigned* key, int keySize, |
365 const SkPaint* paint); | 382 const SkPaint* paint); |
366 | 383 |
367 // Remove all the layers (and unlock any resources) associated with 'picture
ID' | 384 // Remove all the layers (and unlock any resources) associated with 'picture
ID' |
368 void purge(uint32_t pictureID); | 385 void purge(uint32_t pictureID); |
369 | 386 |
370 void purgePlot(GrPlot* plot); | 387 void purgePlot(GrPlot* plot); |
371 | 388 |
372 // Try to find a purgeable plot and clear it out. Return true if a plot | 389 // Try to find a purgeable plot and clear it out. Return true if a plot |
373 // was purged; false otherwise. | 390 // was purged; false otherwise. |
374 bool purgePlot(); | 391 bool purgePlot(); |
375 | 392 |
376 void incPlotLock(int plotIdx) { ++fPlotLocks[plotIdx]; } | 393 void incPlotLock(int plotIdx) { ++fPlotLocks[plotIdx]; } |
377 void decPlotLock(int plotIdx) { | 394 void decPlotLock(int plotIdx) { |
378 SkASSERT(fPlotLocks[plotIdx] > 0); | 395 SkASSERT(fPlotLocks[plotIdx] > 0); |
379 --fPlotLocks[plotIdx]; | 396 --fPlotLocks[plotIdx]; |
380 } | 397 } |
381 | 398 |
382 // for testing | 399 // for testing |
383 friend class TestingAccess; | 400 friend class TestingAccess; |
384 int numLayers() const { return fLayerHash.count(); } | 401 int numLayers() const { return fLayerHash.count(); } |
385 }; | 402 }; |
386 | 403 |
387 #endif | 404 #endif |
OLD | NEW |