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

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: rebase 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 #include "GrGpu.h" 100 #include "GrGpu.h"
100 #include "GrResourceCache.h" 101 #include "GrResourceCache.h"
101 void VisualInteractiveModule::draw(SkCanvas* canvas) { 102 void VisualInteractiveModule::draw(SkCanvas* canvas) {
102 if (!this->advanceRecordIfNecessary(canvas)) { 103 if (!this->advanceRecordIfNecessary(canvas)) {
103 SkDebugf("Exiting VisualBench successfully\n"); 104 SkDebugf("Exiting VisualBench successfully\n");
104 fOwner->closeWindow(); 105 fOwner->closeWindow();
105 return; 106 return;
106 } 107 }
108
109 if (fHasBeenReset) {
110 fHasBeenReset = false;
111 fBenchmark->preTimingHooks(canvas);
112 }
113
107 this->renderFrame(canvas); 114 this->renderFrame(canvas);
108 TimingStateMachine::ParentEvents event = fTSM.nextFrame(canvas, fBenchmark); 115 TimingStateMachine::ParentEvents event = fTSM.nextFrame(false);
109 switch (event) { 116 switch (event) {
110 case TimingStateMachine::kReset_ParentEvents: 117 case TimingStateMachine::kReset_ParentEvents:
118 fBenchmark->postTimingHooks(canvas);
119 fHasBeenReset = true;
111 fOwner->reset(); 120 fOwner->reset();
112 break; 121 break;
113 case TimingStateMachine::kTiming_ParentEvents: 122 case TimingStateMachine::kTiming_ParentEvents:
114 break; 123 break;
115 case TimingStateMachine::kTimingFinished_ParentEvents: 124 case TimingStateMachine::kTimingFinished_ParentEvents:
116 // Record measurements 125 // Record measurements
117 fMeasurements[fCurrentMeasurement++] = fTSM.lastMeasurement(); 126 fMeasurements[fCurrentMeasurement++] = fTSM.lastMeasurement();
118 fCurrentMeasurement &= (kMeasurementCount-1); // fast mod 127 fCurrentMeasurement &= (kMeasurementCount-1); // fast mod
119 SkASSERT(fCurrentMeasurement < kMeasurementCount); 128 SkASSERT(fCurrentMeasurement < kMeasurementCount);
120 this->drawStats(canvas); 129 this->drawStats(canvas);
121 if (fAdvance) { 130 if (fAdvance) {
122 fAdvance = false; 131 fAdvance = false;
123 fTSM.nextBenchmark(canvas, fBenchmark); 132 fTSM.nextBenchmark(canvas, fBenchmark);
133 fBenchmark->postTimingHooks(canvas);
124 fBenchmark.reset(nullptr); 134 fBenchmark.reset(nullptr);
125 fOwner->reset(); 135 fOwner->reset();
126 } else { 136 fHasBeenReset = true;
127 fTSM.nextSample();
128 } 137 }
129 break; 138 break;
130 } 139 }
131 } 140 }
132 141
133 bool VisualInteractiveModule::onHandleChar(SkUnichar c) { 142 bool VisualInteractiveModule::onHandleChar(SkUnichar c) {
134 if (' ' == c) { 143 if (' ' == c) {
135 fAdvance = true; 144 fAdvance = true;
136 } 145 }
137 146
138 return true; 147 return true;
139 } 148 }
OLDNEW
« no previous file with comments | « tools/VisualBench/VisualInteractiveModule.h ('k') | tools/VisualBench/VisualLightweightBenchModule.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698