aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/VerticesTest.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-03-14 14:10:54 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-14 18:40:40 +0000
commitbdce9c2d73e3661f8061f73e35b74ba35d98e5ff (patch)
tree09390b3ba1baf99944c8e260c63dcd9ddf5aea65 /tests/VerticesTest.cpp
parent8199d94c0812a05320064f5f864b4208ffb25dba (diff)
vertices to/from data
precursor to enabling serialization in pictures BUG=skia:6366 Change-Id: Iba89aa98f389b3281e7705d041e3337e89071f03 Reviewed-on: https://skia-review.googlesource.com/9680 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'tests/VerticesTest.cpp')
-rw-r--r--tests/VerticesTest.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/VerticesTest.cpp b/tests/VerticesTest.cpp
new file mode 100644
index 0000000000..9c433baf86
--- /dev/null
+++ b/tests/VerticesTest.cpp
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkVertices.h"
+#include "Test.h"
+
+static bool equal(const SkVertices* v0, const SkVertices* v1) {
+ if (v0->mode() != v1->mode()) {
+ return false;
+ }
+ if (v0->vertexCount() != v1->vertexCount()) {
+ return false;
+ }
+ if (v0->indexCount() != v1->indexCount()) {
+ return false;
+ }
+
+ if (!!v0->texCoords() != !!v1->texCoords()) {
+ return false;
+ }
+ if (!!v0->colors() != !!v1->colors()) {
+ return false;
+ }
+
+ for (int i = 0; i < v0->vertexCount(); ++i) {
+ if (v0->positions()[i] != v1->positions()[i]) {
+ return false;
+ }
+ if (v0->texCoords()) {
+ if (v0->texCoords()[i] != v1->texCoords()[i]) {
+ return false;
+ }
+ }
+ if (v0->colors()) {
+ if (v0->colors()[i] != v1->colors()[i]) {
+ return false;
+ }
+ }
+ }
+ for (int i = 0; i < v0->indexCount(); ++i) {
+ if (v0->indices()[i] != v1->indices()[i]) {
+ return false;
+ }
+ }
+ return true;
+}
+
+DEF_TEST(Vertices, reporter) {
+ int vCount = 4;
+ int iCount = 6;
+
+ const uint32_t texFlags[] = { 0, SkVertices::kHasTexs_Flag };
+ const uint32_t colFlags[] = { 0, SkVertices::kHasColors_Flag };
+ for (auto texF : texFlags) {
+ for (auto colF : colFlags) {
+ uint32_t flags = texF | colF;
+
+ SkVertices::Builder builder(SkCanvas::kTriangles_VertexMode, vCount, iCount, flags);
+
+ for (int i = 0; i < vCount; ++i) {
+ float x = (float)i;
+ builder.positions()[i].set(x, 1);
+ if (builder.texCoords()) {
+ builder.texCoords()[i].set(x, 2);
+ }
+ if (builder.colors()) {
+ builder.colors()[i] = SkColorSetARGB(0xFF, i, 0x80, 0);
+ }
+ }
+ for (int i = 0; i < builder.indexCount(); ++i) {
+ builder.indices()[i] = i % vCount;
+ }
+
+ sk_sp<SkVertices> v0 = builder.detach();
+ sk_sp<SkData> data = v0->encode();
+ sk_sp<SkVertices> v1 = SkVertices::Decode(data->data(), data->size());
+
+ REPORTER_ASSERT(reporter, equal(v0.get(), v1.get()));
+ }
+ }
+}