Improve gradients
Avoid using textures for common gradients (two stops from 0.0 to 1.0)
Change-Id: Iff55d21b126c8cfc4cfb701669f2339c8f6b131a
diff --git a/libs/hwui/GradientCache.h b/libs/hwui/GradientCache.h
index 59515a1..3b7c1fa 100644
--- a/libs/hwui/GradientCache.h
+++ b/libs/hwui/GradientCache.h
@@ -36,16 +36,14 @@
count = 0;
colors = NULL;
positions = NULL;
- tileMode = SkShader::kClamp_TileMode;
}
- GradientCacheEntry(uint32_t* colors, float* positions, int count,
- SkShader::TileMode tileMode) {
- copy(colors, positions, count, tileMode);
+ GradientCacheEntry(uint32_t* colors, float* positions, int count) {
+ copy(colors, positions, count);
}
GradientCacheEntry(const GradientCacheEntry& entry) {
- copy(entry.colors, entry.positions, entry.count, entry.tileMode);
+ copy(entry.colors, entry.positions, entry.count);
}
~GradientCacheEntry() {
@@ -58,7 +56,7 @@
delete[] colors;
delete[] positions;
- copy(entry.colors, entry.positions, entry.count, entry.tileMode);
+ copy(entry.colors, entry.positions, entry.count);
}
return *this;
@@ -67,13 +65,11 @@
bool operator<(const GradientCacheEntry& r) const {
const GradientCacheEntry& rhs = (const GradientCacheEntry&) r;
LTE_INT(count) {
- LTE_INT(tileMode) {
- int result = memcmp(colors, rhs.colors, count * sizeof(uint32_t));
- if (result< 0) return true;
- else if (result == 0) {
- result = memcmp(positions, rhs.positions, count * sizeof(float));
- if (result < 0) return true;
- }
+ int result = memcmp(colors, rhs.colors, count * sizeof(uint32_t));
+ if (result< 0) return true;
+ else if (result == 0) {
+ result = memcmp(positions, rhs.positions, count * sizeof(float));
+ if (result < 0) return true;
}
}
return false;
@@ -86,11 +82,10 @@
private:
- void copy(uint32_t* colors, float* positions, int count, SkShader::TileMode tileMode) {
+ void copy(uint32_t* colors, float* positions, int count) {
this->count = count;
this->colors = new uint32_t[count];
this->positions = new float[count];
- this->tileMode = tileMode;
memcpy(this->colors, colors, count * sizeof(uint32_t));
memcpy(this->positions, positions, count * sizeof(float));
@@ -118,8 +113,8 @@
/**
* Returns the texture associated with the specified shader.
*/
- Texture* get(uint32_t* colors, float* positions,
- int count, SkShader::TileMode tileMode = SkShader::kClamp_TileMode);
+ Texture* get(uint32_t* colors, float* positions, int count);
+
/**
* Clears the cache. This causes all textures to be deleted.
*/
@@ -144,10 +139,16 @@
* returned.
*/
Texture* addLinearGradient(GradientCacheEntry& gradient,
- uint32_t* colors, float* positions, int count,
- SkShader::TileMode tileMode = SkShader::kClamp_TileMode);
+ uint32_t* colors, float* positions, int count);
- void generateTexture(SkBitmap* bitmap, Texture* texture);
+ void generateTexture(uint32_t* colors, float* positions, int count, Texture* texture);
+
+ struct GradientInfo {
+ uint32_t width;
+ bool hasAlpha;
+ };
+
+ void getGradientInfo(const uint32_t* colors, const int count, GradientInfo& info);
GenerationCache<GradientCacheEntry, Texture*> mCache;