Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(788)

Unified Diff: tools/VisualBench/VisualStreamTimingModule.cpp

Issue 1395703002: small tidy of benchmarkstream (Closed) Base URL: https://skia.googlesource.com/skia.git@vb4b
Patch Set: remove debug print Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/VisualBench/VisualStreamTimingModule.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/VisualBench/VisualStreamTimingModule.cpp
diff --git a/tools/VisualBench/VisualStreamTimingModule.cpp b/tools/VisualBench/VisualStreamTimingModule.cpp
index db75890d11ae499e1a74ff4c1084b716bf1b6575..0a57e672211a2152053545bf114200325061f9c7 100644
--- a/tools/VisualBench/VisualStreamTimingModule.cpp
+++ b/tools/VisualBench/VisualStreamTimingModule.cpp
@@ -10,61 +10,66 @@
#include "SkCanvas.h"
VisualStreamTimingModule::VisualStreamTimingModule(VisualBench* owner, bool preWarmBeforeSample)
- : fReinitializeBenchmark(false)
+ : fInitState(kReset_InitState)
, fPreWarmBeforeSample(preWarmBeforeSample)
, fOwner(owner) {
fBenchmarkStream.reset(new VisualBenchmarkStream);
}
-bool VisualStreamTimingModule::nextBenchmarkIfNecessary(SkCanvas* canvas) {
- if (fBenchmark) {
- return true;
- }
-
- fBenchmark.reset(fBenchmarkStream->next());
- if (!fBenchmark) {
- return false;
+inline void VisualStreamTimingModule::handleInitState(SkCanvas* canvas) {
+ switch (fInitState) {
+ case kNewBenchmark_InitState:
+ fOwner->clear(canvas, SK_ColorWHITE, 2);
+ fBenchmarkStream->current()->delayedSetup();
+ // fallthrough
+ case kReset_InitState:
+ fBenchmarkStream->current()->preTimingHooks(canvas);
+ break;
+ case kNone_InitState:
+ break;
}
-
- fOwner->clear(canvas, SK_ColorWHITE, 2);
-
- fBenchmark->delayedSetup();
- fBenchmark->preTimingHooks(canvas);
- return true;
+ fInitState = kNone_InitState;
}
-void VisualStreamTimingModule::draw(SkCanvas* canvas) {
- if (!this->nextBenchmarkIfNecessary(canvas)) {
- SkDebugf("Exiting VisualBench successfully\n");
- fOwner->closeWindow();
- return;
- }
-
- if (fReinitializeBenchmark) {
- fReinitializeBenchmark = false;
- fBenchmark->preTimingHooks(canvas);
- }
-
- this->renderFrame(canvas, fBenchmark, fTSM.loops());
- fOwner->present();
- TimingStateMachine::ParentEvents event = fTSM.nextFrame(fPreWarmBeforeSample);
+inline void VisualStreamTimingModule::handleTimingEvent(SkCanvas* canvas,
+ TimingStateMachine::ParentEvents event) {
switch (event) {
case TimingStateMachine::kReset_ParentEvents:
- fBenchmark->postTimingHooks(canvas);
+ fBenchmarkStream->current()->postTimingHooks(canvas);
fOwner->reset();
- fReinitializeBenchmark = true;
+ fInitState = kReset_InitState;
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 {
+ fInitState = kNewBenchmark_InitState;
+ }
} else {
- fReinitializeBenchmark = true;
+ fInitState = kReset_InitState;
}
break;
}
}
+
+void VisualStreamTimingModule::draw(SkCanvas* canvas) {
+ if (!fBenchmarkStream->current()) {
+ // this should never happen but just to be safe
+ // TODO research why this does happen on mac
+ return;
+ }
+
+ this->handleInitState(canvas);
+ this->renderFrame(canvas, fBenchmarkStream->current(), fTSM.loops());
+ fOwner->present();
+ TimingStateMachine::ParentEvents event = fTSM.nextFrame(fPreWarmBeforeSample);
+ this->handleTimingEvent(canvas, event);
+}
« no previous file with comments | « tools/VisualBench/VisualStreamTimingModule.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698