blob: de477d3336157468157707bc410f64ea772d3b3b [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.comf1754ec2013-06-28 21:32:00 +0000152 SkPicture::InstallPixelRefProc proc;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000153 if (FLAGS_deferImageDecoding) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000154 proc = &lazy_decode_bitmap;
scroggo@google.com1125d392013-05-03 20:43:37 +0000155 } else if (FLAGS_writeEncodedImages) {
156 SkASSERT(!FLAGS_writePath.isEmpty());
157 reset_image_file_base_name(inputFilename);
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000158 proc = &write_image_to_file;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000159 } else {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000160 proc = &SkImageDecoder::DecodeMemory;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000161 }
scroggo@google.com1125d392013-05-03 20:43:37 +0000162
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000163 SkDebugf("deserializing... %s\n", inputPath.c_str());
164
165 SkPicture* picture = SkPicture::CreateFromStream(&inputStream, proc);
166
167 if (NULL == picture) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000168 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
169 return false;
170 }
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000171
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000172 for (int i = 0; i < FLAGS_clone; ++i) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000173 SkPicture* clone = picture->clone();
174 SkDELETE(picture);
175 picture = clone;
176 }
177
178 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
borenet@google.com03fcee82012-09-10 18:18:38 +0000179 inputPath.c_str());
skia.committer@gmail.com1d225f22012-09-14 02:01:10 +0000180
edisonn@google.com84f548c2012-12-18 22:24:03 +0000181 renderer.init(picture);
scroggo@google.comb4773b42012-10-01 20:06:09 +0000182 renderer.setup();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000183
borenet@google.com070d3542012-10-26 13:26:55 +0000184 SkString* outputPath = NULL;
scroggo@google.com1125d392013-05-03 20:43:37 +0000185 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) {
borenet@google.com070d3542012-10-26 13:26:55 +0000186 outputPath = SkNEW(SkString);
187 make_output_filepath(outputPath, *outputDir, inputFilename);
188 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000189
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000190 bool success = renderer.render(outputPath, out);
borenet@google.com070d3542012-10-26 13:26:55 +0000191 if (outputPath) {
192 if (!success) {
193 SkDebugf("Could not write to file %s\n", outputPath->c_str());
194 }
195 SkDELETE(outputPath);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000196 }
scroggo@google.com9a412522012-09-07 15:21:18 +0000197
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000198 renderer.end();
edisonn@google.com84f548c2012-12-18 22:24:03 +0000199
200 SkDELETE(picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000201 return success;
junov@chromium.org777442d2012-06-12 14:56:36 +0000202}
203
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000204static inline int getByte(uint32_t value, int index) {
205 SkASSERT(0 <= index && index < 4);
206 return (value >> (index * 8)) & 0xFF;
207}
208
209static int MaxByteDiff(uint32_t v1, uint32_t v2) {
210 return SkMax32(SkMax32(abs(getByte(v1, 0) - getByte(v2, 0)), abs(getByte(v1, 1) - getByte(v2, 1))),
211 SkMax32(abs(getByte(v1, 2) - getByte(v2, 2)), abs(getByte(v1, 3) - getByte(v2, 3))));
212}
213
junov@chromium.orge286e842013-03-13 17:27:16 +0000214namespace {
215class AutoRestoreBbhType {
216public:
217 AutoRestoreBbhType() {
218 fRenderer = NULL;
junov@chromium.orgd34fda12013-03-13 19:03:26 +0000219 fSavedBbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
junov@chromium.orge286e842013-03-13 17:27:16 +0000220 }
221
222 void set(sk_tools::PictureRenderer* renderer,
223 sk_tools::PictureRenderer::BBoxHierarchyType bbhType) {
224 fRenderer = renderer;
225 fSavedBbhType = renderer->getBBoxHierarchyType();
226 renderer->setBBoxHierarchyType(bbhType);
227 }
228
229 ~AutoRestoreBbhType() {
230 if (NULL != fRenderer) {
231 fRenderer->setBBoxHierarchyType(fSavedBbhType);
232 }
233 }
234
235private:
236 sk_tools::PictureRenderer* fRenderer;
237 sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType;
238};
239}
240
edisonn@google.com84f548c2012-12-18 22:24:03 +0000241static bool render_picture(const SkString& inputPath, const SkString* outputDir,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000242 sk_tools::PictureRenderer& renderer) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000243 int diffs[256] = {0};
edisonn@google.com84f548c2012-12-18 22:24:03 +0000244 SkBitmap* bitmap = NULL;
245 bool success = render_picture(inputPath,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000246 FLAGS_writeWholeImage ? NULL : outputDir,
edisonn@google.com84f548c2012-12-18 22:24:03 +0000247 renderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000248 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000249
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000250 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL)) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000251 SkDebugf("Failed to draw the picture.\n");
252 SkDELETE(bitmap);
253 return false;
254 }
255
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000256 if (FLAGS_validate) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000257 SkBitmap* referenceBitmap = NULL;
junov@chromium.orge286e842013-03-13 17:27:16 +0000258 sk_tools::PictureRenderer* referenceRenderer;
259 // If the renderer uses a BBoxHierarchy, then the reference renderer
skia.committer@gmail.com03682be2013-03-14 07:02:51 +0000260 // will be the same renderer, without the bbh.
junov@chromium.orge286e842013-03-13 17:27:16 +0000261 AutoRestoreBbhType arbbh;
262 if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
263 renderer.getBBoxHierarchyType()) {
264 referenceRenderer = &renderer;
265 referenceRenderer->ref(); // to match auto unref below
266 arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
267 } else {
268 referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer);
269 }
270 SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer);
271
272 success = render_picture(inputPath, NULL, *referenceRenderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000273 &referenceBitmap);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000274
junov@chromium.orgc19c1912013-03-12 19:56:49 +0000275 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getPixels()) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000276 SkDebugf("Failed to draw the reference picture.\n");
277 SkDELETE(bitmap);
278 SkDELETE(referenceBitmap);
279 return false;
280 }
281
282 if (success && (bitmap->width() != referenceBitmap->width())) {
283 SkDebugf("Expected image width: %i, actual image width %i.\n",
284 referenceBitmap->width(), bitmap->width());
285 SkDELETE(bitmap);
286 SkDELETE(referenceBitmap);
287 return false;
288 }
289 if (success && (bitmap->height() != referenceBitmap->height())) {
290 SkDebugf("Expected image height: %i, actual image height %i",
291 referenceBitmap->height(), bitmap->height());
292 SkDELETE(bitmap);
293 SkDELETE(referenceBitmap);
294 return false;
295 }
skia.committer@gmail.coma7d8e3e2012-12-19 02:01:38 +0000296
edisonn@google.com84f548c2012-12-18 22:24:03 +0000297 for (int y = 0; success && y < bitmap->height(); y++) {
298 for (int x = 0; success && x < bitmap->width(); x++) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000299 int diff = MaxByteDiff(*referenceBitmap->getAddr32(x, y),
300 *bitmap->getAddr32(x, y));
301 SkASSERT(diff >= 0 && diff <= 255);
302 diffs[diff]++;
skia.committer@gmail.com4d28d982013-01-17 07:06:06 +0000303
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000304 if (diff > FLAGS_maxComponentDiff) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000305 SkDebugf("Expected pixel at (%i %i) exceedds maximum "
306 "component diff of %i: 0x%x, actual 0x%x\n",
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000307 x, y, FLAGS_maxComponentDiff,
edisonn@google.com01754bf2013-01-11 16:08:07 +0000308 *referenceBitmap->getAddr32(x, y),
edisonn@google.com84f548c2012-12-18 22:24:03 +0000309 *bitmap->getAddr32(x, y));
310 SkDELETE(bitmap);
311 SkDELETE(referenceBitmap);
312 return false;
313 }
314 }
315 }
316 SkDELETE(referenceBitmap);
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000317
318 for (int i = 1; i <= 255; ++i) {
319 if(diffs[i] > 0) {
320 SkDebugf("Number of pixels with max diff of %i is %i\n", i, diffs[i]);
321 }
322 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000323 }
324
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000325 if (FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000326 sk_tools::force_all_opaque(*bitmap);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000327 if (NULL != outputDir && FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000328 SkString inputFilename;
329 sk_tools::get_basename(&inputFilename, inputPath);
330 SkString outputPath;
331 make_output_filepath(&outputPath, *outputDir, inputFilename);
332 outputPath.append(".png");
333 if (!SkImageEncoder::EncodeFile(outputPath.c_str(), *bitmap,
334 SkImageEncoder::kPNG_Type, 100)) {
335 SkDebugf("Failed to draw the picture.\n");
336 success = false;
337 }
338 }
339 }
340 SkDELETE(bitmap);
341
342 return success;
343}
344
345
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000346static int process_input(const char* input, const SkString* outputDir,
347 sk_tools::PictureRenderer& renderer) {
348 SkOSFile::Iter iter(input, "skp");
junov@chromium.org777442d2012-06-12 14:56:36 +0000349 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000350 int failures = 0;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000351 SkDebugf("process_input, %s\n", input);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000352 if (iter.next(&inputFilename)) {
353 do {
354 SkString inputPath;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000355 SkString inputAsSkString(input);
356 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
357 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000358 ++failures;
359 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000360 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000361 } else if (SkStrEndsWith(input, ".skp")) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000362 SkString inputPath(input);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000363 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000364 ++failures;
365 }
366 } else {
367 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000368 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000369 SkDebugf(warning.c_str());
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000370 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000371 return failures;
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000372}
373
caryclark@google.com5987f582012-10-02 18:33:14 +0000374int tool_main(int argc, char** argv);
375int tool_main(int argc, char** argv) {
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000376 SkCommandLineFlags::SetUsage("Render .skp files.");
377 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000378
scroggo@google.com604e0c22013-04-09 21:25:46 +0000379 if (FLAGS_readPath.isEmpty()) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000380 SkDebugf(".skp files or directories are required.\n");
381 exit(-1);
382 }
383
384 if (FLAGS_maxComponentDiff < 0 || FLAGS_maxComponentDiff > 256) {
385 SkDebugf("--maxComponentDiff must be between 0 and 256\n");
386 exit(-1);
387 }
388
389 if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) {
390 SkDebugf("--maxComponentDiff requires --validate\n");
391 exit(-1);
392 }
393
394 if (FLAGS_clone < 0) {
395 SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone);
396 exit(-1);
397 }
398
scroggo@google.com1125d392013-05-03 20:43:37 +0000399 if (FLAGS_writeEncodedImages) {
400 if (FLAGS_writePath.isEmpty()) {
401 SkDebugf("--writeEncodedImages requires --writePath\n");
402 exit(-1);
403 }
404 if (FLAGS_deferImageDecoding) {
405 SkDebugf("--writeEncodedImages is not compatible with --deferImageDecoding\n");
406 exit(-1);
407 }
408 }
409
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000410 SkString errorString;
411 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
412 kRender_PictureTool));
413 if (errorString.size() > 0) {
414 SkDebugf("%s\n", errorString.c_str());
415 }
416
417 if (renderer.get() == NULL) {
418 exit(-1);
419 }
420
borenet@google.com66bcbd12012-09-17 18:26:06 +0000421 SkAutoGraphics ag;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000422
423 SkString outputDir;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000424 if (FLAGS_writePath.count() == 1) {
425 outputDir.set(FLAGS_writePath[0]);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000426 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000427
borenet@google.com66bcbd12012-09-17 18:26:06 +0000428 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000429 for (int i = 0; i < FLAGS_readPath.count(); i ++) {
430 failures += process_input(FLAGS_readPath[i], &outputDir, *renderer.get());
junov@chromium.org777442d2012-06-12 14:56:36 +0000431 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000432 if (failures != 0) {
433 SkDebugf("Failed to render %i pictures.\n", failures);
434 return 1;
435 }
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000436#if SK_SUPPORT_GPU
437#if GR_CACHE_STATS
438 if (renderer->isUsingGpuDevice()) {
439 GrContext* ctx = renderer->getGrContext();
440
441 ctx->printCacheStats();
442 }
443#endif
444#endif
caryclark@google.com868e1f62012-10-02 20:00:03 +0000445 return 0;
junov@chromium.org777442d2012-06-12 14:56:36 +0000446}
caryclark@google.com5987f582012-10-02 18:33:14 +0000447
448#if !defined SK_BUILD_FOR_IOS
449int main(int argc, char * const argv[]) {
450 return tool_main(argc, (char**) argv);
451}
452#endif