blob: 25fd5fca7f495383c8b0554525d8252c9f200b4b [file] [log] [blame]
reed@google.com006db0f2012-06-27 19:33:29 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "BenchTimer.h"
keyar@chromium.org163b5672012-08-01 17:53:29 +00009#include "PictureBenchmark.h"
scroggo@google.com9a412522012-09-07 15:21:18 +000010#include "SkBenchLogger.h"
reed@google.com006db0f2012-06-27 19:33:29 +000011#include "SkCanvas.h"
scroggo@google.com0a36f432012-09-10 20:29:13 +000012#include "SkGraphics.h"
scroggo@google.com5a7c6be2012-10-04 21:46:08 +000013#include "SkImageDecoder.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000014#include "SkMath.h"
reed@google.com006db0f2012-06-27 19:33:29 +000015#include "SkOSFile.h"
16#include "SkPicture.h"
17#include "SkStream.h"
18#include "SkTArray.h"
19#include "picture_utils.h"
20
borenet@google.com13fd5a12012-09-17 21:10:05 +000021const int DEFAULT_REPEATS = 1;
reed@google.com006db0f2012-06-27 19:33:29 +000022
23static void usage(const char* argv0) {
24 SkDebugf("SkPicture benchmarking tool\n");
25 SkDebugf("\n"
26"Usage: \n"
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +000027" %s <inputDir>...\n"
scroggo@google.com5239c322012-09-11 19:15:32 +000028" [--logFile filename][--timers [wcgWC]*][--logPerIter 1|0][--min]\n"
keyar@chromium.org795cd472012-08-02 18:57:53 +000029" [--repeat] \n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000030" [--mode pow2tile minWidth height[] | record | simple\n"
31" | tile width[] height[] | playbackCreation]\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +000032" [--pipe]\n"
junov@chromium.org9313ca42012-11-02 18:11:49 +000033" [--bbh bbhType]\n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000034" [--multi numThreads]\n"
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000035" [--device bitmap"
36#if SK_SUPPORT_GPU
37" | gpu"
38#endif
39"]"
reed@google.com006db0f2012-06-27 19:33:29 +000040, argv0);
41 SkDebugf("\n\n");
42 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000043" inputDir: A list of directories and files to use as input. Files are\n"
scroggo@google.com9a412522012-09-07 15:21:18 +000044" expected to have the .skp extension.\n\n"
45" --logFile filename : destination for writing log output, in addition to stdout.\n");
scroggo@google.com5239c322012-09-11 19:15:32 +000046 SkDebugf(" --logPerIter 1|0 : "
47 "Log each repeat timer instead of mean, default is disabled.\n");
48 SkDebugf(" --min : Print the minimum times (instead of average).\n");
49 SkDebugf(" --timers [wcgWC]* : "
50 "Display wall, cpu, gpu, truncated wall or truncated cpu time for each picture.\n");
reed@google.com006db0f2012-06-27 19:33:29 +000051 SkDebugf(
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000052" --mode pow2tile minWidht height[] | record | simple\n"
53" | tile width[] height[] | playbackCreation:\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +000054" Run in the corresponding mode.\n"
55" Default is simple.\n");
keyar@chromium.orgcf6c44c2012-07-09 19:37:40 +000056 SkDebugf(
scroggo@google.com58b4ead2012-08-31 16:15:22 +000057" pow2tile minWidth height[], Creates tiles with widths\n"
58" that are all a power of two\n"
59" such that they minimize the\n"
60" amount of wasted tile space.\n"
61" minWidth is the minimum width\n"
62" of these tiles and must be a\n"
63" power of two. Simple\n"
64" rendering using these tiles\n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000065" is benchmarked.\n");
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000066 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000067" record, Benchmark picture to picture recording.\n");
68 SkDebugf(
69" simple, Benchmark a simple rendering.\n");
70 SkDebugf(
scroggo@google.com58b4ead2012-08-31 16:15:22 +000071" tile width[] height[], Benchmark simple rendering using\n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000072" tiles with the given dimensions.\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +000073 SkDebugf(
scroggo@google.com9a412522012-09-07 15:21:18 +000074" playbackCreation, Benchmark creation of the SkPicturePlayback.\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +000075 SkDebugf("\n");
76 SkDebugf(
scroggo@google.combcdf2ec2012-09-20 14:42:33 +000077" --multi numThreads : Set the number of threads for multi threaded drawing. Must be greater\n"
78" than 1. Only works with tiled rendering.\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +000079" --pipe: Benchmark SkGPipe rendering. Compatible with tiled, multithreaded rendering.\n");
80 SkDebugf(
junov@chromium.org9313ca42012-11-02 18:11:49 +000081" --bbh bbhType: Set the bounding box hierarchy type to be used. Accepted\n"
82" values are: none, rtree. Default value is none.\n"
83" Not compatible with --pipe.\n");
84 SkDebugf(
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000085" --device bitmap"
86#if SK_SUPPORT_GPU
87" | gpu"
88#endif
89": Use the corresponding device. Default is bitmap.\n");
90 SkDebugf(
91" bitmap, Render to a bitmap.\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000092#if SK_SUPPORT_GPU
keyar@chromium.orga40c20d2012-08-20 15:04:12 +000093 SkDebugf(
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000094" gpu, Render to the GPU.\n");
95#endif
96 SkDebugf("\n");
97 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000098" --repeat: "
reed@google.com006db0f2012-06-27 19:33:29 +000099"Set the number of times to repeat each test."
100" Default is %i.\n", DEFAULT_REPEATS);
reed@google.com006db0f2012-06-27 19:33:29 +0000101}
102
scroggo@google.com9a412522012-09-07 15:21:18 +0000103SkBenchLogger gLogger;
104
borenet@google.com66bcbd12012-09-17 18:26:06 +0000105static bool run_single_benchmark(const SkString& inputPath,
keyar@chromium.org163b5672012-08-01 17:53:29 +0000106 sk_tools::PictureBenchmark& benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000107 SkFILEStream inputStream;
108
reed@google.com006db0f2012-06-27 19:33:29 +0000109 inputStream.setPath(inputPath.c_str());
110 if (!inputStream.isValid()) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000111 SkString err;
112 err.printf("Could not open file %s\n", inputPath.c_str());
113 gLogger.logError(err);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000114 return false;
reed@google.com006db0f2012-06-27 19:33:29 +0000115 }
116
borenet@google.com66bcbd12012-09-17 18:26:06 +0000117 bool success = false;
scroggo@google.com5a7c6be2012-10-04 21:46:08 +0000118 SkPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000119 if (!success) {
120 SkString err;
121 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
122 gLogger.logError(err);
123 return false;
124 }
reed@google.com006db0f2012-06-27 19:33:29 +0000125
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000126 SkString filename;
127 sk_tools::get_basename(&filename, inputPath);
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000128
129 SkString result;
borenet@google.com2d2b9a02012-09-20 18:54:04 +0000130 result.printf("running bench [%i %i] %s ", picture.width(),
131 picture.height(), filename.c_str());
scroggo@google.com9a412522012-09-07 15:21:18 +0000132 gLogger.logProgress(result);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000133
borenet@google.com2d2b9a02012-09-20 18:54:04 +0000134 benchmark.run(&picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000135 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000136}
137
keyar@chromium.org163b5672012-08-01 17:53:29 +0000138static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs,
scroggo@google.com5239c322012-09-11 19:15:32 +0000139 sk_tools::PictureBenchmark* benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000140 const char* argv0 = argv[0];
141 char* const* stop = argv + argc;
142
keyar@chromium.org163b5672012-08-01 17:53:29 +0000143 int repeats = DEFAULT_REPEATS;
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000144 sk_tools::PictureRenderer::SkDeviceTypes deviceType =
145 sk_tools::PictureRenderer::kBitmap_DeviceType;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000146
scroggo@google.com5239c322012-09-11 19:15:32 +0000147 sk_tools::PictureRenderer* renderer = NULL;
148
scroggo@google.com9a412522012-09-07 15:21:18 +0000149 // Create a string to show our current settings.
150 // TODO: Make it prettier. Currently it just repeats the command line.
151 SkString commandLine("bench_pictures:");
152 for (int i = 1; i < argc; i++) {
153 commandLine.appendf(" %s", *(argv+i));
154 }
155 commandLine.append("\n");
156
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000157 bool usePipe = false;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000158 int numThreads = 1;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000159 bool useTiles = false;
160 const char* widthString = NULL;
161 const char* heightString = NULL;
162 bool isPowerOf2Mode = false;
163 const char* mode = NULL;
junov@chromium.org9313ca42012-11-02 18:11:49 +0000164 sk_tools::PictureRenderer::BBoxHierarchyType bbhType =
165 sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
reed@google.com006db0f2012-06-27 19:33:29 +0000166 for (++argv; argv < stop; ++argv) {
167 if (0 == strcmp(*argv, "--repeat")) {
168 ++argv;
169 if (argv < stop) {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000170 repeats = atoi(*argv);
171 if (repeats < 1) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000172 gLogger.logError("--repeat must be given a value > 0\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000173 exit(-1);
174 }
175 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000176 gLogger.logError("Missing arg for --repeat\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000177 usage(argv0);
178 exit(-1);
179 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000180 } else if (0 == strcmp(*argv, "--pipe")) {
181 usePipe = true;
scroggo@google.com9a412522012-09-07 15:21:18 +0000182 } else if (0 == strcmp(*argv, "--logFile")) {
183 argv++;
184 if (argv < stop) {
185 if (!gLogger.SetLogFile(*argv)) {
186 SkString str;
187 str.printf("Could not open %s for writing.", *argv);
188 gLogger.logError(str);
189 usage(argv0);
borenet@google.coma49bffd2012-09-13 18:54:48 +0000190 // TODO(borenet): We're disabling this for now, due to
191 // write-protected Android devices. The very short-term
192 // solution is to ignore the fact that we have no log file.
193 //exit(-1);
scroggo@google.com9a412522012-09-07 15:21:18 +0000194 }
195 } else {
196 gLogger.logError("Missing arg for --logFile\n");
197 usage(argv0);
198 exit(-1);
199 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000200 } else if (0 == strcmp(*argv, "--multi")) {
201 ++argv;
202 if (argv >= stop) {
203 gLogger.logError("Missing arg for --multi\n");
204 usage(argv0);
205 exit(-1);
206 }
207 numThreads = atoi(*argv);
208 if (numThreads < 2) {
209 gLogger.logError("Number of threads must be at least 2.\n");
210 usage(argv0);
211 exit(-1);
212 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000213 } else if (0 == strcmp(*argv, "--bbh")) {
214 ++argv;
215 if (argv >= stop) {
216 gLogger.logError("Missing value for --bbh\n");
217 usage(argv0);
218 exit(-1);
219 }
220 if (0 == strcmp(*argv, "none")) {
221 bbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
222 } else if (0 == strcmp(*argv, "rtree")) {
223 bbhType = sk_tools::PictureRenderer::kRTree_BBoxHierarchyType;
224 } else {
225 SkString err;
226 err.printf("%s is not a valid value for --bbhType\n", *argv);
227 gLogger.logError(err);
228 usage(argv0);
229 exit(-1);
230 }
231
keyar@chromium.org795cd472012-08-02 18:57:53 +0000232 } else if (0 == strcmp(*argv, "--mode")) {
keyar@chromium.org795cd472012-08-02 18:57:53 +0000233
reed@google.com006db0f2012-06-27 19:33:29 +0000234 ++argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000235 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000236 gLogger.logError("Missing mode for --mode\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000237 usage(argv0);
238 exit(-1);
239 }
240
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000241 if (0 == strcmp(*argv, "record")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000242 renderer = SkNEW(sk_tools::RecordPictureRenderer);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000243 } else if (0 == strcmp(*argv, "simple")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000244 renderer = SkNEW(sk_tools::SimplePictureRenderer);
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000245 } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))) {
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000246 useTiles = true;
247 mode = *argv;
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000248
249 if (0 == strcmp(*argv, "pow2tile")) {
250 isPowerOf2Mode = true;
251 }
252
keyar@chromium.org795cd472012-08-02 18:57:53 +0000253 ++argv;
254 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000255 SkString err;
256 err.printf("Missing width for --mode %s\n", mode);
257 gLogger.logError(err);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000258 usage(argv0);
259 exit(-1);
260 }
261
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000262 widthString = *argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000263 ++argv;
264 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000265 gLogger.logError("Missing height for --mode tile\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000266 usage(argv0);
267 exit(-1);
268 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000269 heightString = *argv;
scroggo@google.com9a412522012-09-07 15:21:18 +0000270 } else if (0 == strcmp(*argv, "playbackCreation")) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000271 renderer = SkNEW(sk_tools::PlaybackCreationRenderer);
reed@google.com006db0f2012-06-27 19:33:29 +0000272 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000273 SkString err;
274 err.printf("%s is not a valid mode for --mode\n", *argv);
275 gLogger.logError(err);
keyar@chromium.org0665f252012-07-10 18:30:18 +0000276 usage(argv0);
reed@google.com006db0f2012-06-27 19:33:29 +0000277 exit(-1);
278 }
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000279 } else if (0 == strcmp(*argv, "--device")) {
280 ++argv;
281 if (argv >= stop) {
borenet@google.coma49bffd2012-09-13 18:54:48 +0000282 gLogger.logError("Missing mode for --device\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000283 usage(argv0);
284 exit(-1);
285 }
286
287 if (0 == strcmp(*argv, "bitmap")) {
288 deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType;
289 }
290#if SK_SUPPORT_GPU
291 else if (0 == strcmp(*argv, "gpu")) {
292 deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
293 }
294#endif
295 else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000296 SkString err;
297 err.printf("%s is not a valid mode for --device\n", *argv);
298 gLogger.logError(err);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000299 usage(argv0);
300 exit(-1);
301 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000302 } else if (0 == strcmp(*argv, "--timers")) {
303 ++argv;
304 if (argv < stop) {
305 bool timerWall = false;
306 bool truncatedTimerWall = false;
307 bool timerCpu = false;
308 bool truncatedTimerCpu = false;
309 bool timerGpu = false;
310 for (char* t = *argv; *t; ++t) {
311 switch (*t) {
312 case 'w':
313 timerWall = true;
314 break;
315 case 'c':
316 timerCpu = true;
317 break;
318 case 'W':
319 truncatedTimerWall = true;
320 break;
321 case 'C':
322 truncatedTimerCpu = true;
323 break;
324 case 'g':
325 timerGpu = true;
326 break;
327 default: {
328 break;
329 }
330 }
331 }
332 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu,
333 truncatedTimerCpu, timerGpu);
334 } else {
335 gLogger.logError("Missing arg for --timers\n");
336 usage(argv0);
337 exit(-1);
338 }
339 } else if (0 == strcmp(*argv, "--min")) {
340 benchmark->setPrintMin(true);
341 } else if (0 == strcmp(*argv, "--logPerIter")) {
342 ++argv;
343 if (argv < stop) {
344 bool log = atoi(*argv) != 0;
345 benchmark->setLogPerIter(log);
346 } else {
347 gLogger.logError("Missing arg for --logPerIter\n");
348 usage(argv0);
349 exit(-1);
350 }
reed@google.com006db0f2012-06-27 19:33:29 +0000351 } else if (0 == strcmp(*argv, "--help") || 0 == strcmp(*argv, "-h")) {
352 usage(argv0);
353 exit(0);
354 } else {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000355 inputs->push_back(SkString(*argv));
reed@google.com006db0f2012-06-27 19:33:29 +0000356 }
357 }
358
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000359 if (numThreads > 1 && !useTiles) {
360 gLogger.logError("Multithreaded drawing requires tiled rendering.\n");
361 usage(argv0);
362 exit(-1);
363 }
364
junov@chromium.org9313ca42012-11-02 18:11:49 +0000365 if (usePipe && sk_tools::PictureRenderer::kNone_BBoxHierarchyType != bbhType) {
366 gLogger.logError("--pipe and --bbh cannot be used together\n");
367 usage(argv0);
368 exit(-1);
369 }
370
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000371 if (useTiles) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000372 SkASSERT(NULL == renderer);
373 sk_tools::TiledPictureRenderer* tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000374 if (isPowerOf2Mode) {
375 int minWidth = atoi(widthString);
376 if (!SkIsPow2(minWidth) || minWidth < 0) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000377 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000378 SkString err;
scroggo@google.com5239c322012-09-11 19:15:32 +0000379 err.printf("-mode %s must be given a width"
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000380 " value that is a power of two\n", mode);
scroggo@google.com9a412522012-09-07 15:21:18 +0000381 gLogger.logError(err);
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000382 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000383 exit(-1);
384 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000385 tiledRenderer->setTileMinPowerOf2Width(minWidth);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000386 } else if (sk_tools::is_percentage(widthString)) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000387 tiledRenderer->setTileWidthPercentage(atof(widthString));
388 if (!(tiledRenderer->getTileWidthPercentage() > 0)) {
389 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000390 gLogger.logError("--mode tile must be given a width percentage > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000391 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000392 exit(-1);
393 }
394 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000395 tiledRenderer->setTileWidth(atoi(widthString));
396 if (!(tiledRenderer->getTileWidth() > 0)) {
397 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000398 gLogger.logError("--mode tile must be given a width > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000399 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000400 exit(-1);
401 }
402 }
403
404 if (sk_tools::is_percentage(heightString)) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000405 tiledRenderer->setTileHeightPercentage(atof(heightString));
406 if (!(tiledRenderer->getTileHeightPercentage() > 0)) {
407 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000408 gLogger.logError("--mode tile must be given a height percentage > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000409 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000410 exit(-1);
411 }
412 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000413 tiledRenderer->setTileHeight(atoi(heightString));
414 if (!(tiledRenderer->getTileHeight() > 0)) {
415 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000416 gLogger.logError("--mode tile must be given a height > 0\n");
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000417 usage(argv0);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000418 exit(-1);
419 }
420 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000421 if (numThreads > 1) {
422#if SK_SUPPORT_GPU
423 if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) {
424 tiledRenderer->unref();
425 gLogger.logError("GPU not compatible with multithreaded tiling.\n");
426 usage(argv0);
427 exit(-1);
428 }
429#endif
430 tiledRenderer->setNumberOfThreads(numThreads);
431 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000432 tiledRenderer->setUsePipe(usePipe);
433 renderer = tiledRenderer;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000434 } else if (usePipe) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000435 renderer = SkNEW(sk_tools::PipePictureRenderer);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000436 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000437 if (inputs->count() < 1) {
fmalita@google.comc6157be2012-09-27 13:09:58 +0000438 SkSafeUnref(renderer);
reed@google.com006db0f2012-06-27 19:33:29 +0000439 usage(argv0);
440 exit(-1);
441 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000442
scroggo@google.com5239c322012-09-11 19:15:32 +0000443 if (NULL == renderer) {
444 renderer = SkNEW(sk_tools::SimplePictureRenderer);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000445 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000446
447 renderer->setBBoxHierarchyType(bbhType);
scroggo@google.com5239c322012-09-11 19:15:32 +0000448 benchmark->setRenderer(renderer)->unref();
keyar@chromium.org163b5672012-08-01 17:53:29 +0000449 benchmark->setRepeats(repeats);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000450 benchmark->setDeviceType(deviceType);
scroggo@google.com9a412522012-09-07 15:21:18 +0000451 benchmark->setLogger(&gLogger);
452 // Report current settings:
453 gLogger.logProgress(commandLine);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000454}
reed@google.com006db0f2012-06-27 19:33:29 +0000455
borenet@google.com66bcbd12012-09-17 18:26:06 +0000456static int process_input(const SkString& input,
457 sk_tools::PictureBenchmark& benchmark) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000458 SkOSFile::Iter iter(input.c_str(), "skp");
459 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000460 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000461 if (iter.next(&inputFilename)) {
462 do {
463 SkString inputPath;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000464 sk_tools::make_filepath(&inputPath, input, inputFilename);
borenet@google.com57837bf2012-09-19 17:28:29 +0000465 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000466 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000467 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000468 } while(iter.next(&inputFilename));
borenet@google.com57837bf2012-09-19 17:28:29 +0000469 } else if (SkStrEndsWith(input.c_str(), ".skp")) {
470 if (!run_single_benchmark(input, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000471 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000472 }
473 } else {
474 SkString warning;
475 warning.printf("Warning: skipping %s\n", input.c_str());
476 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000477 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000478 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000479}
480
caryclark@google.com5987f582012-10-02 18:33:14 +0000481int tool_main(int argc, char** argv);
482int tool_main(int argc, char** argv) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000483#ifdef SK_ENABLE_INST_COUNT
484 gPrintInstCount = true;
485#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000486 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000487
scroggo@google.com5239c322012-09-11 19:15:32 +0000488 SkTArray<SkString> inputs;
489 sk_tools::PictureBenchmark benchmark;
490
491 parse_commandline(argc, argv, &inputs, &benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000492
borenet@google.com66bcbd12012-09-17 18:26:06 +0000493 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000494 for (int i = 0; i < inputs.count(); ++i) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000495 failures += process_input(inputs[i], benchmark);
496 }
497
498 if (failures != 0) {
499 SkString err;
500 err.printf("Failed to run %i benchmarks.\n", failures);
501 gLogger.logError(err);
502 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000503 }
caryclark@google.com868e1f62012-10-02 20:00:03 +0000504 return 0;
reed@google.com006db0f2012-06-27 19:33:29 +0000505}
caryclark@google.com5987f582012-10-02 18:33:14 +0000506
507#if !defined SK_BUILD_FOR_IOS
508int main(int argc, char * const argv[]) {
509 return tool_main(argc, (char**) argv);
510}
511#endif