From 059e12ccd20f5c249724a8362d6bac325334ea76 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Wed, 28 Nov 2012 17:35:51 -0800 Subject: Use LruCache instead of GenerationCache in libhwui Change-Id: Ic26ddc7151eb5462bcd243b21daf7187ed6d3bec --- libs/hwui/GradientCache.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'libs/hwui/GradientCache.cpp') 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 #include #include "Caches.h" @@ -42,12 +43,39 @@ static inline T min(T a, T b) { return a < b ? a : 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::kUnlimitedCapacity), + mCache(LruCache::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::kUnlimitedCapacity), + mCache(LruCache::kUnlimitedCapacity), mSize(0), mMaxSize(maxByteSize) { mCache.setOnEntryRemovedListener(this); } -- cgit v1.2.3-59-g8ed1b