Fix SkVertices serialization bug. Also remove Builder getters for counts.
We already checked the SkSafeRange earlier (after its last use). Here we need to be checking the SkSafeMath object. Oops. The counts are directly copied from the constructor to the vertices' fields - the user already knows what they are (and the tests are verifying a tautology). Bug: skia:9984 Change-Id: I33c62e02825718e497834b0dfa40d0d56e46a197 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/280963 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
parent
17b5180931
commit
46aacc7710
@ -98,9 +98,6 @@ public:
|
||||
|
||||
bool isValid() const { return fVertices != nullptr; }
|
||||
|
||||
// if the builder is invalid, these will return 0
|
||||
int vertexCount() const;
|
||||
int indexCount() const;
|
||||
SkPoint* positions();
|
||||
uint16_t* indices(); // returns null if there are no indices
|
||||
|
||||
|
@ -229,14 +229,6 @@ sk_sp<SkVertices> SkVertices::Builder::detach() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int SkVertices::Builder::vertexCount() const {
|
||||
return fVertices ? fVertices->fVertexCount : 0;
|
||||
}
|
||||
|
||||
int SkVertices::Builder::indexCount() const {
|
||||
return fVertices ? fVertices->fIndexCount : 0;
|
||||
}
|
||||
|
||||
SkPoint* SkVertices::Builder::positions() {
|
||||
return fVertices ? const_cast<SkPoint*>(fVertices->fPositions) : nullptr;
|
||||
}
|
||||
@ -464,8 +456,7 @@ sk_sp<SkVertices> SkVertices::Decode(const void* data, size_t length) {
|
||||
size_t isize = (mode == kTriangleFan_VertexMode) ? sizes.fBuilderTriFanISize : sizes.fISize;
|
||||
reader.read(builder.indices(), isize);
|
||||
if (indexCount > 0) {
|
||||
// validate that the indicies are in range
|
||||
SkASSERT(indexCount == builder.indexCount());
|
||||
// validate that the indices are in range
|
||||
const uint16_t* indices = builder.indices();
|
||||
for (int i = 0; i < indexCount; ++i) {
|
||||
if (indices[i] >= (unsigned)vertexCount) {
|
||||
@ -474,7 +465,7 @@ sk_sp<SkVertices> SkVertices::Decode(const void* data, size_t length) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!safe.ok()) {
|
||||
if (!safe_math.ok()) {
|
||||
return nullptr;
|
||||
}
|
||||
return builder.detach();
|
||||
|
@ -94,8 +94,6 @@ DEF_TEST(Vertices, reporter) {
|
||||
uint32_t flags = texF | colF;
|
||||
|
||||
SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, vCount, iCount, flags);
|
||||
REPORTER_ASSERT(reporter, builder.vertexCount() == vCount);
|
||||
REPORTER_ASSERT(reporter, builder.indexCount() == iCount);
|
||||
|
||||
for (int i = 0; i < vCount; ++i) {
|
||||
float x = (float)i;
|
||||
@ -107,7 +105,7 @@ DEF_TEST(Vertices, reporter) {
|
||||
builder.colors()[i] = SkColorSetARGB(0xFF, i, 0x80, 0);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < builder.indexCount(); ++i) {
|
||||
for (int i = 0; i < iCount; ++i) {
|
||||
builder.indices()[i] = i % vCount;
|
||||
}
|
||||
self_test(builder.detach(), reporter);
|
||||
@ -134,18 +132,16 @@ DEF_TEST(Vertices, reporter) {
|
||||
for (const auto& test : attrTests) {
|
||||
SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, vCount, iCount,
|
||||
test.attrs, test.count);
|
||||
REPORTER_ASSERT(reporter, builder.vertexCount() == vCount);
|
||||
REPORTER_ASSERT(reporter, builder.indexCount() == iCount);
|
||||
|
||||
float* customData = (float*)builder.customData();
|
||||
int customDataCount = test.expected_size / sizeof(float);
|
||||
for (int i = 0; i < builder.vertexCount(); ++i) {
|
||||
for (int i = 0; i < vCount; ++i) {
|
||||
builder.positions()[i].set((float)i, 1);
|
||||
for (int j = 0; j < customDataCount; ++j) {
|
||||
customData[i * customDataCount + j] = (float)j;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < builder.indexCount(); ++i) {
|
||||
for (int i = 0; i < iCount; ++i) {
|
||||
builder.indices()[i] = i % vCount;
|
||||
}
|
||||
self_test(builder.detach(), reporter);
|
||||
|
Loading…
Reference in New Issue
Block a user