From 9e10841c27d973b930e1b49a099c69d866659505 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 9 Nov 2010 14:35:20 -0800 Subject: Correctly remove unused paths from the cache. Change-Id: I41d9334dcd9871634037344ab49bf69383498161 --- libs/hwui/PathCache.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'libs/hwui/PathCache.cpp') diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp index b58785a6bd04..04d07dbbee8a 100644 --- a/libs/hwui/PathCache.cpp +++ b/libs/hwui/PathCache.cpp @@ -92,10 +92,13 @@ void PathCache::setMaxSize(uint32_t maxSize) { /////////////////////////////////////////////////////////////////////////////// void PathCache::operator()(PathCacheEntry& path, PathTexture*& texture) { - const uint32_t size = texture->width * texture->height; - mSize -= size; - if (texture) { + const uint32_t size = texture->width * texture->height; + mSize -= size; + + PATH_LOGD("PathCache::callback: delete path: name, size, mSize = %d, %d, %d", + texture->id, size, mSize); + glDeleteTextures(1, &texture->id); delete texture; } @@ -107,12 +110,18 @@ void PathCache::operator()(PathCacheEntry& path, PathTexture*& texture) { void PathCache::remove(SkPath* path) { Mutex::Autolock _l(mLock); + // TODO: Linear search... + Vector pathsToRemove; for (uint32_t i = 0; i < mCache.size(); i++) { if (mCache.getKeyAt(i).path == path) { - mCache.removeAt(i); + pathsToRemove.push(i); } } + + for (size_t i = 0; i < pathsToRemove.size(); i++) { + mCache.removeAt(pathsToRemove.itemAt(i)); + } } PathTexture* PathCache::get(SkPath* path, SkPaint* paint) { @@ -188,6 +197,8 @@ PathTexture* PathCache::addTexture(const PathCacheEntry& entry, if (size < mMaxSize) { mLock.lock(); mSize += size; + PATH_LOGD("PathCache::get: create path: name, size, mSize = %d, %d, %d", + texture->id, size, mSize); mCache.put(entry, texture); mLock.unlock(); } else { -- cgit v1.2.3-59-g8ed1b