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 #define USE_ATLAS 0 | 11 #define USE_ATLAS 0 |
12 | 12 |
13 #include "GrAllocPool.h" | 13 #include "GrAllocPool.h" |
14 #include "GrAtlas.h" | 14 #include "GrAtlas.h" |
15 #include "GrPictureUtils.h" | 15 #include "GrPictureUtils.h" |
16 #include "GrRect.h" | 16 #include "GrRect.h" |
17 #include "SkChecksum.h" | 17 #include "SkChecksum.h" |
18 #include "SkTDynamicHash.h" | 18 #include "SkTDynamicHash.h" |
| 19 #include "SkMessageBus.h" |
19 | 20 |
20 class SkPicture; | 21 class SkPicture; |
21 | 22 |
| 23 // The layer cache listens for these messages to purge picture-related resources
. |
| 24 struct GrPictureDeletedMessage { |
| 25 uint32_t pictureID; |
| 26 }; |
| 27 |
22 // GrPictureInfo stores the atlas plots used by a single picture. A single | 28 // GrPictureInfo stores the atlas plots used by a single picture. A single |
23 // plot may be used to store layers from multiple pictures. | 29 // plot may be used to store layers from multiple pictures. |
24 struct GrPictureInfo { | 30 struct GrPictureInfo { |
25 public: | 31 public: |
26 // for SkTDynamicHash - just use the pictureID as the hash key | 32 // for SkTDynamicHash - just use the pictureID as the hash key |
27 static const uint32_t& GetKey(const GrPictureInfo& pictInfo) { return pictIn
fo.fPictureID; } | 33 static const uint32_t& GetKey(const GrPictureInfo& pictInfo) { return pictIn
fo.fPictureID; } |
28 static uint32_t Hash(const uint32_t& key) { return SkChecksum::Mix(key); } | 34 static uint32_t Hash(const uint32_t& key) { return SkChecksum::Mix(key); } |
29 | 35 |
30 // GrPictureInfo proper | 36 // GrPictureInfo proper |
31 GrPictureInfo(uint32_t pictureID) : fPictureID(pictureID) { } | 37 GrPictureInfo(uint32_t pictureID) : fPictureID(pictureID) { } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 145 |
140 // Inform the cache that layer's cached image is now required. Return true | 146 // Inform the cache that layer's cached image is now required. Return true |
141 // if it was found in the ResourceCache and doesn't need to be regenerated. | 147 // if it was found in the ResourceCache and doesn't need to be regenerated. |
142 // If false is returned the caller should (re)render the layer into the | 148 // If false is returned the caller should (re)render the layer into the |
143 // newly acquired texture. | 149 // newly acquired texture. |
144 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc); | 150 bool lock(GrCachedLayer* layer, const GrTextureDesc& desc); |
145 | 151 |
146 // Inform the cache that layer's cached image is not currently required | 152 // Inform the cache that layer's cached image is not currently required |
147 void unlock(GrCachedLayer* layer); | 153 void unlock(GrCachedLayer* layer); |
148 | 154 |
149 // Remove all the layers (and unlock any resources) associated with 'picture
' | 155 // Setup to be notified when 'picture' is deleted |
150 void purge(const SkPicture* picture); | 156 void trackPicture(const SkPicture* picture); |
| 157 |
| 158 // Cleanup after any SkPicture deletions |
| 159 void processDeletedPictures(); |
151 | 160 |
152 SkDEBUGCODE(void validate() const;) | 161 SkDEBUGCODE(void validate() const;) |
153 | 162 |
154 private: | 163 private: |
155 static const int kNumPlotsX = 2; | 164 static const int kNumPlotsX = 2; |
156 static const int kNumPlotsY = 2; | 165 static const int kNumPlotsY = 2; |
157 | 166 |
158 GrContext* fContext; // pointer back to owning context | 167 GrContext* fContext; // pointer back to owning context |
159 SkAutoTDelete<GrAtlas> fAtlas; // TODO: could lazily allocate | 168 SkAutoTDelete<GrAtlas> fAtlas; // TODO: could lazily allocate |
160 | 169 |
161 // We cache this information here (rather then, say, on the owning picture) | 170 // We cache this information here (rather then, say, on the owning picture) |
162 // because we want to be able to clean it up as needed (e.g., if a picture | 171 // because we want to be able to clean it up as needed (e.g., if a picture |
163 // is leaked and never cleans itself up we still want to be able to | 172 // is leaked and never cleans itself up we still want to be able to |
164 // remove the GrPictureInfo once its layers are purged from all the atlas | 173 // remove the GrPictureInfo once its layers are purged from all the atlas |
165 // plots). | 174 // plots). |
166 SkTDynamicHash<GrPictureInfo, uint32_t> fPictureHash; | 175 SkTDynamicHash<GrPictureInfo, uint32_t> fPictureHash; |
167 | 176 |
168 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key> fLayerHash; | 177 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key> fLayerHash; |
169 | 178 |
| 179 SkMessageBus<GrPictureDeletedMessage>::Inbox fPictDeletionInbox; |
| 180 |
| 181 SkAutoTUnref<SkPicture::DeletionListener> fDeletionListener; |
| 182 |
170 void initAtlas(); | 183 void initAtlas(); |
171 GrCachedLayer* createLayer(const SkPicture* picture, int layerID); | 184 GrCachedLayer* createLayer(const SkPicture* picture, int layerID); |
172 | 185 |
| 186 // Remove all the layers (and unlock any resources) associated with 'picture
ID' |
| 187 void purge(uint32_t pictureID); |
| 188 |
173 // for testing | 189 // for testing |
174 friend class GetNumLayers; | 190 friend class TestingAccess; |
175 int numLayers() const { return fLayerHash.count(); } | 191 int numLayers() const { return fLayerHash.count(); } |
176 }; | 192 }; |
177 | 193 |
178 #endif | 194 #endif |
OLD | NEW |