Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Unified Diff: src/core/SkPictureRecorder.cpp

Issue 750723002: add endRecordingAsDrawable experiment (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: seems to work, TODO around immediate mode drawing Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkPicture.cpp ('k') | src/core/SkRecord.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureRecorder.cpp
diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp
index 3262938ed1b62817fda591dfe360ee89269e7ea6..6d61ab3e07d01f5ce5614822cd7c494695daf1db 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 {
@@ -81,3 +87,80 @@ void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
int drawableCount = 0;
SkRecordDraw(*fRecord, canvas, 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 {
+ SkPicture const* const* drawablePicts = NULL;
+ int drawableCount = 0;
+
+ // TODO: find a way to pass in the array of Drawables instead of forcing a snap...
+ //
+ // Perhaps SkRecordDraw could take two versions, or two different array args (but 1 count)?
+ //
+ SkAutoTDelete<SkPicture::SnapshotArray> pictList;
+ if (fDrawableList) {
+ pictList.reset(fDrawableList->newDrawableSnapshot());
+ drawablePicts = pictList->begin();
+ drawableCount = pictList->count();
+ }
+
+ SkRecordDraw(*fRecord, canvas, drawablePicts, 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)));
+}
« no previous file with comments | « src/core/SkPicture.cpp ('k') | src/core/SkRecord.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698