Thread through a flag to force SkPicture::playback() when recording subpictures.

This makes nanobench picture recording benchmarks somewhat useful again,
as opposed to all taking about 5us to run no matter the content.

ATTN Sheriff: this will probably trigger perf.skia.org alerts.

BUG=skia:

Review URL: https://codereview.chromium.org/1219873002
This commit is contained in:
mtklein 2015-07-01 07:04:37 -07:00 committed by Commit bot
parent c0e80c139e
commit d711d115d2
5 changed files with 29 additions and 8 deletions

View File

@ -33,10 +33,11 @@ void RecordingBench::onDraw(const int loops, SkCanvas*) {
const SkScalar w = fSrc->cullRect().width(), const SkScalar w = fSrc->cullRect().width(),
h = fSrc->cullRect().height(); h = fSrc->cullRect().height();
uint32_t flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag
| SkPictureRecorder::kPlaybackDrawPicture_RecordFlag;
for (int i = 0; i < loops; i++) { for (int i = 0; i < loops; i++) {
SkPictureRecorder recorder; SkPictureRecorder recorder;
fSrc->playback(recorder.beginRecording(w, h, fUseBBH ? &factory : NULL, fSrc->playback(recorder.beginRecording(w, h, fUseBBH ? &factory : NULL, flags));
SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag));
SkSafeUnref(recorder.endRecording()); SkSafeUnref(recorder.endRecording());
} }
} }

View File

@ -33,7 +33,11 @@ public:
enum RecordFlags { enum RecordFlags {
// This flag indicates that, if some BHH is being computed, saveLayer // This flag indicates that, if some BHH is being computed, saveLayer
// information should also be extracted at the same time. // information should also be extracted at the same time.
kComputeSaveLayerInfo_RecordFlag = 0x01 kComputeSaveLayerInfo_RecordFlag = 0x01,
// If you call drawPicture() on the recording canvas, this flag forces
// that to use SkPicture::playback() immediately rather than (e.g.) reffing the picture.
kPlaybackDrawPicture_RecordFlag = 0x02,
}; };
/** Returns the canvas that records the drawing commands. /** Returns the canvas that records the drawing commands.

View File

@ -38,7 +38,10 @@ SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect,
if (!fRecord) { if (!fRecord) {
fRecord.reset(SkNEW(SkRecord)); fRecord.reset(SkNEW(SkRecord));
} }
fRecorder->reset(fRecord.get(), cullRect, &fMiniRecorder); SkRecorder::DrawPictureMode dpm = (recordFlags & kPlaybackDrawPicture_RecordFlag)
? SkRecorder::Playback_DrawPictureMode
: SkRecorder::Record_DrawPictureMode;
fRecorder->reset(fRecord.get(), cullRect, dpm, &fMiniRecorder);
fActivelyRecording = true; fActivelyRecording = true;
return this->getRecordingCanvas(); return this->getRecordingCanvas();
} }

View File

@ -6,6 +6,7 @@
*/ */
#include "SkBigPicture.h" #include "SkBigPicture.h"
#include "SkCanvasPriv.h"
#include "SkPatchUtils.h" #include "SkPatchUtils.h"
#include "SkPicture.h" #include "SkPicture.h"
#include "SkPictureUtils.h" #include "SkPictureUtils.h"
@ -35,18 +36,22 @@ void SkDrawableList::append(SkDrawable* drawable) {
SkRecorder::SkRecorder(SkRecord* record, int width, int height, SkMiniRecorder* mr) SkRecorder::SkRecorder(SkRecord* record, int width, int height, SkMiniRecorder* mr)
: SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip_InitFlag) : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip_InitFlag)
, fDrawPictureMode(Record_DrawPictureMode)
, fApproxBytesUsedBySubPictures(0) , fApproxBytesUsedBySubPictures(0)
, fRecord(record) , fRecord(record)
, fMiniRecorder(mr) {} , fMiniRecorder(mr) {}
SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds, SkMiniRecorder* mr) SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds, SkMiniRecorder* mr)
: SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag) : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag)
, fDrawPictureMode(Record_DrawPictureMode)
, fApproxBytesUsedBySubPictures(0) , fApproxBytesUsedBySubPictures(0)
, fRecord(record) , fRecord(record)
, fMiniRecorder(mr) {} , fMiniRecorder(mr) {}
void SkRecorder::reset(SkRecord* record, const SkRect& bounds, SkMiniRecorder* mr) { void SkRecorder::reset(SkRecord* record, const SkRect& bounds,
DrawPictureMode dpm, SkMiniRecorder* mr) {
this->forgetRecord(); this->forgetRecord();
fDrawPictureMode = dpm;
fRecord = record; fRecord = record;
this->resetForNextPicture(bounds.roundOut()); this->resetForNextPicture(bounds.roundOut());
fMiniRecorder = mr; fMiniRecorder = mr;
@ -254,8 +259,14 @@ void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
} }
void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, const SkPaint* paint) { void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, const SkPaint* paint) {
fApproxBytesUsedBySubPictures += SkPictureUtils::ApproximateBytesUsed(pic); if (fDrawPictureMode == Record_DrawPictureMode) {
APPEND(DrawPicture, this->copy(paint), pic, matrix ? *matrix : SkMatrix::I()); fApproxBytesUsedBySubPictures += SkPictureUtils::ApproximateBytesUsed(pic);
APPEND(DrawPicture, this->copy(paint), pic, matrix ? *matrix : SkMatrix::I());
} else {
SkASSERT(fDrawPictureMode == Playback_DrawPictureMode);
SkAutoCanvasMatrixPaint acmp(this, matrix, paint, pic->cullRect());
pic->playback(this);
}
} }
void SkRecorder::onDrawVertices(VertexMode vmode, void SkRecorder::onDrawVertices(VertexMode vmode,

View File

@ -41,7 +41,8 @@ public:
SkRecorder(SkRecord*, int width, int height, SkMiniRecorder* = nullptr); // legacy version SkRecorder(SkRecord*, int width, int height, SkMiniRecorder* = nullptr); // legacy version
SkRecorder(SkRecord*, const SkRect& bounds, SkMiniRecorder* = nullptr); SkRecorder(SkRecord*, const SkRect& bounds, SkMiniRecorder* = nullptr);
void reset(SkRecord*, const SkRect& bounds, SkMiniRecorder* = nullptr); enum DrawPictureMode { Record_DrawPictureMode, Playback_DrawPictureMode };
void reset(SkRecord*, const SkRect& bounds, DrawPictureMode, SkMiniRecorder* = nullptr);
size_t approxBytesUsedBySubPictures() const { return fApproxBytesUsedBySubPictures; } size_t approxBytesUsedBySubPictures() const { return fApproxBytesUsedBySubPictures; }
@ -137,6 +138,7 @@ private:
return devBounds; return devBounds;
} }
DrawPictureMode fDrawPictureMode;
size_t fApproxBytesUsedBySubPictures; size_t fApproxBytesUsedBySubPictures;
SkRecord* fRecord; SkRecord* fRecord;
SkAutoTDelete<SkDrawableList> fDrawableList; SkAutoTDelete<SkDrawableList> fDrawableList;