aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPictureRecorder.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-05-07 13:41:07 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-07 13:41:07 -0700
commitc92c129ff85b05a714bd1bf921c02d5e14651f8b (patch)
treeea2f915b36a5f6abb746827a4a6f650d5ff13310 /src/core/SkPictureRecorder.cpp
parent2fbd4068bde6a9fb50341c0bdfbb8bf18b70d015 (diff)
Sketch splitting SkPicture into an interface and SkBigPicture.
Adds small pictures for drawRect(), drawTextBlob(), and drawPath(). These cover about 89% of draw calls from Blink SKPs, and about 25% of draw calls from our GMs. SkPicture handles: - serialization and deserialization - unique IDs Everything else is left to the subclasses: - playback(), cullRect() - hasBitmap(), hasText(), suitableForGPU(), etc. - LayerInfo / AccelData if applicable. The time to record a 1-op picture improves a good chunk (2 mallocs to 1), and the time to record a 0-op picture greatly improves (2 mallocs to none): picture_overhead_draw: 450ns -> 350ns picture_overhead_nodraw: 300ns -> 90ns BUG=skia: Review URL: https://codereview.chromium.org/1112523006
Diffstat (limited to 'src/core/SkPictureRecorder.cpp')
-rw-r--r--src/core/SkPictureRecorder.cpp55
1 files changed, 31 insertions, 24 deletions
diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp
index 282e2c22dd..c110e0a2db 100644
--- a/src/core/SkPictureRecorder.cpp
+++ b/src/core/SkPictureRecorder.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkBigPicture.h"
#include "SkData.h"
#include "SkDrawable.h"
#include "SkLayerInfo.h"
@@ -18,7 +19,7 @@
SkPictureRecorder::SkPictureRecorder() {
fActivelyRecording = false;
- fRecorder.reset(SkNEW_ARGS(SkRecorder, (nullptr, SkRect::MakeWH(0,0))));
+ fRecorder.reset(SkNEW_ARGS(SkRecorder, (nullptr, SkRect::MakeWH(0,0), &fMiniRecorder)));
}
SkPictureRecorder::~SkPictureRecorder() {}
@@ -34,8 +35,10 @@ SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect,
SkASSERT(fBBH.get());
}
- fRecord.reset(SkNEW(SkRecord));
- fRecorder->reset(fRecord.get(), cullRect);
+ if (!fRecord) {
+ fRecord.reset(SkNEW(SkRecord));
+ }
+ fRecorder->reset(fRecord.get(), cullRect, &fMiniRecorder);
fActivelyRecording = true;
return this->getRecordingCanvas();
}
@@ -47,19 +50,23 @@ SkCanvas* SkPictureRecorder::getRecordingCanvas() {
SkPicture* SkPictureRecorder::endRecordingAsPicture() {
fActivelyRecording = false;
fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
+
+ if (fRecord->count() == 0) {
+ return fMiniRecorder.detachAsPicture(fCullRect);
+ }
+
// TODO: delay as much of this work until just before first playback?
SkRecordOptimize(fRecord);
SkAutoTUnref<SkLayerInfo> saveLayerData;
if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) {
- SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
-
- saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key)));
+ saveLayerData.reset(SkNEW(SkLayerInfo));
}
SkDrawableList* drawableList = fRecorder->getDrawableList();
- SkPicture::SnapshotArray* pictList = drawableList ? drawableList->newDrawableSnapshot() : NULL;
+ SkBigPicture::SnapshotArray* pictList =
+ drawableList ? drawableList->newDrawableSnapshot() : NULL;
if (fBBH.get()) {
if (saveLayerData) {
@@ -77,12 +84,12 @@ SkPicture* SkPictureRecorder::endRecordingAsPicture() {
for (int i = 0; pictList && i < pictList->count(); i++) {
subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin()[i]);
}
- return SkNEW_ARGS(SkPicture, (fCullRect,
- fRecord.detach(),
- pictList,
- fBBH.detach(),
- saveLayerData.detach(),
- subPictureBytes));
+ return SkNEW_ARGS(SkBigPicture, (fCullRect,
+ fRecord.detach(),
+ pictList,
+ fBBH.detach(),
+ saveLayerData.detach(),
+ subPictureBytes));
}
void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
@@ -133,7 +140,7 @@ protected:
}
SkPicture* onNewPictureSnapshot() override {
- SkPicture::SnapshotArray* pictList = NULL;
+ SkBigPicture::SnapshotArray* pictList = NULL;
if (fDrawableList) {
// TODO: should we plumb-down the BBHFactory and recordFlags from our host
// PictureRecorder?
@@ -143,9 +150,7 @@ protected:
SkAutoTUnref<SkLayerInfo> saveLayerData;
if (fBBH && fDoSaveLayerInfo) {
- SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
-
- saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key)));
+ saveLayerData.reset(SkNEW(SkLayerInfo));
SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (received in constructor)
// TODO: update saveLayer info computation to reuse the already computed
@@ -157,20 +162,22 @@ protected:
for (int i = 0; pictList && i < pictList->count(); i++) {
subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin()[i]);
}
- // SkPicture will take ownership of a ref on both fRecord and fBBH.
+ // 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 SkNEW_ARGS(SkPicture, (fBounds,
- SkRef(fRecord.get()),
- pictList,
- SkSafeRef(fBBH.get()),
- saveLayerData.detach(),
- subPictureBytes));
+ return SkNEW_ARGS(SkBigPicture, (fBounds,
+ SkRef(fRecord.get()),
+ pictList,
+ SkSafeRef(fBBH.get()),
+ saveLayerData.detach(),
+ subPictureBytes));
}
};
SkDrawable* SkPictureRecorder::endRecordingAsDrawable() {
fActivelyRecording = false;
+ fRecorder->flushMiniRecorder();
fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
+
// TODO: delay as much of this work until just before first playback?
SkRecordOptimize(fRecord);