diff options
author | Romain Guy <romainguy@google.com> | 2012-09-07 14:01:30 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-09-07 14:01:31 -0700 |
commit | 55e6b77bda7da1684ca32493d9e03184bd441dab (patch) | |
tree | 452dd95ab11bd568485f2ea36276395cd90f111e /libs/hwui/ResourceCache.cpp | |
parent | 417984dc0d27bdd1b33ae3115593f609961a0c15 (diff) | |
parent | 58ecc204fbcacef34806290492384677a330d4d4 (diff) | |
download | frameworks_base-55e6b77bda7da1684ca32493d9e03184bd441dab.zip frameworks_base-55e6b77bda7da1684ca32493d9e03184bd441dab.tar.gz frameworks_base-55e6b77bda7da1684ca32493d9e03184bd441dab.tar.bz2 |
Merge "Reduce the number of locks acquired by display lists" into jb-mr1-dev
Diffstat (limited to 'libs/hwui/ResourceCache.cpp')
-rw-r--r-- | libs/hwui/ResourceCache.cpp | 130 |
1 files changed, 103 insertions, 27 deletions
diff --git a/libs/hwui/ResourceCache.cpp b/libs/hwui/ResourceCache.cpp index 2153a8b..b0c57d1 100644 --- a/libs/hwui/ResourceCache.cpp +++ b/libs/hwui/ResourceCache.cpp @@ -38,7 +38,7 @@ void ResourceCache::logCache() { ResourceCache::ResourceCache() { Mutex::Autolock _l(mLock); - mCache = new KeyedVector<void *, ResourceReference *>(); + mCache = new KeyedVector<void*, ResourceReference*>(); } ResourceCache::~ResourceCache() { @@ -46,15 +46,17 @@ ResourceCache::~ResourceCache() { delete mCache; } +void ResourceCache::lock() { + mLock.lock(); +} + +void ResourceCache::unlock() { + mLock.unlock(); +} + void ResourceCache::incrementRefcount(void* resource, ResourceType resourceType) { Mutex::Autolock _l(mLock); - ssize_t index = mCache->indexOfKey(resource); - ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; - if (ref == NULL || mCache->size() == 0) { - ref = new ResourceReference(resourceType); - mCache->add(resource, ref); - } - ref->refCount++; + incrementRefcountLocked(resource, resourceType); } void ResourceCache::incrementRefcount(SkBitmap* bitmapResource) { @@ -77,18 +79,39 @@ void ResourceCache::incrementRefcount(SkiaColorFilter* filterResource) { incrementRefcount((void*) filterResource, kColorFilter); } -void ResourceCache::decrementRefcount(void* resource) { - Mutex::Autolock _l(mLock); +void ResourceCache::incrementRefcountLocked(void* resource, ResourceType resourceType) { ssize_t index = mCache->indexOfKey(resource); ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; - if (ref == NULL) { - // Should not get here - shouldn't get a call to decrement if we're not yet tracking it - return; - } - ref->refCount--; - if (ref->refCount == 0) { - deleteResourceReference(resource, ref); + if (ref == NULL || mCache->size() == 0) { + ref = new ResourceReference(resourceType); + mCache->add(resource, ref); } + ref->refCount++; +} + +void ResourceCache::incrementRefcountLocked(SkBitmap* bitmapResource) { + SkSafeRef(bitmapResource->pixelRef()); + SkSafeRef(bitmapResource->getColorTable()); + incrementRefcountLocked((void*) bitmapResource, kBitmap); +} + +void ResourceCache::incrementRefcountLocked(SkPath* pathResource) { + incrementRefcountLocked((void*) pathResource, kPath); +} + +void ResourceCache::incrementRefcountLocked(SkiaShader* shaderResource) { + SkSafeRef(shaderResource->getSkShader()); + incrementRefcountLocked((void*) shaderResource, kShader); +} + +void ResourceCache::incrementRefcountLocked(SkiaColorFilter* filterResource) { + SkSafeRef(filterResource->getSkColorFilter()); + incrementRefcountLocked((void*) filterResource, kColorFilter); +} + +void ResourceCache::decrementRefcount(void* resource) { + Mutex::Autolock _l(mLock); + decrementRefcountLocked(resource); } void ResourceCache::decrementRefcount(SkBitmap* bitmapResource) { @@ -111,27 +134,45 @@ void ResourceCache::decrementRefcount(SkiaColorFilter* filterResource) { decrementRefcount((void*) filterResource); } -void ResourceCache::recycle(SkBitmap* resource) { - Mutex::Autolock _l(mLock); +void ResourceCache::decrementRefcountLocked(void* resource) { ssize_t index = mCache->indexOfKey(resource); - if (index < 0) { - // not tracking this resource; just recycle the pixel data - resource->setPixels(NULL, NULL); - return; - } - ResourceReference* ref = mCache->valueAt(index); + ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; if (ref == NULL) { - // Should not get here - shouldn't get a call to recycle if we're not yet tracking it + // Should not get here - shouldn't get a call to decrement if we're not yet tracking it return; } - ref->recycled = true; + ref->refCount--; if (ref->refCount == 0) { deleteResourceReference(resource, ref); } } +void ResourceCache::decrementRefcountLocked(SkBitmap* bitmapResource) { + SkSafeUnref(bitmapResource->pixelRef()); + SkSafeUnref(bitmapResource->getColorTable()); + decrementRefcountLocked((void*) bitmapResource); +} + +void ResourceCache::decrementRefcountLocked(SkPath* pathResource) { + decrementRefcountLocked((void*) pathResource); +} + +void ResourceCache::decrementRefcountLocked(SkiaShader* shaderResource) { + SkSafeUnref(shaderResource->getSkShader()); + decrementRefcountLocked((void*) shaderResource); +} + +void ResourceCache::decrementRefcountLocked(SkiaColorFilter* filterResource) { + SkSafeUnref(filterResource->getSkColorFilter()); + decrementRefcountLocked((void*) filterResource); +} + void ResourceCache::destructor(SkPath* resource) { Mutex::Autolock _l(mLock); + destructorLocked(resource); +} + +void ResourceCache::destructorLocked(SkPath* resource) { ssize_t index = mCache->indexOfKey(resource); ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; if (ref == NULL) { @@ -150,6 +191,10 @@ void ResourceCache::destructor(SkPath* resource) { void ResourceCache::destructor(SkBitmap* resource) { Mutex::Autolock _l(mLock); + destructorLocked(resource); +} + +void ResourceCache::destructorLocked(SkBitmap* resource) { ssize_t index = mCache->indexOfKey(resource); ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; if (ref == NULL) { @@ -168,6 +213,10 @@ void ResourceCache::destructor(SkBitmap* resource) { void ResourceCache::destructor(SkiaShader* resource) { Mutex::Autolock _l(mLock); + destructorLocked(resource); +} + +void ResourceCache::destructorLocked(SkiaShader* resource) { ssize_t index = mCache->indexOfKey(resource); ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; if (ref == NULL) { @@ -183,6 +232,10 @@ void ResourceCache::destructor(SkiaShader* resource) { void ResourceCache::destructor(SkiaColorFilter* resource) { Mutex::Autolock _l(mLock); + destructorLocked(resource); +} + +void ResourceCache::destructorLocked(SkiaColorFilter* resource) { ssize_t index = mCache->indexOfKey(resource); ResourceReference* ref = index >= 0 ? mCache->valueAt(index) : NULL; if (ref == NULL) { @@ -196,6 +249,29 @@ void ResourceCache::destructor(SkiaColorFilter* resource) { } } +void ResourceCache::recycle(SkBitmap* resource) { + Mutex::Autolock _l(mLock); + recycleLocked(resource); +} + +void ResourceCache::recycleLocked(SkBitmap* resource) { + ssize_t index = mCache->indexOfKey(resource); + if (index < 0) { + // not tracking this resource; just recycle the pixel data + resource->setPixels(NULL, NULL); + return; + } + ResourceReference* ref = mCache->valueAt(index); + if (ref == NULL) { + // Should not get here - shouldn't get a call to recycle if we're not yet tracking it + return; + } + ref->recycled = true; + if (ref->refCount == 0) { + deleteResourceReference(resource, ref); + } +} + /** * This method should only be called while the mLock mutex is held (that mutex is grabbed * by the various destructor() and recycle() methods which call this method). |