diff options
author | msarett <msarett@google.com> | 2016-04-27 09:03:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-27 09:03:17 -0700 |
commit | d636950e8ecba89c0021ce4e76037c67aa6ee2cd (patch) | |
tree | 514b71dbcd0d6486b2f019ec60f106aff01c3a71 /src/core/SkPictureData.cpp | |
parent | f62b2354b376ef56028fde357e8a081436955581 (diff) |
Enable flattening of SkRecordedDrawable
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1913843002
Review-Url: https://codereview.chromium.org/1913843002
Diffstat (limited to 'src/core/SkPictureData.cpp')
-rw-r--r-- | src/core/SkPictureData.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp index 92aa2410ad..4de1cc3cec 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(); @@ -89,6 +99,8 @@ SkPictureData::SkPictureData(const SkPictureRecord& record, void SkPictureData::init() { fPictureRefs = nullptr; fPictureCount = 0; + fDrawableRefs = nullptr; + fDrawableCount = 0; fTextBlobRefs = nullptr; fTextBlobCount = 0; fImageRefs = nullptr; @@ -102,6 +114,14 @@ SkPictureData::~SkPictureData() { } delete[] fPictureRefs; + for (int i = 0; i < fDrawableCount; i++) { + fDrawableRefs[i]->unref(); + } + if (fDrawableCount > 0) { + SkASSERT(fDrawableRefs); + delete[] fDrawableRefs; + } + for (int i = 0; i < fTextBlobCount; i++) { fTextBlobRefs[i]->unref(); } @@ -306,6 +326,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 +477,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 +571,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; |