diff options
author | 2017-03-14 21:05:17 -0400 | |
---|---|---|
committer | 2017-03-15 01:32:38 +0000 | |
commit | 9a8065d34dd090837c2a05bc60533fcc6268e6bb (patch) | |
tree | 1159fe5ece68e428aaf6d528de38825728d5245c | |
parent | 64b974836a594c4f14384ded399ff09e96160215 (diff) |
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>
-rw-r--r-- | include/core/SkVertices.h | 3 | ||||
-rw-r--r-- | src/core/SkVertices.cpp | 11 | ||||
-rw-r--r-- | tests/VerticesTest.cpp | 3 |
3 files changed, 16 insertions, 1 deletions
diff --git a/include/core/SkVertices.h b/include/core/SkVertices.h index 5dbdefaa3c..af4e3bc960 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<SkVertices> Decode(const void*, size_t); sk_sp<SkData> 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 f2a63b9a73..936d70dc09 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> 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 9c433baf86..8cf55142f3 100644 --- a/tests/VerticesTest.cpp +++ b/tests/VerticesTest.cpp @@ -79,6 +79,9 @@ DEF_TEST(Vertices, reporter) { 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())); } } |