diff options
author | Mike Reed <reed@google.com> | 2017-04-05 17:05:16 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-06 18:13:19 +0000 |
commit | 6ff6af90e09068c07910174d11640e44815dd392 (patch) | |
tree | 7edc8ca4c8686f66bd32b706257aeaf6affbb452 /src/core | |
parent | 372bc4e43e6720c1ce91cdfeb2cbe78ca50bc718 (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>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkVertices.cpp | 9 |
1 files changed, 6 insertions, 3 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; } |