Index: src/core/SkPicture.cpp |
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp |
index 5231cb9570b3af97c4694b1c859894620c0ba1d2..9fca86fc5a15570f02fde71683c94ac29865d489 100644 |
--- a/src/core/SkPicture.cpp |
+++ b/src/core/SkPicture.cpp |
@@ -271,12 +271,29 @@ SkPicture::SkPicture(SkScalar width, SkScalar height, |
fData.reset(SkNEW_ARGS(SkPictureData, (record, info, deepCopyOps))); |
} |
+int SkPicture::drawableCount() const { |
+ if (fDrawablePicts.get()) { |
+ return SkToInt(fDrawablePicts->size() / sizeof(SkPicture*)); |
+ } else { |
+ return 0; |
+ } |
+} |
+ |
+SkPicture* const* SkPicture::drawablePicts() const { |
+ if (fDrawablePicts) { |
+ return reinterpret_cast<SkPicture* const*>(fDrawablePicts->data()); |
+ } |
+ return NULL; |
+} |
+ |
// Create an SkPictureData-backed SkPicture from an SkRecord. |
// This for compatibility with serialization code only. This is not cheap. |
-SkPicture* SkPicture::Backport(const SkRecord& src, const SkRect& cullRect) { |
+SkPicture* SkPicture::Backport(const SkRecord& src, |
+ SkPicture* const drawablePicts[], int drawableCount, |
+ const SkRect& cullRect) { |
SkPictureRecord rec(SkISize::Make(cullRect.width(), cullRect.height()), 0/*flags*/); |
rec.beginRecording(); |
- SkRecordDraw(src, &rec, NULL/*bbh*/, NULL/*callback*/); |
+ SkRecordDraw(src, &rec, drawablePicts, drawableCount, NULL/*bbh*/, NULL/*callback*/); |
rec.endRecording(); |
return SkNEW_ARGS(SkPicture, (cullRect.width(), cullRect.height(), rec, false/*deepCopyOps*/)); |
} |
@@ -284,6 +301,12 @@ SkPicture* SkPicture::Backport(const SkRecord& src, const SkRect& cullRect) { |
// fRecord OK |
SkPicture::~SkPicture() { |
this->callDeletionListeners(); |
+ |
+ const int count = this->drawableCount(); |
+ SkPicture* const* pics = this->drawablePicts(); |
+ for (int i = 0; i < count; ++i) { |
+ pics[i]->unref(); |
+ } |
} |
// fRecord OK |
@@ -329,7 +352,8 @@ void SkPicture::playback(SkCanvas* canvas, SkDrawPictureCallback* callback) cons |
(void)canvas->getClipBounds(&clipBounds); |
const bool useBBH = !clipBounds.contains(this->cullRect()); |
- SkRecordDraw(*fRecord, canvas, useBBH ? fBBH.get() : NULL, callback); |
+ SkRecordDraw(*fRecord, canvas, this->drawablePicts(), this->drawableCount(), |
+ useBBH ? fBBH.get() : NULL, callback); |
} |
} |
@@ -447,8 +471,9 @@ SkPicture* SkPicture::Forwardport(const SkPicture& src) { |
SkAutoTDelete<SkRecord> record(SkNEW(SkRecord)); |
SkRecorder canvas(record.get(), src.cullRect().width(), src.cullRect().height()); |
src.playback(&canvas); |
+ SkData* drawablePicts = NULL; // old pictures never have these |
return SkNEW_ARGS(SkPicture, (src.cullRect().width(), src.cullRect().height(), |
- record.detach(), NULL/*bbh*/)); |
+ record.detach(), drawablePicts, NULL/*bbh*/)); |
} |
// fRecord OK |
@@ -519,7 +544,8 @@ void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { |
// If we're a new-format picture, backport to old format for serialization. |
SkAutoTDelete<SkPicture> oldFormat; |
if (NULL == data && fRecord.get()) { |
- oldFormat.reset(Backport(*fRecord, this->cullRect())); |
+ oldFormat.reset(Backport(*fRecord, this->drawablePicts(), this->drawableCount(), |
+ this->cullRect())); |
data = oldFormat->fData.get(); |
SkASSERT(data); |
} |
@@ -544,7 +570,8 @@ void SkPicture::flatten(SkWriteBuffer& buffer) const { |
// If we're a new-format picture, backport to old format for serialization. |
SkAutoTDelete<SkPicture> oldFormat; |
if (NULL == data && fRecord.get()) { |
- oldFormat.reset(Backport(*fRecord, this->cullRect())); |
+ oldFormat.reset(Backport(*fRecord, this->drawablePicts(), this->drawableCount(), |
+ this->cullRect())); |
data = oldFormat->fData.get(); |
SkASSERT(data); |
} |
@@ -626,11 +653,13 @@ uint32_t SkPicture::uniqueID() const { |
} |
// fRecord OK |
-SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkBBoxHierarchy* bbh) |
+SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkData* drawablePicts, |
+ SkBBoxHierarchy* bbh) |
: fCullWidth(width) |
, fCullHeight(height) |
, fRecord(record) |
, fBBH(SkSafeRef(bbh)) |
+ , fDrawablePicts(SkSafeRef(drawablePicts)) |
, fAnalysis(*fRecord) { |
this->needsNewGenID(); |
} |