Chromium Code Reviews| Index: src/core/SkPictureRecorder.cpp |
| diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp |
| index 3262938ed1b62817fda591dfe360ee89269e7ea6..10b14a3a04833c9f2d311d9cdc1cb614215451e9 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" |
| @@ -38,7 +39,8 @@ SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
| return fRecorder.get(); |
| } |
| -SkPicture* SkPictureRecorder::endRecording() { |
| +SkPicture* SkPictureRecorder::endRecordingAsPicture() { |
|
robertphillips
2014/11/24 17:26:10
Might as well remove this dead code.
reed1
2014/11/24 19:12:08
Done.
|
| +#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,80 @@ 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 { |
| + SkPicture::SnapshotArray* pictList = NULL; |
| + if (fDrawableList) { |
| + // TODO: should we plumb-down the BBHFactory and recordFlags from our host |
| + // PictureRecorder? |
| + pictList = fDrawableList->newDrawableSnapshot(); |
| + } |
| + |
| + SkAutoTUnref<SkLayerInfo> saveLayerData; |
| + |
| + if (fBBH && fDoSaveLayerInfo) { |
| + SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); |
| + |
| + saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); |
| + |
| + SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (received in constructor) |
| + // TODO: update saveLayer info computation to reuse the already computed |
| + // bounds in 'fBBH' |
| + SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerData); |
| + } |
| + |
| + 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))); |
| } |