Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Unified Diff: src/core/SkPicture.cpp

Issue 138063005: Serialization of SkPictureImageFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkPicture.cpp
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index 15eb13752524b4c8c7509813334e667fb421f722..09aa1d7f3ff767642b71160f66cb6fecb8c926f4 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -298,6 +298,35 @@ bool SkPicture::StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) {
return true;
}
+bool SkPicture::BufferIsSKP(SkFlattenableReadBuffer& 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
+#ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO
Stephen White 2014/01/15 14:59:02 Considering that this will be the first time that
sugoi 2014/01/15 16:49:22 Done.
+ // V16 is backwards compatible with V15
+ && PRIOR_PICTURE_VERSION != info.fVersion // TODO: remove when .skps regenerated
+#endif
+ ) {
+ return false;
+ }
+
+ if (pInfo != NULL) {
+ *pInfo = info;
+ }
+ return true;
+}
+
SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height)
: fPlayback(playback)
, fRecord(NULL)
@@ -325,6 +354,27 @@ SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro
return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight));
}
+SkPicture* SkPicture::CreateFromBuffer(SkFlattenableReadBuffer& buffer) {
+ SkPictInfo info;
+
+ if (!BufferIsSKP(buffer, &info)) {
+ return NULL;
+ }
+
+ 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;
+ }
+
+ return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight));
+}
+
void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
SkPicturePlayback* playback = fPlayback;
@@ -362,6 +412,43 @@ void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
}
}
+void SkPicture::flatten(SkFlattenableWriteBuffer& buffer) const {
+ SkPicturePlayback* playback = fPlayback;
+
+ if (NULL == playback && fRecord) {
+ playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord));
+ }
+
+ SkPictInfo info;
+
+ 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;
+
+ if (8 == sizeof(void*)) {
+ info.fFlags |= SkPictInfo::kPtrIs64Bit_Flag;
+ }
+
+ // Write 8 magic bytes to ID this file format.
+ SkASSERT(sizeof(kMagic) == 8);
+ buffer.writeByteArray(kMagic, sizeof(kMagic));
+
+ buffer.writeByteArray(&info, sizeof(info));
+ 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();

Powered by Google App Engine
This is Rietveld 408576698