diff options
author | 2010-09-08 18:06:11 -0700 | |
---|---|---|
committer | 2010-09-08 18:06:11 -0700 | |
commit | 9584a542e345fa18fc62eb0b5947f250226f211d (patch) | |
tree | d4b34b8882f317dfa718067407ed03e07d9b685f /libs/hwui/PathCache.cpp | |
parent | e3aa6aa77014b5798f95f6c5817df85910ecaac3 (diff) | |
parent | a2341a9f6addcd79723965ec5b1a1c5ae0f8bd65 (diff) |
Merge "Purge Skia objects from GL caches as needed."
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(); } |