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" |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 9 | #include "CopyTilesRenderer.h" |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 10 | #include "PictureBenchmark.h" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 11 | #include "SkBenchLogger.h" |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 12 | #include "SkCanvas.h" |
scroggo@google.com | 0a36f43 | 2012-09-10 20:29:13 +0000 | [diff] [blame] | 13 | #include "SkGraphics.h" |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 14 | #include "SkImageDecoder.h" |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 15 | #include "SkMath.h" |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 16 | #include "SkOSFile.h" |
| 17 | #include "SkPicture.h" |
| 18 | #include "SkStream.h" |
| 19 | #include "SkTArray.h" |
| 20 | #include "picture_utils.h" |
| 21 | |
borenet@google.com | 13fd5a1 | 2012-09-17 21:10:05 +0000 | [diff] [blame] | 22 | const int DEFAULT_REPEATS = 1; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 23 | |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 24 | static char const * const gFilterTypes[] = { |
| 25 | "paint", |
| 26 | "point", |
| 27 | "line", |
| 28 | "bitmap", |
| 29 | "rect", |
| 30 | "path", |
| 31 | "text", |
| 32 | "all", |
| 33 | }; |
| 34 | |
| 35 | static const size_t kFilterTypesCount = sizeof(gFilterTypes) / sizeof(gFilterTypes[0]); |
| 36 | |
| 37 | static char const * const gFilterFlags[] = { |
| 38 | "antiAlias", |
| 39 | "filterBitmap", |
| 40 | "dither", |
| 41 | "underlineText", |
| 42 | "strikeThruText", |
| 43 | "fakeBoldText", |
| 44 | "linearText", |
| 45 | "subpixelText", |
| 46 | "devKernText", |
| 47 | "LCDRenderText", |
| 48 | "embeddedBitmapText", |
| 49 | "autoHinting", |
| 50 | "verticalText", |
| 51 | "genA8FromLCD", |
| 52 | "blur", |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 53 | "lowBlur", |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 54 | "hinting", |
| 55 | "slightHinting", |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 56 | "AAClip", |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | static const size_t kFilterFlagsCount = sizeof(gFilterFlags) / sizeof(gFilterFlags[0]); |
| 60 | |
| 61 | static SkString filtersName(sk_tools::PictureRenderer::DrawFilterFlags* drawFilters) { |
| 62 | int all = drawFilters[0]; |
| 63 | size_t tIndex; |
| 64 | for (tIndex = 1; tIndex < SkDrawFilter::kTypeCount; ++tIndex) { |
| 65 | all &= drawFilters[tIndex]; |
| 66 | } |
| 67 | SkString result; |
| 68 | for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) { |
| 69 | SkString types; |
| 70 | if (all & (1 << fIndex)) { |
| 71 | types = gFilterTypes[SkDrawFilter::kTypeCount]; |
| 72 | } else { |
| 73 | for (tIndex = 0; tIndex < SkDrawFilter::kTypeCount; ++tIndex) { |
| 74 | if (drawFilters[tIndex] & (1 << fIndex)) { |
| 75 | types += gFilterTypes[tIndex]; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | if (!types.size()) { |
| 80 | continue; |
| 81 | } |
| 82 | result += "_"; |
| 83 | result += types; |
| 84 | result += "."; |
| 85 | result += gFilterFlags[fIndex]; |
| 86 | } |
| 87 | return result; |
| 88 | } |
| 89 | |
| 90 | static SkString filterTypesUsage() { |
| 91 | SkString result; |
| 92 | for (size_t index = 0; index < kFilterTypesCount; ++index) { |
| 93 | result += gFilterTypes[index]; |
| 94 | if (index < kFilterTypesCount - 1) { |
| 95 | result += " | "; |
| 96 | } |
| 97 | } |
| 98 | return result; |
| 99 | } |
| 100 | |
| 101 | static SkString filterFlagsUsage() { |
| 102 | SkString result; |
| 103 | size_t len = 0; |
| 104 | for (size_t index = 0; index < kFilterFlagsCount; ++index) { |
| 105 | result += gFilterFlags[index]; |
| 106 | if (result.size() - len >= 72) { |
| 107 | result += "\n "; |
| 108 | len = result.size(); |
| 109 | } |
| 110 | if (index < kFilterFlagsCount - 1) { |
| 111 | result += " | "; |
| 112 | } |
| 113 | } |
| 114 | return result; |
| 115 | } |
| 116 | |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 117 | static void usage(const char* argv0) { |
| 118 | SkDebugf("SkPicture benchmarking tool\n"); |
| 119 | SkDebugf("\n" |
| 120 | "Usage: \n" |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 121 | " %s <inputDir>...\n" |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 122 | " [--logFile filename][--timers [wcgWC]*][--logPerIter 1|0][--min]\n" |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 123 | " [--repeat] \n" |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 124 | " [--mode pow2tile minWidth height | record | simple\n" |
| 125 | " | tile width height | playbackCreation]\n" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 126 | " [--pipe]\n" |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 127 | " [--bbh bbhType]\n" |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 128 | " [--multi numThreads]\n" |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 129 | " [--device bitmap" |
| 130 | #if SK_SUPPORT_GPU |
| 131 | " | gpu" |
| 132 | #endif |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 133 | "]\n" |
| 134 | " [--filter [%s]:\n [%s]]\n" |
| 135 | , argv0, filterTypesUsage().c_str(), filterFlagsUsage().c_str()); |
| 136 | SkDebugf("\n"); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 137 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 138 | " 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] | 139 | " expected to have the .skp extension.\n\n" |
| 140 | " --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] | 141 | SkDebugf(" --logPerIter 1|0 : " |
| 142 | "Log each repeat timer instead of mean, default is disabled.\n"); |
| 143 | SkDebugf(" --min : Print the minimum times (instead of average).\n"); |
| 144 | SkDebugf(" --timers [wcgWC]* : " |
| 145 | "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] | 146 | SkDebugf( |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 147 | " --mode pow2tile minWidth height | copyTile width height | record | simple\n" |
| 148 | " | tile width height | playbackCreation:\n" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 149 | " Run in the corresponding mode.\n" |
| 150 | " Default is simple.\n"); |
keyar@chromium.org | cf6c44c | 2012-07-09 19:37:40 +0000 | [diff] [blame] | 151 | SkDebugf( |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 152 | " pow2tile minWidth height, Creates tiles with widths\n" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 153 | " that are all a power of two\n" |
| 154 | " such that they minimize the\n" |
| 155 | " amount of wasted tile space.\n" |
| 156 | " minWidth is the minimum width\n" |
| 157 | " of these tiles and must be a\n" |
| 158 | " power of two. Simple\n" |
| 159 | " rendering using these tiles\n" |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 160 | " is benchmarked.\n"); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 161 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 162 | " record, Benchmark picture to picture recording.\n"); |
| 163 | SkDebugf( |
| 164 | " simple, Benchmark a simple rendering.\n"); |
| 165 | SkDebugf( |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 166 | " tile width height, Benchmark simple rendering using\n" |
| 167 | " tiles with the given dimensions.\n" |
| 168 | " copyTile width height, Draw the picture, then copy it into tiles.\n" |
| 169 | " Does not support percentages.\n" |
| 170 | " If the picture is large enough, breaks it into\n" |
| 171 | " larger tiles (and draws the picture once per\n" |
| 172 | " larger tile) to avoid creating a large canvas.\n" |
| 173 | " Add --tiles x y to specify the number of tiles\n" |
| 174 | " per larger tile in the x and y direction.\n" |
| 175 | ); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 176 | SkDebugf( |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 177 | " playbackCreation, Benchmark creation of the SkPicturePlayback.\n"); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 178 | SkDebugf("\n"); |
| 179 | SkDebugf( |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 180 | " --multi numThreads : Set the number of threads for multi threaded drawing. Must be greater\n" |
| 181 | " than 1. Only works with tiled rendering.\n" |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 182 | " --pipe: Benchmark SkGPipe rendering. Currently incompatible with \"mode\".\n"); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 183 | SkDebugf( |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 184 | " --bbh bbhType [width height]: Set the bounding box hierarchy type to\n" |
| 185 | " be used. Accepted values are: none, rtree, grid. Default\n" |
| 186 | " value is none. Not compatible with --pipe. With value\n" |
| 187 | " 'grid', width and height must be specified. 'grid' can\n" |
| 188 | " only be used with modes tile, record, and\n" |
| 189 | " playbackCreation."); |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 190 | SkDebugf( |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 191 | " --device bitmap" |
| 192 | #if SK_SUPPORT_GPU |
| 193 | " | gpu" |
| 194 | #endif |
| 195 | ": Use the corresponding device. Default is bitmap.\n"); |
| 196 | SkDebugf( |
| 197 | " bitmap, Render to a bitmap.\n"); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 198 | #if SK_SUPPORT_GPU |
keyar@chromium.org | a40c20d | 2012-08-20 15:04:12 +0000 | [diff] [blame] | 199 | SkDebugf( |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 200 | " gpu, Render to the GPU.\n"); |
| 201 | #endif |
| 202 | SkDebugf("\n"); |
| 203 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 204 | " --repeat: " |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 205 | "Set the number of times to repeat each test." |
| 206 | " Default is %i.\n", DEFAULT_REPEATS); |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 207 | SkDebugf( |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 208 | " --filter type:flag : Enable canvas filtering to disable a paint flag,\n" |
| 209 | " use no blur or low quality blur, or use no hinting or\n" |
| 210 | " slight hinting. For all flags except AAClip, specify the\n" |
| 211 | " type of primitive to effect, or choose all. for AAClip\n" |
| 212 | " alone, the filter affects all clips independent of type.\n"); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 213 | } |
| 214 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 215 | SkBenchLogger gLogger; |
| 216 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 217 | static bool run_single_benchmark(const SkString& inputPath, |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 218 | sk_tools::PictureBenchmark& benchmark) { |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 219 | SkFILEStream inputStream; |
| 220 | |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 221 | inputStream.setPath(inputPath.c_str()); |
| 222 | if (!inputStream.isValid()) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 223 | SkString err; |
| 224 | err.printf("Could not open file %s\n", inputPath.c_str()); |
| 225 | gLogger.logError(err); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 226 | return false; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 227 | } |
| 228 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 229 | bool success = false; |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 230 | SkPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 231 | if (!success) { |
| 232 | SkString err; |
| 233 | err.printf("Could not read an SkPicture from %s\n", inputPath.c_str()); |
| 234 | gLogger.logError(err); |
| 235 | return false; |
| 236 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 237 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 238 | SkString filename; |
| 239 | sk_tools::get_basename(&filename, inputPath); |
keyar@chromium.org | db9a5fb | 2012-08-21 17:57:59 +0000 | [diff] [blame] | 240 | |
| 241 | SkString result; |
borenet@google.com | 2d2b9a0 | 2012-09-20 18:54:04 +0000 | [diff] [blame] | 242 | result.printf("running bench [%i %i] %s ", picture.width(), |
| 243 | picture.height(), filename.c_str()); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 244 | gLogger.logProgress(result); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 245 | |
borenet@google.com | 2d2b9a0 | 2012-09-20 18:54:04 +0000 | [diff] [blame] | 246 | benchmark.run(&picture); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 247 | return true; |
keyar@chromium.org | 0665f25 | 2012-07-10 18:30:18 +0000 | [diff] [blame] | 248 | } |
| 249 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 250 | #define PRINT_USAGE_AND_EXIT \ |
| 251 | do { \ |
| 252 | usage(argv0); \ |
| 253 | exit(-1); \ |
| 254 | } while (0) |
| 255 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 256 | 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] | 257 | sk_tools::PictureBenchmark* benchmark) { |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 258 | const char* argv0 = argv[0]; |
| 259 | char* const* stop = argv + argc; |
| 260 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 261 | int repeats = DEFAULT_REPEATS; |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 262 | sk_tools::PictureRenderer::SkDeviceTypes deviceType = |
| 263 | sk_tools::PictureRenderer::kBitmap_DeviceType; |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 264 | |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 265 | SkAutoTUnref<sk_tools::PictureRenderer> renderer(NULL); |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 266 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 267 | // Create a string to show our current settings. |
| 268 | // TODO: Make it prettier. Currently it just repeats the command line. |
| 269 | SkString commandLine("bench_pictures:"); |
| 270 | for (int i = 1; i < argc; i++) { |
| 271 | commandLine.appendf(" %s", *(argv+i)); |
| 272 | } |
| 273 | commandLine.append("\n"); |
| 274 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 275 | bool usePipe = false; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 276 | int numThreads = 1; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 277 | bool useTiles = false; |
| 278 | const char* widthString = NULL; |
| 279 | const char* heightString = NULL; |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 280 | int gridWidth = 0; |
| 281 | int gridHeight = 0; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 282 | bool isPowerOf2Mode = false; |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 283 | bool isCopyMode = false; |
| 284 | const char* xTilesString = NULL; |
| 285 | const char* yTilesString = NULL; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 286 | const char* mode = NULL; |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 287 | bool gridSupported = false; |
skia.committer@gmail.com | 1aa90cf | 2012-11-06 13:18:25 +0000 | [diff] [blame] | 288 | sk_tools::PictureRenderer::BBoxHierarchyType bbhType = |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 289 | sk_tools::PictureRenderer::kNone_BBoxHierarchyType; |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 290 | sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount]; |
| 291 | sk_bzero(drawFilters, sizeof(drawFilters)); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 292 | for (++argv; argv < stop; ++argv) { |
| 293 | if (0 == strcmp(*argv, "--repeat")) { |
| 294 | ++argv; |
| 295 | if (argv < stop) { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 296 | repeats = atoi(*argv); |
| 297 | if (repeats < 1) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 298 | gLogger.logError("--repeat must be given a value > 0\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 299 | PRINT_USAGE_AND_EXIT; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 300 | } |
| 301 | } else { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 302 | gLogger.logError("Missing arg for --repeat\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 303 | PRINT_USAGE_AND_EXIT; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 304 | } |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 305 | } else if (0 == strcmp(*argv, "--pipe")) { |
| 306 | usePipe = true; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 307 | } else if (0 == strcmp(*argv, "--logFile")) { |
| 308 | argv++; |
| 309 | if (argv < stop) { |
| 310 | if (!gLogger.SetLogFile(*argv)) { |
| 311 | SkString str; |
| 312 | str.printf("Could not open %s for writing.", *argv); |
| 313 | gLogger.logError(str); |
| 314 | usage(argv0); |
borenet@google.com | a49bffd | 2012-09-13 18:54:48 +0000 | [diff] [blame] | 315 | // TODO(borenet): We're disabling this for now, due to |
| 316 | // write-protected Android devices. The very short-term |
| 317 | // solution is to ignore the fact that we have no log file. |
| 318 | //exit(-1); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 319 | } |
| 320 | } else { |
| 321 | gLogger.logError("Missing arg for --logFile\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 322 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 323 | } |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 324 | } else if (0 == strcmp(*argv, "--multi")) { |
| 325 | ++argv; |
| 326 | if (argv >= stop) { |
| 327 | gLogger.logError("Missing arg for --multi\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 328 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 329 | } |
| 330 | numThreads = atoi(*argv); |
| 331 | if (numThreads < 2) { |
| 332 | gLogger.logError("Number of threads must be at least 2.\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 333 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 334 | } |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 335 | } else if (0 == strcmp(*argv, "--bbh")) { |
| 336 | ++argv; |
| 337 | if (argv >= stop) { |
| 338 | gLogger.logError("Missing value for --bbh\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 339 | PRINT_USAGE_AND_EXIT; |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 340 | } |
| 341 | if (0 == strcmp(*argv, "none")) { |
| 342 | bbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType; |
| 343 | } else if (0 == strcmp(*argv, "rtree")) { |
| 344 | bbhType = sk_tools::PictureRenderer::kRTree_BBoxHierarchyType; |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 345 | } else if (0 == strcmp(*argv, "grid")) { |
| 346 | bbhType = sk_tools::PictureRenderer::kTileGrid_BBoxHierarchyType; |
| 347 | ++argv; |
| 348 | if (argv >= stop) { |
| 349 | gLogger.logError("Missing width for --bbh grid\n"); |
| 350 | PRINT_USAGE_AND_EXIT; |
| 351 | } |
| 352 | gridWidth = atoi(*argv); |
| 353 | ++argv; |
| 354 | if (argv >= stop) { |
| 355 | gLogger.logError("Missing height for --bbh grid\n"); |
| 356 | PRINT_USAGE_AND_EXIT; |
| 357 | } |
| 358 | gridHeight = atoi(*argv); |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 359 | } else { |
| 360 | SkString err; |
| 361 | err.printf("%s is not a valid value for --bbhType\n", *argv); |
| 362 | gLogger.logError(err); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 363 | PRINT_USAGE_AND_EXIT; |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 364 | } |
| 365 | |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 366 | } else if (0 == strcmp(*argv, "--mode")) { |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 367 | if (renderer.get() != NULL) { |
| 368 | SkDebugf("Cannot combine modes.\n"); |
| 369 | PRINT_USAGE_AND_EXIT; |
| 370 | } |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 371 | |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 372 | ++argv; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 373 | if (argv >= stop) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 374 | gLogger.logError("Missing mode for --mode\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 375 | PRINT_USAGE_AND_EXIT; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 376 | } |
| 377 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 378 | if (0 == strcmp(*argv, "record")) { |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 379 | renderer.reset(SkNEW(sk_tools::RecordPictureRenderer)); |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 380 | gridSupported = true; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 381 | } else if (0 == strcmp(*argv, "simple")) { |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 382 | renderer.reset(SkNEW(sk_tools::SimplePictureRenderer)); |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 383 | } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile")) |
| 384 | || 0 == strcmp(*argv, "copyTile")) { |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 385 | useTiles = true; |
| 386 | mode = *argv; |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 387 | |
| 388 | if (0 == strcmp(*argv, "pow2tile")) { |
| 389 | isPowerOf2Mode = true; |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 390 | } else if (0 == strcmp(*argv, "copyTile")) { |
| 391 | isCopyMode = true; |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 392 | } else { |
| 393 | gridSupported = true; |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 394 | } |
| 395 | |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 396 | ++argv; |
| 397 | if (argv >= stop) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 398 | SkString err; |
| 399 | err.printf("Missing width for --mode %s\n", mode); |
| 400 | gLogger.logError(err); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 401 | PRINT_USAGE_AND_EXIT; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 402 | } |
| 403 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 404 | widthString = *argv; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 405 | ++argv; |
| 406 | if (argv >= stop) { |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 407 | SkString err; |
| 408 | err.appendf("Missing height for --mode %s\n", mode); |
| 409 | gLogger.logError(err); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 410 | PRINT_USAGE_AND_EXIT; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 411 | } |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 412 | heightString = *argv; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 413 | } else if (0 == strcmp(*argv, "playbackCreation")) { |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 414 | renderer.reset(SkNEW(sk_tools::PlaybackCreationRenderer)); |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 415 | gridSupported = true; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 416 | } else { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 417 | SkString err; |
| 418 | err.printf("%s is not a valid mode for --mode\n", *argv); |
| 419 | gLogger.logError(err); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 420 | PRINT_USAGE_AND_EXIT; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 421 | } |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 422 | } else if (0 == strcmp(*argv, "--tiles")) { |
| 423 | ++argv; |
| 424 | if (argv >= stop) { |
| 425 | gLogger.logError("Missing x for --tiles\n"); |
| 426 | PRINT_USAGE_AND_EXIT; |
| 427 | } |
| 428 | xTilesString = *argv; |
| 429 | ++argv; |
| 430 | if (argv >= stop) { |
| 431 | gLogger.logError("Missing y for --tiles\n"); |
| 432 | PRINT_USAGE_AND_EXIT; |
| 433 | } |
| 434 | yTilesString = *argv; |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 435 | } else if (0 == strcmp(*argv, "--device")) { |
| 436 | ++argv; |
| 437 | if (argv >= stop) { |
borenet@google.com | a49bffd | 2012-09-13 18:54:48 +0000 | [diff] [blame] | 438 | gLogger.logError("Missing mode for --device\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 439 | PRINT_USAGE_AND_EXIT; |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | if (0 == strcmp(*argv, "bitmap")) { |
| 443 | deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType; |
| 444 | } |
| 445 | #if SK_SUPPORT_GPU |
| 446 | else if (0 == strcmp(*argv, "gpu")) { |
| 447 | deviceType = sk_tools::PictureRenderer::kGPU_DeviceType; |
| 448 | } |
| 449 | #endif |
| 450 | else { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 451 | SkString err; |
| 452 | err.printf("%s is not a valid mode for --device\n", *argv); |
| 453 | gLogger.logError(err); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 454 | PRINT_USAGE_AND_EXIT; |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 455 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 456 | } else if (0 == strcmp(*argv, "--timers")) { |
| 457 | ++argv; |
| 458 | if (argv < stop) { |
| 459 | bool timerWall = false; |
| 460 | bool truncatedTimerWall = false; |
| 461 | bool timerCpu = false; |
| 462 | bool truncatedTimerCpu = false; |
| 463 | bool timerGpu = false; |
| 464 | for (char* t = *argv; *t; ++t) { |
| 465 | switch (*t) { |
| 466 | case 'w': |
| 467 | timerWall = true; |
| 468 | break; |
| 469 | case 'c': |
| 470 | timerCpu = true; |
| 471 | break; |
| 472 | case 'W': |
| 473 | truncatedTimerWall = true; |
| 474 | break; |
| 475 | case 'C': |
| 476 | truncatedTimerCpu = true; |
| 477 | break; |
| 478 | case 'g': |
| 479 | timerGpu = true; |
| 480 | break; |
| 481 | default: { |
| 482 | break; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, |
| 487 | truncatedTimerCpu, timerGpu); |
| 488 | } else { |
| 489 | gLogger.logError("Missing arg for --timers\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 490 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 491 | } |
| 492 | } else if (0 == strcmp(*argv, "--min")) { |
| 493 | benchmark->setPrintMin(true); |
| 494 | } else if (0 == strcmp(*argv, "--logPerIter")) { |
| 495 | ++argv; |
| 496 | if (argv < stop) { |
| 497 | bool log = atoi(*argv) != 0; |
| 498 | benchmark->setLogPerIter(log); |
| 499 | } else { |
| 500 | gLogger.logError("Missing arg for --logPerIter\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 501 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 502 | } |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 503 | } else if (0 == strcmp(*argv, "--filter")) { |
| 504 | ++argv; |
| 505 | if (argv < stop) { |
| 506 | const char* colon = strchr(*argv, ':'); |
| 507 | if (colon) { |
| 508 | int type = -1; |
| 509 | size_t typeLen = colon - *argv; |
| 510 | for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) { |
| 511 | if (typeLen == strlen(gFilterTypes[tIndex]) |
| 512 | && !strncmp(*argv, gFilterTypes[tIndex], typeLen)) { |
| 513 | type = tIndex; |
| 514 | break; |
| 515 | } |
| 516 | } |
| 517 | if (type < 0) { |
| 518 | SkString err; |
| 519 | err.printf("Unknown type for --filter %s\n", *argv); |
| 520 | gLogger.logError(err); |
| 521 | PRINT_USAGE_AND_EXIT; |
| 522 | } |
| 523 | int flag = -1; |
| 524 | size_t flagLen = strlen(*argv) - typeLen - 1; |
| 525 | for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) { |
| 526 | if (flagLen == strlen(gFilterFlags[fIndex]) |
| 527 | && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) { |
| 528 | flag = 1 << fIndex; |
| 529 | break; |
| 530 | } |
| 531 | } |
| 532 | if (flag < 0) { |
| 533 | SkString err; |
| 534 | err.printf("Unknown flag for --filter %s\n", *argv); |
| 535 | gLogger.logError(err); |
| 536 | PRINT_USAGE_AND_EXIT; |
| 537 | } |
| 538 | for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) { |
| 539 | if (type != SkDrawFilter::kTypeCount && index != type) { |
| 540 | continue; |
| 541 | } |
| 542 | drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags) |
| 543 | (drawFilters[index] | flag); |
| 544 | } |
| 545 | } else { |
| 546 | SkString err; |
| 547 | err.printf("Unknown arg for --filter %s : missing colon\n", *argv); |
| 548 | gLogger.logError(err); |
| 549 | PRINT_USAGE_AND_EXIT; |
| 550 | } |
| 551 | } else { |
| 552 | gLogger.logError("Missing arg for --filter\n"); |
| 553 | PRINT_USAGE_AND_EXIT; |
| 554 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 555 | } else if (0 == strcmp(*argv, "--help") || 0 == strcmp(*argv, "-h")) { |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 556 | PRINT_USAGE_AND_EXIT; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 557 | } else { |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 558 | inputs->push_back(SkString(*argv)); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 562 | if (numThreads > 1 && !useTiles) { |
| 563 | gLogger.logError("Multithreaded drawing requires tiled rendering.\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 564 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 565 | } |
| 566 | |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 567 | if (usePipe && sk_tools::PictureRenderer::kNone_BBoxHierarchyType != bbhType) { |
| 568 | gLogger.logError("--pipe and --bbh cannot be used together\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 569 | PRINT_USAGE_AND_EXIT; |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 570 | } |
| 571 | |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 572 | if (sk_tools::PictureRenderer::kTileGrid_BBoxHierarchyType == bbhType && |
| 573 | !gridSupported) { |
| 574 | gLogger.logError("'--bbh grid' is not compatible with specified --mode.\n"); |
| 575 | PRINT_USAGE_AND_EXIT; |
| 576 | } |
| 577 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 578 | if (useTiles) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 579 | SkASSERT(NULL == renderer); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 580 | sk_tools::TiledPictureRenderer* tiledRenderer; |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 581 | if (isCopyMode) { |
| 582 | int x, y; |
| 583 | if (xTilesString != NULL) { |
| 584 | SkASSERT(yTilesString != NULL); |
| 585 | x = atoi(xTilesString); |
| 586 | y = atoi(yTilesString); |
| 587 | if (x <= 0 || y <= 0) { |
| 588 | gLogger.logError("--tiles must be given values > 0\n"); |
| 589 | PRINT_USAGE_AND_EXIT; |
| 590 | } |
| 591 | } else { |
| 592 | x = y = 4; |
| 593 | } |
| 594 | tiledRenderer = SkNEW_ARGS(sk_tools::CopyTilesRenderer, (x, y)); |
| 595 | } else if (numThreads > 1) { |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 596 | tiledRenderer = SkNEW_ARGS(sk_tools::MultiCorePictureRenderer, (numThreads)); |
| 597 | } else { |
| 598 | tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer); |
| 599 | } |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 600 | if (isPowerOf2Mode) { |
| 601 | int minWidth = atoi(widthString); |
| 602 | if (!SkIsPow2(minWidth) || minWidth < 0) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 603 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 604 | SkString err; |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 605 | err.printf("-mode %s must be given a width" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 606 | " value that is a power of two\n", mode); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 607 | gLogger.logError(err); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 608 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 609 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 610 | tiledRenderer->setTileMinPowerOf2Width(minWidth); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 611 | } else if (sk_tools::is_percentage(widthString)) { |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 612 | if (isCopyMode) { |
| 613 | tiledRenderer->unref(); |
| 614 | SkString err; |
| 615 | err.printf("--mode %s does not support percentages.\n", mode); |
| 616 | gLogger.logError(err.c_str()); |
| 617 | PRINT_USAGE_AND_EXIT; |
| 618 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 619 | tiledRenderer->setTileWidthPercentage(atof(widthString)); |
| 620 | if (!(tiledRenderer->getTileWidthPercentage() > 0)) { |
| 621 | tiledRenderer->unref(); |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 622 | SkString err; |
| 623 | err.appendf("--mode %s must be given a width percentage > 0\n", mode); |
| 624 | gLogger.logError(err); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 625 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 626 | } |
| 627 | } else { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 628 | tiledRenderer->setTileWidth(atoi(widthString)); |
| 629 | if (!(tiledRenderer->getTileWidth() > 0)) { |
| 630 | tiledRenderer->unref(); |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 631 | SkString err; |
| 632 | err.appendf("--mode %s must be given a width > 0\n", mode); |
| 633 | gLogger.logError(err); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 634 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
| 638 | if (sk_tools::is_percentage(heightString)) { |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 639 | if (isCopyMode) { |
| 640 | tiledRenderer->unref(); |
| 641 | SkString err; |
| 642 | err.printf("--mode %s does not support percentages.\n", mode); |
| 643 | gLogger.logError(err.c_str()); |
| 644 | PRINT_USAGE_AND_EXIT; |
| 645 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 646 | tiledRenderer->setTileHeightPercentage(atof(heightString)); |
| 647 | if (!(tiledRenderer->getTileHeightPercentage() > 0)) { |
| 648 | tiledRenderer->unref(); |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 649 | SkString err; |
| 650 | err.appendf("--mode %s must be given a height percentage > 0\n", mode); |
| 651 | gLogger.logError(err); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 652 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 653 | } |
| 654 | } else { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 655 | tiledRenderer->setTileHeight(atoi(heightString)); |
| 656 | if (!(tiledRenderer->getTileHeight() > 0)) { |
| 657 | tiledRenderer->unref(); |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 658 | SkString err; |
| 659 | err.appendf("--mode %s must be given a height > 0\n", mode); |
| 660 | gLogger.logError(err); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 661 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 662 | } |
| 663 | } |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 664 | if (numThreads > 1) { |
| 665 | #if SK_SUPPORT_GPU |
| 666 | if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) { |
| 667 | tiledRenderer->unref(); |
| 668 | gLogger.logError("GPU not compatible with multithreaded tiling.\n"); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 669 | PRINT_USAGE_AND_EXIT; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 670 | } |
| 671 | #endif |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 672 | } |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 673 | renderer.reset(tiledRenderer); |
| 674 | if (usePipe) { |
| 675 | SkDebugf("Pipe rendering is currently not compatible with tiling.\n" |
| 676 | "Turning off pipe.\n"); |
| 677 | } |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 678 | } else if (usePipe) { |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 679 | if (renderer.get() != NULL) { |
| 680 | SkDebugf("Pipe is incompatible with other modes.\n"); |
| 681 | PRINT_USAGE_AND_EXIT; |
| 682 | } |
| 683 | renderer.reset(SkNEW(sk_tools::PipePictureRenderer)); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 684 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 685 | if (inputs->count() < 1) { |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 686 | PRINT_USAGE_AND_EXIT; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 687 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 688 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 689 | if (NULL == renderer) { |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 690 | renderer.reset(SkNEW(sk_tools::SimplePictureRenderer)); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 691 | } |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 692 | |
| 693 | renderer->setBBoxHierarchyType(bbhType); |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 694 | renderer->setDrawFilters(drawFilters, filtersName(drawFilters)); |
junov@chromium.org | 7b53706 | 2012-11-06 18:58:43 +0000 | [diff] [blame] | 695 | renderer->setGridSize(gridWidth, gridHeight); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 696 | benchmark->setRenderer(renderer); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 697 | benchmark->setRepeats(repeats); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 698 | benchmark->setDeviceType(deviceType); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 699 | benchmark->setLogger(&gLogger); |
| 700 | // Report current settings: |
| 701 | gLogger.logProgress(commandLine); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 702 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 703 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 704 | static int process_input(const SkString& input, |
| 705 | sk_tools::PictureBenchmark& benchmark) { |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 706 | SkOSFile::Iter iter(input.c_str(), "skp"); |
| 707 | SkString inputFilename; |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 708 | int failures = 0; |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 709 | if (iter.next(&inputFilename)) { |
| 710 | do { |
| 711 | SkString inputPath; |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 712 | sk_tools::make_filepath(&inputPath, input, inputFilename); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 713 | if (!run_single_benchmark(inputPath, benchmark)) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 714 | ++failures; |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 715 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 716 | } while(iter.next(&inputFilename)); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 717 | } else if (SkStrEndsWith(input.c_str(), ".skp")) { |
| 718 | if (!run_single_benchmark(input, benchmark)) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 719 | ++failures; |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 720 | } |
| 721 | } else { |
| 722 | SkString warning; |
| 723 | warning.printf("Warning: skipping %s\n", input.c_str()); |
| 724 | gLogger.logError(warning); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 725 | } |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 726 | return failures; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 727 | } |
| 728 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 729 | int tool_main(int argc, char** argv); |
| 730 | int tool_main(int argc, char** argv) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 731 | #ifdef SK_ENABLE_INST_COUNT |
| 732 | gPrintInstCount = true; |
| 733 | #endif |
scroggo@google.com | 0a36f43 | 2012-09-10 20:29:13 +0000 | [diff] [blame] | 734 | SkAutoGraphics ag; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 735 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 736 | SkTArray<SkString> inputs; |
| 737 | sk_tools::PictureBenchmark benchmark; |
| 738 | |
| 739 | parse_commandline(argc, argv, &inputs, &benchmark); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 740 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 741 | int failures = 0; |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 742 | for (int i = 0; i < inputs.count(); ++i) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 743 | failures += process_input(inputs[i], benchmark); |
| 744 | } |
| 745 | |
| 746 | if (failures != 0) { |
| 747 | SkString err; |
| 748 | err.printf("Failed to run %i benchmarks.\n", failures); |
| 749 | gLogger.logError(err); |
| 750 | return 1; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 751 | } |
caryclark@google.com | 868e1f6 | 2012-10-02 20:00:03 +0000 | [diff] [blame] | 752 | return 0; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 753 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 754 | |
| 755 | #if !defined SK_BUILD_FOR_IOS |
| 756 | int main(int argc, char * const argv[]) { |
| 757 | return tool_main(argc, (char**) argv); |
| 758 | } |
| 759 | #endif |