aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-04-05 17:05:16 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-06 18:13:19 +0000
commit6ff6af90e09068c07910174d11640e44815dd392 (patch)
tree7edc8ca4c8686f66bd32b706257aeaf6affbb452
parent372bc4e43e6720c1ce91cdfeb2cbe78ca50bc718 (diff)
handle odd-index-count in encode/decode
Bug: skia: Change-Id: Iffb123001a77049c6581f63bbc69c62f241a87f8 Reviewed-on: https://skia-review.googlesource.com/11405 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Eric Boren <borenet@google.com>
-rw-r--r--src/core/SkVertices.cpp9
-rw-r--r--tests/VerticesTest.cpp4
2 files changed, 8 insertions, 5 deletions
diff --git a/src/core/SkVertices.cpp b/src/core/SkVertices.cpp
index f9cd39cf93..8dadad056b 100644
--- a/src/core/SkVertices.cpp
+++ b/src/core/SkVertices.cpp
@@ -169,7 +169,8 @@ sk_sp<SkData> SkVertices::encode() const {
Sizes sizes(fVertexCnt, fIndexCnt, this->hasTexCoords(), this->hasColors());
SkASSERT(sizes.isValid());
- const size_t size = kHeaderSize + sizes.fArrays;
+ // need to force alignment to 4 for SkWriter32 -- will pad w/ 0s as needed
+ const size_t size = SkAlign4(kHeaderSize + sizes.fArrays);
sk_sp<SkData> data = SkData::MakeUninitialized(size);
SkWriter32 writer(data->writable_data(), data->size());
@@ -180,7 +181,8 @@ sk_sp<SkData> SkVertices::encode() const {
writer.write(fPositions, sizes.fVSize);
writer.write(fTexs, sizes.fTSize);
writer.write(fColors, sizes.fCSize);
- writer.write(fIndices, sizes.fISize);
+ // if index-count is odd, we won't be 4-bytes aligned, so we call the pad version
+ writer.writePad(fIndices, sizes.fISize);
return data;
}
@@ -203,7 +205,8 @@ sk_sp<SkVertices> SkVertices::Decode(const void* data, size_t length) {
if (!sizes.isValid()) {
return nullptr;
}
- if (kHeaderSize + sizes.fArrays != length) {
+ // logically we can be only 2-byte aligned, but our buffer is always 4-byte aligned
+ if (SkAlign4(kHeaderSize + sizes.fArrays) != length) {
return nullptr;
}
diff --git a/tests/VerticesTest.cpp b/tests/VerticesTest.cpp
index 5c5c6af41d..399aba2f21 100644
--- a/tests/VerticesTest.cpp
+++ b/tests/VerticesTest.cpp
@@ -50,8 +50,8 @@ static bool equal(const SkVertices* v0, const SkVertices* v1) {
}
DEF_TEST(Vertices, reporter) {
- int vCount = 4;
- int iCount = 6;
+ int vCount = 5;
+ int iCount = 9; // odd value exercises padding logic in encode()
const uint32_t texFlags[] = { 0, SkVertices::kHasTexCoords_BuilderFlag };
const uint32_t colFlags[] = { 0, SkVertices::kHasColors_BuilderFlag };