fLastMeasurement = this->elapsed() / (FLAGS_frames * fLoops);
}
-void TimingStateMachine::nextBenchmark(SkCanvas* canvas, Benchmark* benchmark) {
- benchmark->postDraw(canvas);
- benchmark->perCanvasPostDraw(canvas);
+void TimingStateMachine::nextBenchmark() {
fLoops = 1;
fInnerState = kTuning_InnerState;
fState = kPreWarm_State;
ParentEvents nextFrame(bool preWarmBetweenSamples);
/*
- * The caller should call this when they are ready to move to the next benchmark. The caller
- * must call this with the *last* benchmark so post draw hooks can be invoked
+ * The caller should call this when they are ready to move to the next benchmark.
*/
- void nextBenchmark(SkCanvas*, Benchmark*);
+ void nextBenchmark();
/*
* When TimingStateMachine returns kTimingFinished_ParentEvents, then the owner can call
}
}
}
+
+ // seed with an initial benchmark
+ this->next();
}
bool VisualBenchmarkStream::ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
}
Benchmark* VisualBenchmarkStream::next() {
+ Benchmark* bench;
if (!fIsWarmedUp) {
fIsWarmedUp = true;
- return new WarmupBench;
- }
-
- Benchmark* bench;
-
- // skips non matching benches
- while ((bench = this->innerNext()) &&
- (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName()) ||
- !bench->isSuitableFor(Benchmark::kGPU_Backend))) {
- bench->unref();
+ bench = new WarmupBench;
+ } else {
+ // skips non matching benches
+ while ((bench = this->innerNext()) &&
+ (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName()) ||
+ !bench->isSuitableFor(Benchmark::kGPU_Backend))) {
+ bench->unref();
+ }
}
- if (FLAGS_cpu) {
- return new CpuWrappedBenchmark(bench);
+ if (bench && FLAGS_cpu) {
+ bench = new CpuWrappedBenchmark(bench);
}
- return bench;
+
+ fBenchmark.reset(bench);
+ return fBenchmark;
}
Benchmark* VisualBenchmarkStream::innerNext() {
static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic);
Benchmark* next();
+ Benchmark* current() { return fBenchmark.get(); }
private:
Benchmark* innerNext();
const BenchRegistry* fBenches;
const skiagm::GMRegistry* fGMs;
SkTArray<SkString> fSKPs;
+ SkAutoTUnref<Benchmark> fBenchmark;
const char* fSourceType; // What we're benching: bench, GM, SKP, ...
const char* fBenchType; // How we bench it: micro, playback, ...
fBenchmarkStream.reset(new VisualBenchmarkStream);
}
-bool VisualStreamTimingModule::nextBenchmarkIfNecessary(SkCanvas* canvas) {
- if (fBenchmark) {
- return true;
- }
-
- fBenchmark.reset(fBenchmarkStream->next());
- if (!fBenchmark) {
- return false;
- }
-
- fOwner->clear(canvas, SK_ColorWHITE, 2);
-
- fBenchmark->delayedSetup();
- fBenchmark->preTimingHooks(canvas);
- return true;
-}
-
void VisualStreamTimingModule::draw(SkCanvas* canvas) {
- if (!this->nextBenchmarkIfNecessary(canvas)) {
- SkDebugf("Exiting VisualBench successfully\n");
- fOwner->closeWindow();
+ if (!fBenchmarkStream->current()) {
+ // this should never happen but just to be safe
return;
}
if (fReinitializeBenchmark) {
fReinitializeBenchmark = false;
- fBenchmark->preTimingHooks(canvas);
+ fBenchmarkStream->current()->preTimingHooks(canvas);
}
- this->renderFrame(canvas, fBenchmark, fTSM.loops());
+ this->renderFrame(canvas, fBenchmarkStream->current(), fTSM.loops());
fOwner->present();
TimingStateMachine::ParentEvents event = fTSM.nextFrame(fPreWarmBeforeSample);
switch (event) {
case TimingStateMachine::kReset_ParentEvents:
- fBenchmark->postTimingHooks(canvas);
+ fBenchmarkStream->current()->postTimingHooks(canvas);
fOwner->reset();
fReinitializeBenchmark = true;
break;
case TimingStateMachine::kTiming_ParentEvents:
break;
case TimingStateMachine::kTimingFinished_ParentEvents:
- fBenchmark->postTimingHooks(canvas);
+ fBenchmarkStream->current()->postTimingHooks(canvas);
fOwner->reset();
- if (this->timingFinished(fBenchmark, fTSM.loops(), fTSM.lastMeasurement())) {
- fTSM.nextBenchmark(canvas, fBenchmark);
- fBenchmark.reset(nullptr);
+ if (this->timingFinished(fBenchmarkStream->current(), fTSM.loops(),
+ fTSM.lastMeasurement())) {
+ fTSM.nextBenchmark();
+ if (!fBenchmarkStream->next()) {
+ SkDebugf("Exiting VisualBench successfully\n");
+ fOwner->closeWindow();
+ } else {
+ fOwner->clear(canvas, SK_ColorWHITE, 2);
+
+ fBenchmarkStream->current()->delayedSetup();
+ fBenchmarkStream->current()->preTimingHooks(canvas);
+ }
} else {
fReinitializeBenchmark = true;
}
// subclasses should return true to advance the stream
virtual bool timingFinished(Benchmark*, int loops, double measurement)=0;
- bool nextBenchmarkIfNecessary(SkCanvas*);
-
TimingStateMachine fTSM;
SkAutoTDelete<VisualBenchmarkStream> fBenchmarkStream;
- SkAutoTUnref<Benchmark> fBenchmark;
bool fReinitializeBenchmark;
bool fPreWarmBeforeSample;