Loading libs/hwui/ResourceCache.cpp +12 −7 Original line number Diff line number Diff line Loading @@ -185,10 +185,9 @@ void ResourceCache::destructorLocked(const SkBitmap* resource) { if (ref == NULL) { // If we're not tracking this resource, just delete it if (Caches::hasInstance()) { Caches::getInstance().textureCache.removeDeferred(resource); } else { delete resource; Caches::getInstance().textureCache.releaseTexture(resource); } delete resource; return; } ref->destroyed = true; Loading Loading @@ -238,6 +237,9 @@ bool ResourceCache::recycle(SkBitmap* resource) { bool ResourceCache::recycleLocked(SkBitmap* resource) { ssize_t index = mCache->indexOfKey(resource); if (index < 0) { if (Caches::hasInstance()) { Caches::getInstance().textureCache.releaseTexture(resource); } // not tracking this resource; just recycle the pixel data resource->setPixels(NULL, NULL); return true; Loading @@ -262,17 +264,20 @@ bool ResourceCache::recycleLocked(SkBitmap* resource) { */ void ResourceCache::deleteResourceReferenceLocked(const void* resource, ResourceReference* ref) { if (ref->recycled && ref->resourceType == kBitmap) { ((SkBitmap*) resource)->setPixels(NULL, NULL); SkBitmap* bitmap = (SkBitmap*) resource; if (Caches::hasInstance()) { Caches::getInstance().textureCache.releaseTexture(bitmap); } bitmap->setPixels(NULL, NULL); } if (ref->destroyed) { switch (ref->resourceType) { case kBitmap: { SkBitmap* bitmap = (SkBitmap*) resource; if (Caches::hasInstance()) { Caches::getInstance().textureCache.removeDeferred(bitmap); } else { delete bitmap; Caches::getInstance().textureCache.releaseTexture(bitmap); } delete bitmap; } break; case kPath: { Loading libs/hwui/ResourceCache.h +0 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,6 @@ enum ResourceType { class ResourceReference { public: ResourceReference() { refCount = 0; recycled = false; destroyed = false;} ResourceReference(ResourceType type) { refCount = 0; recycled = false; destroyed = false; resourceType = type; } Loading libs/hwui/TextureCache.cpp +12 −14 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <GLES2/gl2.h> #include <SkCanvas.h> #include <SkPixelRef.h> #include <utils/Mutex.h> Loading @@ -36,7 +37,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]; Loading @@ -60,7 +61,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(); } Loading Loading @@ -105,7 +106,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; Loading @@ -124,7 +125,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; } Loading @@ -142,7 +143,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)) { Loading Loading @@ -172,7 +173,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 Loading Loading @@ -219,22 +220,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(); } Loading libs/hwui/TextureCache.h +6 −10 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ namespace uirenderer { * Any texture added to the cache causing the cache to grow beyond the maximum * allowed size will also cause the oldest texture to be kicked out. */ class TextureCache: public OnEntryRemoved<const SkPixelRef*, Texture*> { class TextureCache: public OnEntryRemoved<uint32_t, Texture*> { public: TextureCache(); TextureCache(uint32_t maxByteSize); Loading @@ -59,7 +59,7 @@ public: * Used as a callback when an entry is removed from the cache. * Do not invoke directly. */ void operator()(const SkPixelRef*& pixelRef, Texture*& texture); void operator()(uint32_t&, Texture*& texture); /** * Resets all Textures to not be marked as in use Loading @@ -83,16 +83,12 @@ public: * texture is not kept in the cache. The caller must destroy the texture. */ Texture* getTransient(const SkBitmap* bitmap); /** * Removes the texture associated with the specified bitmap. * Upon remove the texture is freed. */ void remove(const SkBitmap* bitmap); /** * Removes the texture associated with the specified bitmap. This is meant * to be called from threads that are not the EGL context thread. */ void removeDeferred(const SkBitmap* bitmap); void releaseTexture(const SkBitmap* bitmap); /** * Process deferred removals. */ Loading Loading @@ -147,7 +143,7 @@ private: void init(); LruCache<const SkPixelRef*, Texture*> mCache; LruCache<uint32_t, Texture*> mCache; uint32_t mSize; uint32_t mMaxSize; Loading @@ -157,7 +153,7 @@ private: bool mDebugEnabled; Vector<const SkBitmap*> mGarbage; Vector<uint32_t> mGarbage; mutable Mutex mLock; }; // class TextureCache Loading Loading
libs/hwui/ResourceCache.cpp +12 −7 Original line number Diff line number Diff line Loading @@ -185,10 +185,9 @@ void ResourceCache::destructorLocked(const SkBitmap* resource) { if (ref == NULL) { // If we're not tracking this resource, just delete it if (Caches::hasInstance()) { Caches::getInstance().textureCache.removeDeferred(resource); } else { delete resource; Caches::getInstance().textureCache.releaseTexture(resource); } delete resource; return; } ref->destroyed = true; Loading Loading @@ -238,6 +237,9 @@ bool ResourceCache::recycle(SkBitmap* resource) { bool ResourceCache::recycleLocked(SkBitmap* resource) { ssize_t index = mCache->indexOfKey(resource); if (index < 0) { if (Caches::hasInstance()) { Caches::getInstance().textureCache.releaseTexture(resource); } // not tracking this resource; just recycle the pixel data resource->setPixels(NULL, NULL); return true; Loading @@ -262,17 +264,20 @@ bool ResourceCache::recycleLocked(SkBitmap* resource) { */ void ResourceCache::deleteResourceReferenceLocked(const void* resource, ResourceReference* ref) { if (ref->recycled && ref->resourceType == kBitmap) { ((SkBitmap*) resource)->setPixels(NULL, NULL); SkBitmap* bitmap = (SkBitmap*) resource; if (Caches::hasInstance()) { Caches::getInstance().textureCache.releaseTexture(bitmap); } bitmap->setPixels(NULL, NULL); } if (ref->destroyed) { switch (ref->resourceType) { case kBitmap: { SkBitmap* bitmap = (SkBitmap*) resource; if (Caches::hasInstance()) { Caches::getInstance().textureCache.removeDeferred(bitmap); } else { delete bitmap; Caches::getInstance().textureCache.releaseTexture(bitmap); } delete bitmap; } break; case kPath: { Loading
libs/hwui/ResourceCache.h +0 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,6 @@ enum ResourceType { class ResourceReference { public: ResourceReference() { refCount = 0; recycled = false; destroyed = false;} ResourceReference(ResourceType type) { refCount = 0; recycled = false; destroyed = false; resourceType = type; } Loading
libs/hwui/TextureCache.cpp +12 −14 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <GLES2/gl2.h> #include <SkCanvas.h> #include <SkPixelRef.h> #include <utils/Mutex.h> Loading @@ -36,7 +37,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]; Loading @@ -60,7 +61,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(); } Loading Loading @@ -105,7 +106,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; Loading @@ -124,7 +125,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; } Loading @@ -142,7 +143,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)) { Loading Loading @@ -172,7 +173,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 Loading Loading @@ -219,22 +220,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(); } Loading
libs/hwui/TextureCache.h +6 −10 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ namespace uirenderer { * Any texture added to the cache causing the cache to grow beyond the maximum * allowed size will also cause the oldest texture to be kicked out. */ class TextureCache: public OnEntryRemoved<const SkPixelRef*, Texture*> { class TextureCache: public OnEntryRemoved<uint32_t, Texture*> { public: TextureCache(); TextureCache(uint32_t maxByteSize); Loading @@ -59,7 +59,7 @@ public: * Used as a callback when an entry is removed from the cache. * Do not invoke directly. */ void operator()(const SkPixelRef*& pixelRef, Texture*& texture); void operator()(uint32_t&, Texture*& texture); /** * Resets all Textures to not be marked as in use Loading @@ -83,16 +83,12 @@ public: * texture is not kept in the cache. The caller must destroy the texture. */ Texture* getTransient(const SkBitmap* bitmap); /** * Removes the texture associated with the specified bitmap. * Upon remove the texture is freed. */ void remove(const SkBitmap* bitmap); /** * Removes the texture associated with the specified bitmap. This is meant * to be called from threads that are not the EGL context thread. */ void removeDeferred(const SkBitmap* bitmap); void releaseTexture(const SkBitmap* bitmap); /** * Process deferred removals. */ Loading Loading @@ -147,7 +143,7 @@ private: void init(); LruCache<const SkPixelRef*, Texture*> mCache; LruCache<uint32_t, Texture*> mCache; uint32_t mSize; uint32_t mMaxSize; Loading @@ -157,7 +153,7 @@ private: bool mDebugEnabled; Vector<const SkBitmap*> mGarbage; Vector<uint32_t> mGarbage; mutable Mutex mLock; }; // class TextureCache Loading