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" |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 13 | #include "SkMath.h" |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 14 | #include "SkOSFile.h" |
| 15 | #include "SkPicture.h" |
| 16 | #include "SkStream.h" |
| 17 | #include "SkTArray.h" |
| 18 | #include "picture_utils.h" |
| 19 | |
| 20 | const int DEFAULT_REPEATS = 100; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 21 | |
| 22 | static void usage(const char* argv0) { |
| 23 | SkDebugf("SkPicture benchmarking tool\n"); |
| 24 | SkDebugf("\n" |
| 25 | "Usage: \n" |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 26 | " %s <inputDir>...\n" |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 27 | " [--logFile filename][--timers [wcgWC]*][--logPerIter 1|0][--min]\n" |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 28 | " [--repeat] \n" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 29 | " [--mode pow2tile minWidth height[] (multi) | record | simple\n" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 30 | " | tile width[] height[] (multi) | playbackCreation]\n" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 31 | " [--pipe]\n" |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 32 | " [--device bitmap" |
| 33 | #if SK_SUPPORT_GPU |
| 34 | " | gpu" |
| 35 | #endif |
| 36 | "]" |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 37 | , argv0); |
| 38 | SkDebugf("\n\n"); |
| 39 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 40 | " 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] | 41 | " expected to have the .skp extension.\n\n" |
| 42 | " --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^] | 43 | SkDebugf(" --logPerIter 1|0 : " |
| 44 | "Log each repeat timer instead of mean, default is disabled.\n"); |
| 45 | SkDebugf(" --min : Print the minimum times (instead of average).\n"); |
| 46 | SkDebugf(" --timers [wcgWC]* : " |
| 47 | "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] | 48 | SkDebugf( |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 49 | " --mode pow2tile minWidht height[] (multi) | record | simple\n" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 50 | " | tile width[] height[] (multi) | playbackCreation:\n" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 51 | " Run in the corresponding mode.\n" |
| 52 | " Default is simple.\n"); |
keyar@chromium.org | cf6c44c | 2012-07-09 19:37:40 +0000 | [diff] [blame] | 53 | SkDebugf( |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 54 | " pow2tile minWidth height[], Creates tiles with widths\n" |
| 55 | " that are all a power of two\n" |
| 56 | " such that they minimize the\n" |
| 57 | " amount of wasted tile space.\n" |
| 58 | " minWidth is the minimum width\n" |
| 59 | " of these tiles and must be a\n" |
| 60 | " power of two. Simple\n" |
| 61 | " rendering using these tiles\n" |
| 62 | " is benchmarked.\n" |
| 63 | " Append \"multi\" for multithreaded\n" |
| 64 | " drawing.\n"); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 65 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 66 | " record, Benchmark picture to picture recording.\n"); |
| 67 | SkDebugf( |
| 68 | " simple, Benchmark a simple rendering.\n"); |
| 69 | SkDebugf( |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 70 | " tile width[] height[], Benchmark simple rendering using\n" |
| 71 | " tiles with the given dimensions.\n" |
| 72 | " Append \"multi\" for multithreaded\n" |
| 73 | " drawing.\n"); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 74 | SkDebugf( |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 75 | " playbackCreation, Benchmark creation of the SkPicturePlayback.\n"); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 76 | SkDebugf("\n"); |
| 77 | SkDebugf( |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 78 | " --pipe: Benchmark SkGPipe rendering. Compatible with tiled, multithreaded rendering.\n"); |
| 79 | SkDebugf( |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 80 | " --device bitmap" |
| 81 | #if SK_SUPPORT_GPU |
| 82 | " | gpu" |
| 83 | #endif |
| 84 | ": Use the corresponding device. Default is bitmap.\n"); |
| 85 | SkDebugf( |
| 86 | " bitmap, Render to a bitmap.\n"); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 87 | #if SK_SUPPORT_GPU |
keyar@chromium.org | a40c20d | 2012-08-20 15:04:12 +0000 | [diff] [blame] | 88 | SkDebugf( |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 89 | " gpu, Render to the GPU.\n"); |
| 90 | #endif |
| 91 | SkDebugf("\n"); |
| 92 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 93 | " --repeat: " |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 94 | "Set the number of times to repeat each test." |
| 95 | " Default is %i.\n", DEFAULT_REPEATS); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 96 | } |
| 97 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 98 | SkBenchLogger gLogger; |
| 99 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 100 | static void run_single_benchmark(const SkString& inputPath, |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 101 | sk_tools::PictureBenchmark& benchmark) { |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 102 | SkFILEStream inputStream; |
| 103 | |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 104 | inputStream.setPath(inputPath.c_str()); |
| 105 | if (!inputStream.isValid()) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 106 | SkString err; |
| 107 | err.printf("Could not open file %s\n", inputPath.c_str()); |
| 108 | gLogger.logError(err); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 109 | return; |
| 110 | } |
| 111 | |
| 112 | SkPicture picture(&inputStream); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 113 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 114 | SkString filename; |
| 115 | sk_tools::get_basename(&filename, inputPath); |
keyar@chromium.org | db9a5fb | 2012-08-21 17:57:59 +0000 | [diff] [blame] | 116 | |
| 117 | SkString result; |
| 118 | result.printf("running bench [%i %i] %s ", picture.width(), picture.height(), |
| 119 | filename.c_str()); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 120 | gLogger.logProgress(result); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 121 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 122 | benchmark.run(&picture); |
keyar@chromium.org | 0665f25 | 2012-07-10 18:30:18 +0000 | [diff] [blame] | 123 | } |
| 124 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 125 | 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^] | 126 | sk_tools::PictureBenchmark* benchmark) { |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 127 | const char* argv0 = argv[0]; |
| 128 | char* const* stop = argv + argc; |
| 129 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 130 | int repeats = DEFAULT_REPEATS; |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 131 | sk_tools::PictureRenderer::SkDeviceTypes deviceType = |
| 132 | sk_tools::PictureRenderer::kBitmap_DeviceType; |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 133 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 134 | sk_tools::PictureRenderer* renderer = NULL; |
| 135 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 136 | // Create a string to show our current settings. |
| 137 | // TODO: Make it prettier. Currently it just repeats the command line. |
| 138 | SkString commandLine("bench_pictures:"); |
| 139 | for (int i = 1; i < argc; i++) { |
| 140 | commandLine.appendf(" %s", *(argv+i)); |
| 141 | } |
| 142 | commandLine.append("\n"); |
| 143 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 144 | bool usePipe = false; |
| 145 | bool multiThreaded = false; |
| 146 | bool useTiles = false; |
| 147 | const char* widthString = NULL; |
| 148 | const char* heightString = NULL; |
| 149 | bool isPowerOf2Mode = false; |
| 150 | const char* mode = NULL; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 151 | for (++argv; argv < stop; ++argv) { |
| 152 | if (0 == strcmp(*argv, "--repeat")) { |
| 153 | ++argv; |
| 154 | if (argv < stop) { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 155 | repeats = atoi(*argv); |
| 156 | if (repeats < 1) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 157 | gLogger.logError("--repeat must be given a value > 0\n"); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 158 | exit(-1); |
| 159 | } |
| 160 | } else { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 161 | gLogger.logError("Missing arg for --repeat\n"); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 162 | usage(argv0); |
| 163 | exit(-1); |
| 164 | } |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 165 | } else if (0 == strcmp(*argv, "--pipe")) { |
| 166 | usePipe = true; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 167 | } else if (0 == strcmp(*argv, "--logFile")) { |
| 168 | argv++; |
| 169 | if (argv < stop) { |
| 170 | if (!gLogger.SetLogFile(*argv)) { |
| 171 | SkString str; |
| 172 | str.printf("Could not open %s for writing.", *argv); |
| 173 | gLogger.logError(str); |
| 174 | usage(argv0); |
| 175 | exit(-1); |
| 176 | } |
| 177 | } else { |
| 178 | gLogger.logError("Missing arg for --logFile\n"); |
| 179 | usage(argv0); |
| 180 | exit(-1); |
| 181 | } |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 182 | } else if (0 == strcmp(*argv, "--mode")) { |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 183 | |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 184 | ++argv; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 185 | if (argv >= stop) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 186 | gLogger.logError("Missing mode for --mode\n"); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 187 | usage(argv0); |
| 188 | exit(-1); |
| 189 | } |
| 190 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 191 | if (0 == strcmp(*argv, "record")) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 192 | renderer = SkNEW(sk_tools::RecordPictureRenderer); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 193 | } else if (0 == strcmp(*argv, "simple")) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 194 | renderer = SkNEW(sk_tools::SimplePictureRenderer); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 195 | } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))) { |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 196 | useTiles = true; |
| 197 | mode = *argv; |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 198 | |
| 199 | if (0 == strcmp(*argv, "pow2tile")) { |
| 200 | isPowerOf2Mode = true; |
| 201 | } |
| 202 | |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 203 | ++argv; |
| 204 | if (argv >= stop) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 205 | SkString err; |
| 206 | err.printf("Missing width for --mode %s\n", mode); |
| 207 | gLogger.logError(err); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 208 | usage(argv0); |
| 209 | exit(-1); |
| 210 | } |
| 211 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 212 | widthString = *argv; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 213 | ++argv; |
| 214 | if (argv >= stop) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 215 | gLogger.logError("Missing height for --mode tile\n"); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 216 | usage(argv0); |
| 217 | exit(-1); |
| 218 | } |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 219 | heightString = *argv; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 220 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 221 | ++argv; |
| 222 | if (argv < stop && 0 == strcmp(*argv, "multi")) { |
| 223 | multiThreaded = true; |
keyar@chromium.org | 0665f25 | 2012-07-10 18:30:18 +0000 | [diff] [blame] | 224 | } else { |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 225 | --argv; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 226 | } |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 227 | } else if (0 == strcmp(*argv, "playbackCreation")) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 228 | renderer = SkNEW(sk_tools::PlaybackCreationRenderer); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 229 | } else { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 230 | SkString err; |
| 231 | err.printf("%s is not a valid mode for --mode\n", *argv); |
| 232 | gLogger.logError(err); |
keyar@chromium.org | 0665f25 | 2012-07-10 18:30:18 +0000 | [diff] [blame] | 233 | usage(argv0); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 234 | exit(-1); |
| 235 | } |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 236 | } else if (0 == strcmp(*argv, "--device")) { |
| 237 | ++argv; |
| 238 | if (argv >= stop) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 239 | gLogger.logError("Missing mode for --deivce\n"); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 240 | usage(argv0); |
| 241 | exit(-1); |
| 242 | } |
| 243 | |
| 244 | if (0 == strcmp(*argv, "bitmap")) { |
| 245 | deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType; |
| 246 | } |
| 247 | #if SK_SUPPORT_GPU |
| 248 | else if (0 == strcmp(*argv, "gpu")) { |
| 249 | deviceType = sk_tools::PictureRenderer::kGPU_DeviceType; |
| 250 | } |
| 251 | #endif |
| 252 | else { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 253 | SkString err; |
| 254 | err.printf("%s is not a valid mode for --device\n", *argv); |
| 255 | gLogger.logError(err); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 256 | usage(argv0); |
| 257 | exit(-1); |
| 258 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 259 | } else if (0 == strcmp(*argv, "--timers")) { |
| 260 | ++argv; |
| 261 | if (argv < stop) { |
| 262 | bool timerWall = false; |
| 263 | bool truncatedTimerWall = false; |
| 264 | bool timerCpu = false; |
| 265 | bool truncatedTimerCpu = false; |
| 266 | bool timerGpu = false; |
| 267 | for (char* t = *argv; *t; ++t) { |
| 268 | switch (*t) { |
| 269 | case 'w': |
| 270 | timerWall = true; |
| 271 | break; |
| 272 | case 'c': |
| 273 | timerCpu = true; |
| 274 | break; |
| 275 | case 'W': |
| 276 | truncatedTimerWall = true; |
| 277 | break; |
| 278 | case 'C': |
| 279 | truncatedTimerCpu = true; |
| 280 | break; |
| 281 | case 'g': |
| 282 | timerGpu = true; |
| 283 | break; |
| 284 | default: { |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, |
| 290 | truncatedTimerCpu, timerGpu); |
| 291 | } else { |
| 292 | gLogger.logError("Missing arg for --timers\n"); |
| 293 | usage(argv0); |
| 294 | exit(-1); |
| 295 | } |
| 296 | } else if (0 == strcmp(*argv, "--min")) { |
| 297 | benchmark->setPrintMin(true); |
| 298 | } else if (0 == strcmp(*argv, "--logPerIter")) { |
| 299 | ++argv; |
| 300 | if (argv < stop) { |
| 301 | bool log = atoi(*argv) != 0; |
| 302 | benchmark->setLogPerIter(log); |
| 303 | } else { |
| 304 | gLogger.logError("Missing arg for --logPerIter\n"); |
| 305 | usage(argv0); |
| 306 | exit(-1); |
| 307 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 308 | } else if (0 == strcmp(*argv, "--help") || 0 == strcmp(*argv, "-h")) { |
| 309 | usage(argv0); |
| 310 | exit(0); |
| 311 | } else { |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 312 | inputs->push_back(SkString(*argv)); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 316 | if (useTiles) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 317 | SkASSERT(NULL == renderer); |
| 318 | sk_tools::TiledPictureRenderer* tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 319 | if (isPowerOf2Mode) { |
| 320 | int minWidth = atoi(widthString); |
| 321 | if (!SkIsPow2(minWidth) || minWidth < 0) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 322 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 323 | SkString err; |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 324 | err.printf("-mode %s must be given a width" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 325 | " value that is a power of two\n", mode); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 326 | gLogger.logError(err); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 327 | exit(-1); |
| 328 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 329 | tiledRenderer->setTileMinPowerOf2Width(minWidth); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 330 | } else if (sk_tools::is_percentage(widthString)) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 331 | tiledRenderer->setTileWidthPercentage(atof(widthString)); |
| 332 | if (!(tiledRenderer->getTileWidthPercentage() > 0)) { |
| 333 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 334 | gLogger.logError("--mode tile must be given a width percentage > 0\n"); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 335 | exit(-1); |
| 336 | } |
| 337 | } else { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 338 | tiledRenderer->setTileWidth(atoi(widthString)); |
| 339 | if (!(tiledRenderer->getTileWidth() > 0)) { |
| 340 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 341 | gLogger.logError("--mode tile must be given a width > 0\n"); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 342 | exit(-1); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | if (sk_tools::is_percentage(heightString)) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 347 | tiledRenderer->setTileHeightPercentage(atof(heightString)); |
| 348 | if (!(tiledRenderer->getTileHeightPercentage() > 0)) { |
| 349 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 350 | gLogger.logError("--mode tile must be given a height percentage > 0\n"); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 351 | exit(-1); |
| 352 | } |
| 353 | } else { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 354 | tiledRenderer->setTileHeight(atoi(heightString)); |
| 355 | if (!(tiledRenderer->getTileHeight() > 0)) { |
| 356 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 357 | gLogger.logError("--mode tile must be given a height > 0\n"); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 358 | exit(-1); |
| 359 | } |
| 360 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 361 | tiledRenderer->setMultiThreaded(multiThreaded); |
| 362 | tiledRenderer->setUsePipe(usePipe); |
| 363 | renderer = tiledRenderer; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 364 | } else if (usePipe) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 365 | renderer = SkNEW(sk_tools::PipePictureRenderer); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 366 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 367 | if (inputs->count() < 1) { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 368 | SkDELETE(benchmark); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 369 | usage(argv0); |
| 370 | exit(-1); |
| 371 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 372 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 373 | if (NULL == renderer) { |
| 374 | renderer = SkNEW(sk_tools::SimplePictureRenderer); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 375 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 376 | benchmark->setRenderer(renderer)->unref(); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 377 | benchmark->setRepeats(repeats); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 378 | benchmark->setDeviceType(deviceType); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 379 | benchmark->setLogger(&gLogger); |
| 380 | // Report current settings: |
| 381 | gLogger.logProgress(commandLine); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 382 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 383 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 384 | static void process_input(const SkString& input, sk_tools::PictureBenchmark& benchmark) { |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 385 | SkOSFile::Iter iter(input.c_str(), "skp"); |
| 386 | SkString inputFilename; |
| 387 | |
| 388 | if (iter.next(&inputFilename)) { |
| 389 | do { |
| 390 | SkString inputPath; |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 391 | sk_tools::make_filepath(&inputPath, input, inputFilename); |
| 392 | run_single_benchmark(inputPath, benchmark); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 393 | } while(iter.next(&inputFilename)); |
| 394 | } else { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 395 | run_single_benchmark(input, benchmark); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 396 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | int main(int argc, char* const argv[]) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 400 | #ifdef SK_ENABLE_INST_COUNT |
| 401 | gPrintInstCount = true; |
| 402 | #endif |
scroggo@google.com | 0a36f43 | 2012-09-10 20:29:13 +0000 | [diff] [blame] | 403 | SkAutoGraphics ag; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 404 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 405 | SkTArray<SkString> inputs; |
| 406 | sk_tools::PictureBenchmark benchmark; |
| 407 | |
| 408 | parse_commandline(argc, argv, &inputs, &benchmark); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 409 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 410 | for (int i = 0; i < inputs.count(); ++i) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame^] | 411 | process_input(inputs[i], benchmark); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 412 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 413 | } |