Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: src/gpu/GrLayerCache.cpp

Issue 408923002: Add auto purging for SkPicture-related Ganesh resources (esp. layers) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move MessageBus Inbox from GrContext to GrLayerCache Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "GrAtlas.h" 8 #include "GrAtlas.h"
9 #include "GrGpu.h" 9 #include "GrGpu.h"
10 #include "GrLayerCache.h" 10 #include "GrLayerCache.h"
11 11
12 DECLARE_SKMESSAGEBUS_MESSAGE(GrPictureDeletedMessage);
13
12 #ifdef SK_DEBUG 14 #ifdef SK_DEBUG
13 void GrCachedLayer::validate(const GrTexture* backingTexture) const { 15 void GrCachedLayer::validate(const GrTexture* backingTexture) const {
14 SkASSERT(SK_InvalidGenID != fKey.getPictureID()); 16 SkASSERT(SK_InvalidGenID != fKey.getPictureID());
15 SkASSERT(-1 != fKey.getLayerID()); 17 SkASSERT(-1 != fKey.getLayerID());
16 18
17 19
18 if (NULL != fTexture) { 20 if (NULL != fTexture) {
19 // If the layer is in some texture then it must occupy some rectangle 21 // If the layer is in some texture then it must occupy some rectangle
20 SkASSERT(!fRect.isEmpty()); 22 SkASSERT(!fRect.isEmpty());
21 if (!this->isAtlased()) { 23 if (!this->isAtlased()) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 fCache->validate(); 218 fCache->validate();
217 } 219 }
218 ~GrAutoValidateCache() { 220 ~GrAutoValidateCache() {
219 fCache->validate(); 221 fCache->validate();
220 } 222 }
221 private: 223 private:
222 GrLayerCache* fCache; 224 GrLayerCache* fCache;
223 }; 225 };
224 #endif 226 #endif
225 227
226 void GrLayerCache::purge(const SkPicture* picture) { 228 void GrLayerCache::purge(uint32_t pictureID) {
229
227 SkDEBUGCODE(GrAutoValidateCache avc(this);) 230 SkDEBUGCODE(GrAutoValidateCache avc(this);)
228 231
229 // We need to find all the layers associated with 'picture' and remove them. 232 // We need to find all the layers associated with 'picture' and remove them.
230 SkTDArray<GrCachedLayer*> toBeRemoved; 233 SkTDArray<GrCachedLayer*> toBeRemoved;
231 234
232 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash); 235 SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
233 for (; !iter.done(); ++iter) { 236 for (; !iter.done(); ++iter) {
234 if (picture->uniqueID() == (*iter).pictureID()) { 237 if (pictureID == (*iter).pictureID()) {
235 *toBeRemoved.append() = &(*iter); 238 *toBeRemoved.append() = &(*iter);
236 } 239 }
237 } 240 }
238 241
239 for (int i = 0; i < toBeRemoved.count(); ++i) { 242 for (int i = 0; i < toBeRemoved.count(); ++i) {
240 this->unlock(toBeRemoved[i]); 243 this->unlock(toBeRemoved[i]);
241 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i])); 244 fLayerHash.remove(GrCachedLayer::GetKey(*toBeRemoved[i]));
242 SkDELETE(toBeRemoved[i]); 245 SkDELETE(toBeRemoved[i]);
243 } 246 }
244 247
245 GrPictureInfo* pictInfo = fPictureHash.find(picture->uniqueID()); 248 GrPictureInfo* pictInfo = fPictureHash.find(pictureID);
246 if (NULL != pictInfo) { 249 if (NULL != pictInfo) {
247 fPictureHash.remove(picture->uniqueID()); 250 fPictureHash.remove(pictureID);
248 SkDELETE(pictInfo); 251 SkDELETE(pictInfo);
249 } 252 }
250 } 253 }
254
255 void GrLayerCache::processDeletedPictures() {
256 SkTDArray<GrPictureDeletedMessage> deletedPictures;
257 fPictDeletionInbox.poll(&deletedPictures);
258
259 for (int i = 0; i < deletedPictures.count(); i++) {
260 this->purge(deletedPictures[i].pictureID);
261 }
262 }
263
OLDNEW
« include/core/SkPicture.h ('K') | « src/gpu/GrLayerCache.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698