summaryrefslogtreecommitdiffstats
path: root/libs/hwui/ResourceCache.cpp
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2010-11-11 16:30:16 -0800
committerChet Haase <chet@google.com>2010-11-11 16:44:46 -0800
commite7d2295c06ef9b9df6336cbff23007a13fb3f6e4 (patch)
treec7942510b0b0f24cac8a88af0d40d878242a99b8 /libs/hwui/ResourceCache.cpp
parent7c5c9e4717741b3c5961dfbda2b90feca137b309 (diff)
downloadframeworks_base-e7d2295c06ef9b9df6336cbff23007a13fb3f6e4.zip
frameworks_base-e7d2295c06ef9b9df6336cbff23007a13fb3f6e4.tar.gz
frameworks_base-e7d2295c06ef9b9df6336cbff23007a13fb3f6e4.tar.bz2
make ResourceCache for display lists thread-safe
Change-Id: I41885b4ae249d7d7c000bab17bf32340ba85ab3a
Diffstat (limited to 'libs/hwui/ResourceCache.cpp')
-rw-r--r--libs/hwui/ResourceCache.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/libs/hwui/ResourceCache.cpp b/libs/hwui/ResourceCache.cpp
index 9f18948..5ebd2c0 100644
--- a/libs/hwui/ResourceCache.cpp
+++ b/libs/hwui/ResourceCache.cpp
@@ -37,14 +37,17 @@ void ResourceCache::logCache() {
}
ResourceCache::ResourceCache() {
+ Mutex::Autolock _l(mLock);
mCache = new KeyedVector<void *, ResourceReference *>();
}
ResourceCache::~ResourceCache() {
+ Mutex::Autolock _l(mLock);
delete mCache;
}
void ResourceCache::incrementRefcount(void* resource, ResourceType resourceType) {
+ Mutex::Autolock _l(mLock);
for (size_t i = 0; i < mCache->size(); ++i) {
void* ref = mCache->valueAt(i);
}
@@ -73,6 +76,7 @@ void ResourceCache::incrementRefcount(SkiaColorFilter* filterResource) {
}
void ResourceCache::decrementRefcount(void* resource) {
+ Mutex::Autolock _l(mLock);
ResourceReference* ref = mCache->indexOfKey(resource) >= 0 ? mCache->valueFor(resource) : NULL;
if (ref == NULL) {
// Should not get here - shouldn't get a call to decrement if we're not yet tracking it
@@ -101,6 +105,7 @@ void ResourceCache::decrementRefcount(SkiaColorFilter* filterResource) {
}
void ResourceCache::recycle(SkBitmap* resource) {
+ Mutex::Autolock _l(mLock);
if (mCache->indexOfKey(resource) < 0) {
// not tracking this resource; just recycle the pixel data
resource->setPixels(NULL, NULL);
@@ -110,6 +115,7 @@ void ResourceCache::recycle(SkBitmap* resource) {
}
void ResourceCache::recycle(void* resource) {
+ Mutex::Autolock _l(mLock);
ResourceReference* ref = mCache->indexOfKey(resource) >= 0 ? mCache->valueFor(resource) : NULL;
if (ref == NULL) {
// Should not get here - shouldn't get a call to recycle if we're not yet tracking it
@@ -122,6 +128,7 @@ void ResourceCache::recycle(void* resource) {
}
void ResourceCache::destructor(SkBitmap* resource) {
+ Mutex::Autolock _l(mLock);
ResourceReference* ref = mCache->indexOfKey(resource) >= 0 ? mCache->valueFor(resource) : NULL;
if (ref == NULL) {
// If we're not tracking this resource, just delete it
@@ -139,6 +146,7 @@ void ResourceCache::destructor(SkBitmap* resource) {
}
void ResourceCache::destructor(SkiaShader* resource) {
+ Mutex::Autolock _l(mLock);
ResourceReference* ref = mCache->indexOfKey(resource) >= 0 ? mCache->valueFor(resource) : NULL;
if (ref == NULL) {
// If we're not tracking this resource, just delete it
@@ -156,6 +164,7 @@ void ResourceCache::destructor(SkiaShader* resource) {
}
void ResourceCache::destructor(SkiaColorFilter* resource) {
+ Mutex::Autolock _l(mLock);
ResourceReference* ref = mCache->indexOfKey(resource) >= 0 ? mCache->valueFor(resource) : NULL;
if (ref == NULL) {
// If we're not tracking this resource, just delete it
@@ -169,6 +178,10 @@ void ResourceCache::destructor(SkiaColorFilter* resource) {
}
}
+/**
+ * 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).
+ */
void ResourceCache::deleteResourceReference(void* resource, ResourceReference* ref) {
if (ref->recycled && ref->resourceType == kBitmap) {
((SkBitmap*) resource)->setPixels(NULL, NULL);