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; |