diff options
-rw-r--r-- | bench/RecordingBench.cpp | 53 | ||||
-rw-r--r-- | bench/RecordingBench.h | 32 | ||||
-rw-r--r-- | bench/nanobench.cpp | 19 |
3 files changed, 84 insertions, 20 deletions
diff --git a/bench/RecordingBench.cpp b/bench/RecordingBench.cpp index d8034ce5d5..69be911467 100644 --- a/bench/RecordingBench.cpp +++ b/bench/RecordingBench.cpp @@ -11,37 +11,42 @@ #include "SkLiteRecorder.h" #include "SkPictureRecorder.h" -RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH, bool lite) - : fName(name) - , fUseBBH(useBBH) { +PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) { // Flatten the source picture in case it's trivially nested (useless for timing). SkPictureRecorder rec; pic->playback(rec.beginRecording(pic->cullRect(), nullptr, SkPictureRecorder::kPlaybackDrawPicture_RecordFlag)); fSrc = rec.finishRecordingAsPicture(); - - // If we're recording into an SkLiteDL, also record _from_ one. - if (lite) { - fDL = SkLiteDL::New(pic->cullRect()); - SkLiteRecorder r; - r.reset(fDL.get()); - fSrc->playback(&r); - } } -const char* RecordingBench::onGetName() { +const char* PictureCentricBench::onGetName() { return fName.c_str(); } -bool RecordingBench::isSuitableFor(Backend backend) { +bool PictureCentricBench::isSuitableFor(Backend backend) { return backend == kNonRendering_Backend; } -SkIPoint RecordingBench::onGetSize() { +SkIPoint PictureCentricBench::onGetSize() { return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()), SkScalarCeilToInt(fSrc->cullRect().height())); } +/////////////////////////////////////////////////////////////////////////////////////////////////// + +RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH, bool lite) + : INHERITED(name, pic) + , fUseBBH(useBBH) +{ + // If we're recording into an SkLiteDL, also record _from_ one. + if (lite) { + fDL = SkLiteDL::New(fSrc->cullRect()); + SkLiteRecorder r; + r.reset(fDL.get()); + fSrc->playback(&r); + } +} + void RecordingBench::onDraw(int loops, SkCanvas*) { if (fDL) { SkLiteRecorder rec; @@ -61,3 +66,23 @@ void RecordingBench::onDraw(int loops, SkCanvas*) { } } } + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#include "SkPipe.h" +#include "SkStream.h" + +PipingBench::PipingBench(const char* name, const SkPicture* pic) : INHERITED(name, pic) { + fName.prepend("pipe_"); +} + +void PipingBench::onDraw(int loops, SkCanvas*) { + SkDynamicMemoryWStream stream; + SkPipeSerializer serializer; + + while (loops --> 0) { + fSrc->playback(serializer.beginWrite(fSrc->cullRect(), &stream)); + serializer.endWrite(); + stream.reset(); + } +} diff --git a/bench/RecordingBench.h b/bench/RecordingBench.h index 8e0e12ee96..4e34276a88 100644 --- a/bench/RecordingBench.h +++ b/bench/RecordingBench.h @@ -12,23 +12,45 @@ #include "SkPicture.h" #include "SkLiteDL.h" -class RecordingBench : public Benchmark { +class PictureCentricBench : public Benchmark { public: - RecordingBench(const char* name, const SkPicture*, bool useBBH, bool lite); + PictureCentricBench(const char* name, const SkPicture*); protected: const char* onGetName() override; bool isSuitableFor(Backend) override; - void onDraw(int loops, SkCanvas*) override; SkIPoint onGetSize() override; -private: +protected: sk_sp<const SkPicture> fSrc; SkString fName; + + typedef Benchmark INHERITED; +}; + +class RecordingBench : public PictureCentricBench { +public: + RecordingBench(const char* name, const SkPicture*, bool useBBH, bool lite); + +protected: + void onDraw(int loops, SkCanvas*) override; + +private: sk_sp<SkLiteDL> fDL; bool fUseBBH; - typedef Benchmark INHERITED; + typedef PictureCentricBench INHERITED; +}; + +class PipingBench : public PictureCentricBench { +public: + PipingBench(const char* name, const SkPicture*); + +protected: + void onDraw(int loops, SkCanvas*) override; + +private: + typedef PictureCentricBench INHERITED; }; #endif//RecordingBench_DEFINED diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index e929a8069f..6a0fb0445b 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -126,7 +126,7 @@ DEFINE_string(useThermalManager, "0,1,10,1000", "enabled,threshold,sleepTimeMs,T DEFINE_string(sourceType, "", "Apply usual --match rules to source type: bench, gm, skp, image, etc."); DEFINE_string(benchType, "", - "Apply usual --match rules to bench type: micro, recording, playback, skcodec, etc."); + "Apply usual --match rules to bench type: micro, recording, piping, playback, skcodec, etc."); static double now_ms() { return SkTime::GetNSecs() * 1e-6; } @@ -583,6 +583,7 @@ public: BenchmarkStream() : fBenches(BenchRegistry::Head()) , fGMs(skiagm::GMRegistry::Head()) , fCurrentRecording(0) + , fCurrentPiping(0) , fCurrentScale(0) , fCurrentSKP(0) , fCurrentSVG(0) @@ -727,6 +728,21 @@ public: return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh, FLAGS_lite); } + // Add all .skps as PipeBenches. + while (fCurrentPiping < fSKPs.count()) { + const SkString& path = fSKPs[fCurrentPiping++]; + sk_sp<SkPicture> pic = ReadPicture(path.c_str()); + if (!pic) { + continue; + } + SkString name = SkOSPath::Basename(path.c_str()); + fSourceType = "skp"; + fBenchType = "piping"; + fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic.get())); + fSKPOps = pic->approximateOpCount(); + return new PipingBench(name.c_str(), pic.get()); + } + // Then once each for each scale as SKPBenches (playback). while (fCurrentScale < fScales.count()) { while (fCurrentSKP < fSKPs.count()) { @@ -1057,6 +1073,7 @@ private: const char* fSourceType; // What we're benching: bench, GM, SKP, ... const char* fBenchType; // How we bench it: micro, recording, playback, ... int fCurrentRecording; + int fCurrentPiping; int fCurrentScale; int fCurrentSKP; int fCurrentSVG; |