blob: a2dff67d10971d05514337ff286cc6fb728c946e [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
commit-bot@chromium.org56799e22013-07-16 18:21:46 +00008#include "LazyDecodeBitmap.h"
scroggo@google.com4a26d9d2012-11-07 18:01:46 +00009#include "CopyTilesRenderer.h"
junov@chromium.org777442d2012-06-12 14:56:36 +000010#include "SkBitmap.h"
keyar@chromium.org472b3792012-07-20 22:34:27 +000011#include "SkDevice.h"
scroggo@google.comd9ba9a02013-03-21 19:43:15 +000012#include "SkCommandLineFlags.h"
borenet@google.com10ef79e2012-09-10 17:19:06 +000013#include "SkGraphics.h"
scroggo@google.com5a7c6be2012-10-04 21:46:08 +000014#include "SkImageDecoder.h"
edisonn@google.com84f548c2012-12-18 22:24:03 +000015#include "SkImageEncoder.h"
keyar@chromium.orgf4959ab2012-08-23 20:53:25 +000016#include "SkMath.h"
junov@chromium.org777442d2012-06-12 14:56:36 +000017#include "SkOSFile.h"
18#include "SkPicture.h"
19#include "SkStream.h"
20#include "SkString.h"
keyar@chromium.org451bb9f2012-07-26 17:27:57 +000021#include "PictureRenderer.h"
scroggo@google.com161e1ba2013-03-04 16:41:06 +000022#include "PictureRenderingFlags.h"
twiz@google.coma31b8bb2012-06-22 18:24:56 +000023#include "picture_utils.h"
junov@chromium.org777442d2012-06-12 14:56:36 +000024
scroggo@google.com161e1ba2013-03-04 16:41:06 +000025// Flags used by this file, alphabetically:
26DEFINE_int32(clone, 0, "Clone the picture n times before rendering.");
27DECLARE_bool(deferImageDecoding);
28DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Components that differ "
29 "by more than this amount are considered errors, though all diffs are reported. "
30 "Requires --validate.");
scroggo@google.com604e0c22013-04-09 21:25:46 +000031DECLARE_string(readPath);
scroggo@google.com1125d392013-05-03 20:43:37 +000032DEFINE_bool(writeEncodedImages, false, "Any time the skp contains an encoded image, write it to a "
33 "file rather than decoding it. Requires writePath to be set. Skips drawing the full "
34 "skp to a file. Not compatible with deferImageDecoding.");
scroggo@google.com604e0c22013-04-09 21:25:46 +000035DEFINE_string2(writePath, w, "", "Directory to write the rendered images.");
scroggo@google.com161e1ba2013-03-04 16:41:06 +000036DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered image to a "
37 "file, instead of an image for each tile.");
38DEFINE_bool(validate, false, "Verify that the rendered image contains the same pixels as "
junov@chromium.orge286e842013-03-13 17:27:16 +000039 "the picture rendered in simple mode. When used in conjunction with --bbh, results "
40 "are validated against the picture rendered in the same mode, but without the bbh.");
junov@chromium.org777442d2012-06-12 14:56:36 +000041
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +000042static void make_output_filepath(SkString* path, const SkString& dir,
junov@chromium.org777442d2012-06-12 14:56:36 +000043 const SkString& name) {
twiz@google.coma31b8bb2012-06-22 18:24:56 +000044 sk_tools::make_filepath(path, dir, name);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +000045 // Remove ".skp"
46 path->remove(path->size() - 4, 4);
junov@chromium.org777442d2012-06-12 14:56:36 +000047}
48
scroggo@google.com1125d392013-05-03 20:43:37 +000049////////////////////////////////////////////////////////////////////////////////////////////////////
50
51/**
52 * Table for translating from format of data to a suffix.
53 */
54struct Format {
55 SkImageDecoder::Format fFormat;
56 const char* fSuffix;
57};
58static const Format gFormats[] = {
59 { SkImageDecoder::kBMP_Format, ".bmp" },
60 { SkImageDecoder::kGIF_Format, ".gif" },
61 { SkImageDecoder::kICO_Format, ".ico" },
62 { SkImageDecoder::kJPEG_Format, ".jpg" },
63 { SkImageDecoder::kPNG_Format, ".png" },
64 { SkImageDecoder::kWBMP_Format, ".wbmp" },
65 { SkImageDecoder::kWEBP_Format, ".webp" },
66 { SkImageDecoder::kUnknown_Format, "" },
67};
68
69/**
70 * Get an appropriate suffix for an image format.
71 */
72static const char* get_suffix_from_format(SkImageDecoder::Format format) {
73 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
74 if (gFormats[i].fFormat == format) {
75 return gFormats[i].fSuffix;
76 }
77 }
78 return "";
79}
80
81/**
82 * Base name for an image file created from the encoded data in an skp.
83 */
84static SkString gInputFileName;
85
86/**
87 * Number to be appended to the image file name so that it is unique.
88 */
89static uint32_t gImageNo;
90
91/**
92 * Set up the name for writing encoded data to a file.
93 * Sets gInputFileName to name, minus any extension ".*"
94 * Sets gImageNo to 0, so images from file "X.skp" will
95 * look like "X_<gImageNo>.<suffix>", beginning with 0
96 * for each new skp.
97 */
98static void reset_image_file_base_name(const SkString& name) {
99 gImageNo = 0;
100 // Remove ".skp"
101 const char* cName = name.c_str();
102 const char* dot = strrchr(cName, '.');
103 if (dot != NULL) {
104 gInputFileName.set(cName, dot - cName);
105 } else {
106 gInputFileName.set(name);
107 }
108}
109
110/**
111 * Write the raw encoded bitmap data to a file.
112 */
113static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitmap) {
114 SkASSERT(!FLAGS_writePath.isEmpty());
115 SkMemoryStream memStream(buffer, size);
116 SkString outPath;
117 SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&memStream);
118 SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++,
119 get_suffix_from_format(format));
120 SkString dir(FLAGS_writePath[0]);
121 sk_tools::make_filepath(&outPath, dir, name);
122 SkFILEWStream fileStream(outPath.c_str());
123 if (!(fileStream.isValid() && fileStream.write(buffer, size))) {
124 SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str());
125 }
126 // Put in a dummy bitmap.
127 return SkImageDecoder::DecodeStream(&memStream, bitmap, SkBitmap::kNo_Config,
128 SkImageDecoder::kDecodeBounds_Mode);
129}
130
131////////////////////////////////////////////////////////////////////////////////////////////////////
132
borenet@google.com070d3542012-10-26 13:26:55 +0000133static bool render_picture(const SkString& inputPath, const SkString* outputDir,
edisonn@google.com84f548c2012-12-18 22:24:03 +0000134 sk_tools::PictureRenderer& renderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000135 SkBitmap** out) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000136 SkString inputFilename;
137 sk_tools::get_basename(&inputFilename, inputPath);
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000138
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000139 SkFILEStream inputStream;
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000140 inputStream.setPath(inputPath.c_str());
141 if (!inputStream.isValid()) {
142 SkDebugf("Could not open file %s\n", inputPath.c_str());
borenet@google.com66bcbd12012-09-17 18:26:06 +0000143 return false;
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000144 }
145
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000146 SkPicture::InstallPixelRefProc proc;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000147 if (FLAGS_deferImageDecoding) {
commit-bot@chromium.org56799e22013-07-16 18:21:46 +0000148 proc = &sk_tools::LazyDecodeBitmap;
scroggo@google.com1125d392013-05-03 20:43:37 +0000149 } else if (FLAGS_writeEncodedImages) {
150 SkASSERT(!FLAGS_writePath.isEmpty());
151 reset_image_file_base_name(inputFilename);
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000152 proc = &write_image_to_file;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000153 } else {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000154 proc = &SkImageDecoder::DecodeMemory;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000155 }
scroggo@google.com1125d392013-05-03 20:43:37 +0000156
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000157 SkDebugf("deserializing... %s\n", inputPath.c_str());
158
159 SkPicture* picture = SkPicture::CreateFromStream(&inputStream, proc);
160
161 if (NULL == picture) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000162 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
163 return false;
164 }
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000165
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000166 for (int i = 0; i < FLAGS_clone; ++i) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000167 SkPicture* clone = picture->clone();
168 SkDELETE(picture);
169 picture = clone;
170 }
171
172 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
borenet@google.com03fcee82012-09-10 18:18:38 +0000173 inputPath.c_str());
skia.committer@gmail.com1d225f22012-09-14 02:01:10 +0000174
edisonn@google.com84f548c2012-12-18 22:24:03 +0000175 renderer.init(picture);
scroggo@google.comb4773b42012-10-01 20:06:09 +0000176 renderer.setup();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000177
borenet@google.com070d3542012-10-26 13:26:55 +0000178 SkString* outputPath = NULL;
scroggo@google.com1125d392013-05-03 20:43:37 +0000179 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) {
borenet@google.com070d3542012-10-26 13:26:55 +0000180 outputPath = SkNEW(SkString);
181 make_output_filepath(outputPath, *outputDir, inputFilename);
182 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000183
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000184 bool success = renderer.render(outputPath, out);
borenet@google.com070d3542012-10-26 13:26:55 +0000185 if (outputPath) {
186 if (!success) {
187 SkDebugf("Could not write to file %s\n", outputPath->c_str());
188 }
189 SkDELETE(outputPath);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000190 }
scroggo@google.com9a412522012-09-07 15:21:18 +0000191
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000192 renderer.end();
edisonn@google.com84f548c2012-12-18 22:24:03 +0000193
194 SkDELETE(picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000195 return success;
junov@chromium.org777442d2012-06-12 14:56:36 +0000196}
197
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000198static inline int getByte(uint32_t value, int index) {
199 SkASSERT(0 <= index && index < 4);
200 return (value >> (index * 8)) & 0xFF;
201}
202
203static int MaxByteDiff(uint32_t v1, uint32_t v2) {
204 return SkMax32(SkMax32(abs(getByte(v1, 0) - getByte(v2, 0)), abs(getByte(v1, 1) - getByte(v2, 1))),
205 SkMax32(abs(getByte(v1, 2) - getByte(v2, 2)), abs(getByte(v1, 3) - getByte(v2, 3))));
206}
207
junov@chromium.orge286e842013-03-13 17:27:16 +0000208namespace {
209class AutoRestoreBbhType {
210public:
211 AutoRestoreBbhType() {
212 fRenderer = NULL;
junov@chromium.orgd34fda12013-03-13 19:03:26 +0000213 fSavedBbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
junov@chromium.orge286e842013-03-13 17:27:16 +0000214 }
215
216 void set(sk_tools::PictureRenderer* renderer,
217 sk_tools::PictureRenderer::BBoxHierarchyType bbhType) {
218 fRenderer = renderer;
219 fSavedBbhType = renderer->getBBoxHierarchyType();
220 renderer->setBBoxHierarchyType(bbhType);
221 }
222
223 ~AutoRestoreBbhType() {
224 if (NULL != fRenderer) {
225 fRenderer->setBBoxHierarchyType(fSavedBbhType);
226 }
227 }
228
229private:
230 sk_tools::PictureRenderer* fRenderer;
231 sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType;
232};
233}
234
edisonn@google.com84f548c2012-12-18 22:24:03 +0000235static bool render_picture(const SkString& inputPath, const SkString* outputDir,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000236 sk_tools::PictureRenderer& renderer) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000237 int diffs[256] = {0};
edisonn@google.com84f548c2012-12-18 22:24:03 +0000238 SkBitmap* bitmap = NULL;
239 bool success = render_picture(inputPath,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000240 FLAGS_writeWholeImage ? NULL : outputDir,
edisonn@google.com84f548c2012-12-18 22:24:03 +0000241 renderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000242 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000243
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000244 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL)) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000245 SkDebugf("Failed to draw the picture.\n");
246 SkDELETE(bitmap);
247 return false;
248 }
249
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000250 if (FLAGS_validate) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000251 SkBitmap* referenceBitmap = NULL;
junov@chromium.orge286e842013-03-13 17:27:16 +0000252 sk_tools::PictureRenderer* referenceRenderer;
253 // If the renderer uses a BBoxHierarchy, then the reference renderer
skia.committer@gmail.com03682be2013-03-14 07:02:51 +0000254 // will be the same renderer, without the bbh.
junov@chromium.orge286e842013-03-13 17:27:16 +0000255 AutoRestoreBbhType arbbh;
256 if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
257 renderer.getBBoxHierarchyType()) {
258 referenceRenderer = &renderer;
259 referenceRenderer->ref(); // to match auto unref below
260 arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
261 } else {
262 referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer);
263 }
264 SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer);
265
266 success = render_picture(inputPath, NULL, *referenceRenderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000267 &referenceBitmap);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000268
junov@chromium.orgc19c1912013-03-12 19:56:49 +0000269 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getPixels()) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000270 SkDebugf("Failed to draw the reference picture.\n");
271 SkDELETE(bitmap);
272 SkDELETE(referenceBitmap);
273 return false;
274 }
275
276 if (success && (bitmap->width() != referenceBitmap->width())) {
277 SkDebugf("Expected image width: %i, actual image width %i.\n",
278 referenceBitmap->width(), bitmap->width());
279 SkDELETE(bitmap);
280 SkDELETE(referenceBitmap);
281 return false;
282 }
283 if (success && (bitmap->height() != referenceBitmap->height())) {
284 SkDebugf("Expected image height: %i, actual image height %i",
285 referenceBitmap->height(), bitmap->height());
286 SkDELETE(bitmap);
287 SkDELETE(referenceBitmap);
288 return false;
289 }
skia.committer@gmail.coma7d8e3e2012-12-19 02:01:38 +0000290
edisonn@google.com84f548c2012-12-18 22:24:03 +0000291 for (int y = 0; success && y < bitmap->height(); y++) {
292 for (int x = 0; success && x < bitmap->width(); x++) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000293 int diff = MaxByteDiff(*referenceBitmap->getAddr32(x, y),
294 *bitmap->getAddr32(x, y));
295 SkASSERT(diff >= 0 && diff <= 255);
296 diffs[diff]++;
skia.committer@gmail.com4d28d982013-01-17 07:06:06 +0000297
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000298 if (diff > FLAGS_maxComponentDiff) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000299 SkDebugf("Expected pixel at (%i %i) exceedds maximum "
300 "component diff of %i: 0x%x, actual 0x%x\n",
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000301 x, y, FLAGS_maxComponentDiff,
edisonn@google.com01754bf2013-01-11 16:08:07 +0000302 *referenceBitmap->getAddr32(x, y),
edisonn@google.com84f548c2012-12-18 22:24:03 +0000303 *bitmap->getAddr32(x, y));
304 SkDELETE(bitmap);
305 SkDELETE(referenceBitmap);
306 return false;
307 }
308 }
309 }
310 SkDELETE(referenceBitmap);
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000311
312 for (int i = 1; i <= 255; ++i) {
313 if(diffs[i] > 0) {
314 SkDebugf("Number of pixels with max diff of %i is %i\n", i, diffs[i]);
315 }
316 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000317 }
318
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000319 if (FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000320 sk_tools::force_all_opaque(*bitmap);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000321 if (NULL != outputDir && FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000322 SkString inputFilename;
323 sk_tools::get_basename(&inputFilename, inputPath);
324 SkString outputPath;
325 make_output_filepath(&outputPath, *outputDir, inputFilename);
326 outputPath.append(".png");
327 if (!SkImageEncoder::EncodeFile(outputPath.c_str(), *bitmap,
328 SkImageEncoder::kPNG_Type, 100)) {
329 SkDebugf("Failed to draw the picture.\n");
330 success = false;
331 }
332 }
333 }
334 SkDELETE(bitmap);
335
336 return success;
337}
338
339
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000340static int process_input(const char* input, const SkString* outputDir,
341 sk_tools::PictureRenderer& renderer) {
342 SkOSFile::Iter iter(input, "skp");
junov@chromium.org777442d2012-06-12 14:56:36 +0000343 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000344 int failures = 0;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000345 SkDebugf("process_input, %s\n", input);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000346 if (iter.next(&inputFilename)) {
347 do {
348 SkString inputPath;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000349 SkString inputAsSkString(input);
350 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
351 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000352 ++failures;
353 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000354 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000355 } else if (SkStrEndsWith(input, ".skp")) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000356 SkString inputPath(input);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000357 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000358 ++failures;
359 }
360 } else {
361 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000362 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000363 SkDebugf(warning.c_str());
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000364 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000365 return failures;
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000366}
367
caryclark@google.com5987f582012-10-02 18:33:14 +0000368int tool_main(int argc, char** argv);
369int tool_main(int argc, char** argv) {
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000370 SkCommandLineFlags::SetUsage("Render .skp files.");
371 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000372
scroggo@google.com604e0c22013-04-09 21:25:46 +0000373 if (FLAGS_readPath.isEmpty()) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000374 SkDebugf(".skp files or directories are required.\n");
375 exit(-1);
376 }
377
378 if (FLAGS_maxComponentDiff < 0 || FLAGS_maxComponentDiff > 256) {
379 SkDebugf("--maxComponentDiff must be between 0 and 256\n");
380 exit(-1);
381 }
382
383 if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) {
384 SkDebugf("--maxComponentDiff requires --validate\n");
385 exit(-1);
386 }
387
388 if (FLAGS_clone < 0) {
389 SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone);
390 exit(-1);
391 }
392
scroggo@google.com1125d392013-05-03 20:43:37 +0000393 if (FLAGS_writeEncodedImages) {
394 if (FLAGS_writePath.isEmpty()) {
395 SkDebugf("--writeEncodedImages requires --writePath\n");
396 exit(-1);
397 }
398 if (FLAGS_deferImageDecoding) {
399 SkDebugf("--writeEncodedImages is not compatible with --deferImageDecoding\n");
400 exit(-1);
401 }
402 }
403
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000404 SkString errorString;
405 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
406 kRender_PictureTool));
407 if (errorString.size() > 0) {
408 SkDebugf("%s\n", errorString.c_str());
409 }
410
411 if (renderer.get() == NULL) {
412 exit(-1);
413 }
414
borenet@google.com66bcbd12012-09-17 18:26:06 +0000415 SkAutoGraphics ag;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000416
417 SkString outputDir;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000418 if (FLAGS_writePath.count() == 1) {
419 outputDir.set(FLAGS_writePath[0]);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000420 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000421
borenet@google.com66bcbd12012-09-17 18:26:06 +0000422 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000423 for (int i = 0; i < FLAGS_readPath.count(); i ++) {
424 failures += process_input(FLAGS_readPath[i], &outputDir, *renderer.get());
junov@chromium.org777442d2012-06-12 14:56:36 +0000425 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000426 if (failures != 0) {
427 SkDebugf("Failed to render %i pictures.\n", failures);
428 return 1;
429 }
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000430#if SK_SUPPORT_GPU
431#if GR_CACHE_STATS
432 if (renderer->isUsingGpuDevice()) {
433 GrContext* ctx = renderer->getGrContext();
434
435 ctx->printCacheStats();
436 }
437#endif
438#endif
caryclark@google.com868e1f62012-10-02 20:00:03 +0000439 return 0;
junov@chromium.org777442d2012-06-12 14:56:36 +0000440}
caryclark@google.com5987f582012-10-02 18:33:14 +0000441
442#if !defined SK_BUILD_FOR_IOS
443int main(int argc, char * const argv[]) {
444 return tool_main(argc, (char**) argv);
445}
446#endif