add uniqueID

BUG=skia:6366

Change-Id: Ie3215a392040be645524a2294d824d953ba3a1b6
Reviewed-on: https://skia-review.googlesource.com/9703
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/include/core/SkVertices.h b/include/core/SkVertices.h
index 5dbdefa..af4e3bc 100644
--- a/include/core/SkVertices.h
+++ b/include/core/SkVertices.h
@@ -74,6 +74,7 @@
 
     SkCanvas::VertexMode mode() const { return fMode; }
 
+    uint32_t uniqueID() const { return fUniqueID; }
     int vertexCount() const { return fVertexCnt; }
     bool hasColors() const { return SkToBool(fColors); }
     bool hasTexCoords() const { return SkToBool(fTexs); }
@@ -92,7 +93,6 @@
 
     const SkRect& bounds() const { return fBounds; }
 
-
     static sk_sp<SkVertices> Decode(const void*, size_t);
     sk_sp<SkData> encode() const;
 
@@ -104,6 +104,7 @@
     const SkColor* fColors;
     const uint16_t* fIndices;
     SkRect fBounds;
+    uint32_t fUniqueID;
     int fVertexCnt;
     int fIndexCnt;
     SkCanvas::VertexMode fMode;
diff --git a/src/core/SkVertices.cpp b/src/core/SkVertices.cpp
index f2a63b9..936d70d 100644
--- a/src/core/SkVertices.cpp
+++ b/src/core/SkVertices.cpp
@@ -5,11 +5,21 @@
  * found in the LICENSE file.
  */
 
+#include "SkAtomics.h"
 #include "SkVertices.h"
 #include "SkData.h"
 #include "SkReader32.h"
 #include "SkWriter32.h"
 
+static int32_t gNextID = 1;
+static int32_t next_id() {
+    int32_t id;
+    do {
+        id = sk_atomic_inc(&gNextID);
+    } while (id == SK_InvalidGenID);
+    return id;
+}
+
 static size_t compute_arrays_size(int vertexCount, int indexCount, uint32_t builderFlags) {
     if (vertexCount < 0 || indexCount < 0) {
         return 0;   // signal error
@@ -79,6 +89,7 @@
     obj->fColors = fColors;
     obj->fIndices = fIndices;
     obj->fBounds.set(fPositions, fVertexCnt);
+    obj->fUniqueID = next_id();
     obj->fVertexCnt = fVertexCnt;
     obj->fIndexCnt = fIndexCnt;
     obj->fMode = fMode;
diff --git a/tests/VerticesTest.cpp b/tests/VerticesTest.cpp
index 9c433ba..8cf5514 100644
--- a/tests/VerticesTest.cpp
+++ b/tests/VerticesTest.cpp
@@ -79,6 +79,9 @@
             sk_sp<SkData> data = v0->encode();
             sk_sp<SkVertices> v1 = SkVertices::Decode(data->data(), data->size());
 
+            REPORTER_ASSERT(reporter, v0->uniqueID() != 0);
+            REPORTER_ASSERT(reporter, v1->uniqueID() != 0);
+            REPORTER_ASSERT(reporter, v0->uniqueID() != v1->uniqueID());
             REPORTER_ASSERT(reporter, equal(v0.get(), v1.get()));
         }
     }