junov@chromium.org | 777442d | 2012-06-12 14:56:36 +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 | |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 8 | #include "SkBitmap.h" |
| 9 | #include "SkCanvas.h" |
keyar@chromium.org | 472b379 | 2012-07-20 22:34:27 +0000 | [diff] [blame] | 10 | #include "SkDevice.h" |
borenet@google.com | 10ef79e | 2012-09-10 17:19:06 +0000 | [diff] [blame] | 11 | #include "SkGraphics.h" |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 12 | #include "SkImageDecoder.h" |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 13 | #include "SkMath.h" |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 14 | #include "SkOSFile.h" |
| 15 | #include "SkPicture.h" |
| 16 | #include "SkStream.h" |
| 17 | #include "SkString.h" |
senorblanco@chromium.org | 3cbbb54 | 2012-07-13 18:55:53 +0000 | [diff] [blame] | 18 | #include "SkTArray.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 19 | #include "PictureRenderer.h" |
twiz@google.com | a31b8bb | 2012-06-22 18:24:56 +0000 | [diff] [blame] | 20 | #include "picture_utils.h" |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 21 | |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 22 | static void usage(const char* argv0) { |
| 23 | SkDebugf("SkPicture rendering tool\n"); |
| 24 | SkDebugf("\n" |
| 25 | "Usage: \n" |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 26 | " %s <input>... \n" |
| 27 | " [-w <outputDir>]" |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 28 | " [--mode pow2tile minWidth height[%] | simple\n" |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 29 | " | tile width[%] height[%]]\n" |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 30 | " [--pipe]\n" |
| 31 | " [--multi count]\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 | "]" |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 37 | , argv0); |
keyar@chromium.org | 472b379 | 2012-07-20 22:34:27 +0000 | [diff] [blame] | 38 | SkDebugf("\n\n"); |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 39 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 40 | " input: A list of directories and files to use as input. Files are\n" |
| 41 | " expected to have the .skp extension.\n\n"); |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 42 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 43 | " outputDir: directory to write the rendered images.\n\n"); |
keyar@chromium.org | 472b379 | 2012-07-20 22:34:27 +0000 | [diff] [blame] | 44 | SkDebugf( |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 45 | " --mode pow2tile minWidth height[%] | simple\n" |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 46 | " | tile width[%] height[%]: Run in the corresponding mode.\n" |
| 47 | " Default is simple.\n"); |
keyar@chromium.org | 472b379 | 2012-07-20 22:34:27 +0000 | [diff] [blame] | 48 | SkDebugf( |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 49 | " pow2tile minWidth height[%], Creates tiles with widths\n" |
| 50 | " that are all a power of two\n" |
| 51 | " such that they minimize the\n" |
| 52 | " amount of wasted tile space.\n" |
| 53 | " minWidth is the minimum width\n" |
| 54 | " of these tiles and must be a\n" |
| 55 | " power of two. A simple render\n" |
| 56 | " is done with these tiles.\n"); |
| 57 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 58 | " simple, Render using the default rendering method.\n"); |
| 59 | SkDebugf( |
| 60 | " tile width[%] height[%], Do a simple render using tiles\n" |
| 61 | " with the given dimensions.\n"); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 62 | SkDebugf("\n"); |
| 63 | SkDebugf( |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 64 | " --multi count : Set the number of threads for multi threaded drawing. Must be greater\n" |
| 65 | " than 1. Only works with tiled rendering.\n" |
| 66 | " --pipe: Benchmark SkGPipe rendering. Compatible with tiled, multithreaded rendering.\n"); |
| 67 | SkDebugf( |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 68 | " --device bitmap" |
| 69 | #if SK_SUPPORT_GPU |
| 70 | " | gpu" |
| 71 | #endif |
| 72 | ": Use the corresponding device. Default is bitmap.\n"); |
| 73 | SkDebugf( |
| 74 | " bitmap, Render to a bitmap.\n"); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 75 | #if SK_SUPPORT_GPU |
keyar@chromium.org | a40c20d | 2012-08-20 15:04:12 +0000 | [diff] [blame] | 76 | SkDebugf( |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 77 | " gpu, Render to the GPU.\n"); |
| 78 | #endif |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 79 | } |
| 80 | |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 81 | static void make_output_filepath(SkString* path, const SkString& dir, |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 82 | const SkString& name) { |
twiz@google.com | a31b8bb | 2012-06-22 18:24:56 +0000 | [diff] [blame] | 83 | sk_tools::make_filepath(path, dir, name); |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 84 | // Remove ".skp" |
| 85 | path->remove(path->size() - 4, 4); |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 86 | } |
| 87 | |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 88 | static bool render_picture(const SkString& inputPath, const SkString* outputDir, |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 89 | sk_tools::PictureRenderer& renderer) { |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 90 | SkString inputFilename; |
| 91 | sk_tools::get_basename(&inputFilename, inputPath); |
twiz@google.com | a31b8bb | 2012-06-22 18:24:56 +0000 | [diff] [blame] | 92 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 93 | SkFILEStream inputStream; |
twiz@google.com | a31b8bb | 2012-06-22 18:24:56 +0000 | [diff] [blame] | 94 | inputStream.setPath(inputPath.c_str()); |
| 95 | if (!inputStream.isValid()) { |
| 96 | SkDebugf("Could not open file %s\n", inputPath.c_str()); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 97 | return false; |
twiz@google.com | a31b8bb | 2012-06-22 18:24:56 +0000 | [diff] [blame] | 98 | } |
| 99 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 100 | bool success = false; |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 101 | SkPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 102 | if (!success) { |
| 103 | SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str()); |
| 104 | return false; |
| 105 | } |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 106 | |
borenet@google.com | 2d2b9a0 | 2012-09-20 18:54:04 +0000 | [diff] [blame] | 107 | SkDebugf("drawing... [%i %i] %s\n", picture.width(), picture.height(), |
borenet@google.com | 03fcee8 | 2012-09-10 18:18:38 +0000 | [diff] [blame] | 108 | inputPath.c_str()); |
skia.committer@gmail.com | 1d225f2 | 2012-09-14 02:01:10 +0000 | [diff] [blame] | 109 | |
borenet@google.com | 2d2b9a0 | 2012-09-20 18:54:04 +0000 | [diff] [blame] | 110 | renderer.init(&picture); |
scroggo@google.com | b4773b4 | 2012-10-01 20:06:09 +0000 | [diff] [blame] | 111 | renderer.setup(); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 112 | |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 113 | SkString* outputPath = NULL; |
| 114 | if (NULL != outputDir) { |
| 115 | outputPath = SkNEW(SkString); |
| 116 | make_output_filepath(outputPath, *outputDir, inputFilename); |
| 117 | } |
| 118 | success = renderer.render(outputPath); |
| 119 | if (outputPath) { |
| 120 | if (!success) { |
| 121 | SkDebugf("Could not write to file %s\n", outputPath->c_str()); |
| 122 | } |
| 123 | SkDELETE(outputPath); |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 124 | } |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 125 | |
| 126 | renderer.resetState(); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 127 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 128 | renderer.end(); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 129 | return success; |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 130 | } |
| 131 | |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 132 | static int process_input(const SkString& input, const SkString* outputDir, |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 133 | sk_tools::PictureRenderer& renderer) { |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 134 | SkOSFile::Iter iter(input.c_str(), "skp"); |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 135 | SkString inputFilename; |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 136 | int failures = 0; |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 137 | SkDebugf("process_input, %s\n", input.c_str()); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 138 | if (iter.next(&inputFilename)) { |
| 139 | do { |
| 140 | SkString inputPath; |
| 141 | sk_tools::make_filepath(&inputPath, input, inputFilename); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 142 | if (!render_picture(inputPath, outputDir, renderer)) { |
| 143 | ++failures; |
| 144 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 145 | } while(iter.next(&inputFilename)); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 146 | } else if (SkStrEndsWith(input.c_str(), ".skp")) { |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 147 | SkString inputPath(input); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 148 | if (!render_picture(inputPath, outputDir, renderer)) { |
| 149 | ++failures; |
| 150 | } |
| 151 | } else { |
| 152 | SkString warning; |
| 153 | warning.printf("Warning: skipping %s\n", input.c_str()); |
| 154 | SkDebugf(warning.c_str()); |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 155 | } |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 156 | return failures; |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs, |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 160 | sk_tools::PictureRenderer*& renderer, SkString*& outputDir){ |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 161 | const char* argv0 = argv[0]; |
| 162 | char* const* stop = argv + argc; |
| 163 | |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 164 | sk_tools::PictureRenderer::SkDeviceTypes deviceType = |
| 165 | sk_tools::PictureRenderer::kBitmap_DeviceType; |
| 166 | |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 167 | bool usePipe = false; |
| 168 | int numThreads = 1; |
| 169 | bool useTiles = false; |
| 170 | const char* widthString = NULL; |
| 171 | const char* heightString = NULL; |
| 172 | bool isPowerOf2Mode = false; |
| 173 | const char* mode = NULL; |
| 174 | |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 175 | for (++argv; argv < stop; ++argv) { |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 176 | if (0 == strcmp(*argv, "--mode")) { |
| 177 | SkDELETE(renderer); |
| 178 | |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 179 | ++argv; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 180 | if (argv >= stop) { |
| 181 | SkDebugf("Missing mode for --mode\n"); |
| 182 | usage(argv0); |
| 183 | exit(-1); |
| 184 | } |
| 185 | |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 186 | if (0 == strcmp(*argv, "simple")) { |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 187 | renderer = SkNEW(sk_tools::SimplePictureRenderer); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 188 | } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))) { |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 189 | useTiles = true; |
| 190 | mode = *argv; |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 191 | |
| 192 | if (0 == strcmp(*argv, "pow2tile")) { |
| 193 | isPowerOf2Mode = true; |
| 194 | } |
| 195 | |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 196 | ++argv; |
| 197 | if (argv >= stop) { |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 198 | SkDebugf("Missing width for --mode %s\n", mode); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 199 | usage(argv0); |
| 200 | exit(-1); |
| 201 | } |
| 202 | |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 203 | widthString = *argv; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 204 | ++argv; |
| 205 | if (argv >= stop) { |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 206 | SkDebugf("Missing height for --mode tile\n"); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 207 | usage(argv0); |
| 208 | exit(-1); |
| 209 | } |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 210 | heightString = *argv; |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 211 | } else { |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 212 | SkDebugf("%s is not a valid mode for --mode\n", *argv); |
keyar@chromium.org | cc6e5ef | 2012-07-27 20:09:26 +0000 | [diff] [blame] | 213 | usage(argv0); |
| 214 | exit(-1); |
| 215 | } |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 216 | } else if (0 == strcmp(*argv, "--pipe")) { |
| 217 | usePipe = true; |
| 218 | } else if (0 == strcmp(*argv, "--multi")) { |
| 219 | ++argv; |
| 220 | if (argv >= stop) { |
| 221 | SkDebugf("Missing arg for --multi\n"); |
| 222 | usage(argv0); |
| 223 | exit(-1); |
| 224 | } |
| 225 | numThreads = atoi(*argv); |
| 226 | if (numThreads < 2) { |
| 227 | SkDebugf("Number of threads must be at least 2.\n"); |
| 228 | usage(argv0); |
| 229 | exit(-1); |
| 230 | } |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 231 | } else if (0 == strcmp(*argv, "--device")) { |
| 232 | ++argv; |
| 233 | if (argv >= stop) { |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 234 | SkDebugf("Missing mode for --device\n"); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 235 | usage(argv0); |
| 236 | exit(-1); |
| 237 | } |
| 238 | |
| 239 | if (0 == strcmp(*argv, "bitmap")) { |
| 240 | deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType; |
| 241 | } |
| 242 | #if SK_SUPPORT_GPU |
| 243 | else if (0 == strcmp(*argv, "gpu")) { |
| 244 | deviceType = sk_tools::PictureRenderer::kGPU_DeviceType; |
| 245 | } |
| 246 | #endif |
| 247 | else { |
| 248 | SkDebugf("%s is not a valid mode for --device\n", *argv); |
| 249 | usage(argv0); |
| 250 | exit(-1); |
| 251 | } |
| 252 | |
keyar@chromium.org | 472b379 | 2012-07-20 22:34:27 +0000 | [diff] [blame] | 253 | } else if ((0 == strcmp(*argv, "-h")) || (0 == strcmp(*argv, "--help"))) { |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 254 | SkDELETE(renderer); |
keyar@chromium.org | 472b379 | 2012-07-20 22:34:27 +0000 | [diff] [blame] | 255 | usage(argv0); |
| 256 | exit(-1); |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 257 | } else if (0 == strcmp(*argv, "-w")) { |
| 258 | ++argv; |
| 259 | if (argv >= stop) { |
| 260 | SkDebugf("Missing output directory for -w\n"); |
| 261 | usage(argv0); |
| 262 | exit(-1); |
| 263 | } |
| 264 | outputDir = SkNEW_ARGS(SkString, (*argv)); |
keyar@chromium.org | a2333d9 | 2012-07-16 17:29:16 +0000 | [diff] [blame] | 265 | } else { |
| 266 | inputs->push_back(SkString(*argv)); |
| 267 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 268 | } |
keyar@chromium.org | 472b379 | 2012-07-20 22:34:27 +0000 | [diff] [blame] | 269 | |
scroggo@google.com | b6e806b | 2012-10-03 17:32:33 +0000 | [diff] [blame] | 270 | if (numThreads > 1 && !useTiles) { |
| 271 | SkDebugf("Multithreaded drawing requires tiled rendering.\n"); |
| 272 | usage(argv0); |
| 273 | exit(-1); |
| 274 | } |
| 275 | |
| 276 | if (useTiles) { |
| 277 | SkASSERT(NULL == renderer); |
| 278 | sk_tools::TiledPictureRenderer* tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer); |
| 279 | if (isPowerOf2Mode) { |
| 280 | int minWidth = atoi(widthString); |
| 281 | if (!SkIsPow2(minWidth) || minWidth < 0) { |
| 282 | tiledRenderer->unref(); |
| 283 | SkString err; |
| 284 | err.printf("-mode %s must be given a width" |
| 285 | " value that is a power of two\n", mode); |
| 286 | SkDebugf(err.c_str()); |
| 287 | usage(argv0); |
| 288 | exit(-1); |
| 289 | } |
| 290 | tiledRenderer->setTileMinPowerOf2Width(minWidth); |
| 291 | } else if (sk_tools::is_percentage(widthString)) { |
| 292 | tiledRenderer->setTileWidthPercentage(atof(widthString)); |
| 293 | if (!(tiledRenderer->getTileWidthPercentage() > 0)) { |
| 294 | tiledRenderer->unref(); |
| 295 | SkDebugf("--mode tile must be given a width percentage > 0\n"); |
| 296 | usage(argv0); |
| 297 | exit(-1); |
| 298 | } |
| 299 | } else { |
| 300 | tiledRenderer->setTileWidth(atoi(widthString)); |
| 301 | if (!(tiledRenderer->getTileWidth() > 0)) { |
| 302 | tiledRenderer->unref(); |
| 303 | SkDebugf("--mode tile must be given a width > 0\n"); |
| 304 | usage(argv0); |
| 305 | exit(-1); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | if (sk_tools::is_percentage(heightString)) { |
| 310 | tiledRenderer->setTileHeightPercentage(atof(heightString)); |
| 311 | if (!(tiledRenderer->getTileHeightPercentage() > 0)) { |
| 312 | tiledRenderer->unref(); |
| 313 | SkDebugf("--mode tile must be given a height percentage > 0\n"); |
| 314 | usage(argv0); |
| 315 | exit(-1); |
| 316 | } |
| 317 | } else { |
| 318 | tiledRenderer->setTileHeight(atoi(heightString)); |
| 319 | if (!(tiledRenderer->getTileHeight() > 0)) { |
| 320 | tiledRenderer->unref(); |
| 321 | SkDebugf("--mode tile must be given a height > 0\n"); |
| 322 | usage(argv0); |
| 323 | exit(-1); |
| 324 | } |
| 325 | } |
| 326 | if (numThreads > 1) { |
| 327 | #if SK_SUPPORT_GPU |
| 328 | if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) { |
| 329 | tiledRenderer->unref(); |
| 330 | SkDebugf("GPU not compatible with multithreaded tiling.\n"); |
| 331 | usage(argv0); |
| 332 | exit(-1); |
| 333 | } |
| 334 | #endif |
| 335 | tiledRenderer->setNumberOfThreads(numThreads); |
| 336 | } |
| 337 | tiledRenderer->setUsePipe(usePipe); |
| 338 | renderer = tiledRenderer; |
| 339 | } else if (usePipe) { |
| 340 | renderer = SkNEW(sk_tools::PipePictureRenderer); |
| 341 | } |
| 342 | |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 343 | if (inputs->empty()) { |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 344 | SkDELETE(renderer); |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 345 | if (NULL != outputDir) { |
| 346 | SkDELETE(outputDir); |
| 347 | } |
keyar@chromium.org | 472b379 | 2012-07-20 22:34:27 +0000 | [diff] [blame] | 348 | usage(argv0); |
| 349 | exit(-1); |
| 350 | } |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 351 | |
| 352 | if (NULL == renderer) { |
| 353 | renderer = SkNEW(sk_tools::SimplePictureRenderer); |
| 354 | } |
keyar@chromium.org | 4ea96c5 | 2012-08-20 15:03:29 +0000 | [diff] [blame] | 355 | |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 356 | renderer->setDeviceType(deviceType); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 357 | } |
| 358 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 359 | int tool_main(int argc, char** argv); |
| 360 | int tool_main(int argc, char** argv) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 361 | SkAutoGraphics ag; |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 362 | SkTArray<SkString> inputs; |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 363 | sk_tools::PictureRenderer* renderer = NULL; |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 364 | SkString* outputDir = NULL; |
| 365 | parse_commandline(argc, argv, &inputs, renderer, outputDir); |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 366 | SkASSERT(renderer); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 367 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 368 | int failures = 0; |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 369 | for (int i = 0; i < inputs.count(); i ++) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 370 | failures += process_input(inputs[i], outputDir, *renderer); |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 371 | } |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 372 | if (failures != 0) { |
| 373 | SkDebugf("Failed to render %i pictures.\n", failures); |
| 374 | return 1; |
| 375 | } |
robertphillips@google.com | 163c84b | 2012-09-13 15:40:37 +0000 | [diff] [blame] | 376 | #if SK_SUPPORT_GPU |
| 377 | #if GR_CACHE_STATS |
| 378 | if (renderer->isUsingGpuDevice()) { |
| 379 | GrContext* ctx = renderer->getGrContext(); |
| 380 | |
| 381 | ctx->printCacheStats(); |
| 382 | } |
| 383 | #endif |
| 384 | #endif |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame^] | 385 | if (NULL != outputDir) { |
| 386 | SkDELETE(outputDir); |
| 387 | } |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 388 | SkDELETE(renderer); |
caryclark@google.com | 868e1f6 | 2012-10-02 20:00:03 +0000 | [diff] [blame] | 389 | return 0; |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 390 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 391 | |
| 392 | #if !defined SK_BUILD_FOR_IOS |
| 393 | int main(int argc, char * const argv[]) { |
| 394 | return tool_main(argc, (char**) argv); |
| 395 | } |
| 396 | #endif |