Make sure we correctly copy caches keys.
Bug #5136067

Change-Id: I366e840bef44415436dc7b13d89cfb610feed663
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 @@
 
     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 @@
     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
 
 /**
diff --git a/libs/hwui/LayerCache.h b/libs/hwui/LayerCache.h
index a0eae59..63bb824 100644
--- a/libs/hwui/LayerCache.h
+++ b/libs/hwui/LayerCache.h
@@ -119,10 +119,6 @@
             mHeight = uint32_t(ceilf(layerHeight / float(LAYER_SIZE)) * LAYER_SIZE);
         }
 
-        LayerEntry(const LayerEntry& entry):
-            mLayer(entry.mLayer), mWidth(entry.mWidth), mHeight(entry.mHeight) {
-        }
-
         LayerEntry(Layer* layer):
             mLayer(layer), mWidth(layer->getWidth()), mHeight(layer->getHeight()) {
         }
diff --git a/libs/hwui/PatchCache.h b/libs/hwui/PatchCache.h
index 62d0ce1..91b603f 100644
--- a/libs/hwui/PatchCache.h
+++ b/libs/hwui/PatchCache.h
@@ -80,13 +80,6 @@
                 emptyCount(emptyCount), colorKey(colorKey) {
         }
 
-        PatchDescription(const PatchDescription& description):
-                bitmapWidth(description.bitmapWidth), bitmapHeight(description.bitmapHeight),
-                pixelWidth(description.pixelWidth), pixelHeight(description.pixelHeight),
-                xCount(description.xCount), yCount(description.yCount),
-                emptyCount(description.emptyCount), colorKey(description.colorKey) {
-        }
-
         bool operator<(const PatchDescription& rhs) const {
             LTE_FLOAT(bitmapWidth) {
                 LTE_FLOAT(bitmapHeight) {
diff --git a/libs/hwui/PathCache.h b/libs/hwui/PathCache.h
index 7ff8b74..4904a58 100644
--- a/libs/hwui/PathCache.h
+++ b/libs/hwui/PathCache.h
@@ -41,10 +41,6 @@
         path = NULL;
     }
 
-    PathCacheEntry(const PathCacheEntry& entry): ShapeCacheEntry(entry) {
-        path = entry.path;
-    }
-
     bool lessThan(const ShapeCacheEntry& r) const {
         const PathCacheEntry& rhs = (const PathCacheEntry&) r;
         LTE_INT(path) {
diff --git a/libs/hwui/ShapeCache.h b/libs/hwui/ShapeCache.h
index 33953be..0660b69 100644
--- a/libs/hwui/ShapeCache.h
+++ b/libs/hwui/ShapeCache.h
@@ -96,12 +96,6 @@
         pathEffect = NULL;
     }
 
-    ShapeCacheEntry(const ShapeCacheEntry& entry):
-        shapeType(entry.shapeType), join(entry.join), cap(entry.cap),
-        style(entry.style), miter(entry.miter),
-        strokeWidth(entry.strokeWidth), pathEffect(entry.pathEffect) {
-    }
-
     ShapeCacheEntry(ShapeType type, SkPaint* paint) {
         shapeType = type;
         join = paint->getStrokeJoin();
@@ -167,14 +161,6 @@
         mRy = 0;
     }
 
-    RoundRectShapeCacheEntry(const RoundRectShapeCacheEntry& entry):
-            ShapeCacheEntry(entry) {
-        mWidth = entry.mWidth;
-        mHeight = entry.mHeight;
-        mRx = entry.mRx;
-        mRy = entry.mRy;
-    }
-
     bool lessThan(const ShapeCacheEntry& r) const {
         const RoundRectShapeCacheEntry& rhs = (const RoundRectShapeCacheEntry&) r;
         LTE_INT(mWidth) {
@@ -206,11 +192,6 @@
         mRadius = 0;
     }
 
-    CircleShapeCacheEntry(const CircleShapeCacheEntry& entry):
-            ShapeCacheEntry(entry) {
-        mRadius = entry.mRadius;
-    }
-
     bool lessThan(const ShapeCacheEntry& r) const {
         const CircleShapeCacheEntry& rhs = (const CircleShapeCacheEntry&) r;
         LTE_INT(mRadius) {
@@ -234,12 +215,6 @@
         mWidth = mHeight = 0;
     }
 
-    OvalShapeCacheEntry(const OvalShapeCacheEntry& entry):
-            ShapeCacheEntry(entry) {
-        mWidth = entry.mWidth;
-        mHeight = entry.mHeight;
-    }
-
     bool lessThan(const ShapeCacheEntry& r) const {
         const OvalShapeCacheEntry& rhs = (const OvalShapeCacheEntry&) r;
         LTE_INT(mWidth) {
@@ -266,12 +241,6 @@
         mWidth = mHeight = 0;
     }
 
-    RectShapeCacheEntry(const RectShapeCacheEntry& entry):
-            ShapeCacheEntry(entry) {
-        mWidth = entry.mWidth;
-        mHeight = entry.mHeight;
-    }
-
     bool lessThan(const ShapeCacheEntry& r) const {
         const RectShapeCacheEntry& rhs = (const RectShapeCacheEntry&) r;
         LTE_INT(mWidth) {
@@ -306,15 +275,6 @@
         mUseCenter = 0;
     }
 
-    ArcShapeCacheEntry(const ArcShapeCacheEntry& entry):
-            ShapeCacheEntry(entry) {
-        mWidth = entry.mWidth;
-        mHeight = entry.mHeight;
-        mStartAngle = entry.mStartAngle;
-        mSweepAngle = entry.mSweepAngle;
-        mUseCenter = entry.mUseCenter;
-    }
-
     bool lessThan(const ShapeCacheEntry& r) const {
         const ArcShapeCacheEntry& rhs = (const ArcShapeCacheEntry&) r;
         LTE_INT(mWidth) {