summaryrefslogtreecommitdiff
path: root/libs/hwui/GradientCache.cpp
diff options
context:
space:
mode:
author Romain Guy <romainguy@google.com> 2011-08-01 18:56:21 -0700
committer Romain Guy <romainguy@google.com> 2011-08-01 18:56:21 -0700
commit6203f6c8147069976342be8f42add797a50f9557 (patch)
treecb623a81ace2133781fe04d57d5e08aee7aa8121 /libs/hwui/GradientCache.cpp
parent0965a3244b4c3009d08db2e084cdcb681ef66d26 (diff)
Reduce the amount of data cached by the gradients cache.
Change-Id: I8546f5a5ecf38031c9a40bdcc434d4c7f22da63d
Diffstat (limited to 'libs/hwui/GradientCache.cpp')
-rw-r--r--libs/hwui/GradientCache.cpp40
1 files changed, 15 insertions, 25 deletions
diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp
index 996acd5bceac..aacf22a19e7e 100644
--- a/libs/hwui/GradientCache.cpp
+++ b/libs/hwui/GradientCache.cpp
@@ -35,7 +35,7 @@ namespace uirenderer {
///////////////////////////////////////////////////////////////////////////////
GradientCache::GradientCache():
- mCache(GenerationCache<SkShader*, Texture*>::kUnlimitedCapacity),
+ mCache(GenerationCache<GradientCacheEntry, Texture*>::kUnlimitedCapacity),
mSize(0), mMaxSize(MB(DEFAULT_GRADIENT_CACHE_SIZE)) {
char property[PROPERTY_VALUE_MAX];
if (property_get(PROPERTY_GRADIENT_CACHE_SIZE, property, NULL) > 0) {
@@ -49,7 +49,7 @@ GradientCache::GradientCache():
}
GradientCache::GradientCache(uint32_t maxByteSize):
- mCache(GenerationCache<SkShader*, Texture*>::kUnlimitedCapacity),
+ mCache(GenerationCache<GradientCacheEntry, Texture*>::kUnlimitedCapacity),
mSize(0), mMaxSize(maxByteSize) {
mCache.setOnEntryRemovedListener(this);
}
@@ -81,9 +81,8 @@ void GradientCache::setMaxSize(uint32_t maxSize) {
// Callbacks
///////////////////////////////////////////////////////////////////////////////
-void GradientCache::operator()(SkShader*& shader, Texture*& texture) {
- // Already locked here
- if (shader) {
+void GradientCache::operator()(GradientCacheEntry& shader, Texture*& texture) {
+ if (texture) {
const uint32_t size = texture->width * texture->height * 4;
mSize -= size;
}
@@ -98,34 +97,25 @@ void GradientCache::operator()(SkShader*& shader, Texture*& texture) {
// Caching
///////////////////////////////////////////////////////////////////////////////
-Texture* GradientCache::get(SkShader* shader) {
- return mCache.get(shader);
-}
+Texture* GradientCache::get(uint32_t* colors, float* positions,
+ int count, SkShader::TileMode tileMode) {
-void GradientCache::remove(SkShader* shader) {
- mCache.remove(shader);
-}
+ GradientCacheEntry gradient(colors, positions, count, tileMode);
+ Texture* texture = mCache.get(gradient);
-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));
+ if (!texture) {
+ texture = addLinearGradient(gradient, colors, positions, count, tileMode);
}
- mGarbage.clear();
+
+ return texture;
}
void GradientCache::clear() {
mCache.clear();
}
-Texture* GradientCache::addLinearGradient(SkShader* shader, uint32_t* colors,
- float* positions, int count, SkShader::TileMode tileMode) {
+Texture* GradientCache::addLinearGradient(GradientCacheEntry& gradient,
+ uint32_t* colors, float* positions, int count, SkShader::TileMode tileMode) {
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1024, 1);
bitmap.allocPixels();
@@ -156,7 +146,7 @@ Texture* GradientCache::addLinearGradient(SkShader* shader, uint32_t* colors,
generateTexture(&bitmap, texture);
mSize += size;
- mCache.put(shader, texture);
+ mCache.put(gradient, texture);
return texture;
}