diff options
author | Romain Guy <romainguy@google.com> | 2012-11-28 17:35:51 -0800 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2012-11-29 11:44:02 -0800 |
commit | 059e12ccd20f5c249724a8362d6bac325334ea76 (patch) | |
tree | 7b15fa6bc6d2963715ea298a51cca3909c1e50c9 /libs/hwui/GradientCache.cpp | |
parent | c653df46436a796556da2633f90353900344ce39 (diff) |
Use LruCache instead of GenerationCache in libhwui
Change-Id: Ic26ddc7151eb5462bcd243b21daf7187ed6d3bec
Diffstat (limited to 'libs/hwui/GradientCache.cpp')
-rw-r--r-- | libs/hwui/GradientCache.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp index 2e4e3492df03..35a848725be6 100644 --- a/libs/hwui/GradientCache.cpp +++ b/libs/hwui/GradientCache.cpp @@ -16,6 +16,7 @@ #define LOG_TAG "OpenGLRenderer" +#include <utils/JenkinsHash.h> #include <utils/threads.h> #include "Caches.h" @@ -43,11 +44,38 @@ static inline T min(T a, T b) { } /////////////////////////////////////////////////////////////////////////////// +// Cache entry +/////////////////////////////////////////////////////////////////////////////// + +hash_t GradientCacheEntry::hash() const { + uint32_t hash = JenkinsHashMix(0, count); + hash = JenkinsHashMix(hash, tileMode); + for (uint32_t i = 0; i < count; i++) { + hash = JenkinsHashMix(hash, android::hash_type(colors[i])); + hash = JenkinsHashMix(hash, android::hash_type(positions[i])); + } + return JenkinsHashWhiten(hash); +} + +int GradientCacheEntry::compare(const GradientCacheEntry& lhs, const GradientCacheEntry& rhs) { + int deltaInt = int(lhs.count) - int(rhs.count); + if (deltaInt != 0) return deltaInt; + + deltaInt = lhs.tileMode - rhs.tileMode; + if (deltaInt != 0) return deltaInt; + + deltaInt = memcmp(lhs.colors, rhs.colors, lhs.count * sizeof(uint32_t)); + if (deltaInt != 0) return deltaInt; + + return memcmp(lhs.positions, rhs.positions, lhs.count * sizeof(float)); +} + +/////////////////////////////////////////////////////////////////////////////// // Constructors/destructor /////////////////////////////////////////////////////////////////////////////// GradientCache::GradientCache(): - mCache(GenerationCache<GradientCacheEntry, Texture*>::kUnlimitedCapacity), + mCache(LruCache<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) { @@ -63,7 +91,7 @@ GradientCache::GradientCache(): } GradientCache::GradientCache(uint32_t maxByteSize): - mCache(GenerationCache<GradientCacheEntry, Texture*>::kUnlimitedCapacity), + mCache(LruCache<GradientCacheEntry, Texture*>::kUnlimitedCapacity), mSize(0), mMaxSize(maxByteSize) { mCache.setOnEntryRemovedListener(this); } |