| Index: src/core/SkPictureRecorder.cpp
|
| diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp
|
| index 3262938ed1b62817fda591dfe360ee89269e7ea6..c0a10f1cea828c0636313794c694ba5fbed6a41f 100644
|
| --- a/src/core/SkPictureRecorder.cpp
|
| +++ b/src/core/SkPictureRecorder.cpp
|
| @@ -5,6 +5,7 @@
|
| * found in the LICENSE file.
|
| */
|
|
|
| +#include "SkCanvasDrawable.h"
|
| #include "SkData.h"
|
| #include "SkLayerInfo.h"
|
| #include "SkPictureRecorder.h"
|
| @@ -39,6 +40,7 @@ SkCanvas* SkPictureRecorder::getRecordingCanvas() {
|
| }
|
|
|
| SkPicture* SkPictureRecorder::endRecording() {
|
| +#if 0
|
| // TODO: delay as much of this work until just before first playback?
|
| SkRecordOptimize(fRecord);
|
|
|
| @@ -71,6 +73,10 @@ SkPicture* SkPictureRecorder::endRecording() {
|
| }
|
|
|
| return pict;
|
| +#else
|
| + SkAutoTUnref<SkCanvasDrawable> drawable(this->EXPERIMENTAL_endRecordingAsDrawable());
|
| + return drawable->newPictureSnapshot();
|
| +#endif
|
| }
|
|
|
| void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
|
| @@ -79,5 +85,74 @@ void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
|
| }
|
|
|
| int drawableCount = 0;
|
| - SkRecordDraw(*fRecord, canvas, NULL, drawableCount, NULL/*bbh*/, NULL/*callback*/);
|
| + SkRecordDraw(*fRecord, canvas, NULL, NULL, drawableCount, NULL/*bbh*/, NULL/*callback*/);
|
| +}
|
| +
|
| +///////////////////////////////////////////////////////////////////////////////////////////////////
|
| +
|
| +class SkRecordedDrawable : public SkCanvasDrawable {
|
| + SkAutoTUnref<SkRecord> fRecord;
|
| + SkAutoTUnref<SkBBoxHierarchy> fBBH;
|
| + SkAutoTDelete<SkCanvasDrawableList> fDrawableList;
|
| + const SkRect fBounds;
|
| + const bool fDoSaveLayerInfo;
|
| +
|
| +public:
|
| + SkRecordedDrawable(SkRecord* record, SkBBoxHierarchy* bbh, SkCanvasDrawableList* drawableList,
|
| + const SkRect& bounds, bool doSaveLayerInfo)
|
| + : fRecord(SkRef(record))
|
| + , fBBH(SkSafeRef(bbh))
|
| + , fDrawableList(drawableList) // we take ownership
|
| + , fBounds(bounds)
|
| + , fDoSaveLayerInfo(doSaveLayerInfo)
|
| + {}
|
| +
|
| +protected:
|
| + SkRect onGetBounds() SK_OVERRIDE {
|
| + return fBounds;
|
| + }
|
| +
|
| + void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
| + SkCanvasDrawable* const* drawables = NULL;
|
| + int drawableCount = 0;
|
| + if (fDrawableList) {
|
| + drawables = fDrawableList->begin();
|
| + drawableCount = fDrawableList->count();
|
| + }
|
| + SkRecordDraw(*fRecord, canvas, NULL, drawables, drawableCount, fBBH, NULL/*callback*/);
|
| + }
|
| +
|
| + SkPicture* onNewPictureSnapshot() SK_OVERRIDE {
|
| + SkAutoTUnref<SkLayerInfo> saveLayerData;
|
| +
|
| + if (fBBH && fDoSaveLayerInfo) {
|
| + SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
|
| +
|
| + saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key)));
|
| + }
|
| +
|
| + SkPicture::SnapshotArray* pictList = NULL;
|
| + if (fDrawableList) {
|
| + pictList = fDrawableList->newDrawableSnapshot();
|
| + }
|
| + SkPicture* pict = SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBBH));
|
| +
|
| + if (saveLayerData) {
|
| + pict->EXPERIMENTAL_addAccelData(saveLayerData);
|
| + }
|
| + return pict;
|
| + }
|
| +};
|
| +
|
| +SkCanvasDrawable* SkPictureRecorder::EXPERIMENTAL_endRecordingAsDrawable() {
|
| + // TODO: delay as much of this work until just before first playback?
|
| + SkRecordOptimize(fRecord);
|
| +
|
| + if (fBBH.get()) {
|
| + SkRecordFillBounds(fCullRect, *fRecord, fBBH.get());
|
| + }
|
| +
|
| + return SkNEW_ARGS(SkRecordedDrawable, (fRecord, fBBH, fRecorder->detachDrawableList(),
|
| + fCullRect,
|
| + SkToBool(fFlags & kComputeSaveLayerInfo_RecordFlag)));
|
| }
|
|
|