diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPicture.cpp | 30 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.cpp | 35 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.h | 18 | ||||
-rw-r--r-- | src/core/SkReadBuffer.cpp | 3 |
4 files changed, 53 insertions, 33 deletions
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index ae0347cf25..5914ba46cd 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -138,8 +138,10 @@ SkPicture::SkPicture(const SkPicture& src) if (src.fPlayback) { fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback)); } else if (src.fRecord) { + SkPictInfo info; + this->createHeader(&info); // here we do a fake src.endRecording() - fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fRecord)); + fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fRecord, info)); } else { fPlayback = NULL; } @@ -173,6 +175,8 @@ SkPicture* SkPicture::clone() const { void SkPicture::clone(SkPicture* pictures, int count) const { SkPictCopyInfo copyInfo; + SkPictInfo info; + this->createHeader(&info); for (int i = 0; i < count; i++) { SkPicture* clone = &pictures[i]; @@ -190,7 +194,7 @@ void SkPicture::clone(SkPicture* pictures, int count) const { clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, ©Info)); } else if (fRecord) { // here we do a fake src.endRecording() - clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, true)); + clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, info, true)); } else { clone->fPlayback = NULL; } @@ -261,7 +265,9 @@ void SkPicture::endRecording() { if (NULL == fPlayback) { if (NULL != fRecord) { fRecord->endRecording(); - fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); + SkPictInfo info; + this->createHeader(&info); + fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, info)); SkSafeSetNull(fRecord); } } @@ -384,7 +390,7 @@ SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) { SkPicturePlayback* playback; // Check to see if there is a playback to recreate. if (buffer.readBool()) { - playback = SkPicturePlayback::CreateFromBuffer(buffer); + playback = SkPicturePlayback::CreateFromBuffer(buffer, info); if (NULL == playback) { return NULL; } @@ -417,13 +423,13 @@ void SkPicture::createHeader(SkPictInfo* info) const { void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { SkPicturePlayback* playback = fPlayback; + SkPictInfo info; + this->createHeader(&info); if (NULL == playback && fRecord) { - playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); + playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, info)); } - SkPictInfo header; - this->createHeader(&header); - stream->write(&header, sizeof(header)); + stream->write(&info, sizeof(info)); if (playback) { stream->writeBool(true); playback->serialize(stream, encoder); @@ -439,13 +445,13 @@ void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { void SkPicture::flatten(SkWriteBuffer& buffer) const { SkPicturePlayback* playback = fPlayback; + SkPictInfo info; + this->createHeader(&info); if (NULL == playback && fRecord) { - playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); + playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord, info)); } - SkPictInfo header; - this->createHeader(&header); - buffer.writeByteArray(&header, sizeof(header)); + buffer.writeByteArray(&info, sizeof(info)); if (playback) { buffer.writeBool(true); playback->flatten(buffer); diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 8320335e68..f1a947381b 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -24,11 +24,14 @@ template <typename T> int SafeCount(const T* obj) { */ #define SPEW_CLIP_SKIPPINGx -SkPicturePlayback::SkPicturePlayback() { +SkPicturePlayback::SkPicturePlayback(const SkPictInfo& info) : fInfo(info) { this->init(); } -SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record, bool deepCopy) { +SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record, + const SkPictInfo& info, + bool deepCopy) + : fInfo(info) { #ifdef SK_DEBUG_SIZE size_t overallBytes, bitmapBytes, matricesBytes, paintBytes, pathBytes, pictureBytes, regionBytes; @@ -158,7 +161,8 @@ static bool needs_deep_copy(const SkPaint& paint) { paint.getImageFilter(); } -SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src, SkPictCopyInfo* deepCopyInfo) { +SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src, SkPictCopyInfo* deepCopyInfo) + : fInfo(src.fInfo) { this->init(); fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); @@ -479,8 +483,10 @@ static uint32_t pictInfoFlagsToReadBufferFlags(uint32_t pictInfoFlags) { return rbMask; } -bool SkPicturePlayback::parseStreamTag(SkStream* stream, const SkPictInfo& info, uint32_t tag, - size_t size, SkPicture::InstallPixelRefProc proc) { +bool SkPicturePlayback::parseStreamTag(SkStream* stream, + uint32_t tag, + size_t size, + SkPicture::InstallPixelRefProc proc) { /* * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required @@ -506,7 +512,7 @@ bool SkPicturePlayback::parseStreamTag(SkStream* stream, const SkPictInfo& info, // 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) { + if (fInfo.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 @@ -568,7 +574,8 @@ bool SkPicturePlayback::parseStreamTag(SkStream* stream, const SkPictInfo& info, } SkReadBuffer buffer(storage.get(), size); - buffer.setFlags(pictInfoFlagsToReadBufferFlags(info.fFlags)); + buffer.setFlags(pictInfoFlagsToReadBufferFlags(fInfo.fFlags)); + buffer.setPictureVersion(fInfo.fVersion); fFactoryPlayback->setupBuffer(buffer); fTFPlayback.setupBuffer(buffer); @@ -654,16 +661,18 @@ bool SkPicturePlayback::parseBufferTag(SkReadBuffer& buffer, SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkStream* stream, const SkPictInfo& info, SkPicture::InstallPixelRefProc proc) { - SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); + SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (info))); - if (!playback->parseStream(stream, info, proc)) { + if (!playback->parseStream(stream, proc)) { return NULL; } return playback.detach(); } -SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer) { - SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); +SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer, + const SkPictInfo& info) { + SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (info))); + buffer.setPictureVersion(info.fVersion); if (!playback->parseBuffer(buffer)) { return NULL; @@ -671,7 +680,7 @@ SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer) { return playback.detach(); } -bool SkPicturePlayback::parseStream(SkStream* stream, const SkPictInfo& info, +bool SkPicturePlayback::parseStream(SkStream* stream, SkPicture::InstallPixelRefProc proc) { for (;;) { uint32_t tag = stream->readU32(); @@ -680,7 +689,7 @@ bool SkPicturePlayback::parseStream(SkStream* stream, const SkPictInfo& info, } uint32_t size = stream->readU32(); - if (!this->parseStreamTag(stream, info, tag, size, proc)) { + if (!this->parseStreamTag(stream, tag, size, proc)) { return false; // we're invalid } } diff --git a/src/core/SkPicturePlayback.h b/src/core/SkPicturePlayback.h index 89d70a1739..5fc52aeb9c 100644 --- a/src/core/SkPicturePlayback.h +++ b/src/core/SkPicturePlayback.h @@ -76,12 +76,12 @@ struct SkPictCopyInfo { class SkPicturePlayback { public: - SkPicturePlayback(); SkPicturePlayback(const SkPicturePlayback& src, SkPictCopyInfo* deepCopyInfo = NULL); - explicit SkPicturePlayback(const SkPictureRecord& record, bool deepCopy = false); - static SkPicturePlayback* CreateFromStream(SkStream*, const SkPictInfo&, + SkPicturePlayback(const SkPictureRecord& record, const SkPictInfo&, bool deepCopy = false); + static SkPicturePlayback* CreateFromStream(SkStream*, + const SkPictInfo&, SkPicture::InstallPixelRefProc); - static SkPicturePlayback* CreateFromBuffer(SkReadBuffer&); + static SkPicturePlayback* CreateFromBuffer(SkReadBuffer&, const SkPictInfo&); virtual ~SkPicturePlayback(); @@ -106,8 +106,9 @@ public: void resetOpID() { fCurOffset = 0; } protected: - bool parseStream(SkStream*, const SkPictInfo&, - SkPicture::InstallPixelRefProc); + explicit SkPicturePlayback(const SkPictInfo& info); + + bool parseStream(SkStream*, SkPicture::InstallPixelRefProc); bool parseBuffer(SkReadBuffer& buffer); #ifdef SK_DEVELOPER virtual bool preDraw(int opIndex, int type); @@ -217,8 +218,7 @@ public: #endif private: // these help us with reading/writing - bool parseStreamTag(SkStream*, const SkPictInfo&, uint32_t tag, size_t size, - SkPicture::InstallPixelRefProc); + bool parseStreamTag(SkStream*, uint32_t tag, size_t size, SkPicture::InstallPixelRefProc); bool parseBufferTag(SkReadBuffer&, uint32_t tag, size_t size); void flattenToBuffer(SkWriteBuffer&) const; @@ -271,6 +271,8 @@ private: // The offset of the current operation when within the draw method size_t fCurOffset; + const SkPictInfo fInfo; + #ifdef SK_BUILD_FOR_ANDROID SkMutex fDrawMutex; bool fAbortCurrentPlayback; diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp index 6a590ed694..b60dee3ba6 100644 --- a/src/core/SkReadBuffer.cpp +++ b/src/core/SkReadBuffer.cpp @@ -25,6 +25,7 @@ static uint32_t default_flags() { SkReadBuffer::SkReadBuffer() { fFlags = default_flags(); + fPictureVersion = 0; fMemoryPtr = NULL; fBitmapStorage = NULL; @@ -42,6 +43,7 @@ SkReadBuffer::SkReadBuffer() { SkReadBuffer::SkReadBuffer(const void* data, size_t size) { fFlags = default_flags(); + fPictureVersion = 0; fReader.setMemory(data, size); fMemoryPtr = NULL; @@ -60,6 +62,7 @@ SkReadBuffer::SkReadBuffer(const void* data, size_t size) { SkReadBuffer::SkReadBuffer(SkStream* stream) { fFlags = default_flags(); + fPictureVersion = 0; const size_t length = stream->getLength(); fMemoryPtr = sk_malloc_throw(length); stream->read(fMemoryPtr, length); |