Chromium Code Reviews| Index: tools/VisualBench/VisualStreamTimingModule.cpp |
| diff --git a/tools/VisualBench/VisualStreamTimingModule.cpp b/tools/VisualBench/VisualStreamTimingModule.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3cf5911ba5d3b5c47e17a454f1622a6fbbfb7751 |
| --- /dev/null |
| +++ b/tools/VisualBench/VisualStreamTimingModule.cpp |
| @@ -0,0 +1,71 @@ |
| +/* |
| + * Copyright 2015 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
|
robertphillips
2015/10/06 12:19:46
extra line here (and in other files) ?
joshualitt
2015/10/07 19:33:53
Acknowledged.
|
| + * |
| + */ |
| + |
| +#include "VisualStreamTimingModule.h" |
| + |
| +#include "SkCanvas.h" |
| + |
| +VisualStreamTimingModule::VisualStreamTimingModule(VisualBench* owner, bool preWarmBeforeSample) |
| + : fHasBeenReset(false) |
| + , fPreWarmBeforeSample(preWarmBeforeSample) |
|
robertphillips
2015/10/06 12:19:46
We take a ref on the guy who owns us ?
|
| + , fOwner(SkRef(owner)) { |
| + 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(); |
| + return; |
| + } |
| + |
| + if (fHasBeenReset) { |
| + fHasBeenReset = false; |
| + fBenchmark->preTimingHooks(canvas); |
| + } |
| + |
|
robertphillips
2015/10/06 12:19:46
Why not have a 'getCurBenchMark' method on this cl
joshualitt
2015/10/07 19:33:53
will fix in a follow on
|
| + this->renderFrame(canvas, fBenchmark, fTSM.loops()); |
| + fOwner->present(); |
| + TimingStateMachine::ParentEvents event = fTSM.nextFrame(fPreWarmBeforeSample); |
| + switch (event) { |
| + case TimingStateMachine::kReset_ParentEvents: |
| + fBenchmark->postTimingHooks(canvas); |
| + fOwner->reset(); |
| + fHasBeenReset = true; |
| + break; |
| + case TimingStateMachine::kTiming_ParentEvents: |
| + break; |
| + case TimingStateMachine::kTimingFinished_ParentEvents: |
| + fBenchmark->postTimingHooks(canvas); |
| + fOwner->reset(); |
| + if (this->timingFinished(fBenchmark, fTSM.loops(), fTSM.lastMeasurement())) { |
| + fTSM.nextBenchmark(canvas, fBenchmark); |
| + fBenchmark.reset(nullptr); |
| + } else { |
| + fHasBeenReset = true; |
| + } |
| + break; |
| + } |
| +} |