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

Unified Diff: src/core/SkPictureData.cpp

Issue 1837913003: Add support for serializing/deserializing of SkDrawable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 8 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 | « src/core/SkPictureData.h ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureData.cpp
diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp
index 92aa2410ad824edb52904262b7008352d9449640..dd1c9e409f522616264722779bdbf42e85898556 100644
--- a/src/core/SkPictureData.cpp
+++ b/src/core/SkPictureData.cpp
@@ -66,6 +66,16 @@ SkPictureData::SkPictureData(const SkPictureRecord& record,
}
}
+ const SkTDArray<SkDrawable* >& drawables = record.getDrawableRefs();
+ fDrawableCount = drawables.count();
+ if (fDrawableCount > 0) {
+ fDrawableRefs = new SkDrawable* [fDrawableCount];
+ for (int i = 0; i < fDrawableCount; i++) {
+ fDrawableRefs[i] = drawables[i];
+ fDrawableRefs[i]->ref();
+ }
+ }
+
// templatize to consolidate with similar picture logic?
const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs();
fTextBlobCount = blobs.count();
@@ -102,6 +112,11 @@ SkPictureData::~SkPictureData() {
}
delete[] fPictureRefs;
+ for (int i = 0; i < fDrawableCount; i++) {
+ fDrawableRefs[i]->unref();
+ }
+ delete[] fDrawableRefs;
+
for (int i = 0; i < fTextBlobCount; i++) {
fTextBlobRefs[i]->unref();
}
@@ -306,6 +321,13 @@ void SkPictureData::flatten(SkWriteBuffer& buffer) const {
}
}
+ if (fDrawableCount > 0) {
+ write_tag_size(buffer, SK_PICT_DRAWABLE_TAG, fDrawableCount);
+ for (int i = 0; i < fDrawableCount; i++) {
+ buffer.writeFlattenable(fDrawableRefs[i]);
+ }
+ }
+
// Write this picture playback's data into a writebuffer
this->flattenToBuffer(buffer);
buffer.write32(SK_PICT_EOF_TAG);
@@ -450,6 +472,10 @@ static const SkPicture* create_picture_from_buffer(SkReadBuffer& buffer) {
return SkPicture::MakeFromBuffer(buffer).release();
}
+static const SkDrawable* create_drawable_from_buffer(SkReadBuffer& buffer) {
+ return (SkDrawable*) buffer.readFlattenable(SkFlattenable::kSkDrawable_Type);
+}
+
template <typename T>
bool new_array_from_buffer(SkReadBuffer& buffer, uint32_t inCount,
const T*** array, int* outCount, const T* (*factory)(SkReadBuffer&)) {
@@ -540,6 +566,12 @@ bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, uint32_t tag, uint32_t
return false;
}
break;
+ case SK_PICT_DRAWABLE_TAG:
+ if (!new_array_from_buffer(buffer, size, (const SkDrawable***)&fDrawableRefs,
+ &fDrawableCount, create_drawable_from_buffer)) {
+ return false;
+ }
+ break;
default:
// The tag was invalid.
return false;
« no previous file with comments | « src/core/SkPictureData.h ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698