summaryrefslogtreecommitdiff
path: root/libs/hwui/GradientCache.cpp
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2010-11-11 15:36:56 -0800
committerRomain Guy <romainguy@google.com>2010-11-11 15:36:56 -0800
commitfe48f65922d4a3cc4aefe058cee5acec51504a20 (patch)
tree97ea23ae71dade1ef7bf783523bea9cda31dd042 /libs/hwui/GradientCache.cpp
parent50c5e4c36e494d092576d42cf2b406abab20510a (diff)
Free resources only from the GL context thread.
Bug #3179882 Resources were freed following garbage collections on a worker thread. This worker thread had no EGL context, which would cause the renderer to incorrectly assume that the memory was liberated. Change-Id: Ifdb51f94ddf42641e8654522787bfac532976c7c
Diffstat (limited to 'libs/hwui/GradientCache.cpp')
-rw-r--r--libs/hwui/GradientCache.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp
index 97f4cb468c53..a37964eae4cd 100644
--- a/libs/hwui/GradientCache.cpp
+++ b/libs/hwui/GradientCache.cpp
@@ -54,7 +54,6 @@ GradientCache::GradientCache(uint32_t maxByteSize):
}
GradientCache::~GradientCache() {
- Mutex::Autolock _l(mLock);
mCache.clear();
}
@@ -63,17 +62,14 @@ GradientCache::~GradientCache() {
///////////////////////////////////////////////////////////////////////////////
uint32_t GradientCache::getSize() {
- Mutex::Autolock _l(mLock);
return mSize;
}
uint32_t GradientCache::getMaxSize() {
- Mutex::Autolock _l(mLock);
return mMaxSize;
}
void GradientCache::setMaxSize(uint32_t maxSize) {
- Mutex::Autolock _l(mLock);
mMaxSize = maxSize;
while (mSize > mMaxSize) {
mCache.removeOldest();
@@ -102,17 +98,28 @@ void GradientCache::operator()(SkShader*& shader, Texture*& texture) {
///////////////////////////////////////////////////////////////////////////////
Texture* GradientCache::get(SkShader* shader) {
- Mutex::Autolock _l(mLock);
return mCache.get(shader);
}
void GradientCache::remove(SkShader* shader) {
- Mutex::Autolock _l(mLock);
mCache.remove(shader);
}
-void GradientCache::clear() {
+void GradientCache::removeDeferred(SkShader* shader) {
Mutex::Autolock _l(mLock);
+ mGarbage.push(shader);
+}
+
+void GradientCache::clearGarbage() {
+ Mutex::Autolock _l(mLock);
+ size_t count = mGarbage.size();
+ for (size_t i = 0; i < count; i++) {
+ mCache.remove(mGarbage.itemAt(i));
+ }
+ mGarbage.clear();
+}
+
+void GradientCache::clear() {
mCache.clear();
}
@@ -138,21 +145,17 @@ Texture* GradientCache::addLinearGradient(SkShader* shader, uint32_t* colors,
canvas.drawRectCoords(0.0f, 0.0f, bitmap.width(), 1.0f, p);
- mLock.lock();
// Asume the cache is always big enough
const uint32_t size = bitmap.rowBytes() * bitmap.height();
while (mSize + size > mMaxSize) {
mCache.removeOldest();
}
- mLock.unlock();
Texture* texture = new Texture;
generateTexture(&bitmap, texture);
- mLock.lock();
mSize += size;
mCache.put(shader, texture);
- mLock.unlock();
return texture;
}