diff options
author | msarett <msarett@google.com> | 2016-04-27 13:51:20 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-27 13:51:20 -0700 |
commit | 95416f477d2ca264f2fb065455e95778a2289a1d (patch) | |
tree | 41aa18dccbe6e45d771abb4256b850c1ffb09bdd /src/core/SkPictureRecorder.cpp | |
parent | 80f5ea02cf69096e00b8fe01fe54375a9387c9d9 (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
Committed: https://skia.googlesource.com/skia/+/d636950e8ecba89c0021ce4e76037c67aa6ee2cd
Review-Url: https://codereview.chromium.org/1913843002
Diffstat (limited to 'src/core/SkPictureRecorder.cpp')
-rw-r--r-- | src/core/SkPictureRecorder.cpp | 61 |
1 files changed, 1 insertions, 60 deletions
diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp index b6bb34d5b4..a157d0dfe0 100644 --- a/src/core/SkPictureRecorder.cpp +++ b/src/core/SkPictureRecorder.cpp @@ -14,6 +14,7 @@ #include "SkRecord.h" #include "SkRecordDraw.h" #include "SkRecordOpts.h" +#include "SkRecordedDrawable.h" #include "SkRecorder.h" #include "SkTypes.h" @@ -117,66 +118,6 @@ void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { SkRecordDraw(*fRecord, canvas, nullptr, drawables, drawableCount, nullptr/*bbh*/, nullptr/*callback*/); } -/////////////////////////////////////////////////////////////////////////////////////////////////// - -class SkRecordedDrawable : public SkDrawable { - SkAutoTUnref<SkRecord> fRecord; - SkAutoTUnref<SkBBoxHierarchy> fBBH; - SkAutoTDelete<SkDrawableList> fDrawableList; - const SkRect fBounds; - const bool fDoSaveLayerInfo; - -public: - SkRecordedDrawable(SkRecord* record, SkBBoxHierarchy* bbh, SkDrawableList* drawableList, - const SkRect& bounds, bool doSaveLayerInfo) - : fRecord(SkRef(record)) - , fBBH(SkSafeRef(bbh)) - , fDrawableList(drawableList) // we take ownership - , fBounds(bounds) - , fDoSaveLayerInfo(doSaveLayerInfo) - {} - -protected: - SkRect onGetBounds() override { return fBounds; } - - void onDraw(SkCanvas* canvas) override { - SkDrawable* const* drawables = nullptr; - int drawableCount = 0; - if (fDrawableList) { - drawables = fDrawableList->begin(); - drawableCount = fDrawableList->count(); - } - SkRecordDraw(*fRecord, canvas, nullptr, drawables, drawableCount, fBBH, nullptr/*callback*/); - } - - SkPicture* onNewPictureSnapshot() override { - SkBigPicture::SnapshotArray* pictList = nullptr; - if (fDrawableList) { - // TODO: should we plumb-down the BBHFactory and recordFlags from our host - // PictureRecorder? - pictList = fDrawableList->newDrawableSnapshot(); - } - - SkAutoTUnref<SkLayerInfo> saveLayerData; - if (fBBH && fDoSaveLayerInfo) { - // TODO: can we avoid work by not allocating / filling these bounds? - SkAutoTMalloc<SkRect> scratchBounds(fRecord->count()); - saveLayerData.reset(new SkLayerInfo); - - SkRecordComputeLayers(fBounds, *fRecord, scratchBounds, pictList, saveLayerData); - } - - size_t subPictureBytes = 0; - for (int i = 0; pictList && i < pictList->count(); i++) { - subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin()[i]); - } - // SkBigPicture will take ownership of a ref on both fRecord and fBBH. - // We're not willing to give up our ownership, so we must ref them for SkPicture. - return new SkBigPicture(fBounds, SkRef(fRecord.get()), pictList, SkSafeRef(fBBH.get()), - saveLayerData.release(), subPictureBytes); - } -}; - sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable() { fActivelyRecording = false; fRecorder->flushMiniRecorder(); |