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

Unified 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: Fix comment 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrLayerCache.cpp
diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp
index 1a0923004ba11dc2ea83c1a7a149e66251de2441..32f5a5b6c44bf1e5a56cb4dab7cd8bb94ec1045a 100644
--- a/src/gpu/GrLayerCache.cpp
+++ b/src/gpu/GrLayerCache.cpp
@@ -9,6 +9,8 @@
#include "GrGpu.h"
#include "GrLayerCache.h"
+DECLARE_SKMESSAGEBUS_MESSAGE(GrPictureDeletedMessage);
+
#ifdef SK_DEBUG
void GrCachedLayer::validate(const GrTexture* backingTexture) const {
SkASSERT(SK_InvalidGenID != fKey.getPictureID());
@@ -223,7 +225,8 @@ private:
};
#endif
-void GrLayerCache::purge(const SkPicture* picture) {
+void GrLayerCache::purge(uint32_t pictureID) {
+
SkDEBUGCODE(GrAutoValidateCache avc(this);)
// We need to find all the layers associated with 'picture' and remove them.
@@ -231,7 +234,7 @@ void GrLayerCache::purge(const SkPicture* picture) {
SkTDynamicHash<GrCachedLayer, GrCachedLayer::Key>::Iter iter(&fLayerHash);
for (; !iter.done(); ++iter) {
- if (picture->uniqueID() == (*iter).pictureID()) {
+ if (pictureID == (*iter).pictureID()) {
*toBeRemoved.append() = &(*iter);
}
}
@@ -242,9 +245,34 @@ void GrLayerCache::purge(const SkPicture* picture) {
SkDELETE(toBeRemoved[i]);
}
- GrPictureInfo* pictInfo = fPictureHash.find(picture->uniqueID());
+ GrPictureInfo* pictInfo = fPictureHash.find(pictureID);
if (NULL != pictInfo) {
- fPictureHash.remove(picture->uniqueID());
+ fPictureHash.remove(pictureID);
SkDELETE(pictInfo);
}
}
+
+class GrPictureDeletionListener : public SkPicture::DeletionListener {
+ virtual void onDeletion(uint32_t pictureID) SK_OVERRIDE{
+ const GrPictureDeletedMessage message = { pictureID };
+ SkMessageBus<GrPictureDeletedMessage>::Post(message);
+ }
+};
+
+void GrLayerCache::trackPicture(const SkPicture* picture) {
+ if (NULL == fDeletionListener) {
+ fDeletionListener.reset(SkNEW(GrPictureDeletionListener));
+ }
+
+ picture->addDeletionListener(fDeletionListener);
+}
+
+void GrLayerCache::processDeletedPictures() {
+ SkTDArray<GrPictureDeletedMessage> deletedPictures;
+ fPictDeletionInbox.poll(&deletedPictures);
+
+ for (int i = 0; i < deletedPictures.count(); i++) {
+ this->purge(deletedPictures[i].pictureID);
+ }
+}
+
« no previous file with comments | « src/gpu/GrLayerCache.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698