From 9a8065d34dd090837c2a05bc60533fcc6268e6bb Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Tue, 14 Mar 2017 21:05:17 -0400 Subject: [PATCH] add uniqueID BUG=skia:6366 Change-Id: Ie3215a392040be645524a2294d824d953ba3a1b6 Reviewed-on: https://skia-review.googlesource.com/9703 Reviewed-by: Mike Reed Commit-Queue: Mike Reed --- include/core/SkVertices.h | 3 ++- src/core/SkVertices.cpp | 11 +++++++++++ tests/VerticesTest.cpp | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) 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 @@ public: 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 @@ public: const SkRect& bounds() const { return fBounds; } - static sk_sp Decode(const void*, size_t); sk_sp encode() const; @@ -104,6 +104,7 @@ private: 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 @@ sk_sp SkVertices::Builder::detach() { 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 @@ DEF_TEST(Vertices, reporter) { sk_sp data = v0->encode(); sk_sp 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())); } } -- 2.7.4