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

Unified Diff: src/core/SkPicture.cpp

Issue 345553003: Support serialization in SkRecord-backed SkPictures. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: robert Created 6 years, 6 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
« no previous file with comments | « gyp/dm.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPicture.cpp
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index a678047455fc3aab043fd8659c7b107e6105e4ba..75160b8be4bf6afd93ceda34378b5013dca17186 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -10,6 +10,7 @@
#include "SkPictureFlat.h"
#include "SkPicturePlayback.h"
#include "SkPictureRecord.h"
+#include "SkPictureRecorder.h"
#include "SkBBHFactory.h"
#include "SkBitmapDevice.h"
@@ -156,6 +157,14 @@ static SkRecord* copy(const SkRecord& src, int width, int height) {
return dst;
}
+// Create an SkPicturePlayback-backed SkPicture from an SkRecord.
+// This for compatibility with serialization code only. This is not cheap.
+static SkPicture* backport(const SkRecord& src, int width, int height) {
+ SkPictureRecorder recorder;
+ SkRecordDraw(src, recorder.beginRecording(width, height));
+ return recorder.endRecording();
+}
+
// fRecord OK
SkPicture::SkPicture(const SkPicture& src) : INHERITED() {
this->needsNewGenID();
@@ -436,15 +445,25 @@ void SkPicture::createHeader(SkPictInfo* info) const {
}
}
-// fRecord TODO
+// fRecord OK
void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
+ const SkPicturePlayback* playback = fPlayback.get();
+
+ // If we're a new-format picture, backport to old format for serialization.
+ SkAutoTDelete<SkPicture> oldFormat;
+ if (NULL == playback && NULL != fRecord.get()) {
+ oldFormat.reset(backport(*fRecord, fWidth, fHeight));
+ playback = oldFormat->fPlayback.get();
+ SkASSERT(NULL != playback);
+ }
+
SkPictInfo info;
this->createHeader(&info);
stream->write(&info, sizeof(info));
- if (NULL != fPlayback.get()) {
+ if (NULL != playback) {
stream->writeBool(true);
- fPlayback->serialize(stream, encoder);
+ playback->serialize(stream, encoder);
} else {
stream->writeBool(false);
}
@@ -462,15 +481,25 @@ void SkPicture::WriteTagSize(SkWStream* stream, uint32_t tag, size_t size) {
stream->write32(SkToU32(size));
}
-// fRecord TODO
+// fRecord OK
void SkPicture::flatten(SkWriteBuffer& buffer) const {
+ const SkPicturePlayback* playback = fPlayback.get();
+
+ // If we're a new-format picture, backport to old format for serialization.
+ SkAutoTDelete<SkPicture> oldFormat;
+ if (NULL == playback && NULL != fRecord.get()) {
+ oldFormat.reset(backport(*fRecord, fWidth, fHeight));
+ playback = oldFormat->fPlayback.get();
+ SkASSERT(NULL != playback);
+ }
+
SkPictInfo info;
this->createHeader(&info);
buffer.writeByteArray(&info, sizeof(info));
- if (NULL != fPlayback.get()) {
+ if (NULL != playback) {
buffer.writeBool(true);
- fPlayback->flatten(buffer);
+ playback->flatten(buffer);
} else {
buffer.writeBool(false);
}
« no previous file with comments | « gyp/dm.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698