diff options
author | 2010-09-08 18:04:33 -0700 | |
---|---|---|
committer | 2010-09-08 18:04:33 -0700 | |
commit | a2341a9f6addcd79723965ec5b1a1c5ae0f8bd65 (patch) | |
tree | ce61e01a0719f9fc52e48be002fe1d57d3af9c68 /libs/hwui/PathCache.cpp | |
parent | 9aaa8269a3e7291aab84d01c3fc9c744d8f2d2f4 (diff) |
Purge Skia objects from GL caches as needed.
Change-Id: I754c671cf790ad5ae8bf047ad328034217da4ecc
Diffstat (limited to 'libs/hwui/PathCache.cpp')
-rw-r--r-- | libs/hwui/PathCache.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp index 158c0cc70ff0..e8afe37d98cf 100644 --- a/libs/hwui/PathCache.cpp +++ b/libs/hwui/PathCache.cpp @@ -21,6 +21,8 @@ #include <SkCanvas.h> #include <SkRect.h> +#include <utils/threads.h> + #include "PathCache.h" #include "Properties.h" @@ -51,6 +53,7 @@ PathCache::PathCache(uint32_t maxByteSize): } PathCache::~PathCache() { + Mutex::Autolock _l(mLock); mCache.clear(); } @@ -67,14 +70,17 @@ void PathCache::init() { /////////////////////////////////////////////////////////////////////////////// uint32_t PathCache::getSize() { + Mutex::Autolock _l(mLock); return mSize; } uint32_t PathCache::getMaxSize() { + Mutex::Autolock _l(mLock); return mMaxSize; } void PathCache::setMaxSize(uint32_t maxSize) { + Mutex::Autolock _l(mLock); mMaxSize = maxSize; while (mSize > mMaxSize) { mCache.removeOldest(); @@ -99,14 +105,30 @@ void PathCache::operator()(PathCacheEntry& path, PathTexture*& texture) { // Caching /////////////////////////////////////////////////////////////////////////////// +void PathCache::remove(SkPath* path) { + Mutex::Autolock _l(mLock); + // TODO: Linear search... + for (uint32_t i = 0; i < mCache.size(); i++) { + if (mCache.getKeyAt(i).path == path) { + mCache.removeAt(i); + return; + } + } +} + PathTexture* PathCache::get(SkPath* path, SkPaint* paint) { PathCacheEntry entry(path, paint); + + mLock.lock(); PathTexture* texture = mCache.get(entry); + mLock.unlock(); if (!texture) { texture = addTexture(entry, path, paint); } else if (path->getGenerationID() != texture->generation) { + mLock.lock(); mCache.remove(entry); + mLock.unlock(); texture = addTexture(entry, path, paint); } @@ -132,9 +154,11 @@ PathTexture* PathCache::addTexture(const PathCacheEntry& entry, const uint32_t size = width * height; // Don't even try to cache a bitmap that's bigger than the cache if (size < mMaxSize) { + mLock.lock(); while (mSize + size > mMaxSize) { mCache.removeOldest(); } + mLock.unlock(); } PathTexture* texture = new PathTexture; @@ -157,8 +181,10 @@ PathTexture* PathCache::addTexture(const PathCacheEntry& entry, generateTexture(bitmap, texture); if (size < mMaxSize) { + mLock.lock(); mSize += size; mCache.put(entry, texture); + mLock.unlock(); } else { texture->cleanup = true; } @@ -167,6 +193,7 @@ PathTexture* PathCache::addTexture(const PathCacheEntry& entry, } void PathCache::clear() { + Mutex::Autolock _l(mLock); mCache.clear(); } |