diff options
author | 2015-09-18 08:07:31 -0700 | |
---|---|---|
committer | 2015-09-18 08:07:31 -0700 | |
commit | 3b0d532df72db806c255cad98538fcbb4d9678a8 (patch) | |
tree | 96d66c4b40e72f52a10067640f5c95025427a8da /src/core/SkImageCacherator.cpp | |
parent | 3566d44d852b2fc1773e41e80c0c19610aa6d43b (diff) |
Purge cached resources on SkImage destruction.
BUG=532981
R=reed@google.com,mtklein@google.com
Review URL: https://codereview.chromium.org/1352883004
Diffstat (limited to 'src/core/SkImageCacherator.cpp')
-rw-r--r-- | src/core/SkImageCacherator.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index 91e342a79b..b35e053b0d 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -7,6 +7,7 @@ #include "SkBitmap.h" #include "SkBitmapCache.h" +#include "SkImage_Base.h" #include "SkImageCacherator.h" #include "SkMallocPixelRef.h" #include "SkNextID.h" @@ -109,7 +110,7 @@ bool SkImageCacherator::generateBitmap(SkBitmap* bitmap) { ////////////////////////////////////////////////////////////////////////////////////////////////// -bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap) { +bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client) { if (SkBitmapCache::Find(fUniqueID, bitmap)) { return check_output_bitmap(*bitmap, fUniqueID); } @@ -120,11 +121,15 @@ bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap) { bitmap->pixelRef()->setImmutableWithID(fUniqueID); SkBitmapCache::Add(fUniqueID, *bitmap); + if (client) { + as_IB(client)->notifyAddedToCache(); + } + return true; } -bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap) { - if (this->tryLockAsBitmap(bitmap)) { +bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client) { + if (this->tryLockAsBitmap(bitmap, client)) { return check_output_bitmap(*bitmap, fUniqueID); } @@ -156,6 +161,10 @@ bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap) { bitmap->pixelRef()->setImmutableWithID(fUniqueID); SkBitmapCache::Add(fUniqueID, *bitmap); + if (client) { + as_IB(client)->notifyAddedToCache(); + } + return check_output_bitmap(*bitmap, fUniqueID); #else return false; @@ -209,7 +218,8 @@ static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) { * 4. Ask the generator to return YUV planes, which the GPU can convert * 5. Ask the generator to return RGB(A) data, which the GPU can convert */ -GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usage) { +GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usage, + const SkImage* client) { #if SK_SUPPORT_GPU if (!ctx) { return nullptr; @@ -262,7 +272,7 @@ GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa // 5. Ask the generator to return RGB(A) data, which the GPU can convert SkBitmap bitmap; - if (this->tryLockAsBitmap(&bitmap)) { + if (this->tryLockAsBitmap(&bitmap, client)) { return GrRefCachedBitmapTexture(ctx, bitmap, usage); } #endif |