blob: f06cfeb1481d490be3a3b057fdd401dfab489ddc [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
borenet@google.com66bcbd12012-09-17 18:26:06 +0000152 bool success = false;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000153 SkPicture* picture;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000154 if (FLAGS_deferImageDecoding) {
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000155 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bitmap));
scroggo@google.com1125d392013-05-03 20:43:37 +0000156 } else if (FLAGS_writeEncodedImages) {
157 SkASSERT(!FLAGS_writePath.isEmpty());
158 reset_image_file_base_name(inputFilename);
159 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &write_image_to_file));
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000160 } else {
161 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder::DecodeMemory));
162 }
scroggo@google.com1125d392013-05-03 20:43:37 +0000163
borenet@google.com66bcbd12012-09-17 18:26:06 +0000164 if (!success) {
165 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
166 return false;
167 }
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000168
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000169 for (int i = 0; i < FLAGS_clone; ++i) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000170 SkPicture* clone = picture->clone();
171 SkDELETE(picture);
172 picture = clone;
173 }
174
175 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
borenet@google.com03fcee82012-09-10 18:18:38 +0000176 inputPath.c_str());
skia.committer@gmail.com1d225f22012-09-14 02:01:10 +0000177
edisonn@google.com84f548c2012-12-18 22:24:03 +0000178 renderer.init(picture);
scroggo@google.comb4773b42012-10-01 20:06:09 +0000179 renderer.setup();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000180
borenet@google.com070d3542012-10-26 13:26:55 +0000181 SkString* outputPath = NULL;
scroggo@google.com1125d392013-05-03 20:43:37 +0000182 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) {
borenet@google.com070d3542012-10-26 13:26:55 +0000183 outputPath = SkNEW(SkString);
184 make_output_filepath(outputPath, *outputDir, inputFilename);
185 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000186
187 success = renderer.render(outputPath, out);
borenet@google.com070d3542012-10-26 13:26:55 +0000188 if (outputPath) {
189 if (!success) {
190 SkDebugf("Could not write to file %s\n", outputPath->c_str());
191 }
192 SkDELETE(outputPath);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000193 }
scroggo@google.com9a412522012-09-07 15:21:18 +0000194
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000195 renderer.end();
edisonn@google.com84f548c2012-12-18 22:24:03 +0000196
197 SkDELETE(picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000198 return success;
junov@chromium.org777442d2012-06-12 14:56:36 +0000199}
200
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000201static inline int getByte(uint32_t value, int index) {
202 SkASSERT(0 <= index && index < 4);
203 return (value >> (index * 8)) & 0xFF;
204}
205
206static int MaxByteDiff(uint32_t v1, uint32_t v2) {
207 return SkMax32(SkMax32(abs(getByte(v1, 0) - getByte(v2, 0)), abs(getByte(v1, 1) - getByte(v2, 1))),
208 SkMax32(abs(getByte(v1, 2) - getByte(v2, 2)), abs(getByte(v1, 3) - getByte(v2, 3))));
209}
210
junov@chromium.orge286e842013-03-13 17:27:16 +0000211namespace {
212class AutoRestoreBbhType {
213public:
214 AutoRestoreBbhType() {
215 fRenderer = NULL;
junov@chromium.orgd34fda12013-03-13 19:03:26 +0000216 fSavedBbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
junov@chromium.orge286e842013-03-13 17:27:16 +0000217 }
218
219 void set(sk_tools::PictureRenderer* renderer,
220 sk_tools::PictureRenderer::BBoxHierarchyType bbhType) {
221 fRenderer = renderer;
222 fSavedBbhType = renderer->getBBoxHierarchyType();
223 renderer->setBBoxHierarchyType(bbhType);
224 }
225
226 ~AutoRestoreBbhType() {
227 if (NULL != fRenderer) {
228 fRenderer->setBBoxHierarchyType(fSavedBbhType);
229 }
230 }
231
232private:
233 sk_tools::PictureRenderer* fRenderer;
234 sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType;
235};
236}
237
edisonn@google.com84f548c2012-12-18 22:24:03 +0000238static bool render_picture(const SkString& inputPath, const SkString* outputDir,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000239 sk_tools::PictureRenderer& renderer) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000240 int diffs[256] = {0};
edisonn@google.com84f548c2012-12-18 22:24:03 +0000241 SkBitmap* bitmap = NULL;
242 bool success = render_picture(inputPath,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000243 FLAGS_writeWholeImage ? NULL : outputDir,
edisonn@google.com84f548c2012-12-18 22:24:03 +0000244 renderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000245 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000246
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000247 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL)) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000248 SkDebugf("Failed to draw the picture.\n");
249 SkDELETE(bitmap);
250 return false;
251 }
252
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000253 if (FLAGS_validate) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000254 SkBitmap* referenceBitmap = NULL;
junov@chromium.orge286e842013-03-13 17:27:16 +0000255 sk_tools::PictureRenderer* referenceRenderer;
256 // If the renderer uses a BBoxHierarchy, then the reference renderer
skia.committer@gmail.com03682be2013-03-14 07:02:51 +0000257 // will be the same renderer, without the bbh.
junov@chromium.orge286e842013-03-13 17:27:16 +0000258 AutoRestoreBbhType arbbh;
259 if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
260 renderer.getBBoxHierarchyType()) {
261 referenceRenderer = &renderer;
262 referenceRenderer->ref(); // to match auto unref below
263 arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
264 } else {
265 referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer);
266 }
267 SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer);
268
269 success = render_picture(inputPath, NULL, *referenceRenderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000270 &referenceBitmap);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000271
junov@chromium.orgc19c1912013-03-12 19:56:49 +0000272 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getPixels()) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000273 SkDebugf("Failed to draw the reference picture.\n");
274 SkDELETE(bitmap);
275 SkDELETE(referenceBitmap);
276 return false;
277 }
278
279 if (success && (bitmap->width() != referenceBitmap->width())) {
280 SkDebugf("Expected image width: %i, actual image width %i.\n",
281 referenceBitmap->width(), bitmap->width());
282 SkDELETE(bitmap);
283 SkDELETE(referenceBitmap);
284 return false;
285 }
286 if (success && (bitmap->height() != referenceBitmap->height())) {
287 SkDebugf("Expected image height: %i, actual image height %i",
288 referenceBitmap->height(), bitmap->height());
289 SkDELETE(bitmap);
290 SkDELETE(referenceBitmap);
291 return false;
292 }
skia.committer@gmail.coma7d8e3e2012-12-19 02:01:38 +0000293
edisonn@google.com84f548c2012-12-18 22:24:03 +0000294 for (int y = 0; success && y < bitmap->height(); y++) {
295 for (int x = 0; success && x < bitmap->width(); x++) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000296 int diff = MaxByteDiff(*referenceBitmap->getAddr32(x, y),
297 *bitmap->getAddr32(x, y));
298 SkASSERT(diff >= 0 && diff <= 255);
299 diffs[diff]++;
skia.committer@gmail.com4d28d982013-01-17 07:06:06 +0000300
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000301 if (diff > FLAGS_maxComponentDiff) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000302 SkDebugf("Expected pixel at (%i %i) exceedds maximum "
303 "component diff of %i: 0x%x, actual 0x%x\n",
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000304 x, y, FLAGS_maxComponentDiff,
edisonn@google.com01754bf2013-01-11 16:08:07 +0000305 *referenceBitmap->getAddr32(x, y),
edisonn@google.com84f548c2012-12-18 22:24:03 +0000306 *bitmap->getAddr32(x, y));
307 SkDELETE(bitmap);
308 SkDELETE(referenceBitmap);
309 return false;
310 }
311 }
312 }
313 SkDELETE(referenceBitmap);
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000314
315 for (int i = 1; i <= 255; ++i) {
316 if(diffs[i] > 0) {
317 SkDebugf("Number of pixels with max diff of %i is %i\n", i, diffs[i]);
318 }
319 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000320 }
321
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000322 if (FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000323 sk_tools::force_all_opaque(*bitmap);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000324 if (NULL != outputDir && FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000325 SkString inputFilename;
326 sk_tools::get_basename(&inputFilename, inputPath);
327 SkString outputPath;
328 make_output_filepath(&outputPath, *outputDir, inputFilename);
329 outputPath.append(".png");
330 if (!SkImageEncoder::EncodeFile(outputPath.c_str(), *bitmap,
331 SkImageEncoder::kPNG_Type, 100)) {
332 SkDebugf("Failed to draw the picture.\n");
333 success = false;
334 }
335 }
336 }
337 SkDELETE(bitmap);
338
339 return success;
340}
341
342
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000343static int process_input(const char* input, const SkString* outputDir,
344 sk_tools::PictureRenderer& renderer) {
345 SkOSFile::Iter iter(input, "skp");
junov@chromium.org777442d2012-06-12 14:56:36 +0000346 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000347 int failures = 0;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000348 SkDebugf("process_input, %s\n", input);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000349 if (iter.next(&inputFilename)) {
350 do {
351 SkString inputPath;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000352 SkString inputAsSkString(input);
353 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
354 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000355 ++failures;
356 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000357 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000358 } else if (SkStrEndsWith(input, ".skp")) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000359 SkString inputPath(input);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000360 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000361 ++failures;
362 }
363 } else {
364 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000365 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000366 SkDebugf(warning.c_str());
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000367 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000368 return failures;
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000369}
370
caryclark@google.com5987f582012-10-02 18:33:14 +0000371int tool_main(int argc, char** argv);
372int tool_main(int argc, char** argv) {
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000373 SkCommandLineFlags::SetUsage("Render .skp files.");
374 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000375
scroggo@google.com604e0c22013-04-09 21:25:46 +0000376 if (FLAGS_readPath.isEmpty()) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000377 SkDebugf(".skp files or directories are required.\n");
378 exit(-1);
379 }
380
381 if (FLAGS_maxComponentDiff < 0 || FLAGS_maxComponentDiff > 256) {
382 SkDebugf("--maxComponentDiff must be between 0 and 256\n");
383 exit(-1);
384 }
385
386 if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) {
387 SkDebugf("--maxComponentDiff requires --validate\n");
388 exit(-1);
389 }
390
391 if (FLAGS_clone < 0) {
392 SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone);
393 exit(-1);
394 }
395
scroggo@google.com1125d392013-05-03 20:43:37 +0000396 if (FLAGS_writeEncodedImages) {
397 if (FLAGS_writePath.isEmpty()) {
398 SkDebugf("--writeEncodedImages requires --writePath\n");
399 exit(-1);
400 }
401 if (FLAGS_deferImageDecoding) {
402 SkDebugf("--writeEncodedImages is not compatible with --deferImageDecoding\n");
403 exit(-1);
404 }
405 }
406
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000407 SkString errorString;
408 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
409 kRender_PictureTool));
410 if (errorString.size() > 0) {
411 SkDebugf("%s\n", errorString.c_str());
412 }
413
414 if (renderer.get() == NULL) {
415 exit(-1);
416 }
417
borenet@google.com66bcbd12012-09-17 18:26:06 +0000418 SkAutoGraphics ag;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000419
420 SkString outputDir;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000421 if (FLAGS_writePath.count() == 1) {
422 outputDir.set(FLAGS_writePath[0]);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000423 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000424
borenet@google.com66bcbd12012-09-17 18:26:06 +0000425 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000426 for (int i = 0; i < FLAGS_readPath.count(); i ++) {
427 failures += process_input(FLAGS_readPath[i], &outputDir, *renderer.get());
junov@chromium.org777442d2012-06-12 14:56:36 +0000428 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000429 if (failures != 0) {
430 SkDebugf("Failed to render %i pictures.\n", failures);
431 return 1;
432 }
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000433#if SK_SUPPORT_GPU
434#if GR_CACHE_STATS
435 if (renderer->isUsingGpuDevice()) {
436 GrContext* ctx = renderer->getGrContext();
437
438 ctx->printCacheStats();
439 }
440#endif
441#endif
caryclark@google.com868e1f62012-10-02 20:00:03 +0000442 return 0;
junov@chromium.org777442d2012-06-12 14:56:36 +0000443}
caryclark@google.com5987f582012-10-02 18:33:14 +0000444
445#if !defined SK_BUILD_FOR_IOS
446int main(int argc, char * const argv[]) {
447 return tool_main(argc, (char**) argv);
448}
449#endif