OLD | NEW |
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" | |
12 #include "SkApplication.h" | |
13 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
14 #include "SkCommandLineFlags.h" | 12 #include "SkCommandLineFlags.h" |
15 #include "SkForceLinking.h" | 13 #include "SkForceLinking.h" |
16 #include "SkGraphics.h" | |
17 #include "SkGr.h" | |
18 #include "SkImageDecoder.h" | 14 #include "SkImageDecoder.h" |
19 #include "SkOSFile.h" | |
20 #include "SkStream.h" | |
21 #include "Stats.h" | |
22 #include "gl/GrGLInterface.h" | |
23 | 15 |
24 __SK_FORCE_IMAGE_DECODER_LINKING; | 16 __SK_FORCE_IMAGE_DECODER_LINKING; |
25 | 17 |
26 VisualInteractiveModule::VisualInteractiveModule(VisualBench* owner) | 18 VisualInteractiveModule::VisualInteractiveModule(VisualBench* owner) |
27 : fCurrentMeasurement(0) | 19 : INHERITED(owner, false) |
28 , fBenchmark(nullptr) | 20 , fCurrentMeasurement(0) |
29 , fAdvance(false) | 21 , fAdvance(false) { |
30 , fHasBeenReset(false) | |
31 , fOwner(SkRef(owner)) { | |
32 fBenchmarkStream.reset(new VisualBenchmarkStream); | |
33 | |
34 memset(fMeasurements, 0, sizeof(fMeasurements)); | 22 memset(fMeasurements, 0, sizeof(fMeasurements)); |
35 } | 23 } |
36 | 24 |
37 inline void VisualInteractiveModule::renderFrame(SkCanvas* canvas) { | 25 void VisualInteractiveModule::renderFrame(SkCanvas* canvas, Benchmark* benchmark
, int loops) { |
38 fBenchmark->draw(fTSM.loops(), canvas); | 26 benchmark->draw(loops, canvas); |
39 this->drawStats(canvas); | 27 this->drawStats(canvas); |
40 canvas->flush(); | 28 canvas->flush(); |
41 fOwner->present(); | |
42 } | 29 } |
43 | 30 |
44 void VisualInteractiveModule::drawStats(SkCanvas* canvas) { | 31 void VisualInteractiveModule::drawStats(SkCanvas* canvas) { |
45 static const float kPixelPerMS = 2.0f; | 32 static const float kPixelPerMS = 2.0f; |
46 static const int kDisplayWidth = 130; | 33 static const int kDisplayWidth = 130; |
47 static const int kDisplayHeight = 100; | 34 static const int kDisplayHeight = 100; |
48 static const int kDisplayPadding = 10; | 35 static const int kDisplayPadding = 10; |
49 static const int kGraphPadding = 3; | 36 static const int kGraphPadding = 3; |
50 static const float kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps | 37 static const float kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps |
51 | 38 |
(...skipping 21 matching lines...) Expand all Loading... |
73 int endY = startY - (int)(fMeasurements[i] * kPixelPerMS + 0.5); // rou
nd to nearest value | 60 int endY = startY - (int)(fMeasurements[i] * kPixelPerMS + 0.5); // rou
nd to nearest value |
74 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY), | 61 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY), |
75 SkIntToScalar(x), SkIntToScalar(endY), paint); | 62 SkIntToScalar(x), SkIntToScalar(endY), paint); |
76 i++; | 63 i++; |
77 i &= (kMeasurementCount - 1); // fast mod | 64 i &= (kMeasurementCount - 1); // fast mod |
78 x += xStep; | 65 x += xStep; |
79 } while (i != fCurrentMeasurement); | 66 } while (i != fCurrentMeasurement); |
80 | 67 |
81 } | 68 } |
82 | 69 |
83 bool VisualInteractiveModule::advanceRecordIfNecessary(SkCanvas* canvas) { | 70 bool VisualInteractiveModule::timingFinished(Benchmark* benchmark, int loops, do
uble measurement) { |
84 if (fBenchmark) { | 71 // Record measurements |
| 72 fMeasurements[fCurrentMeasurement++] = measurement; |
| 73 fCurrentMeasurement &= (kMeasurementCount-1); // fast mod |
| 74 SkASSERT(fCurrentMeasurement < kMeasurementCount); |
| 75 if (fAdvance) { |
| 76 fAdvance = false; |
85 return true; | 77 return true; |
86 } | 78 } |
87 | 79 return false; |
88 fBenchmark.reset(fBenchmarkStream->next()); | |
89 if (!fBenchmark) { | |
90 return false; | |
91 } | |
92 | |
93 // clear both buffers | |
94 fOwner->clear(canvas, SK_ColorWHITE, 2); | |
95 | |
96 fBenchmark->delayedSetup(); | |
97 fBenchmark->preTimingHooks(canvas); | |
98 return true; | |
99 } | |
100 #include "GrGpu.h" | |
101 #include "GrResourceCache.h" | |
102 void VisualInteractiveModule::draw(SkCanvas* canvas) { | |
103 if (!this->advanceRecordIfNecessary(canvas)) { | |
104 SkDebugf("Exiting VisualBench successfully\n"); | |
105 fOwner->closeWindow(); | |
106 return; | |
107 } | |
108 | |
109 if (fHasBeenReset) { | |
110 fHasBeenReset = false; | |
111 fBenchmark->preTimingHooks(canvas); | |
112 } | |
113 | |
114 this->renderFrame(canvas); | |
115 TimingStateMachine::ParentEvents event = fTSM.nextFrame(false); | |
116 switch (event) { | |
117 case TimingStateMachine::kReset_ParentEvents: | |
118 fBenchmark->postTimingHooks(canvas); | |
119 fHasBeenReset = true; | |
120 fOwner->reset(); | |
121 break; | |
122 case TimingStateMachine::kTiming_ParentEvents: | |
123 break; | |
124 case TimingStateMachine::kTimingFinished_ParentEvents: | |
125 // Record measurements | |
126 fMeasurements[fCurrentMeasurement++] = fTSM.lastMeasurement(); | |
127 fCurrentMeasurement &= (kMeasurementCount-1); // fast mod | |
128 SkASSERT(fCurrentMeasurement < kMeasurementCount); | |
129 this->drawStats(canvas); | |
130 if (fAdvance) { | |
131 fAdvance = false; | |
132 fTSM.nextBenchmark(canvas, fBenchmark); | |
133 fBenchmark->postTimingHooks(canvas); | |
134 fBenchmark.reset(nullptr); | |
135 fOwner->reset(); | |
136 fHasBeenReset = true; | |
137 } | |
138 break; | |
139 } | |
140 } | 80 } |
141 | 81 |
142 bool VisualInteractiveModule::onHandleChar(SkUnichar c) { | 82 bool VisualInteractiveModule::onHandleChar(SkUnichar c) { |
143 if (' ' == c) { | 83 if (' ' == c) { |
144 fAdvance = true; | 84 fAdvance = true; |
145 } | 85 } |
146 | 86 |
147 return true; | 87 return true; |
148 } | 88 } |
OLD | NEW |