diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-06 18:47:25 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-06 18:47:25 +0000 |
commit | 8b4799a98b05d626432b11115b5c2f0e0bb1772d (patch) | |
tree | 498c0c8e90b9dc401627ac2725b32dabca8bffda /src | |
parent | 670b98ea5df48daef5d23e2bb7570d408207c333 (diff) |
Revert of r13347 (Serialization of SkPictureImageFilter - https://codereview.chromium.org/138063005) due to bump in skp file format
git-svn-id: http://skia.googlecode.com/svn/trunk@13348 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPicture.cpp | 106 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.cpp | 40 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.h | 3 | ||||
-rw-r--r-- | src/effects/SkPictureImageFilter.cpp | 18 |
4 files changed, 19 insertions, 148 deletions
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 0d31ab403e..ca1b6fa22a 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -265,7 +265,6 @@ void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) { #include "SkStream.h" static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; -static const size_t kHeaderSize = sizeof(kMagic) + sizeof(SkPictInfo); bool SkPicture::StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) { if (NULL == stream) { @@ -274,8 +273,8 @@ bool SkPicture::StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) { // Check magic bytes. char magic[sizeof(kMagic)]; - if (!stream->read(magic, sizeof(kMagic)) || - (0 != memcmp(magic, kMagic, sizeof(kMagic)))) { + stream->read(magic, sizeof(kMagic)); + if (0 != memcmp(magic, kMagic, sizeof(kMagic))) { return false; } @@ -294,30 +293,6 @@ bool SkPicture::StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) { return true; } -bool SkPicture::BufferIsSKP(SkReadBuffer& buffer, SkPictInfo* pInfo) { - // Check magic bytes. - char magic[sizeof(kMagic)]; - - if (!buffer.readByteArray(magic, sizeof(kMagic)) || - (0 != memcmp(magic, kMagic, sizeof(kMagic)))) { - return false; - } - - SkPictInfo info; - if (!buffer.readByteArray(&info, sizeof(SkPictInfo))) { - return false; - } - - if (PICTURE_VERSION != info.fVersion) { - return false; - } - - if (pInfo != NULL) { - *pInfo = info; - } - return true; -} - SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) : fPlayback(playback) , fRecord(NULL) @@ -345,56 +320,31 @@ SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); } -SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) { - SkPictInfo info; - - if (!BufferIsSKP(buffer, &info)) { - return NULL; - } +void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { + SkPicturePlayback* playback = fPlayback; - SkPicturePlayback* playback; - // Check to see if there is a playback to recreate. - if (buffer.readBool()) { - playback = SkPicturePlayback::CreateFromBuffer(buffer); - if (NULL == playback) { - return NULL; - } - } else { - playback = NULL; + if (NULL == playback && fRecord) { + playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); } - return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); -} + SkPictInfo info; -void SkPicture::createHeader(void* header) const { - // Copy magic bytes at the beginning of the header - SkASSERT(sizeof(kMagic) == 8); - memcpy(header, kMagic, sizeof(kMagic)); - - // Set piture info after magic bytes in the header - SkPictInfo* info = (SkPictInfo*)(((char*)header) + sizeof(kMagic)); - info->fVersion = PICTURE_VERSION; - info->fWidth = fWidth; - info->fHeight = fHeight; - info->fFlags = SkPictInfo::kCrossProcess_Flag; + info.fVersion = PICTURE_VERSION; + info.fWidth = fWidth; + info.fHeight = fHeight; + info.fFlags = SkPictInfo::kCrossProcess_Flag; // TODO: remove this flag, since we're always float (now) - info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; + info.fFlags |= SkPictInfo::kScalarIsFloat_Flag; if (8 == sizeof(void*)) { - info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; + info.fFlags |= SkPictInfo::kPtrIs64Bit_Flag; } -} -void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { - SkPicturePlayback* playback = fPlayback; - - if (NULL == playback && fRecord) { - playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); - } + // Write 8 magic bytes to ID this file format. + SkASSERT(sizeof(kMagic) == 8); + stream->write(kMagic, sizeof(kMagic)); - char header[kHeaderSize]; - createHeader(&header); - stream->write(header, kHeaderSize); + stream->write(&info, sizeof(info)); if (playback) { stream->writeBool(true); playback->serialize(stream, encoder); @@ -407,28 +357,6 @@ void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { } } -void SkPicture::flatten(SkWriteBuffer& buffer) const { - SkPicturePlayback* playback = fPlayback; - - if (NULL == playback && fRecord) { - playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); - } - - char header[kHeaderSize]; - createHeader(&header); - buffer.writeByteArray(header, kHeaderSize); - if (playback) { - buffer.writeBool(true); - playback->flatten(buffer); - // delete playback if it is a local version (i.e. cons'd up just now) - if (playback != fPlayback) { - SkDELETE(playback); - } - } else { - buffer.writeBool(false); - } -} - bool SkPicture::willPlayBackBitmaps() const { if (!fPlayback) return false; return fPlayback->containsBitmaps(); diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 8b8c6b0862..e71a17fda5 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -431,22 +431,6 @@ void SkPicturePlayback::serialize(SkWStream* stream, 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); -} - /////////////////////////////////////////////////////////////////////////////// /** @@ -609,15 +593,6 @@ SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkStream* stream, 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 (;;) { @@ -634,21 +609,6 @@ bool SkPicturePlayback::parseStream(SkStream* stream, const SkPictInfo& info, 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 - } - } - return true; -} - /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkPicturePlayback.h b/src/core/SkPicturePlayback.h index 909488b4b7..efa67225b5 100644 --- a/src/core/SkPicturePlayback.h +++ b/src/core/SkPicturePlayback.h @@ -64,14 +64,12 @@ public: explicit SkPicturePlayback(const SkPictureRecord& record, bool deepCopy = false); static SkPicturePlayback* CreateFromStream(SkStream*, const SkPictInfo&, SkPicture::InstallPixelRefProc); - static SkPicturePlayback* CreateFromBuffer(SkReadBuffer&); virtual ~SkPicturePlayback(); void draw(SkCanvas& canvas, SkDrawPictureCallback*); void serialize(SkWStream*, SkPicture::EncodeBitmap) const; - void flatten(SkWriteBuffer&) const; void dumpSize() const; @@ -86,7 +84,6 @@ public: protected: bool parseStream(SkStream*, const SkPictInfo&, SkPicture::InstallPixelRefProc); - bool parseBuffer(SkReadBuffer& buffer); #ifdef SK_DEVELOPER virtual bool preDraw(int opIndex, int type); virtual void postDraw(int opIndex); diff --git a/src/effects/SkPictureImageFilter.cpp b/src/effects/SkPictureImageFilter.cpp index 6e76231867..c78b2499ec 100644 --- a/src/effects/SkPictureImageFilter.cpp +++ b/src/effects/SkPictureImageFilter.cpp @@ -34,27 +34,13 @@ SkPictureImageFilter::~SkPictureImageFilter() { SkPictureImageFilter::SkPictureImageFilter(SkReadBuffer& buffer) : INHERITED(0, buffer), fPicture(NULL) { -#ifdef SK_ALLOW_PICTUREIMAGEFILTER_SERIALIZATION - if (buffer.readBool()) { - fPicture = SkPicture::CreateFromBuffer(buffer); - } -#else - buffer.readBool(); -#endif + // FIXME: unflatten picture here. buffer.readRect(&fRect); } void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { this->INHERITED::flatten(buffer); -#ifdef SK_ALLOW_PICTUREIMAGEFILTER_SERIALIZATION - bool hasPicture = (fPicture != NULL); - buffer.writeBool(hasPicture); - if (hasPicture) { - fPicture->flatten(buffer); - } -#else - buffer.writeBool(false); -#endif + // FIXME: flatten picture here. buffer.writeRect(fRect); } |