diff options
author | 2014-11-25 18:51:29 +0000 | |
---|---|---|
committer | 2014-11-25 18:51:29 +0000 | |
commit | fb7ff703e0f5fbf16c7805a162a3c5f44de5914b (patch) | |
tree | ca56e4c0d00eb8a465bb09547a29faad77002691 /libs/hwui/TextureCache.cpp | |
parent | 82f5fde34c8a98ace75fbc0dab8ffb97485808e9 (diff) | |
parent | 5ab86ba05decf12e8ee3f693aab6b265905049c6 (diff) |
am 5ab86ba0: am 89a63f02: am 0c31d97a: Merge "Switch TextureCache to SkPixelRef::fStableId" into lmp-mr1-dev
* commit '5ab86ba05decf12e8ee3f693aab6b265905049c6':
Switch TextureCache to SkPixelRef::fStableId
Diffstat (limited to 'libs/hwui/TextureCache.cpp')
-rw-r--r-- | libs/hwui/TextureCache.cpp | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp index b1fa3835d3c8..3677face1743 100644 --- a/libs/hwui/TextureCache.cpp +++ b/libs/hwui/TextureCache.cpp @@ -20,6 +20,7 @@ #include <GLES2/gl2.h> #include <SkCanvas.h> +#include <SkPixelRef.h> #include <utils/Mutex.h> @@ -37,7 +38,7 @@ namespace uirenderer { /////////////////////////////////////////////////////////////////////////////// TextureCache::TextureCache(): - mCache(LruCache<const SkPixelRef*, Texture*>::kUnlimitedCapacity), + mCache(LruCache<uint32_t, Texture*>::kUnlimitedCapacity), mSize(0), mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE)), mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE) { char property[PROPERTY_VALUE_MAX]; @@ -61,7 +62,7 @@ TextureCache::TextureCache(): } TextureCache::TextureCache(uint32_t maxByteSize): - mCache(LruCache<const SkPixelRef*, Texture*>::kUnlimitedCapacity), + mCache(LruCache<uint32_t, Texture*>::kUnlimitedCapacity), mSize(0), mMaxSize(maxByteSize) { init(); } @@ -106,7 +107,7 @@ void TextureCache::setFlushRate(float flushRate) { // Callbacks /////////////////////////////////////////////////////////////////////////////// -void TextureCache::operator()(const SkPixelRef*&, Texture*& texture) { +void TextureCache::operator()(uint32_t&, Texture*& texture) { // This will be called already locked if (texture) { mSize -= texture->bitmapSize; @@ -125,7 +126,7 @@ void TextureCache::operator()(const SkPixelRef*&, Texture*& texture) { /////////////////////////////////////////////////////////////////////////////// void TextureCache::resetMarkInUse() { - LruCache<const SkPixelRef*, Texture*>::Iterator iter(mCache); + LruCache<uint32_t, Texture*>::Iterator iter(mCache); while (iter.next()) { iter.value()->isInUse = false; } @@ -143,7 +144,7 @@ bool TextureCache::canMakeTextureFromBitmap(const SkBitmap* bitmap) { // Returns a prepared Texture* that either is already in the cache or can fit // in the cache (and is thus added to the cache) Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) { - Texture* texture = mCache.get(bitmap->pixelRef()); + Texture* texture = mCache.get(bitmap->pixelRef()->getStableID()); if (!texture) { if (!canMakeTextureFromBitmap(bitmap)) { @@ -173,7 +174,7 @@ Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) { if (mDebugEnabled) { ALOGD("Texture created, size = %d", size); } - mCache.put(bitmap->pixelRef(), texture); + mCache.put(bitmap->pixelRef()->getStableID(), texture); } } else if (!texture->isInUse && bitmap->getGenerationID() != texture->generation) { // Texture was in the cache but is dirty, re-upload @@ -220,22 +221,19 @@ Texture* TextureCache::getTransient(const SkBitmap* bitmap) { return texture; } -void TextureCache::remove(const SkBitmap* bitmap) { - mCache.remove(bitmap->pixelRef()); -} +void TextureCache::releaseTexture(const SkBitmap* bitmap) { + if (!bitmap || !bitmap->pixelRef()) return; -void TextureCache::removeDeferred(const SkBitmap* bitmap) { Mutex::Autolock _l(mLock); - mGarbage.push(bitmap); + mGarbage.push(bitmap->pixelRef()->getStableID()); } void TextureCache::clearGarbage() { Mutex::Autolock _l(mLock); size_t count = mGarbage.size(); for (size_t i = 0; i < count; i++) { - const SkBitmap* bitmap = mGarbage.itemAt(i); - mCache.remove(bitmap->pixelRef()); - delete bitmap; + uint32_t pixelRefId = mGarbage.itemAt(i); + mCache.remove(pixelRefId); } mGarbage.clear(); } |