diff options
-rw-r--r-- | include/core/SkPicture.h | 3 | ||||
-rw-r--r-- | include/core/SkStream.h | 8 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.cpp | 68 | ||||
-rw-r--r-- | src/core/SkStream.cpp | 9 | ||||
-rw-r--r-- | src/utils/SkMD5.h | 2 | ||||
-rw-r--r-- | tools/skpinfo.cpp | 11 |
6 files changed, 78 insertions, 23 deletions
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index 2689ae000d..d36d162aee 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -250,13 +250,14 @@ protected: // V19: encode matrices and regions into the ops stream // V20: added bool to SkPictureImageFilter's serialization (to allow SkPicture serialization) // V21: add pushCull, popCull + // V22: SK_PICT_FACTORY_TAG's size is now the chunk size in bytes // Note: If the picture version needs to be increased then please follow the // steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw // Only SKPs within the min/current picture version range (inclusive) can be read. static const uint32_t MIN_PICTURE_VERSION = 19; - static const uint32_t CURRENT_PICTURE_VERSION = 21; + static const uint32_t CURRENT_PICTURE_VERSION = 22; // fPlayback, fRecord, fWidth & fHeight are protected to allow derived classes to // install their own SkPicturePlayback-derived players,SkPictureRecord-derived diff --git a/include/core/SkStream.h b/include/core/SkStream.h index 6e0ab569d5..29aac1356c 100644 --- a/include/core/SkStream.h +++ b/include/core/SkStream.h @@ -205,7 +205,7 @@ public: bool writeScalar(SkScalar); bool writePackedUInt(size_t); - bool writeStream(SkStream* input, size_t length); + bool writeStream(SkStream* input, size_t length); /** * Append an SkData object to the stream, such that it can be read @@ -216,6 +216,12 @@ public: * just write the raw content of the SkData object to the stream. */ bool writeData(const SkData*); + + /** + * This returns the number of bytes in the stream required to store + * 'value'. + */ + static int SizeOfPackedUInt(size_t value); }; //////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 7cc2a556be..abddf8225a 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -307,27 +307,46 @@ bool SkPicturePlayback::containsBitmaps() const { #include "SkStream.h" -static void writeTagSize(SkWriteBuffer& buffer, uint32_t tag, - uint32_t size) { +static void write_tag_size(SkWriteBuffer& buffer, uint32_t tag, uint32_t size) { buffer.writeUInt(tag); buffer.writeUInt(size); } -static void writeTagSize(SkWStream* stream, uint32_t tag, - uint32_t size) { +static void write_tag_size(SkWStream* stream, uint32_t tag, uint32_t size) { stream->write32(tag); stream->write32(size); } -static void writeFactories(SkWStream* stream, const SkFactorySet& rec) { - int count = rec.count(); +static size_t compute_chunk_size(SkFlattenable::Factory* array, int count) { + size_t size = 4; // for 'count' + + for (int i = 0; i < count; i++) { + const char* name = SkFlattenable::FactoryToName(array[i]); + if (NULL == name || 0 == *name) { + size += SkWStream::SizeOfPackedUInt(0); + } else { + size_t len = strlen(name); + size += SkWStream::SizeOfPackedUInt(len); + size += len; + } + } + + return size; +} - writeTagSize(stream, SK_PICT_FACTORY_TAG, count); +static void write_factories(SkWStream* stream, const SkFactorySet& rec) { + int count = rec.count(); SkAutoSTMalloc<16, SkFlattenable::Factory> storage(count); SkFlattenable::Factory* array = (SkFlattenable::Factory*)storage.get(); rec.copyToArray(array); + size_t size = compute_chunk_size(array, count); + + // TODO: write_tag_size should really take a size_t + write_tag_size(stream, SK_PICT_FACTORY_TAG, (uint32_t) size); + stream->write32(count); + for (int i = 0; i < count; i++) { const char* name = SkFlattenable::FactoryToName(array[i]); // SkDebugf("---- write factories [%d] %p <%s>\n", i, array[i], name); @@ -339,12 +358,14 @@ static void writeFactories(SkWStream* stream, const SkFactorySet& rec) { stream->write(name, len); } } + + } static void writeTypefaces(SkWStream* stream, const SkRefCntSet& rec) { int count = rec.count(); - writeTagSize(stream, SK_PICT_TYPEFACE_TAG, count); + write_tag_size(stream, SK_PICT_TYPEFACE_TAG, count); SkAutoSTMalloc<16, SkTypeface*> storage(count); SkTypeface** array = (SkTypeface**)storage.get(); @@ -359,32 +380,32 @@ void SkPicturePlayback::flattenToBuffer(SkWriteBuffer& buffer) const { int i, n; if ((n = SafeCount(fBitmaps)) > 0) { - writeTagSize(buffer, SK_PICT_BITMAP_BUFFER_TAG, n); + write_tag_size(buffer, SK_PICT_BITMAP_BUFFER_TAG, n); for (i = 0; i < n; i++) { buffer.writeBitmap((*fBitmaps)[i]); } } if ((n = SafeCount(fPaints)) > 0) { - writeTagSize(buffer, SK_PICT_PAINT_BUFFER_TAG, n); + write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n); for (i = 0; i < n; i++) { buffer.writePaint((*fPaints)[i]); } } if ((n = SafeCount(fPathHeap.get())) > 0) { - writeTagSize(buffer, SK_PICT_PATH_BUFFER_TAG, n); + write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n); fPathHeap->flatten(buffer); } } void SkPicturePlayback::serialize(SkWStream* stream, SkPicture::EncodeBitmap encoder) const { - writeTagSize(stream, SK_PICT_READER_TAG, fOpData->size()); + write_tag_size(stream, SK_PICT_READER_TAG, fOpData->size()); stream->write(fOpData->bytes(), fOpData->size()); if (fPictureCount > 0) { - writeTagSize(stream, SK_PICT_PICTURE_TAG, fPictureCount); + write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictureCount); for (int i = 0; i < fPictureCount; i++) { fPictureRefs[i]->serialize(stream, encoder); } @@ -403,13 +424,13 @@ void SkPicturePlayback::serialize(SkWStream* stream, this->flattenToBuffer(buffer); - // We have to write these to sets into the stream *before* we write + // We have to write these two sets into the stream *before* we write // the buffer, since parsing that buffer will require that we already // have these sets available to use. - writeFactories(stream, factSet); + write_factories(stream, factSet); writeTypefaces(stream, typefaceSet); - writeTagSize(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWritten()); + write_tag_size(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWritten()); buffer.writeToStream(stream); } @@ -417,11 +438,11 @@ void SkPicturePlayback::serialize(SkWStream* stream, } void SkPicturePlayback::flatten(SkWriteBuffer& buffer) const { - writeTagSize(buffer, SK_PICT_READER_TAG, fOpData->size()); + write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size()); buffer.writeByteArray(fOpData->bytes(), fOpData->size()); if (fPictureCount > 0) { - writeTagSize(buffer, SK_PICT_PICTURE_TAG, fPictureCount); + write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictureCount); for (int i = 0; i < fPictureCount; i++) { fPictureRefs[i]->flatten(buffer); } @@ -481,6 +502,17 @@ bool SkPicturePlayback::parseStreamTag(SkStream* stream, const SkPictInfo& info, } break; case SK_PICT_FACTORY_TAG: { SkASSERT(!haveBuffer); + // Remove this code when v21 and below are no longer supported. At the + // same time add a new 'count' variable and use it rather then reusing 'size'. +#ifndef DISABLE_V21_COMPATIBILITY_CODE + if (info.fVersion >= 22) { + // in v22 this tag's size represents the size of the chunk in bytes + // and the number of factory strings is written out separately +#endif + size = stream->readU32(); +#ifndef DISABLE_V21_COMPATIBILITY_CODE + } +#endif fFactoryPlayback = SkNEW_ARGS(SkFactoryPlayback, (size)); for (size_t i = 0; i < size; i++) { SkString str; diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index 0d30b5214c..70f97d2f7c 100644 --- a/src/core/SkStream.cpp +++ b/src/core/SkStream.cpp @@ -140,6 +140,15 @@ bool SkWStream::writeScalar(SkScalar value) { return this->write(&value, sizeof(value)); } +int SkWStream::SizeOfPackedUInt(size_t value) { + if (value <= SK_MAX_BYTE_FOR_U8) { + return 1; + } else if (value <= 0xFFFF) { + return 3; + } + return 5; +} + bool SkWStream::writePackedUInt(size_t value) { uint8_t data[5]; size_t len = 1; diff --git a/src/utils/SkMD5.h b/src/utils/SkMD5.h index 6b4fc53636..0148641edc 100644 --- a/src/utils/SkMD5.h +++ b/src/utils/SkMD5.h @@ -25,7 +25,7 @@ public: * Note that this treats the buffer as a series of uint8_t values. */ virtual bool write(const void* buffer, size_t size) SK_OVERRIDE { - update(reinterpret_cast<const uint8_t*>(buffer), size); + this->update(reinterpret_cast<const uint8_t*>(buffer), size); return true; } diff --git a/tools/skpinfo.cpp b/tools/skpinfo.cpp index 97171c5999..087d7a3565 100644 --- a/tools/skpinfo.cpp +++ b/tools/skpinfo.cpp @@ -103,9 +103,16 @@ int tool_main(int argc, char** argv) { case SK_PICT_FACTORY_TAG: if (FLAGS_tags && !FLAGS_quiet) { SkDebugf("SK_PICT_FACTORY_TAG %d\n", chunkSize); - SkDebugf("Exiting early due to format limitations\n"); } - return kSuccess; // TODO: need to store size in bytes + // Remove this code when v21 and below are no longer supported +#ifndef DISABLE_V21_COMPATIBILITY_CODE + if (info.fVersion < 22) { + if (!FLAGS_quiet) { + SkDebugf("Exiting early due to format limitations\n"); + } + return kSuccess; // TODO: need to store size in bytes + } +#endif break; case SK_PICT_TYPEFACE_TAG: if (FLAGS_tags && !FLAGS_quiet) { |