| 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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // The layer cache listens for these messages to purge picture-related resources
. | 24 // The layer cache listens for these messages to purge picture-related resources
. |
| 25 struct GrPictureDeletedMessage { | 25 struct GrPictureDeletedMessage { |
| 26 uint32_t pictureID; | 26 uint32_t pictureID; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 // GrPictureInfo stores the atlas plots used by a single picture. A single | 29 // GrPictureInfo stores the atlas plots used by a single picture. A single |
| 30 // plot may be used to store layers from multiple pictures. | 30 // plot may be used to store layers from multiple pictures. |
| 31 struct GrPictureInfo { | 31 struct GrPictureInfo { |
| 32 public: | 32 public: |
| 33 static const int kNumPlots = 4; |
| 34 |
| 33 // for SkTDynamicHash - just use the pictureID as the hash key | 35 // for SkTDynamicHash - just use the pictureID as the hash key |
| 34 static const uint32_t& GetKey(const GrPictureInfo& pictInfo) { return pictIn
fo.fPictureID; } | 36 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); } | 37 static uint32_t Hash(const uint32_t& key) { return SkChecksum::Mix(key); } |
| 36 | 38 |
| 37 // GrPictureInfo proper | 39 // GrPictureInfo proper |
| 38 GrPictureInfo(uint32_t pictureID) : fPictureID(pictureID) { } | 40 GrPictureInfo(uint32_t pictureID) : fPictureID(pictureID) { |
| 41 #if !GR_CACHE_HOISTED_LAYERS |
| 42 memset(fPlotUses, 0, sizeof(fPlotUses)); |
| 43 #endif |
| 44 } |
| 45 |
| 46 #if !GR_CACHE_HOISTED_LAYERS |
| 47 void incPlotUsage(int plotID) { |
| 48 SkASSERT(plotID < kNumPlots); |
| 49 fPlotUses[plotID]++; |
| 50 } |
| 51 |
| 52 void decPlotUsage(int plotID) { |
| 53 SkASSERT(plotID < kNumPlots); |
| 54 SkASSERT(fPlotUses[plotID] > 0); |
| 55 fPlotUses[plotID]--; |
| 56 } |
| 57 |
| 58 int plotUsage(int plotID) const { |
| 59 SkASSERT(plotID < kNumPlots); |
| 60 return fPlotUses[plotID]; |
| 61 } |
| 62 #endif |
| 39 | 63 |
| 40 const uint32_t fPictureID; | 64 const uint32_t fPictureID; |
| 65 GrAtlas::ClientPlotUsage fPlotUsage; |
| 41 | 66 |
| 42 GrAtlas::ClientPlotUsage fPlotUsage; | 67 #if !GR_CACHE_HOISTED_LAYERS |
| 68 private: |
| 69 int fPlotUses[kNumPlots]; |
| 70 #endif |
| 43 }; | 71 }; |
| 44 | 72 |
| 45 // GrCachedLayer encapsulates the caching information for a single saveLayer. | 73 // GrCachedLayer encapsulates the caching information for a single saveLayer. |
| 46 // | 74 // |
| 47 // Atlased layers get a ref to the backing GrTexture while non-atlased layers | 75 // Atlased layers get a ref to the backing GrTexture while non-atlased layers |
| 48 // get a ref to the GrTexture in which they reside. In both cases 'fRect' | 76 // get a ref to the GrTexture in which they reside. In both cases 'fRect' |
| 49 // contains the layer's extent in its texture. | 77 // contains the layer's extent in its texture. |
| 50 // Atlased layers also get a pointer to the plot in which they reside. | 78 // Atlased layers also get a pointer to the plot in which they reside. |
| 51 // For non-atlased layers, the lock field just corresponds to locking in | 79 // For non-atlased layers, the lock field just corresponds to locking in |
| 52 // the resource cache. For atlased layers, it implements an additional level | 80 // the resource cache. For atlased layers, it implements an additional level |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 SkASSERT(fPlotLocks[plotIdx] > 0); | 340 SkASSERT(fPlotLocks[plotIdx] > 0); |
| 313 --fPlotLocks[plotIdx]; | 341 --fPlotLocks[plotIdx]; |
| 314 } | 342 } |
| 315 | 343 |
| 316 // for testing | 344 // for testing |
| 317 friend class TestingAccess; | 345 friend class TestingAccess; |
| 318 int numLayers() const { return fLayerHash.count(); } | 346 int numLayers() const { return fLayerHash.count(); } |
| 319 }; | 347 }; |
| 320 | 348 |
| 321 #endif | 349 #endif |
| OLD | NEW |