| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 9 | #include "PictureBenchmark.h" |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 10 | #include "SkBenchLogger.h" |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
| scroggo@google.com | 0a36f43 | 2012-09-10 20:29:13 +0000 | [diff] [blame] | 12 | #include "SkGraphics.h" |
| scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 13 | #include "SkImageDecoder.h" |
| keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 14 | #include "SkMath.h" |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 15 | #include "SkOSFile.h" |
| 16 | #include "SkPicture.h" |
| 17 | #include "SkStream.h" |
| 18 | #include "SkTArray.h" |
| 19 | #include "picture_utils.h" |
| 20 | |
| borenet@google.com | 13fd5a1 | 2012-09-17 21:10:05 +0000 | [diff] [blame] | 21 | const int DEFAULT_REPEATS = 1; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 22 | |
| 23 | static void usage(const char* argv0) { |
| 24 | SkDebugf("SkPicture benchmarking tool\n"); |
| 25 | SkDebugf("\n" |
| 26 | "Usage: \n" |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 27 | " %s <inputDir>...\n" |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 28 | " [--logFile filename][--timers [wcgWC]*][--logPerIter 1|0][--min]\n" |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 29 | " [--repeat] \n" |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 30 | " [--mode pow2tile minWidth height[] | record | simple\n" |
| 31 | " | tile width[] height[] | playbackCreation]\n" |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 32 | " [--pipe]\n" |
| junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 33 | " [--bbh bbhType]\n" |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 34 | " [--multi numThreads]\n" |
| keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 35 | " [--device bitmap" |
| 36 | #if SK_SUPPORT_GPU |
| 37 | " | gpu" |
| 38 | #endif |
| 39 | "]" |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 40 | , argv0); |
| 41 | SkDebugf("\n\n"); |
| 42 | SkDebugf( |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 43 | " inputDir: A list of directories and files to use as input. Files are\n" |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 44 | " expected to have the .skp extension.\n\n" |
| 45 | " --logFile filename : destination for writing log output, in addition to stdout.\n"); |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 46 | 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.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 51 | SkDebugf( |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 52 | " --mode pow2tile minWidht height[] | record | simple\n" |
| 53 | " | tile width[] height[] | playbackCreation:\n" |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 54 | " Run in the corresponding mode.\n" |
| 55 | " Default is simple.\n"); |
| keyar@chromium.org | cf6c44c | 2012-07-09 19:37:40 +0000 | [diff] [blame] | 56 | SkDebugf( |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 57 | " 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.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 65 | " is benchmarked.\n"); |
| keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 66 | SkDebugf( |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 67 | " record, Benchmark picture to picture recording.\n"); |
| 68 | SkDebugf( |
| 69 | " simple, Benchmark a simple rendering.\n"); |
| 70 | SkDebugf( |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 71 | " tile width[] height[], Benchmark simple rendering using\n" |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 72 | " tiles with the given dimensions.\n"); |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 73 | SkDebugf( |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 74 | " playbackCreation, Benchmark creation of the SkPicturePlayback.\n"); |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 75 | SkDebugf("\n"); |
| 76 | SkDebugf( |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 77 | " --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.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 79 | " --pipe: Benchmark SkGPipe rendering. Currently incompatible with \"mode\".\n"); |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 80 | SkDebugf( |
| junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame^] | 81 | " --bbh bbhType [width height]: Set the bounding box hierarchy type to\n" |
| 82 | " be used. Accepted values are: none, rtree, grid. Default\n" |
| 83 | " value is none. Not compatible with --pipe. With value\n" |
| 84 | " 'grid', width and height must be specified. 'grid' can\n" |
| 85 | " only be used with modes tile, record, and\n" |
| 86 | " playbackCreation."); |
| junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 87 | SkDebugf( |
| keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 88 | " --device bitmap" |
| 89 | #if SK_SUPPORT_GPU |
| 90 | " | gpu" |
| 91 | #endif |
| 92 | ": Use the corresponding device. Default is bitmap.\n"); |
| 93 | SkDebugf( |
| 94 | " bitmap, Render to a bitmap.\n"); |
| keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 95 | #if SK_SUPPORT_GPU |
| keyar@chromium.org | a40c20d | 2012-08-20 15:04:12 +0000 | [diff] [blame] | 96 | SkDebugf( |
| keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 97 | " gpu, Render to the GPU.\n"); |
| 98 | #endif |
| 99 | SkDebugf("\n"); |
| 100 | SkDebugf( |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 101 | " --repeat: " |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 102 | "Set the number of times to repeat each test." |
| 103 | " Default is %i.\n", DEFAULT_REPEATS); |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 106 | SkBenchLogger gLogger; |
| 107 | |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 108 | static bool run_single_benchmark(const SkString& inputPath, |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 109 | sk_tools::PictureBenchmark& benchmark) { |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 110 | SkFILEStream inputStream; |
| 111 | |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 112 | inputStream.setPath(inputPath.c_str()); |
| 113 | if (!inputStream.isValid()) { |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 114 | SkString err; |
| 115 | err.printf("Could not open file %s\n", inputPath.c_str()); |
| 116 | gLogger.logError(err); |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 117 | return false; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 120 | bool success = false; |
| scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 121 | SkPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream); |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 122 | if (!success) { |
| 123 | SkString err; |
| 124 | err.printf("Could not read an SkPicture from %s\n", inputPath.c_str()); |
| 125 | gLogger.logError(err); |
| 126 | return false; |
| 127 | } |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 128 | |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 129 | SkString filename; |
| 130 | sk_tools::get_basename(&filename, inputPath); |
| keyar@chromium.org | db9a5fb | 2012-08-21 17:57:59 +0000 | [diff] [blame] | 131 | |
| 132 | SkString result; |
| borenet@google.com | 2d2b9a0 | 2012-09-20 18:54:04 +0000 | [diff] [blame] | 133 | result.printf("running bench [%i %i] %s ", picture.width(), |
| 134 | picture.height(), filename.c_str()); |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 135 | gLogger.logProgress(result); |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 136 | |
| borenet@google.com | 2d2b9a0 | 2012-09-20 18:54:04 +0000 | [diff] [blame] | 137 | benchmark.run(&picture); |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 138 | return true; |
| keyar@chromium.org | 0665f25 | 2012-07-10 18:30:18 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 141 | #define PRINT_USAGE_AND_EXIT \ |
| 142 | do { \ |
| 143 | usage(argv0); \ |
| 144 | exit(-1); \ |
| 145 | } while (0) |
| 146 | |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 147 | static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs, |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 148 | sk_tools::PictureBenchmark* benchmark) { |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 149 | const char* argv0 = argv[0]; |
| 150 | char* const* stop = argv + argc; |
| 151 | |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 152 | int repeats = DEFAULT_REPEATS; |
| keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 153 | sk_tools::PictureRenderer::SkDeviceTypes deviceType = |
| 154 | sk_tools::PictureRenderer::kBitmap_DeviceType; |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 155 | |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 156 | SkAutoTUnref<sk_tools::PictureRenderer> renderer(NULL); |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 157 | |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 158 | // Create a string to show our current settings. |
| 159 | // TODO: Make it prettier. Currently it just repeats the command line. |
| 160 | SkString commandLine("bench_pictures:"); |
| 161 | for (int i = 1; i < argc; i++) { |
| 162 | commandLine.appendf(" %s", *(argv+i)); |
| 163 | } |
| 164 | commandLine.append("\n"); |
| 165 | |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 166 | bool usePipe = false; |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 167 | int numThreads = 1; |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 168 | bool useTiles = false; |
| 169 | const char* widthString = NULL; |
| 170 | const char* heightString = NULL; |
| junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame^] | 171 | int gridWidth = 0; |
| 172 | int gridHeight = 0; |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 173 | bool isPowerOf2Mode = false; |
| 174 | const char* mode = NULL; |
| junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame^] | 175 | bool gridSupported = false; |
| skia.committer@gmail.com | 1aa90cf | 2012-11-06 13:18:25 +0000 | [diff] [blame] | 176 | sk_tools::PictureRenderer::BBoxHierarchyType bbhType = |
| junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 177 | sk_tools::PictureRenderer::kNone_BBoxHierarchyType; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 178 | for (++argv; argv < stop; ++argv) { |
| 179 | if (0 == strcmp(*argv, "--repeat")) { |
| 180 | ++argv; |
| 181 | if (argv < stop) { |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 182 | repeats = atoi(*argv); |
| 183 | if (repeats < 1) { |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 184 | gLogger.logError("--repeat must be given a value > 0\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 185 | PRINT_USAGE_AND_EXIT; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 186 | } |
| 187 | } else { |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 188 | gLogger.logError("Missing arg for --repeat\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 189 | PRINT_USAGE_AND_EXIT; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 190 | } |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 191 | } else if (0 == strcmp(*argv, "--pipe")) { |
| 192 | usePipe = true; |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 193 | } else if (0 == strcmp(*argv, "--logFile")) { |
| 194 | argv++; |
| 195 | if (argv < stop) { |
| 196 | if (!gLogger.SetLogFile(*argv)) { |
| 197 | SkString str; |
| 198 | str.printf("Could not open %s for writing.", *argv); |
| 199 | gLogger.logError(str); |
| 200 | usage(argv0); |
| borenet@google.com | a49bffd | 2012-09-13 18:54:48 +0000 | [diff] [blame] | 201 | // TODO(borenet): We're disabling this for now, due to |
| 202 | // write-protected Android devices. The very short-term |
| 203 | // solution is to ignore the fact that we have no log file. |
| 204 | //exit(-1); |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 205 | } |
| 206 | } else { |
| 207 | gLogger.logError("Missing arg for --logFile\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 208 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 209 | } |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 210 | } else if (0 == strcmp(*argv, "--multi")) { |
| 211 | ++argv; |
| 212 | if (argv >= stop) { |
| 213 | gLogger.logError("Missing arg for --multi\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 214 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 215 | } |
| 216 | numThreads = atoi(*argv); |
| 217 | if (numThreads < 2) { |
| 218 | gLogger.logError("Number of threads must be at least 2.\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 219 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 220 | } |
| junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 221 | } else if (0 == strcmp(*argv, "--bbh")) { |
| 222 | ++argv; |
| 223 | if (argv >= stop) { |
| 224 | gLogger.logError("Missing value for --bbh\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 225 | PRINT_USAGE_AND_EXIT; |
| junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 226 | } |
| 227 | if (0 == strcmp(*argv, "none")) { |
| 228 | bbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType; |
| 229 | } else if (0 == strcmp(*argv, "rtree")) { |
| 230 | bbhType = sk_tools::PictureRenderer::kRTree_BBoxHierarchyType; |
| junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame^] | 231 | } else if (0 == strcmp(*argv, "grid")) { |
| 232 | bbhType = sk_tools::PictureRenderer::kTileGrid_BBoxHierarchyType; |
| 233 | ++argv; |
| 234 | if (argv >= stop) { |
| 235 | gLogger.logError("Missing width for --bbh grid\n"); |
| 236 | PRINT_USAGE_AND_EXIT; |
| 237 | } |
| 238 | gridWidth = atoi(*argv); |
| 239 | ++argv; |
| 240 | if (argv >= stop) { |
| 241 | gLogger.logError("Missing height for --bbh grid\n"); |
| 242 | PRINT_USAGE_AND_EXIT; |
| 243 | } |
| 244 | gridHeight = atoi(*argv); |
| junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 245 | } else { |
| 246 | SkString err; |
| 247 | err.printf("%s is not a valid value for --bbhType\n", *argv); |
| 248 | gLogger.logError(err); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 249 | PRINT_USAGE_AND_EXIT; |
| junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 252 | } else if (0 == strcmp(*argv, "--mode")) { |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 253 | if (renderer.get() != NULL) { |
| 254 | SkDebugf("Cannot combine modes.\n"); |
| 255 | PRINT_USAGE_AND_EXIT; |
| 256 | } |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 257 | |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 258 | ++argv; |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 259 | if (argv >= stop) { |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 260 | gLogger.logError("Missing mode for --mode\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 261 | PRINT_USAGE_AND_EXIT; |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 264 | if (0 == strcmp(*argv, "record")) { |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 265 | renderer.reset(SkNEW(sk_tools::RecordPictureRenderer)); |
| junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame^] | 266 | gridSupported = true; |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 267 | } else if (0 == strcmp(*argv, "simple")) { |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 268 | renderer.reset(SkNEW(sk_tools::SimplePictureRenderer)); |
| keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 269 | } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))) { |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 270 | useTiles = true; |
| 271 | mode = *argv; |
| keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 272 | |
| 273 | if (0 == strcmp(*argv, "pow2tile")) { |
| 274 | isPowerOf2Mode = true; |
| junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame^] | 275 | } else { |
| 276 | gridSupported = true; |
| keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 279 | ++argv; |
| 280 | if (argv >= stop) { |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 281 | SkString err; |
| 282 | err.printf("Missing width for --mode %s\n", mode); |
| 283 | gLogger.logError(err); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 284 | PRINT_USAGE_AND_EXIT; |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 287 | widthString = *argv; |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 288 | ++argv; |
| 289 | if (argv >= stop) { |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 290 | gLogger.logError("Missing height for --mode tile\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 291 | PRINT_USAGE_AND_EXIT; |
| keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 292 | } |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 293 | heightString = *argv; |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 294 | } else if (0 == strcmp(*argv, "playbackCreation")) { |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 295 | renderer.reset(SkNEW(sk_tools::PlaybackCreationRenderer)); |
| junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame^] | 296 | gridSupported = true; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 297 | } else { |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 298 | SkString err; |
| 299 | err.printf("%s is not a valid mode for --mode\n", *argv); |
| 300 | gLogger.logError(err); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 301 | PRINT_USAGE_AND_EXIT; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 302 | } |
| keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 303 | } else if (0 == strcmp(*argv, "--device")) { |
| 304 | ++argv; |
| 305 | if (argv >= stop) { |
| borenet@google.com | a49bffd | 2012-09-13 18:54:48 +0000 | [diff] [blame] | 306 | gLogger.logError("Missing mode for --device\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 307 | PRINT_USAGE_AND_EXIT; |
| keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | if (0 == strcmp(*argv, "bitmap")) { |
| 311 | deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType; |
| 312 | } |
| 313 | #if SK_SUPPORT_GPU |
| 314 | else if (0 == strcmp(*argv, "gpu")) { |
| 315 | deviceType = sk_tools::PictureRenderer::kGPU_DeviceType; |
| 316 | } |
| 317 | #endif |
| 318 | else { |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 319 | SkString err; |
| 320 | err.printf("%s is not a valid mode for --device\n", *argv); |
| 321 | gLogger.logError(err); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 322 | PRINT_USAGE_AND_EXIT; |
| keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 323 | } |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 324 | } else if (0 == strcmp(*argv, "--timers")) { |
| 325 | ++argv; |
| 326 | if (argv < stop) { |
| 327 | bool timerWall = false; |
| 328 | bool truncatedTimerWall = false; |
| 329 | bool timerCpu = false; |
| 330 | bool truncatedTimerCpu = false; |
| 331 | bool timerGpu = false; |
| 332 | for (char* t = *argv; *t; ++t) { |
| 333 | switch (*t) { |
| 334 | case 'w': |
| 335 | timerWall = true; |
| 336 | break; |
| 337 | case 'c': |
| 338 | timerCpu = true; |
| 339 | break; |
| 340 | case 'W': |
| 341 | truncatedTimerWall = true; |
| 342 | break; |
| 343 | case 'C': |
| 344 | truncatedTimerCpu = true; |
| 345 | break; |
| 346 | case 'g': |
| 347 | timerGpu = true; |
| 348 | break; |
| 349 | default: { |
| 350 | break; |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, |
| 355 | truncatedTimerCpu, timerGpu); |
| 356 | } else { |
| 357 | gLogger.logError("Missing arg for --timers\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 358 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 359 | } |
| 360 | } else if (0 == strcmp(*argv, "--min")) { |
| 361 | benchmark->setPrintMin(true); |
| 362 | } else if (0 == strcmp(*argv, "--logPerIter")) { |
| 363 | ++argv; |
| 364 | if (argv < stop) { |
| 365 | bool log = atoi(*argv) != 0; |
| 366 | benchmark->setLogPerIter(log); |
| 367 | } else { |
| 368 | gLogger.logError("Missing arg for --logPerIter\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 369 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 370 | } |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 371 | } else if (0 == strcmp(*argv, "--help") || 0 == strcmp(*argv, "-h")) { |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 372 | PRINT_USAGE_AND_EXIT; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 373 | } else { |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 374 | inputs->push_back(SkString(*argv)); |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 378 | if (numThreads > 1 && !useTiles) { |
| 379 | gLogger.logError("Multithreaded drawing requires tiled rendering.\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 380 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 383 | if (usePipe && sk_tools::PictureRenderer::kNone_BBoxHierarchyType != bbhType) { |
| 384 | gLogger.logError("--pipe and --bbh cannot be used together\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 385 | PRINT_USAGE_AND_EXIT; |
| junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame^] | 388 | if (sk_tools::PictureRenderer::kTileGrid_BBoxHierarchyType == bbhType && |
| 389 | !gridSupported) { |
| 390 | gLogger.logError("'--bbh grid' is not compatible with specified --mode.\n"); |
| 391 | PRINT_USAGE_AND_EXIT; |
| 392 | } |
| 393 | |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 394 | if (useTiles) { |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 395 | SkASSERT(NULL == renderer); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 396 | sk_tools::TiledPictureRenderer* tiledRenderer; |
| 397 | if (numThreads > 1) { |
| 398 | tiledRenderer = SkNEW_ARGS(sk_tools::MultiCorePictureRenderer, (numThreads)); |
| 399 | } else { |
| 400 | tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer); |
| 401 | } |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 402 | if (isPowerOf2Mode) { |
| 403 | int minWidth = atoi(widthString); |
| 404 | if (!SkIsPow2(minWidth) || minWidth < 0) { |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 405 | tiledRenderer->unref(); |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 406 | SkString err; |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 407 | err.printf("-mode %s must be given a width" |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 408 | " value that is a power of two\n", mode); |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 409 | gLogger.logError(err); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 410 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 411 | } |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 412 | tiledRenderer->setTileMinPowerOf2Width(minWidth); |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 413 | } else if (sk_tools::is_percentage(widthString)) { |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 414 | tiledRenderer->setTileWidthPercentage(atof(widthString)); |
| 415 | if (!(tiledRenderer->getTileWidthPercentage() > 0)) { |
| 416 | tiledRenderer->unref(); |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 417 | gLogger.logError("--mode tile must be given a width percentage > 0\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 418 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 419 | } |
| 420 | } else { |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 421 | tiledRenderer->setTileWidth(atoi(widthString)); |
| 422 | if (!(tiledRenderer->getTileWidth() > 0)) { |
| 423 | tiledRenderer->unref(); |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 424 | gLogger.logError("--mode tile must be given a width > 0\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 425 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | if (sk_tools::is_percentage(heightString)) { |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 430 | tiledRenderer->setTileHeightPercentage(atof(heightString)); |
| 431 | if (!(tiledRenderer->getTileHeightPercentage() > 0)) { |
| 432 | tiledRenderer->unref(); |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 433 | gLogger.logError("--mode tile must be given a height percentage > 0\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 434 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 435 | } |
| 436 | } else { |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 437 | tiledRenderer->setTileHeight(atoi(heightString)); |
| 438 | if (!(tiledRenderer->getTileHeight() > 0)) { |
| 439 | tiledRenderer->unref(); |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 440 | gLogger.logError("--mode tile must be given a height > 0\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 441 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 442 | } |
| 443 | } |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 444 | if (numThreads > 1) { |
| 445 | #if SK_SUPPORT_GPU |
| 446 | if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) { |
| 447 | tiledRenderer->unref(); |
| 448 | gLogger.logError("GPU not compatible with multithreaded tiling.\n"); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 449 | PRINT_USAGE_AND_EXIT; |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 450 | } |
| 451 | #endif |
| scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 452 | } |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 453 | renderer.reset(tiledRenderer); |
| 454 | if (usePipe) { |
| 455 | SkDebugf("Pipe rendering is currently not compatible with tiling.\n" |
| 456 | "Turning off pipe.\n"); |
| 457 | } |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 458 | } else if (usePipe) { |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 459 | if (renderer.get() != NULL) { |
| 460 | SkDebugf("Pipe is incompatible with other modes.\n"); |
| 461 | PRINT_USAGE_AND_EXIT; |
| 462 | } |
| 463 | renderer.reset(SkNEW(sk_tools::PipePictureRenderer)); |
| scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 464 | } |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 465 | if (inputs->count() < 1) { |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 466 | PRINT_USAGE_AND_EXIT; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 467 | } |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 468 | |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 469 | if (NULL == renderer) { |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 470 | renderer.reset(SkNEW(sk_tools::SimplePictureRenderer)); |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 471 | } |
| junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 472 | |
| 473 | renderer->setBBoxHierarchyType(bbhType); |
| junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame^] | 474 | renderer->setGridSize(gridWidth, gridHeight); |
| scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 475 | benchmark->setRenderer(renderer); |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 476 | benchmark->setRepeats(repeats); |
| keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 477 | benchmark->setDeviceType(deviceType); |
| scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 478 | benchmark->setLogger(&gLogger); |
| 479 | // Report current settings: |
| 480 | gLogger.logProgress(commandLine); |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 481 | } |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 482 | |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 483 | static int process_input(const SkString& input, |
| 484 | sk_tools::PictureBenchmark& benchmark) { |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 485 | SkOSFile::Iter iter(input.c_str(), "skp"); |
| 486 | SkString inputFilename; |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 487 | int failures = 0; |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 488 | if (iter.next(&inputFilename)) { |
| 489 | do { |
| 490 | SkString inputPath; |
| keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 491 | sk_tools::make_filepath(&inputPath, input, inputFilename); |
| borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 492 | if (!run_single_benchmark(inputPath, benchmark)) { |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 493 | ++failures; |
| borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 494 | } |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 495 | } while(iter.next(&inputFilename)); |
| borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 496 | } else if (SkStrEndsWith(input.c_str(), ".skp")) { |
| 497 | if (!run_single_benchmark(input, benchmark)) { |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 498 | ++failures; |
| borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 499 | } |
| 500 | } else { |
| 501 | SkString warning; |
| 502 | warning.printf("Warning: skipping %s\n", input.c_str()); |
| 503 | gLogger.logError(warning); |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 504 | } |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 505 | return failures; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 508 | int tool_main(int argc, char** argv); |
| 509 | int tool_main(int argc, char** argv) { |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 510 | #ifdef SK_ENABLE_INST_COUNT |
| 511 | gPrintInstCount = true; |
| 512 | #endif |
| scroggo@google.com | 0a36f43 | 2012-09-10 20:29:13 +0000 | [diff] [blame] | 513 | SkAutoGraphics ag; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 514 | |
| scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 515 | SkTArray<SkString> inputs; |
| 516 | sk_tools::PictureBenchmark benchmark; |
| 517 | |
| 518 | parse_commandline(argc, argv, &inputs, &benchmark); |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 519 | |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 520 | int failures = 0; |
| keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 521 | for (int i = 0; i < inputs.count(); ++i) { |
| borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 522 | failures += process_input(inputs[i], benchmark); |
| 523 | } |
| 524 | |
| 525 | if (failures != 0) { |
| 526 | SkString err; |
| 527 | err.printf("Failed to run %i benchmarks.\n", failures); |
| 528 | gLogger.logError(err); |
| 529 | return 1; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 530 | } |
| caryclark@google.com | 868e1f6 | 2012-10-02 20:00:03 +0000 | [diff] [blame] | 531 | return 0; |
| reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 532 | } |
| caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 533 | |
| 534 | #if !defined SK_BUILD_FOR_IOS |
| 535 | int main(int argc, char * const argv[]) { |
| 536 | return tool_main(argc, (char**) argv); |
| 537 | } |
| 538 | #endif |