blob: 3aa027f250a4a23b170bae55efe15d7261db6197 [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"
keyar@chromium.org472b3792012-07-20 22:34:27 +000010#include "SkDevice.h"
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000011#include "SkCommandLineFlags.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"
edisonn@google.com84f548c2012-12-18 22:24:03 +000014#include "SkImageEncoder.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000015#include "SkMath.h"
junov@chromium.org777442d2012-06-12 14:56:36 +000016#include "SkOSFile.h"
17#include "SkPicture.h"
18#include "SkStream.h"
19#include "SkString.h"
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000020#include "PictureRenderer.h"
scroggo@google.com161e1ba2013-03-04 16:41:06 +000021#include "PictureRenderingFlags.h"
twiz@google.coma31b8bb2012-06-22 18:24:56 +000022#include "picture_utils.h"
junov@chromium.org777442d2012-06-12 14:56:36 +000023
scroggo@google.com161e1ba2013-03-04 16:41:06 +000024// Flags used by this file, alphabetically:
25DEFINE_int32(clone, 0, "Clone the picture n times before rendering.");
26DECLARE_bool(deferImageDecoding);
27DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Components that differ "
28 "by more than this amount are considered errors, though all diffs are reported. "
29 "Requires --validate.");
scroggo@google.com604e0c22013-04-09 21:25:46 +000030DECLARE_string(readPath);
scroggo@google.com1125d392013-05-03 20:43:37 +000031DEFINE_bool(writeEncodedImages, false, "Any time the skp contains an encoded image, write it to a "
32 "file rather than decoding it. Requires writePath to be set. Skips drawing the full "
33 "skp to a file. Not compatible with deferImageDecoding.");
scroggo@google.com604e0c22013-04-09 21:25:46 +000034DEFINE_string2(writePath, w, "", "Directory to write the rendered images.");
scroggo@google.com161e1ba2013-03-04 16:41:06 +000035DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered image to a "
36 "file, instead of an image for each tile.");
37DEFINE_bool(validate, false, "Verify that the rendered image contains the same pixels as "
junov@chromium.orge286e842013-03-13 17:27:16 +000038 "the picture rendered in simple mode. When used in conjunction with --bbh, results "
39 "are validated against the picture rendered in the same mode, but without the bbh.");
junov@chromium.org777442d2012-06-12 14:56:36 +000040
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +000041static void make_output_filepath(SkString* path, const SkString& dir,
junov@chromium.org777442d2012-06-12 14:56:36 +000042 const SkString& name) {
twiz@google.coma31b8bb2012-06-22 18:24:56 +000043 sk_tools::make_filepath(path, dir, name);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +000044 // Remove ".skp"
45 path->remove(path->size() - 4, 4);
junov@chromium.org777442d2012-06-12 14:56:36 +000046}
47
scroggo@google.combb281f72013-03-18 21:37:39 +000048// Defined in PictureRenderingFlags.cpp
49extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap);
scroggo@google.comf8d7d272013-02-22 21:38:35 +000050
scroggo@google.com1125d392013-05-03 20:43:37 +000051////////////////////////////////////////////////////////////////////////////////////////////////////
52
53/**
54 * Table for translating from format of data to a suffix.
55 */
56struct Format {
57 SkImageDecoder::Format fFormat;
58 const char* fSuffix;
59};
60static const Format gFormats[] = {
61 { SkImageDecoder::kBMP_Format, ".bmp" },
62 { SkImageDecoder::kGIF_Format, ".gif" },
63 { SkImageDecoder::kICO_Format, ".ico" },
64 { SkImageDecoder::kJPEG_Format, ".jpg" },
65 { SkImageDecoder::kPNG_Format, ".png" },
66 { SkImageDecoder::kWBMP_Format, ".wbmp" },
67 { SkImageDecoder::kWEBP_Format, ".webp" },
68 { SkImageDecoder::kUnknown_Format, "" },
69};
70
71/**
72 * Get an appropriate suffix for an image format.
73 */
74static const char* get_suffix_from_format(SkImageDecoder::Format format) {
75 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
76 if (gFormats[i].fFormat == format) {
77 return gFormats[i].fSuffix;
78 }
79 }
80 return "";
81}
82
83/**
84 * Base name for an image file created from the encoded data in an skp.
85 */
86static SkString gInputFileName;
87
88/**
89 * Number to be appended to the image file name so that it is unique.
90 */
91static uint32_t gImageNo;
92
93/**
94 * Set up the name for writing encoded data to a file.
95 * Sets gInputFileName to name, minus any extension ".*"
96 * Sets gImageNo to 0, so images from file "X.skp" will
97 * look like "X_<gImageNo>.<suffix>", beginning with 0
98 * for each new skp.
99 */
100static void reset_image_file_base_name(const SkString& name) {
101 gImageNo = 0;
102 // Remove ".skp"
103 const char* cName = name.c_str();
104 const char* dot = strrchr(cName, '.');
105 if (dot != NULL) {
106 gInputFileName.set(cName, dot - cName);
107 } else {
108 gInputFileName.set(name);
109 }
110}
111
112/**
113 * Write the raw encoded bitmap data to a file.
114 */
115static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitmap) {
116 SkASSERT(!FLAGS_writePath.isEmpty());
117 SkMemoryStream memStream(buffer, size);
118 SkString outPath;
119 SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&memStream);
120 SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++,
121 get_suffix_from_format(format));
122 SkString dir(FLAGS_writePath[0]);
123 sk_tools::make_filepath(&outPath, dir, name);
124 SkFILEWStream fileStream(outPath.c_str());
125 if (!(fileStream.isValid() && fileStream.write(buffer, size))) {
126 SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str());
127 }
128 // Put in a dummy bitmap.
129 return SkImageDecoder::DecodeStream(&memStream, bitmap, SkBitmap::kNo_Config,
130 SkImageDecoder::kDecodeBounds_Mode);
131}
132
133////////////////////////////////////////////////////////////////////////////////////////////////////
134
borenet@google.com070d3542012-10-26 13:26:55 +0000135static bool render_picture(const SkString& inputPath, const SkString* outputDir,
edisonn@google.com84f548c2012-12-18 22:24:03 +0000136 sk_tools::PictureRenderer& renderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000137 SkBitmap** out) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000138 SkString inputFilename;
139 sk_tools::get_basename(&inputFilename, inputPath);
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000140
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000141 SkFILEStream inputStream;
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000142 inputStream.setPath(inputPath.c_str());
143 if (!inputStream.isValid()) {
144 SkDebugf("Could not open file %s\n", inputPath.c_str());
borenet@google.com66bcbd12012-09-17 18:26:06 +0000145 return false;
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000146 }
147
borenet@google.com66bcbd12012-09-17 18:26:06 +0000148 bool success = false;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000149 SkPicture* picture;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000150 if (FLAGS_deferImageDecoding) {
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000151 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bitmap));
scroggo@google.com1125d392013-05-03 20:43:37 +0000152 } else if (FLAGS_writeEncodedImages) {
153 SkASSERT(!FLAGS_writePath.isEmpty());
154 reset_image_file_base_name(inputFilename);
155 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &write_image_to_file));
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000156 } else {
157 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder::DecodeMemory));
158 }
scroggo@google.com1125d392013-05-03 20:43:37 +0000159
borenet@google.com66bcbd12012-09-17 18:26:06 +0000160 if (!success) {
161 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
162 return false;
163 }
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000164
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000165 for (int i = 0; i < FLAGS_clone; ++i) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000166 SkPicture* clone = picture->clone();
167 SkDELETE(picture);
168 picture = clone;
169 }
170
171 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
borenet@google.com03fcee82012-09-10 18:18:38 +0000172 inputPath.c_str());
skia.committer@gmail.com1d225f22012-09-14 02:01:10 +0000173
edisonn@google.com84f548c2012-12-18 22:24:03 +0000174 renderer.init(picture);
scroggo@google.comb4773b42012-10-01 20:06:09 +0000175 renderer.setup();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000176
borenet@google.com070d3542012-10-26 13:26:55 +0000177 SkString* outputPath = NULL;
scroggo@google.com1125d392013-05-03 20:43:37 +0000178 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) {
borenet@google.com070d3542012-10-26 13:26:55 +0000179 outputPath = SkNEW(SkString);
180 make_output_filepath(outputPath, *outputDir, inputFilename);
181 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000182
183 success = renderer.render(outputPath, out);
borenet@google.com070d3542012-10-26 13:26:55 +0000184 if (outputPath) {
185 if (!success) {
186 SkDebugf("Could not write to file %s\n", outputPath->c_str());
187 }
188 SkDELETE(outputPath);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000189 }
scroggo@google.com9a412522012-09-07 15:21:18 +0000190
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000191 renderer.end();
edisonn@google.com84f548c2012-12-18 22:24:03 +0000192
193 SkDELETE(picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000194 return success;
junov@chromium.org777442d2012-06-12 14:56:36 +0000195}
196
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000197static inline int getByte(uint32_t value, int index) {
198 SkASSERT(0 <= index && index < 4);
199 return (value >> (index * 8)) & 0xFF;
200}
201
202static int MaxByteDiff(uint32_t v1, uint32_t v2) {
203 return SkMax32(SkMax32(abs(getByte(v1, 0) - getByte(v2, 0)), abs(getByte(v1, 1) - getByte(v2, 1))),
204 SkMax32(abs(getByte(v1, 2) - getByte(v2, 2)), abs(getByte(v1, 3) - getByte(v2, 3))));
205}
206
junov@chromium.orge286e842013-03-13 17:27:16 +0000207namespace {
208class AutoRestoreBbhType {
209public:
210 AutoRestoreBbhType() {
211 fRenderer = NULL;
junov@chromium.orgd34fda12013-03-13 19:03:26 +0000212 fSavedBbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
junov@chromium.orge286e842013-03-13 17:27:16 +0000213 }
214
215 void set(sk_tools::PictureRenderer* renderer,
216 sk_tools::PictureRenderer::BBoxHierarchyType bbhType) {
217 fRenderer = renderer;
218 fSavedBbhType = renderer->getBBoxHierarchyType();
219 renderer->setBBoxHierarchyType(bbhType);
220 }
221
222 ~AutoRestoreBbhType() {
223 if (NULL != fRenderer) {
224 fRenderer->setBBoxHierarchyType(fSavedBbhType);
225 }
226 }
227
228private:
229 sk_tools::PictureRenderer* fRenderer;
230 sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType;
231};
232}
233
edisonn@google.com84f548c2012-12-18 22:24:03 +0000234static bool render_picture(const SkString& inputPath, const SkString* outputDir,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000235 sk_tools::PictureRenderer& renderer) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000236 int diffs[256] = {0};
edisonn@google.com84f548c2012-12-18 22:24:03 +0000237 SkBitmap* bitmap = NULL;
238 bool success = render_picture(inputPath,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000239 FLAGS_writeWholeImage ? NULL : outputDir,
edisonn@google.com84f548c2012-12-18 22:24:03 +0000240 renderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000241 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000242
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000243 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL)) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000244 SkDebugf("Failed to draw the picture.\n");
245 SkDELETE(bitmap);
246 return false;
247 }
248
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000249 if (FLAGS_validate) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000250 SkBitmap* referenceBitmap = NULL;
junov@chromium.orge286e842013-03-13 17:27:16 +0000251 sk_tools::PictureRenderer* referenceRenderer;
252 // If the renderer uses a BBoxHierarchy, then the reference renderer
skia.committer@gmail.com03682be2013-03-14 07:02:51 +0000253 // will be the same renderer, without the bbh.
junov@chromium.orge286e842013-03-13 17:27:16 +0000254 AutoRestoreBbhType arbbh;
255 if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
256 renderer.getBBoxHierarchyType()) {
257 referenceRenderer = &renderer;
258 referenceRenderer->ref(); // to match auto unref below
259 arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
260 } else {
261 referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer);
262 }
263 SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer);
264
265 success = render_picture(inputPath, NULL, *referenceRenderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000266 &referenceBitmap);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000267
junov@chromium.orgc19c1912013-03-12 19:56:49 +0000268 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getPixels()) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000269 SkDebugf("Failed to draw the reference picture.\n");
270 SkDELETE(bitmap);
271 SkDELETE(referenceBitmap);
272 return false;
273 }
274
275 if (success && (bitmap->width() != referenceBitmap->width())) {
276 SkDebugf("Expected image width: %i, actual image width %i.\n",
277 referenceBitmap->width(), bitmap->width());
278 SkDELETE(bitmap);
279 SkDELETE(referenceBitmap);
280 return false;
281 }
282 if (success && (bitmap->height() != referenceBitmap->height())) {
283 SkDebugf("Expected image height: %i, actual image height %i",
284 referenceBitmap->height(), bitmap->height());
285 SkDELETE(bitmap);
286 SkDELETE(referenceBitmap);
287 return false;
288 }
skia.committer@gmail.coma7d8e3e2012-12-19 02:01:38 +0000289
edisonn@google.com84f548c2012-12-18 22:24:03 +0000290 for (int y = 0; success && y < bitmap->height(); y++) {
291 for (int x = 0; success && x < bitmap->width(); x++) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000292 int diff = MaxByteDiff(*referenceBitmap->getAddr32(x, y),
293 *bitmap->getAddr32(x, y));
294 SkASSERT(diff >= 0 && diff <= 255);
295 diffs[diff]++;
skia.committer@gmail.com4d28d982013-01-17 07:06:06 +0000296
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000297 if (diff > FLAGS_maxComponentDiff) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000298 SkDebugf("Expected pixel at (%i %i) exceedds maximum "
299 "component diff of %i: 0x%x, actual 0x%x\n",
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000300 x, y, FLAGS_maxComponentDiff,
edisonn@google.com01754bf2013-01-11 16:08:07 +0000301 *referenceBitmap->getAddr32(x, y),
edisonn@google.com84f548c2012-12-18 22:24:03 +0000302 *bitmap->getAddr32(x, y));
303 SkDELETE(bitmap);
304 SkDELETE(referenceBitmap);
305 return false;
306 }
307 }
308 }
309 SkDELETE(referenceBitmap);
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000310
311 for (int i = 1; i <= 255; ++i) {
312 if(diffs[i] > 0) {
313 SkDebugf("Number of pixels with max diff of %i is %i\n", i, diffs[i]);
314 }
315 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000316 }
317
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000318 if (FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000319 sk_tools::force_all_opaque(*bitmap);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000320 if (NULL != outputDir && FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000321 SkString inputFilename;
322 sk_tools::get_basename(&inputFilename, inputPath);
323 SkString outputPath;
324 make_output_filepath(&outputPath, *outputDir, inputFilename);
325 outputPath.append(".png");
326 if (!SkImageEncoder::EncodeFile(outputPath.c_str(), *bitmap,
327 SkImageEncoder::kPNG_Type, 100)) {
328 SkDebugf("Failed to draw the picture.\n");
329 success = false;
330 }
331 }
332 }
333 SkDELETE(bitmap);
334
335 return success;
336}
337
338
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000339static int process_input(const char* input, const SkString* outputDir,
340 sk_tools::PictureRenderer& renderer) {
341 SkOSFile::Iter iter(input, "skp");
junov@chromium.org777442d2012-06-12 14:56:36 +0000342 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000343 int failures = 0;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000344 SkDebugf("process_input, %s\n", input);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000345 if (iter.next(&inputFilename)) {
346 do {
347 SkString inputPath;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000348 SkString inputAsSkString(input);
349 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
350 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000351 ++failures;
352 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000353 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000354 } else if (SkStrEndsWith(input, ".skp")) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000355 SkString inputPath(input);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000356 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000357 ++failures;
358 }
359 } else {
360 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000361 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000362 SkDebugf(warning.c_str());
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000363 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000364 return failures;
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000365}
366
caryclark@google.com5987f582012-10-02 18:33:14 +0000367int tool_main(int argc, char** argv);
368int tool_main(int argc, char** argv) {
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000369 SkCommandLineFlags::SetUsage("Render .skp files.");
370 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000371
scroggo@google.com604e0c22013-04-09 21:25:46 +0000372 if (FLAGS_readPath.isEmpty()) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000373 SkDebugf(".skp files or directories are required.\n");
374 exit(-1);
375 }
376
377 if (FLAGS_maxComponentDiff < 0 || FLAGS_maxComponentDiff > 256) {
378 SkDebugf("--maxComponentDiff must be between 0 and 256\n");
379 exit(-1);
380 }
381
382 if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) {
383 SkDebugf("--maxComponentDiff requires --validate\n");
384 exit(-1);
385 }
386
387 if (FLAGS_clone < 0) {
388 SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone);
389 exit(-1);
390 }
391
scroggo@google.com1125d392013-05-03 20:43:37 +0000392 if (FLAGS_writeEncodedImages) {
393 if (FLAGS_writePath.isEmpty()) {
394 SkDebugf("--writeEncodedImages requires --writePath\n");
395 exit(-1);
396 }
397 if (FLAGS_deferImageDecoding) {
398 SkDebugf("--writeEncodedImages is not compatible with --deferImageDecoding\n");
399 exit(-1);
400 }
401 }
402
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000403 SkString errorString;
404 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
405 kRender_PictureTool));
406 if (errorString.size() > 0) {
407 SkDebugf("%s\n", errorString.c_str());
408 }
409
410 if (renderer.get() == NULL) {
411 exit(-1);
412 }
413
borenet@google.com66bcbd12012-09-17 18:26:06 +0000414 SkAutoGraphics ag;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000415
416 SkString outputDir;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000417 if (FLAGS_writePath.count() == 1) {
418 outputDir.set(FLAGS_writePath[0]);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000419 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000420
borenet@google.com66bcbd12012-09-17 18:26:06 +0000421 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000422 for (int i = 0; i < FLAGS_readPath.count(); i ++) {
423 failures += process_input(FLAGS_readPath[i], &outputDir, *renderer.get());
junov@chromium.org777442d2012-06-12 14:56:36 +0000424 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000425 if (failures != 0) {
426 SkDebugf("Failed to render %i pictures.\n", failures);
427 return 1;
428 }
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000429#if SK_SUPPORT_GPU
430#if GR_CACHE_STATS
431 if (renderer->isUsingGpuDevice()) {
432 GrContext* ctx = renderer->getGrContext();
433
434 ctx->printCacheStats();
435 }
436#endif
437#endif
caryclark@google.com868e1f62012-10-02 20:00:03 +0000438 return 0;
junov@chromium.org777442d2012-06-12 14:56:36 +0000439}
caryclark@google.com5987f582012-10-02 18:33:14 +0000440
441#if !defined SK_BUILD_FOR_IOS
442int main(int argc, char * const argv[]) {
443 return tool_main(argc, (char**) argv);
444}
445#endif