blob: 70bc22132b06663b2dfb09992271462e61b8454a [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
commit-bot@chromium.orgff36a1d2013-07-24 20:37:30 +000042DEFINE_bool(bench_record, false, "If true, drop into an infinite loop of recording the picture.");
43
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +000044static void make_output_filepath(SkString* path, const SkString& dir,
junov@chromium.org777442d2012-06-12 14:56:36 +000045 const SkString& name) {
twiz@google.coma31b8bb2012-06-22 18:24:56 +000046 sk_tools::make_filepath(path, dir, name);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +000047 // Remove ".skp"
48 path->remove(path->size() - 4, 4);
junov@chromium.org777442d2012-06-12 14:56:36 +000049}
50
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
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000148 SkPicture::InstallPixelRefProc proc;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000149 if (FLAGS_deferImageDecoding) {
commit-bot@chromium.org56799e22013-07-16 18:21:46 +0000150 proc = &sk_tools::LazyDecodeBitmap;
scroggo@google.com1125d392013-05-03 20:43:37 +0000151 } else if (FLAGS_writeEncodedImages) {
152 SkASSERT(!FLAGS_writePath.isEmpty());
153 reset_image_file_base_name(inputFilename);
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000154 proc = &write_image_to_file;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000155 } else {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000156 proc = &SkImageDecoder::DecodeMemory;
scroggo@google.comf8d7d272013-02-22 21:38:35 +0000157 }
scroggo@google.com1125d392013-05-03 20:43:37 +0000158
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000159 SkDebugf("deserializing... %s\n", inputPath.c_str());
160
161 SkPicture* picture = SkPicture::CreateFromStream(&inputStream, proc);
162
163 if (NULL == picture) {
borenet@google.com66bcbd12012-09-17 18:26:06 +0000164 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
165 return false;
166 }
keyar@chromium.org451bb9f2012-07-26 17:27:57 +0000167
commit-bot@chromium.orgff36a1d2013-07-24 20:37:30 +0000168 while (FLAGS_bench_record) {
169 const int kRecordFlags = 0;
170 SkPicture other;
171 picture->draw(other.beginRecording(picture->width(), picture->height(), kRecordFlags));
172 other.endRecording();
173 }
174
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000175 for (int i = 0; i < FLAGS_clone; ++i) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000176 SkPicture* clone = picture->clone();
177 SkDELETE(picture);
178 picture = clone;
179 }
180
181 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
borenet@google.com03fcee82012-09-10 18:18:38 +0000182 inputPath.c_str());
skia.committer@gmail.com1d225f22012-09-14 02:01:10 +0000183
edisonn@google.com84f548c2012-12-18 22:24:03 +0000184 renderer.init(picture);
scroggo@google.comb4773b42012-10-01 20:06:09 +0000185 renderer.setup();
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000186
borenet@google.com070d3542012-10-26 13:26:55 +0000187 SkString* outputPath = NULL;
scroggo@google.com1125d392013-05-03 20:43:37 +0000188 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) {
borenet@google.com070d3542012-10-26 13:26:55 +0000189 outputPath = SkNEW(SkString);
190 make_output_filepath(outputPath, *outputDir, inputFilename);
191 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000192
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000193 bool success = renderer.render(outputPath, out);
borenet@google.com070d3542012-10-26 13:26:55 +0000194 if (outputPath) {
195 if (!success) {
196 SkDebugf("Could not write to file %s\n", outputPath->c_str());
197 }
198 SkDELETE(outputPath);
scroggo@google.com81f9d2e2012-09-20 14:54:21 +0000199 }
scroggo@google.com9a412522012-09-07 15:21:18 +0000200
keyar@chromium.org9d696c02012-08-07 17:11:33 +0000201 renderer.end();
edisonn@google.com84f548c2012-12-18 22:24:03 +0000202
203 SkDELETE(picture);
borenet@google.com66bcbd12012-09-17 18:26:06 +0000204 return success;
junov@chromium.org777442d2012-06-12 14:56:36 +0000205}
206
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000207static inline int getByte(uint32_t value, int index) {
208 SkASSERT(0 <= index && index < 4);
209 return (value >> (index * 8)) & 0xFF;
210}
211
212static int MaxByteDiff(uint32_t v1, uint32_t v2) {
213 return SkMax32(SkMax32(abs(getByte(v1, 0) - getByte(v2, 0)), abs(getByte(v1, 1) - getByte(v2, 1))),
214 SkMax32(abs(getByte(v1, 2) - getByte(v2, 2)), abs(getByte(v1, 3) - getByte(v2, 3))));
215}
216
junov@chromium.orge286e842013-03-13 17:27:16 +0000217namespace {
218class AutoRestoreBbhType {
219public:
220 AutoRestoreBbhType() {
221 fRenderer = NULL;
junov@chromium.orgd34fda12013-03-13 19:03:26 +0000222 fSavedBbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
junov@chromium.orge286e842013-03-13 17:27:16 +0000223 }
224
225 void set(sk_tools::PictureRenderer* renderer,
226 sk_tools::PictureRenderer::BBoxHierarchyType bbhType) {
227 fRenderer = renderer;
228 fSavedBbhType = renderer->getBBoxHierarchyType();
229 renderer->setBBoxHierarchyType(bbhType);
230 }
231
232 ~AutoRestoreBbhType() {
233 if (NULL != fRenderer) {
234 fRenderer->setBBoxHierarchyType(fSavedBbhType);
235 }
236 }
237
238private:
239 sk_tools::PictureRenderer* fRenderer;
240 sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType;
241};
242}
243
edisonn@google.com84f548c2012-12-18 22:24:03 +0000244static bool render_picture(const SkString& inputPath, const SkString* outputDir,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000245 sk_tools::PictureRenderer& renderer) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000246 int diffs[256] = {0};
edisonn@google.com84f548c2012-12-18 22:24:03 +0000247 SkBitmap* bitmap = NULL;
248 bool success = render_picture(inputPath,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000249 FLAGS_writeWholeImage ? NULL : outputDir,
edisonn@google.com84f548c2012-12-18 22:24:03 +0000250 renderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000251 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000252
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000253 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL)) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000254 SkDebugf("Failed to draw the picture.\n");
255 SkDELETE(bitmap);
256 return false;
257 }
258
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000259 if (FLAGS_validate) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000260 SkBitmap* referenceBitmap = NULL;
junov@chromium.orge286e842013-03-13 17:27:16 +0000261 sk_tools::PictureRenderer* referenceRenderer;
262 // If the renderer uses a BBoxHierarchy, then the reference renderer
skia.committer@gmail.com03682be2013-03-14 07:02:51 +0000263 // will be the same renderer, without the bbh.
junov@chromium.orge286e842013-03-13 17:27:16 +0000264 AutoRestoreBbhType arbbh;
265 if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
266 renderer.getBBoxHierarchyType()) {
267 referenceRenderer = &renderer;
268 referenceRenderer->ref(); // to match auto unref below
269 arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
270 } else {
271 referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer);
272 }
273 SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer);
274
275 success = render_picture(inputPath, NULL, *referenceRenderer,
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000276 &referenceBitmap);
edisonn@google.com84f548c2012-12-18 22:24:03 +0000277
junov@chromium.orgc19c1912013-03-12 19:56:49 +0000278 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getPixels()) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000279 SkDebugf("Failed to draw the reference picture.\n");
280 SkDELETE(bitmap);
281 SkDELETE(referenceBitmap);
282 return false;
283 }
284
285 if (success && (bitmap->width() != referenceBitmap->width())) {
286 SkDebugf("Expected image width: %i, actual image width %i.\n",
287 referenceBitmap->width(), bitmap->width());
288 SkDELETE(bitmap);
289 SkDELETE(referenceBitmap);
290 return false;
291 }
292 if (success && (bitmap->height() != referenceBitmap->height())) {
293 SkDebugf("Expected image height: %i, actual image height %i",
294 referenceBitmap->height(), bitmap->height());
295 SkDELETE(bitmap);
296 SkDELETE(referenceBitmap);
297 return false;
298 }
skia.committer@gmail.coma7d8e3e2012-12-19 02:01:38 +0000299
edisonn@google.com84f548c2012-12-18 22:24:03 +0000300 for (int y = 0; success && y < bitmap->height(); y++) {
301 for (int x = 0; success && x < bitmap->width(); x++) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000302 int diff = MaxByteDiff(*referenceBitmap->getAddr32(x, y),
303 *bitmap->getAddr32(x, y));
304 SkASSERT(diff >= 0 && diff <= 255);
305 diffs[diff]++;
skia.committer@gmail.com4d28d982013-01-17 07:06:06 +0000306
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000307 if (diff > FLAGS_maxComponentDiff) {
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000308 SkDebugf("Expected pixel at (%i %i) exceedds maximum "
309 "component diff of %i: 0x%x, actual 0x%x\n",
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000310 x, y, FLAGS_maxComponentDiff,
edisonn@google.com01754bf2013-01-11 16:08:07 +0000311 *referenceBitmap->getAddr32(x, y),
edisonn@google.com84f548c2012-12-18 22:24:03 +0000312 *bitmap->getAddr32(x, y));
313 SkDELETE(bitmap);
314 SkDELETE(referenceBitmap);
315 return false;
316 }
317 }
318 }
319 SkDELETE(referenceBitmap);
edisonn@google.comca1b3ff2013-01-16 18:18:48 +0000320
321 for (int i = 1; i <= 255; ++i) {
322 if(diffs[i] > 0) {
323 SkDebugf("Number of pixels with max diff of %i is %i\n", i, diffs[i]);
324 }
325 }
edisonn@google.com84f548c2012-12-18 22:24:03 +0000326 }
327
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000328 if (FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000329 sk_tools::force_all_opaque(*bitmap);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000330 if (NULL != outputDir && FLAGS_writeWholeImage) {
edisonn@google.com84f548c2012-12-18 22:24:03 +0000331 SkString inputFilename;
332 sk_tools::get_basename(&inputFilename, inputPath);
333 SkString outputPath;
334 make_output_filepath(&outputPath, *outputDir, inputFilename);
335 outputPath.append(".png");
336 if (!SkImageEncoder::EncodeFile(outputPath.c_str(), *bitmap,
337 SkImageEncoder::kPNG_Type, 100)) {
338 SkDebugf("Failed to draw the picture.\n");
339 success = false;
340 }
341 }
342 }
343 SkDELETE(bitmap);
344
345 return success;
346}
347
348
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000349static int process_input(const char* input, const SkString* outputDir,
350 sk_tools::PictureRenderer& renderer) {
351 SkOSFile::Iter iter(input, "skp");
junov@chromium.org777442d2012-06-12 14:56:36 +0000352 SkString inputFilename;
borenet@google.com66bcbd12012-09-17 18:26:06 +0000353 int failures = 0;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000354 SkDebugf("process_input, %s\n", input);
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000355 if (iter.next(&inputFilename)) {
356 do {
357 SkString inputPath;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000358 SkString inputAsSkString(input);
359 sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
360 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000361 ++failures;
362 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000363 } while(iter.next(&inputFilename));
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000364 } else if (SkStrEndsWith(input, ".skp")) {
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000365 SkString inputPath(input);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000366 if (!render_picture(inputPath, outputDir, renderer)) {
borenet@google.com57837bf2012-09-19 17:28:29 +0000367 ++failures;
368 }
369 } else {
370 SkString warning;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000371 warning.printf("Warning: skipping %s\n", input);
borenet@google.com57837bf2012-09-19 17:28:29 +0000372 SkDebugf(warning.c_str());
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000373 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000374 return failures;
keyar@chromium.org1cbd47c2012-07-13 18:22:59 +0000375}
376
caryclark@google.com5987f582012-10-02 18:33:14 +0000377int tool_main(int argc, char** argv);
378int tool_main(int argc, char** argv) {
scroggo@google.comd9ba9a02013-03-21 19:43:15 +0000379 SkCommandLineFlags::SetUsage("Render .skp files.");
380 SkCommandLineFlags::Parse(argc, argv);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000381
scroggo@google.com604e0c22013-04-09 21:25:46 +0000382 if (FLAGS_readPath.isEmpty()) {
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000383 SkDebugf(".skp files or directories are required.\n");
384 exit(-1);
385 }
386
387 if (FLAGS_maxComponentDiff < 0 || FLAGS_maxComponentDiff > 256) {
388 SkDebugf("--maxComponentDiff must be between 0 and 256\n");
389 exit(-1);
390 }
391
392 if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) {
393 SkDebugf("--maxComponentDiff requires --validate\n");
394 exit(-1);
395 }
396
397 if (FLAGS_clone < 0) {
398 SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone);
399 exit(-1);
400 }
401
scroggo@google.com1125d392013-05-03 20:43:37 +0000402 if (FLAGS_writeEncodedImages) {
403 if (FLAGS_writePath.isEmpty()) {
404 SkDebugf("--writeEncodedImages requires --writePath\n");
405 exit(-1);
406 }
407 if (FLAGS_deferImageDecoding) {
408 SkDebugf("--writeEncodedImages is not compatible with --deferImageDecoding\n");
409 exit(-1);
410 }
411 }
412
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000413 SkString errorString;
414 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
415 kRender_PictureTool));
416 if (errorString.size() > 0) {
417 SkDebugf("%s\n", errorString.c_str());
418 }
419
420 if (renderer.get() == NULL) {
421 exit(-1);
422 }
423
borenet@google.com66bcbd12012-09-17 18:26:06 +0000424 SkAutoGraphics ag;
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000425
426 SkString outputDir;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000427 if (FLAGS_writePath.count() == 1) {
428 outputDir.set(FLAGS_writePath[0]);
scroggo@google.com161e1ba2013-03-04 16:41:06 +0000429 }
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +0000430
borenet@google.com66bcbd12012-09-17 18:26:06 +0000431 int failures = 0;
scroggo@google.com604e0c22013-04-09 21:25:46 +0000432 for (int i = 0; i < FLAGS_readPath.count(); i ++) {
433 failures += process_input(FLAGS_readPath[i], &outputDir, *renderer.get());
junov@chromium.org777442d2012-06-12 14:56:36 +0000434 }
borenet@google.com66bcbd12012-09-17 18:26:06 +0000435 if (failures != 0) {
436 SkDebugf("Failed to render %i pictures.\n", failures);
437 return 1;
438 }
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000439#if SK_SUPPORT_GPU
440#if GR_CACHE_STATS
441 if (renderer->isUsingGpuDevice()) {
442 GrContext* ctx = renderer->getGrContext();
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000443 ctx->printCacheStats();
commit-bot@chromium.org03e3e892013-10-02 18:19:17 +0000444#ifdef SK_DEVELOPER
445 ctx->dumpFontCache();
446#endif
robertphillips@google.com163c84b2012-09-13 15:40:37 +0000447 }
448#endif
449#endif
caryclark@google.com868e1f62012-10-02 20:00:03 +0000450 return 0;
junov@chromium.org777442d2012-06-12 14:56:36 +0000451}
caryclark@google.com5987f582012-10-02 18:33:14 +0000452
453#if !defined SK_BUILD_FOR_IOS
454int main(int argc, char * const argv[]) {
455 return tool_main(argc, (char**) argv);
456}
457#endif