blob: 60d79fcd8c2d7c4538bba1a135630be670a81af5 [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"
scroggo@google.com4a26d9d2012-11-07 18:01:46 +00009#include "CopyTilesRenderer.h"
keyar@chromium.org163b5672012-08-01 17:53:29 +000010#include "PictureBenchmark.h"
scroggo@google.com9a412522012-09-07 15:21:18 +000011#include "SkBenchLogger.h"
scroggo@google.comf8d7d272013-02-22 21:38:35 +000012#include "SkBitmapFactory.h"
reed@google.com006db0f2012-06-27 19:33:29 +000013#include "SkCanvas.h"
scroggo@google.com0a36f432012-09-10 20:29:13 +000014#include "SkGraphics.h"
scroggo@google.com5a7c6be2012-10-04 21:46:08 +000015#include "SkImageDecoder.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000016#include "SkMath.h"
reed@google.com006db0f2012-06-27 19:33:29 +000017#include "SkOSFile.h"
18#include "SkPicture.h"
19#include "SkStream.h"
20#include "SkTArray.h"
21#include "picture_utils.h"
22
borenet@google.com13fd5a12012-09-17 21:10:05 +000023const int DEFAULT_REPEATS = 1;
reed@google.com006db0f2012-06-27 19:33:29 +000024
caryclark@google.coma3622372012-11-06 21:26:13 +000025static char const * const gFilterTypes[] = {
26 "paint",
27 "point",
28 "line",
29 "bitmap",
30 "rect",
jvanverth@google.comd3c208c2013-01-22 13:54:52 +000031 "oval",
caryclark@google.coma3622372012-11-06 21:26:13 +000032 "path",
33 "text",
34 "all",
35};
36
37static const size_t kFilterTypesCount = sizeof(gFilterTypes) / sizeof(gFilterTypes[0]);
38
39static char const * const gFilterFlags[] = {
40 "antiAlias",
41 "filterBitmap",
42 "dither",
43 "underlineText",
44 "strikeThruText",
45 "fakeBoldText",
46 "linearText",
47 "subpixelText",
48 "devKernText",
49 "LCDRenderText",
50 "embeddedBitmapText",
51 "autoHinting",
52 "verticalText",
53 "genA8FromLCD",
54 "blur",
55 "hinting",
56 "slightHinting",
caryclark@google.come3e940c2012-11-07 16:42:17 +000057 "AAClip",
caryclark@google.coma3622372012-11-06 21:26:13 +000058};
59
60static const size_t kFilterFlagsCount = sizeof(gFilterFlags) / sizeof(gFilterFlags[0]);
61
62static SkString filtersName(sk_tools::PictureRenderer::DrawFilterFlags* drawFilters) {
63 int all = drawFilters[0];
64 size_t tIndex;
65 for (tIndex = 1; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
66 all &= drawFilters[tIndex];
67 }
68 SkString result;
69 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
70 SkString types;
71 if (all & (1 << fIndex)) {
72 types = gFilterTypes[SkDrawFilter::kTypeCount];
73 } else {
74 for (tIndex = 0; tIndex < SkDrawFilter::kTypeCount; ++tIndex) {
75 if (drawFilters[tIndex] & (1 << fIndex)) {
76 types += gFilterTypes[tIndex];
77 }
78 }
79 }
80 if (!types.size()) {
81 continue;
82 }
83 result += "_";
84 result += types;
85 result += ".";
86 result += gFilterFlags[fIndex];
87 }
88 return result;
89}
90
91static SkString filterTypesUsage() {
92 SkString result;
93 for (size_t index = 0; index < kFilterTypesCount; ++index) {
94 result += gFilterTypes[index];
95 if (index < kFilterTypesCount - 1) {
96 result += " | ";
97 }
98 }
99 return result;
100}
101
102static SkString filterFlagsUsage() {
103 SkString result;
104 size_t len = 0;
105 for (size_t index = 0; index < kFilterFlagsCount; ++index) {
106 result += gFilterFlags[index];
107 if (result.size() - len >= 72) {
108 result += "\n ";
109 len = result.size();
110 }
111 if (index < kFilterFlagsCount - 1) {
112 result += " | ";
113 }
114 }
115 return result;
116}
117
reed@google.com006db0f2012-06-27 19:33:29 +0000118static void usage(const char* argv0) {
119 SkDebugf("SkPicture benchmarking tool\n");
120 SkDebugf("\n"
121"Usage: \n"
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000122" %s <inputDir>...\n"
scroggo@google.com5239c322012-09-11 19:15:32 +0000123" [--logFile filename][--timers [wcgWC]*][--logPerIter 1|0][--min]\n"
scroggo@google.comcbcef702012-12-13 22:09:28 +0000124" [--repeat][--timeIndividualTiles] \n"
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000125" [--mode pow2tile minWidth height | record | simple\n"
126" | tile width height | playbackCreation]\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000127" [--pipe]\n"
junov@chromium.org9313ca42012-11-02 18:11:49 +0000128" [--bbh bbhType]\n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000129" [--multi numThreads]\n"
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000130" [--enable-deferred-image-decoding]\n"
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000131" [--viewport width height][--scale sf]\n"
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000132" [--device bitmap"
133#if SK_SUPPORT_GPU
134" | gpu"
scroggo@google.com0556ea02013-02-08 19:38:21 +0000135#if SK_ANGLE
136" | angle"
137#endif
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000138#endif
caryclark@google.coma3622372012-11-06 21:26:13 +0000139"]\n"
140" [--filter [%s]:\n [%s]]\n"
141, argv0, filterTypesUsage().c_str(), filterFlagsUsage().c_str());
142 SkDebugf("\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000143 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +0000144" inputDir: A list of directories and files to use as input. Files are\n"
scroggo@google.com9a412522012-09-07 15:21:18 +0000145" expected to have the .skp extension.\n\n"
146" --logFile filename : destination for writing log output, in addition to stdout.\n");
scroggo@google.com5239c322012-09-11 19:15:32 +0000147 SkDebugf(" --logPerIter 1|0 : "
148 "Log each repeat timer instead of mean, default is disabled.\n");
149 SkDebugf(" --min : Print the minimum times (instead of average).\n");
150 SkDebugf(" --timers [wcgWC]* : "
151 "Display wall, cpu, gpu, truncated wall or truncated cpu time for each picture.\n");
scroggo@google.comcbcef702012-12-13 22:09:28 +0000152 SkDebugf(" --timeIndividualTiles : Report times for drawing individual tiles, rather than\n"
153" times for drawing the whole page.\n"
154" Requires --mode tile\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000155 SkDebugf(
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000156" --mode pow2tile minWidth height | copyTile width height | record | simple\n"
157" | tile width height | playbackCreation:\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000158" Run in the corresponding mode.\n"
159" Default is simple.\n");
keyar@chromium.orgcf6c44c2012-07-09 19:37:40 +0000160 SkDebugf(
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000161" pow2tile minWidth height, Creates tiles with widths\n"
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000162" that are all a power of two\n"
163" such that they minimize the\n"
164" amount of wasted tile space.\n"
165" minWidth is the minimum width\n"
166" of these tiles and must be a\n"
167" power of two. Simple\n"
168" rendering using these tiles\n"
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000169" is benchmarked.\n");
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000170 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +0000171" record, Benchmark picture to picture recording.\n");
172 SkDebugf(
173" simple, Benchmark a simple rendering.\n");
174 SkDebugf(
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000175" tile width height, Benchmark simple rendering using\n"
176" tiles with the given dimensions.\n"
177" copyTile width height, Draw the picture, then copy it into tiles.\n"
178" Does not support percentages.\n"
179" If the picture is large enough, breaks it into\n"
180" larger tiles (and draws the picture once per\n"
181" larger tile) to avoid creating a large canvas.\n"
182" Add --tiles x y to specify the number of tiles\n"
183" per larger tile in the x and y direction.\n"
184 );
keyar@chromium.org795cd472012-08-02 18:57:53 +0000185 SkDebugf(
scroggo@google.com9a412522012-09-07 15:21:18 +0000186" playbackCreation, Benchmark creation of the SkPicturePlayback.\n");
keyar@chromium.org795cd472012-08-02 18:57:53 +0000187 SkDebugf("\n");
188 SkDebugf(
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000189" --multi numThreads : Set the number of threads for multi threaded drawing. Must be greater\n"
190" than 1. Only works with tiled rendering.\n"
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000191" --enable-deferred-image-decoding : Defer decoding until drawing images. Has no effect if\n"
192" the provided skp does not have its images encoded.\n"
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000193" --viewport width height : Set the viewport.\n"
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000194" --scale sf : Scale drawing by sf.\n"
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000195" --pipe: Benchmark SkGPipe rendering. Currently incompatible with \"mode\".\n");
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000196 SkDebugf(
junov@chromium.org7b537062012-11-06 18:58:43 +0000197" --bbh bbhType [width height]: Set the bounding box hierarchy type to\n"
198" be used. Accepted values are: none, rtree, grid. Default\n"
199" value is none. Not compatible with --pipe. With value\n"
200" 'grid', width and height must be specified. 'grid' can\n"
201" only be used with modes tile, record, and\n"
202" playbackCreation.");
junov@chromium.org9313ca42012-11-02 18:11:49 +0000203 SkDebugf(
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000204" --device bitmap"
205#if SK_SUPPORT_GPU
206" | gpu"
207#endif
208": Use the corresponding device. Default is bitmap.\n");
209 SkDebugf(
210" bitmap, Render to a bitmap.\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000211#if SK_SUPPORT_GPU
keyar@chromium.orga40c20d2012-08-20 15:04:12 +0000212 SkDebugf(
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000213" gpu, Render to the GPU.\n");
scroggo@google.com0556ea02013-02-08 19:38:21 +0000214#if SK_ANGLE
215 SkDebugf(
216" angle, Render using Angle.\n");
217#endif
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000218#endif
219 SkDebugf("\n");
220 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +0000221" --repeat: "
reed@google.com006db0f2012-06-27 19:33:29 +0000222"Set the number of times to repeat each test."
223" Default is %i.\n", DEFAULT_REPEATS);
caryclark@google.coma3622372012-11-06 21:26:13 +0000224 SkDebugf(
caryclark@google.come3e940c2012-11-07 16:42:17 +0000225" --filter type:flag : Enable canvas filtering to disable a paint flag,\n"
226" use no blur or low quality blur, or use no hinting or\n"
227" slight hinting. For all flags except AAClip, specify the\n"
228" type of primitive to effect, or choose all. for AAClip\n"
229" alone, the filter affects all clips independent of type.\n");
reed@google.com006db0f2012-06-27 19:33:29 +0000230}
231
scroggo@google.com9a412522012-09-07 15:21:18 +0000232SkBenchLogger gLogger;
233
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000234bool lazy_decode = false;
235
236#include "SkData.h"
237#include "SkLruImageCache.h"
238
239static SkLruImageCache gLruImageCache(1024*1024);
240
241static bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap) {
242 void* copiedBuffer = sk_malloc_throw(size);
243 memcpy(copiedBuffer, buffer, size);
244 SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size));
245 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget);
246 factory.setImageCache(&gLruImageCache);
247 return factory.installPixelRef(data, bitmap);
248}
249
borenet@google.com66bcbd12012-09-17 18:26:06 +0000250static bool run_single_benchmark(const SkString& inputPath,
keyar@chromium.org163b5672012-08-01 17:53:29 +0000251 sk_tools::PictureBenchmark& benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000252 SkFILEStream inputStream;
253
reed@google.com006db0f2012-06-27 19:33:29 +0000254 inputStream.setPath(inputPath.c_str());
255 if (!inputStream.isValid()) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000256 SkString err;
257 err.printf("Could not open file %s\n", inputPath.c_str());
258 gLogger.logError(err);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000259 return false;
reed@google.com006db0f2012-06-27 19:33:29 +0000260 }
261
borenet@google.com66bcbd12012-09-17 18:26:06 +0000262 bool success = false;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000263 SkPicture* picture;
264 if (lazy_decode) {
265 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bitmap));
266 } else {
267 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder::DecodeMemory));
268 }
269 SkAutoTDelete<SkPicture> ad(picture);
270
borenet@google.com66bcbd12012-09-17 18:26:06 +0000271 if (!success) {
272 SkString err;
273 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
274 gLogger.logError(err);
275 return false;
276 }
reed@google.com006db0f2012-06-27 19:33:29 +0000277
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000278 SkString filename;
279 sk_tools::get_basename(&filename, inputPath);
keyar@chromium.orgdb9a5fb2012-08-21 17:57:59 +0000280
281 SkString result;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000282 result.printf("running bench [%i %i] %s ", picture->width(), picture->height(),
283 filename.c_str());
scroggo@google.com9a412522012-09-07 15:21:18 +0000284 gLogger.logProgress(result);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000285
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000286 benchmark.run(picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000287 return true;
keyar@chromium.org0665f252012-07-10 18:30:18 +0000288}
289
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000290#define PRINT_USAGE_AND_EXIT \
291 do { \
292 usage(argv0); \
293 exit(-1); \
294 } while (0)
295
keyar@chromium.org163b5672012-08-01 17:53:29 +0000296static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs,
scroggo@google.com5239c322012-09-11 19:15:32 +0000297 sk_tools::PictureBenchmark* benchmark) {
reed@google.com006db0f2012-06-27 19:33:29 +0000298 const char* argv0 = argv[0];
299 char* const* stop = argv + argc;
300
keyar@chromium.org163b5672012-08-01 17:53:29 +0000301 int repeats = DEFAULT_REPEATS;
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000302 sk_tools::PictureRenderer::SkDeviceTypes deviceType =
303 sk_tools::PictureRenderer::kBitmap_DeviceType;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000304
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000305 SkAutoTUnref<sk_tools::PictureRenderer> renderer(NULL);
scroggo@google.com5239c322012-09-11 19:15:32 +0000306
scroggo@google.com9a412522012-09-07 15:21:18 +0000307 // Create a string to show our current settings.
308 // TODO: Make it prettier. Currently it just repeats the command line.
309 SkString commandLine("bench_pictures:");
310 for (int i = 1; i < argc; i++) {
311 commandLine.appendf(" %s", *(argv+i));
312 }
313 commandLine.append("\n");
314
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000315 bool usePipe = false;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000316 int numThreads = 1;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000317 bool useTiles = false;
318 const char* widthString = NULL;
319 const char* heightString = NULL;
junov@chromium.org7b537062012-11-06 18:58:43 +0000320 int gridWidth = 0;
321 int gridHeight = 0;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000322 bool isPowerOf2Mode = false;
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000323 bool isCopyMode = false;
324 const char* xTilesString = NULL;
325 const char* yTilesString = NULL;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000326 const char* mode = NULL;
junov@chromium.org7b537062012-11-06 18:58:43 +0000327 bool gridSupported = false;
skia.committer@gmail.com1aa90cf2012-11-06 13:18:25 +0000328 sk_tools::PictureRenderer::BBoxHierarchyType bbhType =
junov@chromium.org9313ca42012-11-02 18:11:49 +0000329 sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
caryclark@google.coma3622372012-11-06 21:26:13 +0000330 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount];
331 sk_bzero(drawFilters, sizeof(drawFilters));
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000332 SkISize viewport;
333 viewport.setEmpty();
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000334 SkScalar scaleFactor = SK_Scalar1;
reed@google.com006db0f2012-06-27 19:33:29 +0000335 for (++argv; argv < stop; ++argv) {
336 if (0 == strcmp(*argv, "--repeat")) {
337 ++argv;
338 if (argv < stop) {
keyar@chromium.org163b5672012-08-01 17:53:29 +0000339 repeats = atoi(*argv);
340 if (repeats < 1) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000341 gLogger.logError("--repeat must be given a value > 0\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000342 PRINT_USAGE_AND_EXIT;
reed@google.com006db0f2012-06-27 19:33:29 +0000343 }
344 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000345 gLogger.logError("Missing arg for --repeat\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000346 PRINT_USAGE_AND_EXIT;
reed@google.com006db0f2012-06-27 19:33:29 +0000347 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000348 } else if (0 == strcmp(*argv, "--pipe")) {
349 usePipe = true;
scroggo@google.com9a412522012-09-07 15:21:18 +0000350 } else if (0 == strcmp(*argv, "--logFile")) {
351 argv++;
352 if (argv < stop) {
353 if (!gLogger.SetLogFile(*argv)) {
354 SkString str;
355 str.printf("Could not open %s for writing.", *argv);
356 gLogger.logError(str);
357 usage(argv0);
borenet@google.coma49bffd2012-09-13 18:54:48 +0000358 // TODO(borenet): We're disabling this for now, due to
359 // write-protected Android devices. The very short-term
360 // solution is to ignore the fact that we have no log file.
361 //exit(-1);
scroggo@google.com9a412522012-09-07 15:21:18 +0000362 }
363 } else {
364 gLogger.logError("Missing arg for --logFile\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000365 PRINT_USAGE_AND_EXIT;
scroggo@google.com9a412522012-09-07 15:21:18 +0000366 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000367 } else if (0 == strcmp(*argv, "--multi")) {
368 ++argv;
369 if (argv >= stop) {
370 gLogger.logError("Missing arg for --multi\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000371 PRINT_USAGE_AND_EXIT;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000372 }
373 numThreads = atoi(*argv);
374 if (numThreads < 2) {
375 gLogger.logError("Number of threads must be at least 2.\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000376 PRINT_USAGE_AND_EXIT;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000377 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000378 } else if (0 == strcmp(*argv, "--bbh")) {
379 ++argv;
380 if (argv >= stop) {
381 gLogger.logError("Missing value for --bbh\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000382 PRINT_USAGE_AND_EXIT;
junov@chromium.org9313ca42012-11-02 18:11:49 +0000383 }
384 if (0 == strcmp(*argv, "none")) {
385 bbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
386 } else if (0 == strcmp(*argv, "rtree")) {
387 bbhType = sk_tools::PictureRenderer::kRTree_BBoxHierarchyType;
junov@chromium.org7b537062012-11-06 18:58:43 +0000388 } else if (0 == strcmp(*argv, "grid")) {
389 bbhType = sk_tools::PictureRenderer::kTileGrid_BBoxHierarchyType;
390 ++argv;
391 if (argv >= stop) {
392 gLogger.logError("Missing width for --bbh grid\n");
393 PRINT_USAGE_AND_EXIT;
394 }
395 gridWidth = atoi(*argv);
396 ++argv;
397 if (argv >= stop) {
398 gLogger.logError("Missing height for --bbh grid\n");
399 PRINT_USAGE_AND_EXIT;
400 }
401 gridHeight = atoi(*argv);
junov@chromium.org9313ca42012-11-02 18:11:49 +0000402 } else {
403 SkString err;
404 err.printf("%s is not a valid value for --bbhType\n", *argv);
405 gLogger.logError(err);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000406 PRINT_USAGE_AND_EXIT;
junov@chromium.org9313ca42012-11-02 18:11:49 +0000407 }
408
keyar@chromium.org795cd472012-08-02 18:57:53 +0000409 } else if (0 == strcmp(*argv, "--mode")) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000410 if (renderer.get() != NULL) {
411 SkDebugf("Cannot combine modes.\n");
412 PRINT_USAGE_AND_EXIT;
413 }
keyar@chromium.org795cd472012-08-02 18:57:53 +0000414
reed@google.com006db0f2012-06-27 19:33:29 +0000415 ++argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000416 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000417 gLogger.logError("Missing mode for --mode\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000418 PRINT_USAGE_AND_EXIT;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000419 }
420
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000421 if (0 == strcmp(*argv, "record")) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000422 renderer.reset(SkNEW(sk_tools::RecordPictureRenderer));
junov@chromium.org7b537062012-11-06 18:58:43 +0000423 gridSupported = true;
reed@google.com5a34fd32012-12-10 16:05:09 +0000424 } else if (0 == strcmp(*argv, "clone")) {
425 renderer.reset(sk_tools::CreatePictureCloneRenderer());
keyar@chromium.org795cd472012-08-02 18:57:53 +0000426 } else if (0 == strcmp(*argv, "simple")) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000427 renderer.reset(SkNEW(sk_tools::SimplePictureRenderer));
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000428 } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))
429 || 0 == strcmp(*argv, "copyTile")) {
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000430 useTiles = true;
431 mode = *argv;
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000432
433 if (0 == strcmp(*argv, "pow2tile")) {
434 isPowerOf2Mode = true;
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000435 } else if (0 == strcmp(*argv, "copyTile")) {
436 isCopyMode = true;
junov@chromium.org7b537062012-11-06 18:58:43 +0000437 } else {
438 gridSupported = true;
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000439 }
440
keyar@chromium.org795cd472012-08-02 18:57:53 +0000441 ++argv;
442 if (argv >= stop) {
scroggo@google.com9a412522012-09-07 15:21:18 +0000443 SkString err;
444 err.printf("Missing width for --mode %s\n", mode);
445 gLogger.logError(err);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000446 PRINT_USAGE_AND_EXIT;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000447 }
448
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000449 widthString = *argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000450 ++argv;
451 if (argv >= stop) {
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000452 SkString err;
453 err.appendf("Missing height for --mode %s\n", mode);
454 gLogger.logError(err);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000455 PRINT_USAGE_AND_EXIT;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000456 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000457 heightString = *argv;
scroggo@google.com9a412522012-09-07 15:21:18 +0000458 } else if (0 == strcmp(*argv, "playbackCreation")) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000459 renderer.reset(SkNEW(sk_tools::PlaybackCreationRenderer));
junov@chromium.org7b537062012-11-06 18:58:43 +0000460 gridSupported = true;
reed@google.comfe7b1ed2012-11-29 21:00:39 +0000461 } else if (0 == strcmp(*argv, "gatherPixelRefs")) {
462 renderer.reset(sk_tools::CreateGatherPixelRefsRenderer());
reed@google.com006db0f2012-06-27 19:33:29 +0000463 } else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000464 SkString err;
465 err.printf("%s is not a valid mode for --mode\n", *argv);
466 gLogger.logError(err);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000467 PRINT_USAGE_AND_EXIT;
reed@google.com006db0f2012-06-27 19:33:29 +0000468 }
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000469 } else if (0 == strcmp(*argv, "--viewport")) {
470 ++argv;
471 if (argv >= stop) {
472 gLogger.logError("Missing width for --viewport\n");
473 PRINT_USAGE_AND_EXIT;
474 }
475 viewport.fWidth = atoi(*argv);
476 ++argv;
477 if (argv >= stop) {
478 gLogger.logError("Missing height for --viewport\n");
479 PRINT_USAGE_AND_EXIT;
480 }
481 viewport.fHeight = atoi(*argv);
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000482 } else if (0 == strcmp(*argv, "--scale")) {
483 ++argv;
484 if (argv >= stop) {
485 gLogger.logError("Missing scaleFactor for --scale\n");
486 PRINT_USAGE_AND_EXIT;
487 }
reed@google.com89d15a22013-01-07 22:26:05 +0000488 scaleFactor = SkDoubleToScalar(atof(*argv));
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000489 } else if (0 == strcmp(*argv, "--tiles")) {
490 ++argv;
491 if (argv >= stop) {
492 gLogger.logError("Missing x for --tiles\n");
493 PRINT_USAGE_AND_EXIT;
494 }
495 xTilesString = *argv;
496 ++argv;
497 if (argv >= stop) {
498 gLogger.logError("Missing y for --tiles\n");
499 PRINT_USAGE_AND_EXIT;
500 }
501 yTilesString = *argv;
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000502 } else if (0 == strcmp(*argv, "--device")) {
503 ++argv;
504 if (argv >= stop) {
borenet@google.coma49bffd2012-09-13 18:54:48 +0000505 gLogger.logError("Missing mode for --device\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000506 PRINT_USAGE_AND_EXIT;
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000507 }
508
509 if (0 == strcmp(*argv, "bitmap")) {
510 deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType;
511 }
512#if SK_SUPPORT_GPU
513 else if (0 == strcmp(*argv, "gpu")) {
514 deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
515 }
516#endif
scroggo@google.com0556ea02013-02-08 19:38:21 +0000517#if SK_ANGLE
518 else if (0 == strcmp(*argv, "angle")) {
519 deviceType = sk_tools::PictureRenderer::kAngle_DeviceType;
520 }
521#endif
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000522 else {
scroggo@google.com9a412522012-09-07 15:21:18 +0000523 SkString err;
524 err.printf("%s is not a valid mode for --device\n", *argv);
525 gLogger.logError(err);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000526 PRINT_USAGE_AND_EXIT;
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000527 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000528 } else if (0 == strcmp(*argv, "--timers")) {
529 ++argv;
530 if (argv < stop) {
531 bool timerWall = false;
532 bool truncatedTimerWall = false;
533 bool timerCpu = false;
534 bool truncatedTimerCpu = false;
535 bool timerGpu = false;
536 for (char* t = *argv; *t; ++t) {
537 switch (*t) {
538 case 'w':
539 timerWall = true;
540 break;
541 case 'c':
542 timerCpu = true;
543 break;
544 case 'W':
545 truncatedTimerWall = true;
546 break;
547 case 'C':
548 truncatedTimerCpu = true;
549 break;
550 case 'g':
551 timerGpu = true;
552 break;
553 default: {
554 break;
555 }
556 }
557 }
558 benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu,
559 truncatedTimerCpu, timerGpu);
560 } else {
561 gLogger.logError("Missing arg for --timers\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000562 PRINT_USAGE_AND_EXIT;
scroggo@google.com5239c322012-09-11 19:15:32 +0000563 }
scroggo@google.comcbcef702012-12-13 22:09:28 +0000564 } else if (0 == strcmp(*argv, "--timeIndividualTiles")) {
565 benchmark->setTimeIndividualTiles(true);
scroggo@google.com5239c322012-09-11 19:15:32 +0000566 } else if (0 == strcmp(*argv, "--min")) {
567 benchmark->setPrintMin(true);
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000568 } else if (0 == strcmp(*argv, "--enable-deferred-image-decoding")) {
569 lazy_decode = true;
scroggo@google.com5239c322012-09-11 19:15:32 +0000570 } else if (0 == strcmp(*argv, "--logPerIter")) {
571 ++argv;
572 if (argv < stop) {
573 bool log = atoi(*argv) != 0;
574 benchmark->setLogPerIter(log);
575 } else {
576 gLogger.logError("Missing arg for --logPerIter\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000577 PRINT_USAGE_AND_EXIT;
scroggo@google.com5239c322012-09-11 19:15:32 +0000578 }
caryclark@google.coma3622372012-11-06 21:26:13 +0000579 } else if (0 == strcmp(*argv, "--filter")) {
580 ++argv;
581 if (argv < stop) {
582 const char* colon = strchr(*argv, ':');
583 if (colon) {
584 int type = -1;
585 size_t typeLen = colon - *argv;
586 for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) {
587 if (typeLen == strlen(gFilterTypes[tIndex])
588 && !strncmp(*argv, gFilterTypes[tIndex], typeLen)) {
589 type = tIndex;
590 break;
591 }
592 }
593 if (type < 0) {
594 SkString err;
595 err.printf("Unknown type for --filter %s\n", *argv);
596 gLogger.logError(err);
597 PRINT_USAGE_AND_EXIT;
598 }
599 int flag = -1;
600 size_t flagLen = strlen(*argv) - typeLen - 1;
601 for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) {
602 if (flagLen == strlen(gFilterFlags[fIndex])
603 && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) {
604 flag = 1 << fIndex;
605 break;
606 }
607 }
608 if (flag < 0) {
609 SkString err;
610 err.printf("Unknown flag for --filter %s\n", *argv);
611 gLogger.logError(err);
612 PRINT_USAGE_AND_EXIT;
613 }
614 for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) {
615 if (type != SkDrawFilter::kTypeCount && index != type) {
616 continue;
617 }
618 drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags)
619 (drawFilters[index] | flag);
620 }
621 } else {
622 SkString err;
623 err.printf("Unknown arg for --filter %s : missing colon\n", *argv);
624 gLogger.logError(err);
625 PRINT_USAGE_AND_EXIT;
626 }
627 } else {
628 gLogger.logError("Missing arg for --filter\n");
629 PRINT_USAGE_AND_EXIT;
630 }
reed@google.com006db0f2012-06-27 19:33:29 +0000631 } else if (0 == strcmp(*argv, "--help") || 0 == strcmp(*argv, "-h")) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000632 PRINT_USAGE_AND_EXIT;
reed@google.com006db0f2012-06-27 19:33:29 +0000633 } else {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000634 inputs->push_back(SkString(*argv));
reed@google.com006db0f2012-06-27 19:33:29 +0000635 }
636 }
637
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000638 if (numThreads > 1 && !useTiles) {
639 gLogger.logError("Multithreaded drawing requires tiled rendering.\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000640 PRINT_USAGE_AND_EXIT;
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000641 }
642
junov@chromium.org9313ca42012-11-02 18:11:49 +0000643 if (usePipe && sk_tools::PictureRenderer::kNone_BBoxHierarchyType != bbhType) {
644 gLogger.logError("--pipe and --bbh cannot be used together\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000645 PRINT_USAGE_AND_EXIT;
junov@chromium.org9313ca42012-11-02 18:11:49 +0000646 }
647
junov@chromium.org7b537062012-11-06 18:58:43 +0000648 if (sk_tools::PictureRenderer::kTileGrid_BBoxHierarchyType == bbhType &&
649 !gridSupported) {
650 gLogger.logError("'--bbh grid' is not compatible with specified --mode.\n");
651 PRINT_USAGE_AND_EXIT;
652 }
653
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000654 if (useTiles) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000655 SkASSERT(NULL == renderer);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000656 sk_tools::TiledPictureRenderer* tiledRenderer;
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000657 if (isCopyMode) {
658 int x, y;
659 if (xTilesString != NULL) {
660 SkASSERT(yTilesString != NULL);
661 x = atoi(xTilesString);
662 y = atoi(yTilesString);
663 if (x <= 0 || y <= 0) {
664 gLogger.logError("--tiles must be given values > 0\n");
665 PRINT_USAGE_AND_EXIT;
666 }
667 } else {
668 x = y = 4;
669 }
670 tiledRenderer = SkNEW_ARGS(sk_tools::CopyTilesRenderer, (x, y));
scroggo@google.comcbcef702012-12-13 22:09:28 +0000671 if (benchmark->timeIndividualTiles()) {
672 gLogger.logError("timeIndividualTiles is not compatible with copyTile\n");
673 PRINT_USAGE_AND_EXIT;
674 }
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000675 } else if (numThreads > 1) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000676 tiledRenderer = SkNEW_ARGS(sk_tools::MultiCorePictureRenderer, (numThreads));
677 } else {
678 tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer);
679 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000680 if (isPowerOf2Mode) {
681 int minWidth = atoi(widthString);
682 if (!SkIsPow2(minWidth) || minWidth < 0) {
scroggo@google.com5239c322012-09-11 19:15:32 +0000683 tiledRenderer->unref();
scroggo@google.com9a412522012-09-07 15:21:18 +0000684 SkString err;
scroggo@google.com5239c322012-09-11 19:15:32 +0000685 err.printf("-mode %s must be given a width"
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000686 " value that is a power of two\n", mode);
scroggo@google.com9a412522012-09-07 15:21:18 +0000687 gLogger.logError(err);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000688 PRINT_USAGE_AND_EXIT;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000689 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000690 tiledRenderer->setTileMinPowerOf2Width(minWidth);
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000691 } else if (sk_tools::is_percentage(widthString)) {
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000692 if (isCopyMode) {
693 tiledRenderer->unref();
694 SkString err;
695 err.printf("--mode %s does not support percentages.\n", mode);
696 gLogger.logError(err.c_str());
697 PRINT_USAGE_AND_EXIT;
698 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000699 tiledRenderer->setTileWidthPercentage(atof(widthString));
700 if (!(tiledRenderer->getTileWidthPercentage() > 0)) {
701 tiledRenderer->unref();
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000702 SkString err;
703 err.appendf("--mode %s must be given a width percentage > 0\n", mode);
704 gLogger.logError(err);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000705 PRINT_USAGE_AND_EXIT;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000706 }
707 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000708 tiledRenderer->setTileWidth(atoi(widthString));
709 if (!(tiledRenderer->getTileWidth() > 0)) {
710 tiledRenderer->unref();
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000711 SkString err;
712 err.appendf("--mode %s must be given a width > 0\n", mode);
713 gLogger.logError(err);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000714 PRINT_USAGE_AND_EXIT;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000715 }
716 }
717
718 if (sk_tools::is_percentage(heightString)) {
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000719 if (isCopyMode) {
720 tiledRenderer->unref();
721 SkString err;
722 err.printf("--mode %s does not support percentages.\n", mode);
723 gLogger.logError(err.c_str());
724 PRINT_USAGE_AND_EXIT;
725 }
scroggo@google.com5239c322012-09-11 19:15:32 +0000726 tiledRenderer->setTileHeightPercentage(atof(heightString));
727 if (!(tiledRenderer->getTileHeightPercentage() > 0)) {
728 tiledRenderer->unref();
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000729 SkString err;
730 err.appendf("--mode %s must be given a height percentage > 0\n", mode);
731 gLogger.logError(err);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000732 PRINT_USAGE_AND_EXIT;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000733 }
734 } else {
scroggo@google.com5239c322012-09-11 19:15:32 +0000735 tiledRenderer->setTileHeight(atoi(heightString));
736 if (!(tiledRenderer->getTileHeight() > 0)) {
737 tiledRenderer->unref();
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000738 SkString err;
739 err.appendf("--mode %s must be given a height > 0\n", mode);
740 gLogger.logError(err);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000741 PRINT_USAGE_AND_EXIT;
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000742 }
743 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000744 if (numThreads > 1) {
scroggo@google.com0556ea02013-02-08 19:38:21 +0000745 switch (deviceType) {
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000746#if SK_SUPPORT_GPU
scroggo@google.com0556ea02013-02-08 19:38:21 +0000747 case sk_tools::PictureRenderer::kGPU_DeviceType:
748 // fall through
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000749#endif
scroggo@google.com0556ea02013-02-08 19:38:21 +0000750#if SK_ANGLE
751 case sk_tools::PictureRenderer::kAngle_DeviceType:
752#endif
753 tiledRenderer->unref();
754 gLogger.logError("GPU not compatible with multithreaded tiling.\n");
755 PRINT_USAGE_AND_EXIT;
756 break;
757 default:
758 break;
759 }
scroggo@google.combcdf2ec2012-09-20 14:42:33 +0000760 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000761 renderer.reset(tiledRenderer);
762 if (usePipe) {
scroggo@google.comcbcef702012-12-13 22:09:28 +0000763 gLogger.logError("Pipe rendering is currently not compatible with tiling.\n"
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000764 "Turning off pipe.\n");
765 }
scroggo@google.comcbcef702012-12-13 22:09:28 +0000766 } else {
767 if (benchmark->timeIndividualTiles()) {
768 gLogger.logError("timeIndividualTiles requires tiled rendering.\n");
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000769 PRINT_USAGE_AND_EXIT;
770 }
scroggo@google.comcbcef702012-12-13 22:09:28 +0000771 if (usePipe) {
772 if (renderer.get() != NULL) {
773 gLogger.logError("Pipe is incompatible with other modes.\n");
774 PRINT_USAGE_AND_EXIT;
775 }
776 renderer.reset(SkNEW(sk_tools::PipePictureRenderer));
777 }
scroggo@google.com58b4ead2012-08-31 16:15:22 +0000778 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000779 if (inputs->count() < 1) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000780 PRINT_USAGE_AND_EXIT;
reed@google.com006db0f2012-06-27 19:33:29 +0000781 }
keyar@chromium.org163b5672012-08-01 17:53:29 +0000782
scroggo@google.com5239c322012-09-11 19:15:32 +0000783 if (NULL == renderer) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000784 renderer.reset(SkNEW(sk_tools::SimplePictureRenderer));
keyar@chromium.org163b5672012-08-01 17:53:29 +0000785 }
junov@chromium.org9313ca42012-11-02 18:11:49 +0000786
787 renderer->setBBoxHierarchyType(bbhType);
caryclark@google.coma3622372012-11-06 21:26:13 +0000788 renderer->setDrawFilters(drawFilters, filtersName(drawFilters));
junov@chromium.org7b537062012-11-06 18:58:43 +0000789 renderer->setGridSize(gridWidth, gridHeight);
scroggo@google.comc0d5e542012-12-13 21:40:48 +0000790 renderer->setViewport(viewport);
scroggo@google.com82ec0b02012-12-17 19:25:54 +0000791 renderer->setScaleFactor(scaleFactor);
scroggo@google.com0556ea02013-02-08 19:38:21 +0000792 if (!renderer->setDeviceType(deviceType)) {
793 gLogger.logError("Invalid deviceType.\n");
794 PRINT_USAGE_AND_EXIT;
795 }
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000796 benchmark->setRenderer(renderer);
keyar@chromium.org163b5672012-08-01 17:53:29 +0000797 benchmark->setRepeats(repeats);
scroggo@google.com9a412522012-09-07 15:21:18 +0000798 benchmark->setLogger(&gLogger);
799 // Report current settings:
800 gLogger.logProgress(commandLine);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000801}
reed@google.com006db0f2012-06-27 19:33:29 +0000802
borenet@google.com66bcbd12012-09-17 18:26:06 +0000803static int process_input(const SkString& input,
804 sk_tools::PictureBenchmark& benchmark) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000805 SkOSFile::Iter iter(input.c_str(), "skp");
806 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000807 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000808 if (iter.next(&inputFilename)) {
809 do {
810 SkString inputPath;
keyar@chromium.org163b5672012-08-01 17:53:29 +0000811 sk_tools::make_filepath(&inputPath, input, inputFilename);
borenet@google.com57837bf2012-09-19 17:28:29 +0000812 if (!run_single_benchmark(inputPath, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000813 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000814 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000815 } while(iter.next(&inputFilename));
borenet@google.com57837bf2012-09-19 17:28:29 +0000816 } else if (SkStrEndsWith(input.c_str(), ".skp")) {
817 if (!run_single_benchmark(input, benchmark)) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000818 ++failures;
borenet@google.com57837bf2012-09-19 17:28:29 +0000819 }
820 } else {
821 SkString warning;
822 warning.printf("Warning: skipping %s\n", input.c_str());
823 gLogger.logError(warning);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000824 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000825 return failures;
reed@google.com006db0f2012-06-27 19:33:29 +0000826}
827
caryclark@google.com5987f582012-10-02 18:33:14 +0000828int tool_main(int argc, char** argv);
829int tool_main(int argc, char** argv) {
bsalomon@google.com4e230682013-01-15 20:37:04 +0000830#if SK_ENABLE_INST_COUNT
scroggo@google.com5239c322012-09-11 19:15:32 +0000831 gPrintInstCount = true;
832#endif
scroggo@google.com0a36f432012-09-10 20:29:13 +0000833 SkAutoGraphics ag;
reed@google.com006db0f2012-06-27 19:33:29 +0000834
scroggo@google.com5239c322012-09-11 19:15:32 +0000835 SkTArray<SkString> inputs;
836 sk_tools::PictureBenchmark benchmark;
837
838 parse_commandline(argc, argv, &inputs, &benchmark);
reed@google.com006db0f2012-06-27 19:33:29 +0000839
borenet@google.com66bcbd12012-09-17 18:26:06 +0000840 int failures = 0;
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000841 for (int i = 0; i < inputs.count(); ++i) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000842 failures += process_input(inputs[i], benchmark);
843 }
844
845 if (failures != 0) {
846 SkString err;
847 err.printf("Failed to run %i benchmarks.\n", failures);
848 gLogger.logError(err);
849 return 1;
reed@google.com006db0f2012-06-27 19:33:29 +0000850 }
caryclark@google.com868e1f62012-10-02 20:00:03 +0000851 return 0;
reed@google.com006db0f2012-06-27 19:33:29 +0000852}
caryclark@google.com5987f582012-10-02 18:33:14 +0000853
854#if !defined SK_BUILD_FOR_IOS
855int main(int argc, char * const argv[]) {
856 return tool_main(argc, (char**) argv);
857}
858#endif