blob: 250058e80abfee700b2c72c747193ab3cff0cb07 [file] [log] [blame]
junov@chromium.org777442d2012-06-12 14:56:36 +00001/*
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
scroggo@google.com4a26d9d2012-11-07 18:01:46 +00008#include "CopyTilesRenderer.h"
junov@chromium.org777442d2012-06-12 14:56:36 +00009#include "SkBitmap.h"
10#include "SkCanvas.h"
keyar@chromium.org472b3792012-07-20 22:34:27 +000011#include "SkDevice.h"
borenet@google.com10ef79e2012-09-10 17:19:06 +000012#include "SkGraphics.h"
scroggo@google.com5a7c6be2012-10-04 21:46:08 +000013#include "SkImageDecoder.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000014#include "SkMath.h"
junov@chromium.org777442d2012-06-12 14:56:36 +000015#include "SkOSFile.h"
16#include "SkPicture.h"
17#include "SkStream.h"
18#include "SkString.h"
senorblanco@chromium.org3cbbb542012-07-13 18:55:53 +000019#include "SkTArray.h"
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000020#include "PictureRenderer.h"
twiz@google.coma31b8bb2012-06-22 18:24:56 +000021#include "picture_utils.h"
junov@chromium.org777442d2012-06-12 14:56:36 +000022
junov@chromium.org777442d2012-06-12 14:56:36 +000023static void usage(const char* argv0) {
24 SkDebugf("SkPicture rendering tool\n");
25 SkDebugf("\n"
26"Usage: \n"
borenet@google.com070d3542012-10-26 13:26:55 +000027" %s <input>... \n"
scroggo@google.com4a26d9d2012-11-07 18:01:46 +000028" [-w <outputDir>]\n"
29" [--mode pow2tile minWidth height | copyTile width height | simple\n"
30" | tile width height]\n"
scroggo@google.comb6e806b2012-10-03 17:32:33 +000031" [--pipe]\n"
32" [--multi count]\n"
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000033" [--device bitmap"
34#if SK_SUPPORT_GPU
35" | gpu"
36#endif
37"]"
junov@chromium.org777442d2012-06-12 14:56:36 +000038, argv0);
keyar@chromium.org472b3792012-07-20 22:34:27 +000039 SkDebugf("\n\n");
junov@chromium.org777442d2012-06-12 14:56:36 +000040 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000041" input: A list of directories and files to use as input. Files are\n"
42" expected to have the .skp extension.\n\n");
junov@chromium.org777442d2012-06-12 14:56:36 +000043 SkDebugf(
keyar@chromium.org795cd472012-08-02 18:57:53 +000044" outputDir: directory to write the rendered images.\n\n");
keyar@chromium.org472b3792012-07-20 22:34:27 +000045 SkDebugf(
scroggo@google.com4a26d9d2012-11-07 18:01:46 +000046" --mode pow2tile minWidth height | copyTile width height | simple\n"
47" | tile width height | rerecord: Run in the corresponding mode.\n"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000048" Default is simple.\n");
keyar@chromium.org472b3792012-07-20 22:34:27 +000049 SkDebugf(
scroggo@google.com4a26d9d2012-11-07 18:01:46 +000050" pow2tile minWidth height, Creates tiles with widths\n"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000051" that are all a power of two\n"
52" such that they minimize the\n"
53" amount of wasted tile space.\n"
54" minWidth is the minimum width\n"
55" of these tiles and must be a\n"
56" power of two. A simple render\n"
57" is done with these tiles.\n");
58 SkDebugf(
scroggo@google.coma9e3a362012-11-07 17:52:48 +000059" simple, Render using the default rendering method.\n"
60" rerecord, Record the picture as a new skp, with the bitmaps PNG encoded.\n"
61 );
keyar@chromium.org795cd472012-08-02 18:57:53 +000062 SkDebugf(
scroggo@google.com4a26d9d2012-11-07 18:01:46 +000063" tile width height, Do a simple render using tiles\n"
64" with the given dimensions.\n"
65" copyTile width height, Draw the picture, then copy it into tiles.\n"
66" Does not support percentages.\n"
67" If the picture is large enough, breaks it into\n"
68" larger tiles (and draws the picture once per\n"
69" larger tile) to avoid creating a large canvas.\n"
70" Add --tiles x y to specify the number of tiles\n"
71" per larger tile in the x and y direction.\n"
72 );
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000073 SkDebugf("\n");
74 SkDebugf(
scroggo@google.comb6e806b2012-10-03 17:32:33 +000075" --multi count : Set the number of threads for multi threaded drawing. Must be greater\n"
76" than 1. Only works with tiled rendering.\n"
scroggo@google.coma62da2f2012-11-02 21:28:12 +000077" --pipe: Benchmark SkGPipe rendering. Currently incompatible with \"mode\".\n");
scroggo@google.comb6e806b2012-10-03 17:32:33 +000078 SkDebugf(
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000079" --device bitmap"
80#if SK_SUPPORT_GPU
81" | gpu"
82#endif
83": Use the corresponding device. Default is bitmap.\n");
84 SkDebugf(
85" bitmap, Render to a bitmap.\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000086#if SK_SUPPORT_GPU
keyar@chromium.orga40c20d2012-08-20 15:04:12 +000087 SkDebugf(
keyar@chromium.orgc81686c2012-08-20 15:04:04 +000088" gpu, Render to the GPU.\n");
89#endif
junov@chromium.org777442d2012-06-12 14:56:36 +000090}
91
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +000092static void make_output_filepath(SkString* path, const SkString& dir,
junov@chromium.org777442d2012-06-12 14:56:36 +000093 const SkString& name) {
twiz@google.coma31b8bb2012-06-22 18:24:56 +000094 sk_tools::make_filepath(path, dir, name);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +000095 // Remove ".skp"
96 path->remove(path->size() - 4, 4);
junov@chromium.org777442d2012-06-12 14:56:36 +000097}
98
borenet@google.com070d3542012-10-26 13:26:55 +000099static bool render_picture(const SkString& inputPath, const SkString* outputDir,
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000100 sk_tools::PictureRenderer& renderer) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000101 SkString inputFilename;
102 sk_tools::get_basename(&inputFilename, inputPath);
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000103
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000104 SkFILEStream inputStream;
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000105 inputStream.setPath(inputPath.c_str());
106 if (!inputStream.isValid()) {
107 SkDebugf("Could not open file %s\n", inputPath.c_str());
borenet@google.com66bcbd12012-09-17 18:26:06 +0000108 return false;
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000109 }
110
borenet@google.com66bcbd12012-09-17 18:26:06 +0000111 bool success = false;
scroggo@google.com5a7c6be2012-10-04 21:46:08 +0000112 SkPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000113 if (!success) {
114 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
115 return false;
116 }
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000117
borenet@google.com2d2b9a02012-09-20 18:54:04 +0000118 SkDebugf("drawing... [%i %i] %s\n", picture.width(), picture.height(),
borenet@google.com03fcee82012-09-10 18:18:38 +0000119 inputPath.c_str());
skia.committer@gmail.com1d225f22012-09-14 02:01:10 +0000120
borenet@google.com2d2b9a02012-09-20 18:54:04 +0000121 renderer.init(&picture);
scroggo@google.comb4773b42012-10-01 20:06:09 +0000122 renderer.setup();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000123
borenet@google.com070d3542012-10-26 13:26:55 +0000124 SkString* outputPath = NULL;
125 if (NULL != outputDir) {
126 outputPath = SkNEW(SkString);
127 make_output_filepath(outputPath, *outputDir, inputFilename);
128 }
129 success = renderer.render(outputPath);
130 if (outputPath) {
131 if (!success) {
132 SkDebugf("Could not write to file %s\n", outputPath->c_str());
133 }
134 SkDELETE(outputPath);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000135 }
scroggo@google.com9a412522012-09-07 15:21:18 +0000136
137 renderer.resetState();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000138
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000139 renderer.end();
borenet@google.com66bcbd12012-09-17 18:26:06 +0000140 return success;
junov@chromium.org777442d2012-06-12 14:56:36 +0000141}
142
borenet@google.com070d3542012-10-26 13:26:55 +0000143static int process_input(const SkString& input, const SkString* outputDir,
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000144 sk_tools::PictureRenderer& renderer) {
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000145 SkOSFile::Iter iter(input.c_str(), "skp");
junov@chromium.org777442d2012-06-12 14:56:36 +0000146 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000147 int failures = 0;
borenet@google.com070d3542012-10-26 13:26:55 +0000148 SkDebugf("process_input, %s\n", input.c_str());
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000149 if (iter.next(&inputFilename)) {
150 do {
151 SkString inputPath;
152 sk_tools::make_filepath(&inputPath, input, inputFilename);
borenet@google.com57837bf2012-09-19 17:28:29 +0000153 if (!render_picture(inputPath, outputDir, renderer)) {
154 ++failures;
155 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000156 } while(iter.next(&inputFilename));
borenet@google.com57837bf2012-09-19 17:28:29 +0000157 } else if (SkStrEndsWith(input.c_str(), ".skp")) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000158 SkString inputPath(input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000159 if (!render_picture(inputPath, outputDir, renderer)) {
160 ++failures;
161 }
162 } else {
163 SkString warning;
164 warning.printf("Warning: skipping %s\n", input.c_str());
165 SkDebugf(warning.c_str());
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000166 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000167 return failures;
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000168}
169
170static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs,
borenet@google.com070d3542012-10-26 13:26:55 +0000171 sk_tools::PictureRenderer*& renderer, SkString*& outputDir){
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000172 const char* argv0 = argv[0];
173 char* const* stop = argv + argc;
174
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000175 sk_tools::PictureRenderer::SkDeviceTypes deviceType =
176 sk_tools::PictureRenderer::kBitmap_DeviceType;
177
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000178 bool usePipe = false;
179 int numThreads = 1;
180 bool useTiles = false;
181 const char* widthString = NULL;
182 const char* heightString = NULL;
183 bool isPowerOf2Mode = false;
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000184 bool isCopyMode = false;
185 const char* xTilesString = NULL;
186 const char* yTilesString = NULL;
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000187 const char* mode = NULL;
188
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000189 for (++argv; argv < stop; ++argv) {
keyar@chromium.org795cd472012-08-02 18:57:53 +0000190 if (0 == strcmp(*argv, "--mode")) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000191 if (renderer != NULL) {
192 renderer->unref();
193 SkDebugf("Cannot combine modes.\n");
194 usage(argv0);
195 exit(-1);
196 }
keyar@chromium.org795cd472012-08-02 18:57:53 +0000197
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000198 ++argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000199 if (argv >= stop) {
200 SkDebugf("Missing mode for --mode\n");
201 usage(argv0);
202 exit(-1);
203 }
204
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000205 if (0 == strcmp(*argv, "simple")) {
keyar@chromium.org795cd472012-08-02 18:57:53 +0000206 renderer = SkNEW(sk_tools::SimplePictureRenderer);
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000207 } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))
208 || 0 == strcmp(*argv, "copyTile")) {
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000209 useTiles = true;
210 mode = *argv;
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000211
212 if (0 == strcmp(*argv, "pow2tile")) {
213 isPowerOf2Mode = true;
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000214 } else if (0 == strcmp(*argv, "copyTile")) {
215 isCopyMode = true;
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000216 }
217
keyar@chromium.org795cd472012-08-02 18:57:53 +0000218 ++argv;
219 if (argv >= stop) {
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +0000220 SkDebugf("Missing width for --mode %s\n", mode);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000221 usage(argv0);
222 exit(-1);
223 }
224
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000225 widthString = *argv;
keyar@chromium.org795cd472012-08-02 18:57:53 +0000226 ++argv;
227 if (argv >= stop) {
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000228 SkDebugf("Missing height for --mode %s\n", mode);
keyar@chromium.org795cd472012-08-02 18:57:53 +0000229 usage(argv0);
230 exit(-1);
231 }
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000232 heightString = *argv;
scroggo@google.coma9e3a362012-11-07 17:52:48 +0000233 } else if (0 == strcmp(*argv, "rerecord")) {
234 renderer = SkNEW(sk_tools::RecordPictureRenderer);
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000235 } else {
keyar@chromium.org795cd472012-08-02 18:57:53 +0000236 SkDebugf("%s is not a valid mode for --mode\n", *argv);
keyar@chromium.orgcc6e5ef2012-07-27 20:09:26 +0000237 usage(argv0);
238 exit(-1);
239 }
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000240 } else if (0 == strcmp(*argv, "--tiles")) {
241 ++argv;
242 if (argv >= stop) {
243 SkDebugf("Missing x for --tiles\n");
244 usage(argv0);
245 exit(-1);
246 }
247 xTilesString = *argv;
248 ++argv;
249 if (argv >= stop) {
250 SkDebugf("Missing y for --tiles\n");
251 usage(argv0);
252 exit(-1);
253 }
254 yTilesString = *argv;
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000255 } else if (0 == strcmp(*argv, "--pipe")) {
256 usePipe = true;
257 } else if (0 == strcmp(*argv, "--multi")) {
258 ++argv;
259 if (argv >= stop) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000260 SkSafeUnref(renderer);
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000261 SkDebugf("Missing arg for --multi\n");
262 usage(argv0);
263 exit(-1);
264 }
265 numThreads = atoi(*argv);
266 if (numThreads < 2) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000267 SkSafeUnref(renderer);
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000268 SkDebugf("Number of threads must be at least 2.\n");
269 usage(argv0);
270 exit(-1);
271 }
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000272 } else if (0 == strcmp(*argv, "--device")) {
273 ++argv;
274 if (argv >= stop) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000275 SkSafeUnref(renderer);
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000276 SkDebugf("Missing mode for --device\n");
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000277 usage(argv0);
278 exit(-1);
279 }
280
281 if (0 == strcmp(*argv, "bitmap")) {
282 deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType;
283 }
284#if SK_SUPPORT_GPU
285 else if (0 == strcmp(*argv, "gpu")) {
286 deviceType = sk_tools::PictureRenderer::kGPU_DeviceType;
287 }
288#endif
289 else {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000290 SkSafeUnref(renderer);
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000291 SkDebugf("%s is not a valid mode for --device\n", *argv);
292 usage(argv0);
293 exit(-1);
294 }
295
keyar@chromium.org472b3792012-07-20 22:34:27 +0000296 } else if ((0 == strcmp(*argv, "-h")) || (0 == strcmp(*argv, "--help"))) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000297 SkSafeUnref(renderer);
keyar@chromium.org472b3792012-07-20 22:34:27 +0000298 usage(argv0);
299 exit(-1);
borenet@google.com070d3542012-10-26 13:26:55 +0000300 } else if (0 == strcmp(*argv, "-w")) {
301 ++argv;
302 if (argv >= stop) {
303 SkDebugf("Missing output directory for -w\n");
304 usage(argv0);
305 exit(-1);
306 }
307 outputDir = SkNEW_ARGS(SkString, (*argv));
keyar@chromium.orga2333d92012-07-16 17:29:16 +0000308 } else {
309 inputs->push_back(SkString(*argv));
310 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000311 }
keyar@chromium.org472b3792012-07-20 22:34:27 +0000312
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000313 if (numThreads > 1 && !useTiles) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000314 SkSafeUnref(renderer);
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000315 SkDebugf("Multithreaded drawing requires tiled rendering.\n");
316 usage(argv0);
317 exit(-1);
318 }
319
320 if (useTiles) {
321 SkASSERT(NULL == renderer);
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000322 sk_tools::TiledPictureRenderer* tiledRenderer;
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000323 if (isCopyMode) {
324 int x, y;
325 if (xTilesString != NULL) {
326 SkASSERT(yTilesString != NULL);
327 x = atoi(xTilesString);
328 y = atoi(yTilesString);
329 if (x <= 0 || y <= 0) {
330 SkDebugf("--tiles must be given values > 0\n");
331 usage(argv0);
332 exit(-1);
333 }
334 } else {
335 x = y = 4;
336 }
337 tiledRenderer = SkNEW_ARGS(sk_tools::CopyTilesRenderer, (x, y));
338 } else if (numThreads > 1) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000339 tiledRenderer = SkNEW_ARGS(sk_tools::MultiCorePictureRenderer, (numThreads));
340 } else {
341 tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer);
342 }
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000343 if (isPowerOf2Mode) {
344 int minWidth = atoi(widthString);
345 if (!SkIsPow2(minWidth) || minWidth < 0) {
346 tiledRenderer->unref();
347 SkString err;
348 err.printf("-mode %s must be given a width"
349 " value that is a power of two\n", mode);
350 SkDebugf(err.c_str());
351 usage(argv0);
352 exit(-1);
353 }
354 tiledRenderer->setTileMinPowerOf2Width(minWidth);
355 } else if (sk_tools::is_percentage(widthString)) {
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000356 if (isCopyMode) {
357 tiledRenderer->unref();
358 SkString err;
359 err.printf("--mode %s does not support percentages.\n", mode);
360 SkDebugf(err.c_str());
361 usage(argv0);
362 exit(-1);
363 }
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000364 tiledRenderer->setTileWidthPercentage(atof(widthString));
365 if (!(tiledRenderer->getTileWidthPercentage() > 0)) {
366 tiledRenderer->unref();
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000367 SkDebugf("--mode %s must be given a width percentage > 0\n", mode);
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000368 usage(argv0);
369 exit(-1);
370 }
371 } else {
372 tiledRenderer->setTileWidth(atoi(widthString));
373 if (!(tiledRenderer->getTileWidth() > 0)) {
374 tiledRenderer->unref();
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000375 SkDebugf("--mode %s must be given a width > 0\n", mode);
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000376 usage(argv0);
377 exit(-1);
378 }
379 }
380
381 if (sk_tools::is_percentage(heightString)) {
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000382 if (isCopyMode) {
383 tiledRenderer->unref();
384 SkString err;
385 err.printf("--mode %s does not support percentages.\n", mode);
386 SkDebugf(err.c_str());
387 usage(argv0);
388 exit(-1);
389 }
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000390 tiledRenderer->setTileHeightPercentage(atof(heightString));
391 if (!(tiledRenderer->getTileHeightPercentage() > 0)) {
392 tiledRenderer->unref();
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000393 SkDebugf("--mode %s must be given a height percentage > 0\n", mode);
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000394 usage(argv0);
395 exit(-1);
396 }
397 } else {
398 tiledRenderer->setTileHeight(atoi(heightString));
399 if (!(tiledRenderer->getTileHeight() > 0)) {
400 tiledRenderer->unref();
scroggo@google.com4a26d9d2012-11-07 18:01:46 +0000401 SkDebugf("--mode %s must be given a height > 0\n", mode);
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000402 usage(argv0);
403 exit(-1);
404 }
405 }
406 if (numThreads > 1) {
407#if SK_SUPPORT_GPU
408 if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) {
409 tiledRenderer->unref();
410 SkDebugf("GPU not compatible with multithreaded tiling.\n");
411 usage(argv0);
412 exit(-1);
413 }
414#endif
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000415 }
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000416 renderer = tiledRenderer;
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000417 if (usePipe) {
418 SkDebugf("Pipe rendering is currently not compatible with tiling.\n"
419 "Turning off pipe.\n");
420 }
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000421 } else if (usePipe) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000422 if (renderer != NULL) {
423 renderer->unref();
424 SkDebugf("Pipe is incompatible with other modes.\n");
425 usage(argv0);
426 exit(-1);
427 }
scroggo@google.comb6e806b2012-10-03 17:32:33 +0000428 renderer = SkNEW(sk_tools::PipePictureRenderer);
429 }
430
borenet@google.com070d3542012-10-26 13:26:55 +0000431 if (inputs->empty()) {
scroggo@google.coma62da2f2012-11-02 21:28:12 +0000432 SkSafeUnref(renderer);
borenet@google.com070d3542012-10-26 13:26:55 +0000433 if (NULL != outputDir) {
434 SkDELETE(outputDir);
435 }
keyar@chromium.org472b3792012-07-20 22:34:27 +0000436 usage(argv0);
437 exit(-1);
438 }
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000439
440 if (NULL == renderer) {
441 renderer = SkNEW(sk_tools::SimplePictureRenderer);
442 }
keyar@chromium.org4ea96c52012-08-20 15:03:29 +0000443
keyar@chromium.orgc81686c2012-08-20 15:04:04 +0000444 renderer->setDeviceType(deviceType);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000445}
446
caryclark@google.com5987f582012-10-02 18:33:14 +0000447int tool_main(int argc, char** argv);
448int tool_main(int argc, char** argv) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000449 SkAutoGraphics ag;
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000450 SkTArray<SkString> inputs;
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000451 sk_tools::PictureRenderer* renderer = NULL;
borenet@google.com070d3542012-10-26 13:26:55 +0000452 SkString* outputDir = NULL;
453 parse_commandline(argc, argv, &inputs, renderer, outputDir);
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000454 SkASSERT(renderer);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000455
borenet@google.com66bcbd12012-09-17 18:26:06 +0000456 int failures = 0;
borenet@google.com070d3542012-10-26 13:26:55 +0000457 for (int i = 0; i < inputs.count(); i ++) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000458 failures += process_input(inputs[i], outputDir, *renderer);
junov@chromium.org777442d2012-06-12 14:56:36 +0000459 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000460 if (failures != 0) {
461 SkDebugf("Failed to render %i pictures.\n", failures);
462 return 1;
463 }
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000464#if SK_SUPPORT_GPU
465#if GR_CACHE_STATS
466 if (renderer->isUsingGpuDevice()) {
467 GrContext* ctx = renderer->getGrContext();
468
469 ctx->printCacheStats();
470 }
471#endif
472#endif
borenet@google.com070d3542012-10-26 13:26:55 +0000473 if (NULL != outputDir) {
474 SkDELETE(outputDir);
475 }
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000476 SkDELETE(renderer);
caryclark@google.com868e1f62012-10-02 20:00:03 +0000477 return 0;
junov@chromium.org777442d2012-06-12 14:56:36 +0000478}
caryclark@google.com5987f582012-10-02 18:33:14 +0000479
480#if !defined SK_BUILD_FOR_IOS
481int main(int argc, char * const argv[]) {
482 return tool_main(argc, (char**) argv);
483}
484#endif