skia2/tests/VerticesTest.cpp
Mike Reed 0c492cfe17 Revert[3] "store vertices arrays inline with object"""
This reverts commit 7d9f9e3020.

Reason for revert: speculative revert to try to fix google3

Original change's description:
> Revert[2] "store vertices arrays inline with object""
> 
> This reverts commit 9e62df6ecd.
> 
> Reason for revert: behavior in reader32 fixed
> 
> Fix is here: https://skia-review.googlesource.com/c/9729/
> 
> Original change's description:
> > Revert "store vertices arrays inline with object"
> > 
> > This reverts commit eaaebb19a1.
> > 
> > Reason for revert: may call SkReader32::read(null, 0) -- reader needs to handle this
> > 
> > Original change's description:
> > > store vertices arrays inline with object
> > > 
> > > Also unify some of naming (esp. around texCoords)
> > > 
> > > BUG=skia:6366
> > > 
> > > Change-Id: I5a6793f029cccf0cd0a2c1d180b259ce4eab526f
> > > Reviewed-on: https://skia-review.googlesource.com/9705
> > > Commit-Queue: Mike Reed <reed@google.com>
> > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > 
> > 
> > TBR=bsalomon@google.com,reed@google.com,reviews@skia.org
> > NOPRESUBMIT=true
> > NOTREECHECKS=true
> > NOTRY=true
> > BUG=skia:6366
> > 
> > Change-Id: Ie421654bcd74d74f8be6676291e3d6e16e2a7a16
> > Reviewed-on: https://skia-review.googlesource.com/9727
> > Reviewed-by: Mike Reed <reed@google.com>
> > Commit-Queue: Mike Reed <reed@google.com>
> > 
> 
> TBR=bsalomon@google.com,reviews@skia.org,reed@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:6366
> 
> Change-Id: I1f12108fff8f551d66455cfadd6d5dd9412e9aa8
> Reviewed-on: https://skia-review.googlesource.com/9760
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Mike Reed <reed@google.com>
> 

TBR=bsalomon@google.com,reviews@skia.org,reed@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:6366

Change-Id: Ie23130a07fbecd5664e37291bc167008a6b496bc
Reviewed-on: https://skia-review.googlesource.com/9806
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2017-03-16 16:44:39 +00:00

89 lines
2.6 KiB
C++

/*
* 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, v0->uniqueID() != 0);
REPORTER_ASSERT(reporter, v1->uniqueID() != 0);
REPORTER_ASSERT(reporter, v0->uniqueID() != v1->uniqueID());
REPORTER_ASSERT(reporter, equal(v0.get(), v1.get()));
}
}
}