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