Index: src/core/SkPicturePlayback.cpp |
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp |
index e71a17fda51095ec44fa49d4e4aa6f81b2493b0b..8b8c6b0862dad7bb6d0bc643de3b09b0abca4fd7 100644 |
--- a/src/core/SkPicturePlayback.cpp |
+++ b/src/core/SkPicturePlayback.cpp |
@@ -431,6 +431,22 @@ |
stream->write32(PICT_EOF_TAG); |
} |
+void SkPicturePlayback::flatten(SkWriteBuffer& buffer) const { |
+ writeTagSize(buffer, PICT_READER_TAG, fOpData->size()); |
+ buffer.writeByteArray(fOpData->bytes(), fOpData->size()); |
+ |
+ if (fPictureCount > 0) { |
+ writeTagSize(buffer, PICT_PICTURE_TAG, fPictureCount); |
+ for (int i = 0; i < fPictureCount; i++) { |
+ fPictureRefs[i]->flatten(buffer); |
+ } |
+ } |
+ |
+ // Write this picture playback's data into a writebuffer |
+ this->flattenToBuffer(buffer); |
+ buffer.write32(PICT_EOF_TAG); |
+} |
+ |
/////////////////////////////////////////////////////////////////////////////// |
/** |
@@ -593,6 +609,15 @@ |
return playback.detach(); |
} |
+SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer) { |
+ SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); |
+ |
+ if (!playback->parseBuffer(buffer)) { |
+ return NULL; |
+ } |
+ return playback.detach(); |
+} |
+ |
bool SkPicturePlayback::parseStream(SkStream* stream, const SkPictInfo& info, |
SkPicture::InstallPixelRefProc proc) { |
for (;;) { |
@@ -603,6 +628,21 @@ |
uint32_t size = stream->readU32(); |
if (!this->parseStreamTag(stream, info, tag, size, proc)) { |
+ return false; // we're invalid |
+ } |
+ } |
+ return true; |
+} |
+ |
+bool SkPicturePlayback::parseBuffer(SkReadBuffer& buffer) { |
+ for (;;) { |
+ uint32_t tag = buffer.readUInt(); |
+ if (PICT_EOF_TAG == tag) { |
+ break; |
+ } |
+ |
+ uint32_t size = buffer.readUInt(); |
+ if (!this->parseBufferTag(buffer, tag, size)) { |
return false; // we're invalid |
} |
} |