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

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

Issue 1385073002: Create VisualStreamTimingModule (Closed) Base URL: https://skia.googlesource.com/skia.git@vb3a
Patch Set: feedback inc 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 *
7 */ 6 */
8 7
9 #include "VisualInteractiveModule.h" 8 #include "VisualInteractiveModule.h"
10 9
11 #include "ProcStats.h"
12 #include "SkApplication.h"
13 #include "SkCanvas.h" 10 #include "SkCanvas.h"
14 #include "SkCommandLineFlags.h" 11 #include "SkCommandLineFlags.h"
15 #include "SkForceLinking.h" 12 #include "SkForceLinking.h"
16 #include "SkGraphics.h"
17 #include "SkGr.h"
18 #include "SkImageDecoder.h" 13 #include "SkImageDecoder.h"
19 #include "SkOSFile.h"
20 #include "SkStream.h"
21 #include "Stats.h"
22 #include "gl/GrGLInterface.h"
23 14
24 __SK_FORCE_IMAGE_DECODER_LINKING; 15 __SK_FORCE_IMAGE_DECODER_LINKING;
25 16
26 VisualInteractiveModule::VisualInteractiveModule(VisualBench* owner) 17 VisualInteractiveModule::VisualInteractiveModule(VisualBench* owner)
27 : fCurrentMeasurement(0) 18 : INHERITED(owner, false)
28 , fBenchmark(nullptr) 19 , fCurrentMeasurement(0)
29 , fAdvance(false) 20 , fAdvance(false) {
30 , fHasBeenReset(false)
31 , fOwner(SkRef(owner)) {
32 fBenchmarkStream.reset(new VisualBenchmarkStream);
33
34 memset(fMeasurements, 0, sizeof(fMeasurements)); 21 memset(fMeasurements, 0, sizeof(fMeasurements));
35 } 22 }
36 23
37 inline void VisualInteractiveModule::renderFrame(SkCanvas* canvas) { 24 void VisualInteractiveModule::renderFrame(SkCanvas* canvas, Benchmark* benchmark , int loops) {
38 fBenchmark->draw(fTSM.loops(), canvas); 25 benchmark->draw(loops, canvas);
39 this->drawStats(canvas); 26 this->drawStats(canvas);
40 canvas->flush(); 27 canvas->flush();
41 fOwner->present();
42 } 28 }
43 29
44 void VisualInteractiveModule::drawStats(SkCanvas* canvas) { 30 void VisualInteractiveModule::drawStats(SkCanvas* canvas) {
45 static const float kPixelPerMS = 2.0f; 31 static const float kPixelPerMS = 2.0f;
46 static const int kDisplayWidth = 130; 32 static const int kDisplayWidth = 130;
47 static const int kDisplayHeight = 100; 33 static const int kDisplayHeight = 100;
48 static const int kDisplayPadding = 10; 34 static const int kDisplayPadding = 10;
49 static const int kGraphPadding = 3; 35 static const int kGraphPadding = 3;
50 static const float kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps 36 static const float kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps
51 37
(...skipping 21 matching lines...) Expand all
73 int endY = startY - (int)(fMeasurements[i] * kPixelPerMS + 0.5); // rou nd to nearest value 59 int endY = startY - (int)(fMeasurements[i] * kPixelPerMS + 0.5); // rou nd to nearest value
74 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY), 60 canvas->drawLine(SkIntToScalar(x), SkIntToScalar(startY),
75 SkIntToScalar(x), SkIntToScalar(endY), paint); 61 SkIntToScalar(x), SkIntToScalar(endY), paint);
76 i++; 62 i++;
77 i &= (kMeasurementCount - 1); // fast mod 63 i &= (kMeasurementCount - 1); // fast mod
78 x += xStep; 64 x += xStep;
79 } while (i != fCurrentMeasurement); 65 } while (i != fCurrentMeasurement);
80 66
81 } 67 }
82 68
83 bool VisualInteractiveModule::advanceRecordIfNecessary(SkCanvas* canvas) { 69 bool VisualInteractiveModule::timingFinished(Benchmark* benchmark, int loops, do uble measurement) {
84 if (fBenchmark) { 70 // Record measurements
71 fMeasurements[fCurrentMeasurement++] = measurement;
72 fCurrentMeasurement &= (kMeasurementCount-1); // fast mod
73 SkASSERT(fCurrentMeasurement < kMeasurementCount);
74 if (fAdvance) {
75 fAdvance = false;
85 return true; 76 return true;
86 } 77 }
87 78 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 } 79 }
141 80
142 bool VisualInteractiveModule::onHandleChar(SkUnichar c) { 81 bool VisualInteractiveModule::onHandleChar(SkUnichar c) {
143 if (' ' == c) { 82 if (' ' == c) {
144 fAdvance = true; 83 fAdvance = true;
145 } 84 }
146 85
147 return true; 86 return true;
148 } 87 }
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