blob: 4a7e708c134de2bdc88412f0bc6ddda7f1216c69 [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"
scroggo@google.com7def5e12013-05-31 14:00:10 +000012#include "SkForceLinking.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.com7def5e12013-05-31 14:00:10 +000025// Required to ensure that image decoders get linked correctly.
26__SK_FORCE_IMAGE_DECODER_LINKING;
27
scroggo@google.com161e1ba2013-03-04 16:41:06 +000028// Flags used by this file, alphabetically:
29DEFINE_int32(clone, 0, "Clone the picture n times before rendering.");
30DECLARE_bool(deferImageDecoding);
31DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Components that differ "
32 "by more than this amount are considered errors, though all diffs are reported. "
33 "Requires --validate.");
scroggo@google.com604e0c22013-04-09 21:25:46 +000034DECLARE_string(readPath);
scroggo@google.com1125d392013-05-03 20:43:37 +000035DEFINE_bool(writeEncodedImages, false, "Any time the skp contains an encoded image, write it to a "
36 "file rather than decoding it. Requires writePath to be set. Skips drawing the full "
37 "skp to a file. Not compatible with deferImageDecoding.");
scroggo@google.com604e0c22013-04-09 21:25:46 +000038DEFINE_string2(writePath, w, "", "Directory to write the rendered images.");
scroggo@google.com161e1ba2013-03-04 16:41:06 +000039DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered image to a "
40 "file, instead of an image for each tile.");
41DEFINE_bool(validate, false, "Verify that the rendered image contains the same pixels as "
junov@chromium.orge286e842013-03-13 17:27:16 +000042 "the picture rendered in simple mode. When used in conjunction with --bbh, results "
43 "are validated against the picture rendered in the same mode, but without the bbh.");
junov@chromium.org777442d2012-06-12 14:56:36 +000044
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +000045static void make_output_filepath(SkString* path, const SkString& dir,
junov@chromium.org777442d2012-06-12 14:56:36 +000046 const SkString& name) {
twiz@google.coma31b8bb2012-06-22 18:24:56 +000047 sk_tools::make_filepath(path, dir, name);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +000048 // Remove ".skp"
49 path->remove(path->size() - 4, 4);
junov@chromium.org777442d2012-06-12 14:56:36 +000050}
51
scroggo@google.combb281f72013-03-18 21:37:39 +000052// Defined in PictureRenderingFlags.cpp
53extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap);
scroggo@google.comf8d7d272013-02-22 21:38:35 +000054
scroggo@google.com1125d392013-05-03 20:43:37 +000055////////////////////////////////////////////////////////////////////////////////////////////////////
56
57/**
58 * Table for translating from format of data to a suffix.
59 */
60struct Format {
61 SkImageDecoder::Format fFormat;
62 const char* fSuffix;
63};
64static const Format gFormats[] = {
65 { SkImageDecoder::kBMP_Format, ".bmp" },
66 { SkImageDecoder::kGIF_Format, ".gif" },
67 { SkImageDecoder::kICO_Format, ".ico" },
68 { SkImageDecoder::kJPEG_Format, ".jpg" },
69 { SkImageDecoder::kPNG_Format, ".png" },
70 { SkImageDecoder::kWBMP_Format, ".wbmp" },
71 { SkImageDecoder::kWEBP_Format, ".webp" },
72 { SkImageDecoder::kUnknown_Format, "" },
73};
74
75/**
76 * Get an appropriate suffix for an image format.
77 */
78static const char* get_suffix_from_format(SkImageDecoder::Format format) {
79 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
80 if (gFormats[i].fFormat == format) {
81 return gFormats[i].fSuffix;
82 }
83 }
84 return "";
85}
86
87/**
88 * Base name for an image file created from the encoded data in an skp.
89 */
90static SkString gInputFileName;
91
92/**
93 * Number to be appended to the image file name so that it is unique.
94 */
95static uint32_t gImageNo;
96
97/**
98 * Set up the name for writing encoded data to a file.
99 * Sets gInputFileName to name, minus any extension ".*"
100 * Sets gImageNo to 0, so images from file "X.skp" will
101 * look like "X_<gImageNo>.<suffix>", beginning with 0
102 * for each new skp.
103 */
104static void reset_image_file_base_name(const SkString& name) {
105 gImageNo = 0;
106 // Remove ".skp"
107 const char* cName = name.c_str();
108 const char* dot = strrchr(cName, '.');
109 if (dot != NULL) {
110 gInputFileName.set(cName, dot - cName);
111 } else {
112 gInputFileName.set(name);
113 }
114}
115
116/**
117 * Write the raw encoded bitmap data to a file.
118 */
119static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitmap) {
120 SkASSERT(!FLAGS_writePath.isEmpty());
121 SkMemoryStream memStream(buffer, size);
122 SkString outPath;
123 SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&memStream);
124 SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++,
125 get_suffix_from_format(format));
126 SkString dir(FLAGS_writePath[0]);
127 sk_tools::make_filepath(&outPath, dir, name);
128 SkFILEWStream fileStream(outPath.c_str());
129 if (!(fileStream.isValid() && fileStream.write(buffer, size))) {
130 SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str());
131 }
132 // Put in a dummy bitmap.
133 return SkImageDecoder::DecodeStream(&memStream, bitmap, SkBitmap::kNo_Config,
134 SkImageDecoder::kDecodeBounds_Mode);
135}
136
137////////////////////////////////////////////////////////////////////////////////////////////////////
138
borenet@google.com070d3542012-10-26 13:26:55 +0000139static bool render_picture(const SkString& inputPath, const SkString* outputDir,
edisonn@google.com84f548c2012-12-18 22:24:03 +0000140 sk_tools::PictureRenderer& renderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000141 SkBitmap** out) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000142 SkString inputFilename;
143 sk_tools::get_basename(&inputFilename, inputPath);
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000144
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000145 SkFILEStream inputStream;
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000146 inputStream.setPath(inputPath.c_str());
147 if (!inputStream.isValid()) {
148 SkDebugf("Could not open file %s\n", inputPath.c_str());
borenet@google.com66bcbd12012-09-17 18:26:06 +0000149 return false;
twiz@google.coma31b8bb2012-06-22 18:24:56 +0000150 }
151
scroggo@google.com5330e442013-06-28 17:52:53 +0000152 SkDebugf("deserializing... %s\n", inputPath.c_str());
153
borenet@google.com66bcbd12012-09-17 18:26:06 +0000154 bool success = false;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000155 SkPicture* picture;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000156 if (FLAGS_deferImageDecoding) {
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000157 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bitmap));
scroggo@google.com1125d392013-05-03 20:43:37 +0000158 } else if (FLAGS_writeEncodedImages) {
159 SkASSERT(!FLAGS_writePath.isEmpty());
160 reset_image_file_base_name(inputFilename);
161 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &write_image_to_file));
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000162 } else {
163 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder::DecodeMemory));
164 }
scroggo@google.com1125d392013-05-03 20:43:37 +0000165
borenet@google.com66bcbd12012-09-17 18:26:06 +0000166 if (!success) {
167 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
168 return false;
169 }
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000170
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000171 for (int i = 0; i < FLAGS_clone; ++i) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000172 SkPicture* clone = picture->clone();
173 SkDELETE(picture);
174 picture = clone;
175 }
176
177 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
borenet@google.com03fcee82012-09-10 18:18:38 +0000178 inputPath.c_str());
skia.committer@gmail.com1d225f22012-09-14 02:01:10 +0000179
edisonn@google.com84f548c2012-12-18 22:24:03 +0000180 renderer.init(picture);
scroggo@google.comb4773b42012-10-01 20:06:09 +0000181 renderer.setup();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000182
borenet@google.com070d3542012-10-26 13:26:55 +0000183 SkString* outputPath = NULL;
scroggo@google.com1125d392013-05-03 20:43:37 +0000184 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) {
borenet@google.com070d3542012-10-26 13:26:55 +0000185 outputPath = SkNEW(SkString);
186 make_output_filepath(outputPath, *outputDir, inputFilename);
187 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000188
189 success = renderer.render(outputPath, out);
borenet@google.com070d3542012-10-26 13:26:55 +0000190 if (outputPath) {
191 if (!success) {
192 SkDebugf("Could not write to file %s\n", outputPath->c_str());
193 }
194 SkDELETE(outputPath);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000195 }
scroggo@google.com9a412522012-09-07 15:21:18 +0000196
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000197 renderer.end();
edisonn@google.com84f548c2012-12-18 22:24:03 +0000198
199 SkDELETE(picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000200 return success;
junov@chromium.org777442d2012-06-12 14:56:36 +0000201}
202
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000203static inline int getByte(uint32_t value, int index) {
204 SkASSERT(0 <= index && index < 4);
205 return (value >> (index * 8)) & 0xFF;
206}
207
208static int MaxByteDiff(uint32_t v1, uint32_t v2) {
209 return SkMax32(SkMax32(abs(getByte(v1, 0) - getByte(v2, 0)), abs(getByte(v1, 1) - getByte(v2, 1))),
210 SkMax32(abs(getByte(v1, 2) - getByte(v2, 2)), abs(getByte(v1, 3) - getByte(v2, 3))));
211}
212
junov@chromium.orge286e842013-03-13 17:27:16 +0000213namespace {
214class AutoRestoreBbhType {
215public:
216 AutoRestoreBbhType() {
217 fRenderer = NULL;
junov@chromium.orgd34fda12013-03-13 19:03:26 +0000218 fSavedBbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
junov@chromium.orge286e842013-03-13 17:27:16 +0000219 }
220
221 void set(sk_tools::PictureRenderer* renderer,
222 sk_tools::PictureRenderer::BBoxHierarchyType bbhType) {
223 fRenderer = renderer;
224 fSavedBbhType = renderer->getBBoxHierarchyType();
225 renderer->setBBoxHierarchyType(bbhType);
226 }
227
228 ~AutoRestoreBbhType() {
229 if (NULL != fRenderer) {
230 fRenderer->setBBoxHierarchyType(fSavedBbhType);
231 }
232 }
233
234private:
235 sk_tools::PictureRenderer* fRenderer;
236 sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType;
237};
238}
239
edisonn@google.com84f548c2012-12-18 22:24:03 +0000240static bool render_picture(const SkString& inputPath, const SkString* outputDir,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000241 sk_tools::PictureRenderer& renderer) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000242 int diffs[256] = {0};
edisonn@google.com84f548c2012-12-18 22:24:03 +0000243 SkBitmap* bitmap = NULL;
244 bool success = render_picture(inputPath,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000245 FLAGS_writeWholeImage ? NULL : outputDir,
edisonn@google.com84f548c2012-12-18 22:24:03 +0000246 renderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000247 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000248
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000249 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL)) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000250 SkDebugf("Failed to draw the picture.\n");
251 SkDELETE(bitmap);
252 return false;
253 }
254
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000255 if (FLAGS_validate) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000256 SkBitmap* referenceBitmap = NULL;
junov@chromium.orge286e842013-03-13 17:27:16 +0000257 sk_tools::PictureRenderer* referenceRenderer;
258 // If the renderer uses a BBoxHierarchy, then the reference renderer
skia.committer@gmail.com03682be2013-03-14 07:02:51 +0000259 // will be the same renderer, without the bbh.
junov@chromium.orge286e842013-03-13 17:27:16 +0000260 AutoRestoreBbhType arbbh;
261 if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
262 renderer.getBBoxHierarchyType()) {
263 referenceRenderer = &renderer;
264 referenceRenderer->ref(); // to match auto unref below
265 arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
266 } else {
267 referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer);
268 }
269 SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer);
270
271 success = render_picture(inputPath, NULL, *referenceRenderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000272 &referenceBitmap);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000273
junov@chromium.orgc19c1912013-03-12 19:56:49 +0000274 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getPixels()) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000275 SkDebugf("Failed to draw the reference picture.\n");
276 SkDELETE(bitmap);
277 SkDELETE(referenceBitmap);
278 return false;
279 }
280
281 if (success && (bitmap->width() != referenceBitmap->width())) {
282 SkDebugf("Expected image width: %i, actual image width %i.\n",
283 referenceBitmap->width(), bitmap->width());
284 SkDELETE(bitmap);
285 SkDELETE(referenceBitmap);
286 return false;
287 }
288 if (success && (bitmap->height() != referenceBitmap->height())) {
289 SkDebugf("Expected image height: %i, actual image height %i",
290 referenceBitmap->height(), bitmap->height());
291 SkDELETE(bitmap);
292 SkDELETE(referenceBitmap);
293 return false;
294 }
skia.committer@gmail.coma7d8e3e2012-12-19 02:01:38 +0000295
edisonn@google.com84f548c2012-12-18 22:24:03 +0000296 for (int y = 0; success && y < bitmap->height(); y++) {
297 for (int x = 0; success && x < bitmap->width(); x++) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000298 int diff = MaxByteDiff(*referenceBitmap->getAddr32(x, y),
299 *bitmap->getAddr32(x, y));
300 SkASSERT(diff >= 0 && diff <= 255);
301 diffs[diff]++;
skia.committer@gmail.com4d28d982013-01-17 07:06:06 +0000302
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000303 if (diff > FLAGS_maxComponentDiff) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000304 SkDebugf("Expected pixel at (%i %i) exceedds maximum "
305 "component diff of %i: 0x%x, actual 0x%x\n",
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000306 x, y, FLAGS_maxComponentDiff,
edisonn@google.com01754bf2013-01-11 16:08:07 +0000307 *referenceBitmap->getAddr32(x, y),
edisonn@google.com84f548c2012-12-18 22:24:03 +0000308 *bitmap->getAddr32(x, y));
309 SkDELETE(bitmap);
310 SkDELETE(referenceBitmap);
311 return false;
312 }
313 }
314 }
315 SkDELETE(referenceBitmap);
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000316
317 for (int i = 1; i <= 255; ++i) {
318 if(diffs[i] > 0) {
319 SkDebugf("Number of pixels with max diff of %i is %i\n", i, diffs[i]);
320 }
321 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000322 }
323
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000324 if (FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000325 sk_tools::force_all_opaque(*bitmap);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000326 if (NULL != outputDir && FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000327 SkString inputFilename;
328 sk_tools::get_basename(&inputFilename, inputPath);
329 SkString outputPath;
330 make_output_filepath(&outputPath, *outputDir, inputFilename);
331 outputPath.append(".png");
332 if (!SkImageEncoder::EncodeFile(outputPath.c_str(), *bitmap,
333 SkImageEncoder::kPNG_Type, 100)) {
334 SkDebugf("Failed to draw the picture.\n");
335 success = false;
336 }
337 }
338 }
339 SkDELETE(bitmap);
340
341 return success;
342}
343
344
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000345static int process_input(const char* input, const SkString* outputDir,
346 sk_tools::PictureRenderer& renderer) {
347 SkOSFile::Iter iter(input, "skp");
junov@chromium.org777442d2012-06-12 14:56:36 +0000348 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000349 int failures = 0;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000350 SkDebugf("process_input, %s\n", input);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000351 if (iter.next(&inputFilename)) {
352 do {
353 SkString inputPath;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000354 SkString inputAsSkString(input);
355 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
356 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000357 ++failures;
358 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000359 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000360 } else if (SkStrEndsWith(input, ".skp")) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000361 SkString inputPath(input);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000362 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000363 ++failures;
364 }
365 } else {
366 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000367 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000368 SkDebugf(warning.c_str());
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000369 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000370 return failures;
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000371}
372
caryclark@google.com5987f582012-10-02 18:33:14 +0000373int tool_main(int argc, char** argv);
374int tool_main(int argc, char** argv) {
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000375 SkCommandLineFlags::SetUsage("Render .skp files.");
376 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000377
scroggo@google.com604e0c22013-04-09 21:25:46 +0000378 if (FLAGS_readPath.isEmpty()) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000379 SkDebugf(".skp files or directories are required.\n");
380 exit(-1);
381 }
382
383 if (FLAGS_maxComponentDiff < 0 || FLAGS_maxComponentDiff > 256) {
384 SkDebugf("--maxComponentDiff must be between 0 and 256\n");
385 exit(-1);
386 }
387
388 if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) {
389 SkDebugf("--maxComponentDiff requires --validate\n");
390 exit(-1);
391 }
392
393 if (FLAGS_clone < 0) {
394 SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone);
395 exit(-1);
396 }
397
scroggo@google.com1125d392013-05-03 20:43:37 +0000398 if (FLAGS_writeEncodedImages) {
399 if (FLAGS_writePath.isEmpty()) {
400 SkDebugf("--writeEncodedImages requires --writePath\n");
401 exit(-1);
402 }
403 if (FLAGS_deferImageDecoding) {
404 SkDebugf("--writeEncodedImages is not compatible with --deferImageDecoding\n");
405 exit(-1);
406 }
407 }
408
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000409 SkString errorString;
410 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
411 kRender_PictureTool));
412 if (errorString.size() > 0) {
413 SkDebugf("%s\n", errorString.c_str());
414 }
415
416 if (renderer.get() == NULL) {
417 exit(-1);
418 }
419
borenet@google.com66bcbd12012-09-17 18:26:06 +0000420 SkAutoGraphics ag;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000421
422 SkString outputDir;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000423 if (FLAGS_writePath.count() == 1) {
424 outputDir.set(FLAGS_writePath[0]);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000425 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000426
borenet@google.com66bcbd12012-09-17 18:26:06 +0000427 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000428 for (int i = 0; i < FLAGS_readPath.count(); i ++) {
429 failures += process_input(FLAGS_readPath[i], &outputDir, *renderer.get());
junov@chromium.org777442d2012-06-12 14:56:36 +0000430 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000431 if (failures != 0) {
432 SkDebugf("Failed to render %i pictures.\n", failures);
433 return 1;
434 }
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000435#if SK_SUPPORT_GPU
436#if GR_CACHE_STATS
437 if (renderer->isUsingGpuDevice()) {
438 GrContext* ctx = renderer->getGrContext();
439
440 ctx->printCacheStats();
441 }
442#endif
443#endif
caryclark@google.com868e1f62012-10-02 20:00:03 +0000444 return 0;
junov@chromium.org777442d2012-06-12 14:56:36 +0000445}
caryclark@google.com5987f582012-10-02 18:33:14 +0000446
447#if !defined SK_BUILD_FOR_IOS
448int main(int argc, char * const argv[]) {
449 return tool_main(argc, (char**) argv);
450}
451#endif