diff options
Diffstat (limited to 'libs/hwui/GradientCache.h')
-rw-r--r-- | libs/hwui/GradientCache.h | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/libs/hwui/GradientCache.h b/libs/hwui/GradientCache.h index 45c1005..7339853 100644 --- a/libs/hwui/GradientCache.h +++ b/libs/hwui/GradientCache.h @@ -38,28 +38,27 @@ struct GradientCacheEntry { GradientCacheEntry(uint32_t* colors, float* positions, int count, SkShader::TileMode tileMode) { - 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)); + copy(colors, positions, count, tileMode); } GradientCacheEntry(const GradientCacheEntry& entry) { - this->count = entry.count; - this->colors = new uint32_t[count]; - this->positions = new float[count]; - this->tileMode = entry.tileMode; - - memcpy(this->colors, entry.colors, count * sizeof(uint32_t)); - memcpy(this->positions, entry.positions, count * sizeof(float)); + copy(entry.colors, entry.positions, entry.count, entry.tileMode); } ~GradientCacheEntry() { - if (colors) delete[] colors; - if (positions) delete[] positions; + delete[] colors; + delete[] positions; + } + + GradientCacheEntry& operator=(const GradientCacheEntry& entry) { + if (this != &entry) { + delete[] colors; + delete[] positions; + + copy(entry.colors, entry.positions, entry.count, entry.tileMode); + } + + return *this; } bool operator<(const GradientCacheEntry& r) const { @@ -82,6 +81,18 @@ struct GradientCacheEntry { int count; SkShader::TileMode tileMode; +private: + + void copy(uint32_t* colors, float* positions, int count, SkShader::TileMode tileMode) { + 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)); + } + }; // GradientCacheEntry /** |