| 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 |
| 11 #include "GrAtlas.h" | 11 #include "GrAtlas.h" |
| 12 #include "GrRect.h" | 12 #include "GrRect.h" |
| 13 | 13 |
| 14 #include "SkChecksum.h" | 14 #include "SkChecksum.h" |
| 15 #include "SkMessageBus.h" | 15 #include "SkMessageBus.h" |
| 16 #include "SkPicture.h" | 16 #include "SkPicture.h" |
| 17 #include "SkTDynamicHash.h" | 17 #include "SkTDynamicHash.h" |
| 18 | 18 |
| 19 // Set to 0 to disable caching of hoisted layers | 19 // Set to 0 to disable caching of hoisted layers |
| 20 #define GR_CACHE_HOISTED_LAYERS 0 | 20 #define GR_CACHE_HOISTED_LAYERS 0 |
| 21 | 21 |
| 22 // The layer cache listens for these messages to purge picture-related resources
. | 22 // GrPictureInfo stores the atlas plots used by a single picture. A single |
| 23 struct GrPictureDeletedMessage { | |
| 24 uint32_t pictureID; | |
| 25 }; | |
| 26 | |
| 27 // GrPictureInfo stores the atlas plots used by a single picture. A single | |
| 28 // plot may be used to store layers from multiple pictures. | 23 // plot may be used to store layers from multiple pictures. |
| 29 struct GrPictureInfo { | 24 struct GrPictureInfo { |
| 30 public: | 25 public: |
| 31 static const int kNumPlots = 4; | 26 static const int kNumPlots = 4; |
| 32 | 27 |
| 33 // for SkTDynamicHash - just use the pictureID as the hash key | 28 // for SkTDynamicHash - just use the pictureID as the hash key |
| 34 static const uint32_t& GetKey(const GrPictureInfo& pictInfo) { return pictIn
fo.fPictureID; } | 29 static const uint32_t& GetKey(const GrPictureInfo& pictInfo) { return pictIn
fo.fPictureID; } |
| 35 static uint32_t Hash(const uint32_t& key) { return SkChecksum::Mix(key); } | 30 static uint32_t Hash(const uint32_t& key) { return SkChecksum::Mix(key); } |
| 36 | 31 |
| 37 // GrPictureInfo proper | 32 // GrPictureInfo proper |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // addUse is just here to keep the API symmetric | 250 // addUse is just here to keep the API symmetric |
| 256 void addUse(GrCachedLayer* layer) { layer->addUse(); } | 251 void addUse(GrCachedLayer* layer) { layer->addUse(); } |
| 257 void removeUse(GrCachedLayer* layer) { | 252 void removeUse(GrCachedLayer* layer) { |
| 258 layer->removeUse(); | 253 layer->removeUse(); |
| 259 if (layer->uses() == 0) { | 254 if (layer->uses() == 0) { |
| 260 // If no one cares about the layer allow it to be recycled. | 255 // If no one cares about the layer allow it to be recycled. |
| 261 this->unlock(layer); | 256 this->unlock(layer); |
| 262 } | 257 } |
| 263 } | 258 } |
| 264 | 259 |
| 265 // Setup to be notified when 'picture' is deleted | |
| 266 void trackPicture(const SkPicture* picture); | |
| 267 | |
| 268 // Cleanup after any SkPicture deletions | 260 // Cleanup after any SkPicture deletions |
| 269 void processDeletedPictures(); | 261 void processDeletedPictures(); |
| 270 | 262 |
| 271 SkDEBUGCODE(void validate() const;) | 263 SkDEBUGCODE(void validate() const;) |
| 272 | 264 |
| 273 #ifdef SK_DEVELOPER | 265 #ifdef SK_DEVELOPER |
| 274 void writeLayersToDisk(const SkString& dirName); | 266 void writeLayersToDisk(const SkString& dirName); |
| 275 #endif | 267 #endif |
| 276 | 268 |
| 277 static bool PlausiblyAtlasable(int width, int height) { | 269 static bool PlausiblyAtlasable(int width, int height) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 297 | 289 |
| 298 // We cache this information here (rather then, say, on the owning picture) | 290 // We cache this information here (rather then, say, on the owning picture) |
| 299 // because we want to be able to clean it up as needed (e.g., if a picture | 291 // because we want to be able to clean it up as needed (e.g., if a picture |
| 300 // is leaked and never cleans itself up we still want to be able to | 292 // is leaked and never cleans itself up we still want to be able to |
| 301 // remove the GrPictureInfo once its layers are purged from all the atlas | 293 // remove the GrPictureInfo once its layers are purged from all the atlas |
| 302 // plots). | 294 // plots). |
| 303 SkTDynamicHash<GrPictureInfo, uint32_t> fPictureHash; | 295 SkTDynamicHash<GrPictureInfo, uint32_t> fPictureHash; |
| 304 | 296 |
| 305 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key> fLayerHash; | 297 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key> fLayerHash; |
| 306 | 298 |
| 307 SkMessageBus<GrPictureDeletedMessage>::Inbox fPictDeletionInbox; | 299 SkMessageBus<SkPicture::DeletionMessage>::Inbox fPictDeletionInbox; |
| 308 | |
| 309 SkAutoTUnref<SkPicture::DeletionListener> fDeletionListener; | |
| 310 | 300 |
| 311 // This implements a plot-centric locking mechanism (since the atlas | 301 // This implements a plot-centric locking mechanism (since the atlas |
| 312 // backing texture is always locked). Each layer that is locked (i.e., | 302 // backing texture is always locked). Each layer that is locked (i.e., |
| 313 // needed for the current rendering) in a plot increments the plot lock | 303 // needed for the current rendering) in a plot increments the plot lock |
| 314 // count for that plot. Similarly, once a rendering is complete all the | 304 // count for that plot. Similarly, once a rendering is complete all the |
| 315 // layers used in it decrement the lock count for the used plots. | 305 // layers used in it decrement the lock count for the used plots. |
| 316 // Plots with a 0 lock count are open for recycling/purging. | 306 // Plots with a 0 lock count are open for recycling/purging. |
| 317 int fPlotLocks[kNumPlotsX * kNumPlotsY]; | 307 int fPlotLocks[kNumPlotsX * kNumPlotsY]; |
| 318 | 308 |
| 319 // Inform the cache that layer's cached image is not currently required | 309 // Inform the cache that layer's cached image is not currently required |
| (...skipping 18 matching lines...) Expand all Loading... |
| 338 SkASSERT(fPlotLocks[plotIdx] > 0); | 328 SkASSERT(fPlotLocks[plotIdx] > 0); |
| 339 --fPlotLocks[plotIdx]; | 329 --fPlotLocks[plotIdx]; |
| 340 } | 330 } |
| 341 | 331 |
| 342 // for testing | 332 // for testing |
| 343 friend class TestingAccess; | 333 friend class TestingAccess; |
| 344 int numLayers() const { return fLayerHash.count(); } | 334 int numLayers() const { return fLayerHash.count(); } |
| 345 }; | 335 }; |
| 346 | 336 |
| 347 #endif | 337 #endif |
| OLD | NEW |