aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPictureFlat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkPictureFlat.cpp')
-rw-r--r--src/core/SkPictureFlat.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/core/SkPictureFlat.cpp b/src/core/SkPictureFlat.cpp
index 2f8d1e198c..ec04495db9 100644
--- a/src/core/SkPictureFlat.cpp
+++ b/src/core/SkPictureFlat.cpp
@@ -80,6 +80,12 @@ SkFlatData* SkFlatData::Create(SkChunkAlloc* heap, const void* obj,
flattenProc(buffer, obj);
uint32_t size = buffer.size();
+
+#if !SK_PREFER_32BIT_CHECKSUM
+ uint32_t unpaddedSize = size;
+ size = SkAlign8(size);
+#endif
+
// allocate enough memory to hold both SkFlatData and the serialized
// contents
SkFlatData* result = (SkFlatData*) heap->allocThrow(size + sizeof(SkFlatData));
@@ -88,7 +94,18 @@ SkFlatData* SkFlatData::Create(SkChunkAlloc* heap, const void* obj,
// put the serialized contents into the data section of the new allocation
buffer.flatten(result->data());
- result->fChecksum = SkChecksum::Compute(result->data32(), size);
+#if SK_PREFER_32BIT_CHECKSUM
+ result->fChecksum =
+ SkComputeChecksum32(reinterpret_cast<uint32_t*>(result->data()), size);
+#else
+ if (size != unpaddedSize) {
+ // Flat data is padded: put zeros in the last 32 bits.
+ SkASSERT(size - 4 == unpaddedSize);
+ *((uint32_t*)((char*)result->data() + unpaddedSize)) = 0;
+ }
+ result->fChecksum =
+ SkComputeChecksum64(reinterpret_cast<uint64_t*>(result->data()), size);
+#endif
return result;
}