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

Side by Side Diff: tools/VisualBench.cpp

Issue 1183193003: Load visualbench pictures one at a time. (Closed) Base URL: https://skia.googlesource.com/skia.git@stuff
Patch Set: reupload? Created 5 years, 6 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
« no previous file with comments | « tools/VisualBench.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "VisualBench.h" 9 #include "VisualBench.h"
10 10
(...skipping 10 matching lines...) Expand all
21 #include "SkStream.h" 21 #include "SkStream.h"
22 #include "Stats.h" 22 #include "Stats.h"
23 #include "gl/GrGLInterface.h" 23 #include "gl/GrGLInterface.h"
24 24
25 __SK_FORCE_IMAGE_DECODER_LINKING; 25 __SK_FORCE_IMAGE_DECODER_LINKING;
26 26
27 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); 27 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag.");
28 DEFINE_int32(samples, 10, "Number of times to render each skp."); 28 DEFINE_int32(samples, 10, "Number of times to render each skp.");
29 DEFINE_int32(loops, 5, "Number of times to time."); 29 DEFINE_int32(loops, 5, "Number of times to time.");
30 DEFINE_int32(msaa, 0, "Number of msaa samples."); 30 DEFINE_int32(msaa, 0, "Number of msaa samples.");
31 DEFINE_bool2(fullscreen, f, true, "Run fullscreen.");
31 32
32 static SkString humanize(double ms) { 33 static SkString humanize(double ms) {
33 if (FLAGS_verbose) { 34 if (FLAGS_verbose) {
34 return SkStringPrintf("%llu", (uint64_t)(ms*1e6)); 35 return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
35 } 36 }
36 return HumanizeMs(ms); 37 return HumanizeMs(ms);
37 } 38 }
38 39
39 #define HUMANIZE(time) humanize(time).c_str() 40 #define HUMANIZE(time) humanize(time).c_str()
40 41
41 VisualBench::VisualBench(void* hwnd, int argc, char** argv) 42 VisualBench::VisualBench(void* hwnd, int argc, char** argv)
42 : INHERITED(hwnd) 43 : INHERITED(hwnd)
43 , fLoop(0) 44 , fLoop(0)
44 , fCurrentPicture(0) 45 , fCurrentPictureIdx(-1)
45 , fCurrentSample(0) 46 , fCurrentSample(0)
46 , fState(kPreWarm_State) { 47 , fState(kPreWarm_State) {
47 SkCommandLineFlags::Parse(argc, argv); 48 SkCommandLineFlags::Parse(argc, argv);
48 49
49 // load all SKPs 50 // read all the skp file names.
50 SkTArray<SkString> skps;
51 for (int i = 0; i < FLAGS_skps.count(); i++) { 51 for (int i = 0; i < FLAGS_skps.count(); i++) {
52 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { 52 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
53 skps.push_back() = FLAGS_skps[i]; 53 fRecords.push_back().fFilename = FLAGS_skps[i];
54 fTimings.push_back().fName = FLAGS_skps[i];
55 } else { 54 } else {
56 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); 55 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
57 SkString path; 56 SkString path;
58 while (it.next(&path)) { 57 while (it.next(&path)) {
59 skps.push_back() = SkOSPath::Join(FLAGS_skps[i], path.c_str()); 58 fRecords.push_back().fFilename = SkOSPath::Join(FLAGS_skps[i], p ath.c_str());;
60 fTimings.push_back().fName = path.c_str();
61 } 59 }
62 } 60 }
63 } 61 }
64 62
65 for (int i = 0; i < skps.count(); i++) { 63 if (fRecords.empty()) {
66 SkFILEStream stream(skps[i].c_str());
67 if (stream.isValid()) {
68 fPictures.push_back(SkPicture::CreateFromStream(&stream));
69 } else {
70 SkDebugf("couldn't load picture at \"path\"\n", skps[i].c_str());
71 }
72 }
73
74 if (fPictures.empty()) {
75 SkDebugf("no valid skps found\n"); 64 SkDebugf("no valid skps found\n");
76 } 65 }
77 66
78 this->setTitle(); 67 this->setTitle();
79 this->setupBackend(); 68 this->setupBackend();
80 } 69 }
81 70
82 VisualBench::~VisualBench() { 71 VisualBench::~VisualBench() {
83 for (int i = 0; i < fPictures.count(); i++) {
84 fPictures[i]->~SkPicture();
85 }
86 INHERITED::detach(); 72 INHERITED::detach();
87 } 73 }
88 74
89 void VisualBench::setTitle() { 75 void VisualBench::setTitle() {
90 SkString title("VisualBench"); 76 SkString title("VisualBench");
91 INHERITED::setTitle(title.c_str()); 77 INHERITED::setTitle(title.c_str());
92 } 78 }
93 79
94 SkSurface* VisualBench::createSurface() { 80 SkSurface* VisualBench::createSurface() {
95 SkSurfaceProps props(INHERITED::getSurfaceProps()); 81 SkSurfaceProps props(INHERITED::getSurfaceProps());
96 return SkSurface::NewRenderTargetDirect(fRenderTarget, &props); 82 return SkSurface::NewRenderTargetDirect(fRenderTarget, &props);
97 } 83 }
98 84
99 bool VisualBench::setupBackend() { 85 bool VisualBench::setupBackend() {
100 this->setColorType(kRGBA_8888_SkColorType); 86 this->setColorType(kRGBA_8888_SkColorType);
101 this->setVisibleP(true); 87 this->setVisibleP(true);
102 this->setClipToBounds(false); 88 this->setClipToBounds(false);
103 89
104 if (!this->makeFullscreen()) { 90 if (FLAGS_fullscreen) {
105 SkDebugf("Could not go fullscreen!"); 91 if (!this->makeFullscreen()) {
92 SkDebugf("Could not go fullscreen!");
93 }
106 } 94 }
107 if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) { 95 if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) {
108 SkDebugf("Not possible to create backend.\n"); 96 SkDebugf("Not possible to create backend.\n");
109 INHERITED::detach(); 97 INHERITED::detach();
110 return false; 98 return false;
111 } 99 }
112 100
113 this->setVsync(false); 101 this->setVsync(false);
114 this->resetContext(); 102 this->resetContext();
115 return true; 103 return true;
(...skipping 11 matching lines...) Expand all
127 this->setupRenderTarget(); 115 this->setupRenderTarget();
128 } 116 }
129 117
130 void VisualBench::setupRenderTarget() { 118 void VisualBench::setupRenderTarget() {
131 if (fContext) { 119 if (fContext) {
132 fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fCon text)); 120 fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fCon text));
133 } 121 }
134 } 122 }
135 123
136 inline void VisualBench::renderFrame(SkCanvas* canvas) { 124 inline void VisualBench::renderFrame(SkCanvas* canvas) {
137 canvas->drawPicture(fPictures[fCurrentPicture]); 125 canvas->drawPicture(fPicture);
138 fContext->flush(); 126 fContext->flush();
139 INHERITED::present(); 127 INHERITED::present();
140 } 128 }
141 129
142 void VisualBench::printStats() { 130 void VisualBench::printStats() {
143 const SkTArray<double>& measurements = fTimings[fCurrentPicture].fMeasuremen ts; 131 const SkTArray<double>& measurements = fRecords[fCurrentPictureIdx].fMeasure ments;
132 SkString shortName = SkOSPath::Basename(fRecords[fCurrentPictureIdx].fFilena me.c_str());
144 if (FLAGS_verbose) { 133 if (FLAGS_verbose) {
145 for (int i = 0; i < measurements.count(); i++) { 134 for (int i = 0; i < measurements.count(); i++) {
146 SkDebugf("%s ", HUMANIZE(measurements[i])); 135 SkDebugf("%s ", HUMANIZE(measurements[i]));
147 } 136 }
148 SkDebugf("%s\n", fTimings[fCurrentPicture].fName.c_str()); 137 SkDebugf("%s\n", shortName.c_str());
149 } else { 138 } else {
150 SkASSERT(measurements.count()); 139 SkASSERT(measurements.count());
151 Stats stats(measurements.begin(), measurements.count()); 140 Stats stats(measurements.begin(), measurements.count());
152 const double stdDevPercent = 100 * sqrt(stats.var) / stats.mean; 141 const double stdDevPercent = 100 * sqrt(stats.var) / stats.mean;
153 SkDebugf("%4d/%-4dMB\t%s\t%s\t%s\t%s\t%.0f%%\t%s\n", 142 SkDebugf("%4d/%-4dMB\t%s\t%s\t%s\t%s\t%.0f%%\t%s\n",
154 sk_tools::getCurrResidentSetSizeMB(), 143 sk_tools::getCurrResidentSetSizeMB(),
155 sk_tools::getMaxResidentSetSizeMB(), 144 sk_tools::getMaxResidentSetSizeMB(),
156 HUMANIZE(stats.min), 145 HUMANIZE(stats.min),
157 HUMANIZE(stats.median), 146 HUMANIZE(stats.median),
158 HUMANIZE(stats.mean), 147 HUMANIZE(stats.mean),
159 HUMANIZE(stats.max), 148 HUMANIZE(stats.max),
160 stdDevPercent, 149 stdDevPercent,
161 fTimings[fCurrentPicture].fName.c_str()); 150 shortName.c_str());
162 } 151 }
163 } 152 }
164 153
165 void VisualBench::timePicture(SkCanvas* canvas) { 154 bool VisualBench::advanceRecordIfNecessary() {
155 if (fPicture) {
156 return true;
157 }
158 ++fCurrentPictureIdx;
159 while (true) {
160 if (fCurrentPictureIdx >= fRecords.count()) {
161 return false;
162 }
163 if (this->loadPicture()) {
164 return true;
165 }
166 fRecords.removeShuffle(fCurrentPictureIdx);
167 }
168 }
169
170 bool VisualBench::loadPicture() {
171 const char* fileName = fRecords[fCurrentPictureIdx].fFilename.c_str();
172 SkFILEStream stream(fileName);
173 if (stream.isValid()) {
174 fPicture.reset(SkPicture::CreateFromStream(&stream));
175 if (SkToBool(fPicture)) {
176 return true;
177 }
178 }
179 SkDebugf("couldn't load picture at \"%s\"\n", fileName);
180 return false;
181 }
182
183 void VisualBench::draw(SkCanvas* canvas) {
184 if (!this->advanceRecordIfNecessary()) {
185 this->closeWindow();
186 return;
187 }
166 this->renderFrame(canvas); 188 this->renderFrame(canvas);
167 switch (fState) { 189 switch (fState) {
168 case kPreWarm_State: { 190 case kPreWarm_State: {
169 if (fCurrentSample >= FLAGS_gpuFrameLag) { 191 if (fCurrentSample >= FLAGS_gpuFrameLag) {
170 // TODO we currently time across all frames to make sure we capt ure all GPU work 192 // TODO we currently time across all frames to make sure we capt ure all GPU work
171 // We should also rendering an empty SKP to get a baseline to su btract from 193 // We should also rendering an empty SKP to get a baseline to su btract from
172 // our timing 194 // our timing
173 fState = kTiming_State; 195 fState = kTiming_State;
174 fCurrentSample -= FLAGS_gpuFrameLag; 196 fCurrentSample -= FLAGS_gpuFrameLag;
175 fTimer.start(); 197 fTimer.start();
176 } else { 198 } else {
177 fCurrentSample++; 199 fCurrentSample++;
178 } 200 }
179 break; 201 break;
180 } 202 }
181 case kTiming_State: { 203 case kTiming_State: {
182 if (fCurrentSample >= FLAGS_samples) { 204 if (fCurrentSample >= FLAGS_samples) {
183 fTimer.end(); 205 fTimer.end();
184 fTimings[fCurrentPicture].fMeasurements.push_back(fTimer.fWall / FLAGS_samples); 206 fRecords[fCurrentPictureIdx].fMeasurements.push_back(fTimer.fWal l / FLAGS_samples);
185 this->resetContext(); 207 this->resetContext();
186 fTimer = WallTimer(); 208 fTimer = WallTimer();
187 fState = kPreWarm_State; 209 fState = kPreWarm_State;
188 fCurrentSample = 0; 210 fCurrentSample = 0;
189 if (fLoop++ > FLAGS_loops) { 211 if (fLoop++ > FLAGS_loops) {
190 this->printStats(); 212 this->printStats();
191 fCurrentPicture++; 213 fPicture.reset(NULL);
192 fLoop = 0; 214 fLoop = 0;
193 } 215 }
194 } else { 216 } else {
195 fCurrentSample++; 217 fCurrentSample++;
196 } 218 }
197 break; 219 break;
198 } 220 }
199 } 221 }
200 }
201
202 void VisualBench::draw(SkCanvas* canvas) {
203 if (fCurrentPicture < fPictures.count()) {
204 this->timePicture(canvas);
205 } else {
206 this->closeWindow();
207 }
208 222
209 // Invalidate the window to force a redraw. Poor man's animation mechanism. 223 // Invalidate the window to force a redraw. Poor man's animation mechanism.
210 this->inval(NULL); 224 this->inval(NULL);
211 } 225 }
212 226
213 void VisualBench::onSizeChange() { 227 void VisualBench::onSizeChange() {
214 this->setupRenderTarget(); 228 this->setupRenderTarget();
215 } 229 }
216 230
217 bool VisualBench::onHandleChar(SkUnichar unichar) { 231 bool VisualBench::onHandleChar(SkUnichar unichar) {
218 return true; 232 return true;
219 } 233 }
220 234
221 // Externally declared entry points 235 // Externally declared entry points
222 void application_init() { 236 void application_init() {
223 SkGraphics::Init(); 237 SkGraphics::Init();
224 SkEvent::Init(); 238 SkEvent::Init();
225 } 239 }
226 240
227 void application_term() { 241 void application_term() {
228 SkEvent::Term(); 242 SkEvent::Term();
229 SkGraphics::Term(); 243 SkGraphics::Term();
230 } 244 }
231 245
232 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { 246 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
233 return new VisualBench(hwnd, argc, argv); 247 return new VisualBench(hwnd, argc, argv);
234 } 248 }
235 249
OLDNEW
« no previous file with comments | « tools/VisualBench.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698