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

Side by Side Diff: tools/VisualBench/VisualInteractiveModule.cpp

Issue 1386933002: Cleanup timing state machine (Closed) Base URL: https://skia.googlesource.com/skia.git@vb2
Patch Set: tweak 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 * 6 *
7 */ 7 */
8 8
9 #include "VisualInteractiveModule.h" 9 #include "VisualInteractiveModule.h"
10 10
11 #include "ProcStats.h" 11 #include "ProcStats.h"
12 #include "SkApplication.h" 12 #include "SkApplication.h"
13 #include "SkCanvas.h" 13 #include "SkCanvas.h"
14 #include "SkCommandLineFlags.h" 14 #include "SkCommandLineFlags.h"
15 #include "SkForceLinking.h" 15 #include "SkForceLinking.h"
16 #include "SkGraphics.h" 16 #include "SkGraphics.h"
17 #include "SkGr.h" 17 #include "SkGr.h"
18 #include "SkImageDecoder.h" 18 #include "SkImageDecoder.h"
19 #include "SkOSFile.h" 19 #include "SkOSFile.h"
20 #include "SkStream.h" 20 #include "SkStream.h"
21 #include "Stats.h" 21 #include "Stats.h"
22 #include "gl/GrGLInterface.h" 22 #include "gl/GrGLInterface.h"
23 23
24 __SK_FORCE_IMAGE_DECODER_LINKING; 24 __SK_FORCE_IMAGE_DECODER_LINKING;
25 25
26 VisualInteractiveModule::VisualInteractiveModule(VisualBench* owner) 26 VisualInteractiveModule::VisualInteractiveModule(VisualBench* owner)
27 : fCurrentMeasurement(0) 27 : fCurrentMeasurement(0)
28 , fBenchmark(nullptr) 28 , fBenchmark(nullptr)
29 , fAdvance(false) 29 , fAdvance(false)
30 , fHasBeenReset(false)
30 , fOwner(SkRef(owner)) { 31 , fOwner(SkRef(owner)) {
31 fBenchmarkStream.reset(new VisualBenchmarkStream); 32 fBenchmarkStream.reset(new VisualBenchmarkStream);
32 33
33 memset(fMeasurements, 0, sizeof(fMeasurements)); 34 memset(fMeasurements, 0, sizeof(fMeasurements));
34 } 35 }
35 36
36 inline void VisualInteractiveModule::renderFrame(SkCanvas* canvas) { 37 inline void VisualInteractiveModule::renderFrame(SkCanvas* canvas) {
37 fBenchmark->draw(fTSM.loops(), canvas); 38 fBenchmark->draw(fTSM.loops(), canvas);
38 this->drawStats(canvas); 39 this->drawStats(canvas);
39 canvas->flush(); 40 canvas->flush();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 87
87 fBenchmark.reset(fBenchmarkStream->next()); 88 fBenchmark.reset(fBenchmarkStream->next());
88 if (!fBenchmark) { 89 if (!fBenchmark) {
89 return false; 90 return false;
90 } 91 }
91 92
92 // clear both buffers 93 // clear both buffers
93 fOwner->clear(canvas, SK_ColorWHITE, 2); 94 fOwner->clear(canvas, SK_ColorWHITE, 2);
94 95
95 fBenchmark->delayedSetup(); 96 fBenchmark->delayedSetup();
96 97 fBenchmark->preTimingHooks(canvas);
97 return true; 98 return true;
98 } 99 }
99 100
100 void VisualInteractiveModule::draw(SkCanvas* canvas) { 101 void VisualInteractiveModule::draw(SkCanvas* canvas) {
101 if (!this->advanceRecordIfNecessary(canvas)) { 102 if (!this->advanceRecordIfNecessary(canvas)) {
102 SkDebugf("Exiting VisualBench successfully\n"); 103 SkDebugf("Exiting VisualBench successfully\n");
103 fOwner->closeWindow(); 104 fOwner->closeWindow();
104 return; 105 return;
105 } 106 }
107
108 if (fHasBeenReset) {
109 fHasBeenReset = false;
110 fBenchmark->preTimingHooks(canvas);
111 }
112
106 this->renderFrame(canvas); 113 this->renderFrame(canvas);
107 TimingStateMachine::ParentEvents event = fTSM.nextFrame(canvas, fBenchmark); 114 TimingStateMachine::ParentEvents event = fTSM.nextFrame(false);
108 switch (event) { 115 switch (event) {
109 case TimingStateMachine::kReset_ParentEvents: 116 case TimingStateMachine::kReset_ParentEvents:
117 fBenchmark->postTimingHooks(canvas);
118 fHasBeenReset = true;
110 fOwner->reset(); 119 fOwner->reset();
111 break; 120 break;
112 case TimingStateMachine::kTiming_ParentEvents: 121 case TimingStateMachine::kTiming_ParentEvents:
113 break; 122 break;
114 case TimingStateMachine::kTimingFinished_ParentEvents: 123 case TimingStateMachine::kTimingFinished_ParentEvents:
115 // Record measurements 124 // Record measurements
116 fMeasurements[fCurrentMeasurement++] = fTSM.lastMeasurement(); 125 fMeasurements[fCurrentMeasurement++] = fTSM.lastMeasurement();
117 fCurrentMeasurement &= (kMeasurementCount-1); // fast mod 126 fCurrentMeasurement &= (kMeasurementCount-1); // fast mod
118 SkASSERT(fCurrentMeasurement < kMeasurementCount); 127 SkASSERT(fCurrentMeasurement < kMeasurementCount);
119 this->drawStats(canvas); 128 this->drawStats(canvas);
120 if (fAdvance) { 129 if (fAdvance) {
121 fAdvance = false; 130 fAdvance = false;
122 fTSM.nextBenchmark(canvas, fBenchmark); 131 fTSM.nextBenchmark(canvas, fBenchmark);
132 fBenchmark->postTimingHooks(canvas);
123 fBenchmark.reset(nullptr); 133 fBenchmark.reset(nullptr);
124 fOwner->reset(); 134 fOwner->reset();
125 } else { 135 fHasBeenReset = true;
126 fTSM.nextSample();
127 } 136 }
128 break; 137 break;
129 } 138 }
130 } 139 }
131 140
132 bool VisualInteractiveModule::onHandleChar(SkUnichar c) { 141 bool VisualInteractiveModule::onHandleChar(SkUnichar c) {
133 if (' ' == c) { 142 if (' ' == c) {
134 fAdvance = true; 143 fAdvance = true;
135 } 144 }
136 145
137 return true; 146 return true;
138 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698