junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 8 | #include "CopyTilesRenderer.h" |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 9 | #include "SkBitmap.h" |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 10 | #include "SkBitmapFactory.h" |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
keyar@chromium.org | 472b379 | 2012-07-20 22:34:27 +0000 | [diff] [blame] | 12 | #include "SkDevice.h" |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 13 | #include "SkFlags.h" |
borenet@google.com | 10ef79e | 2012-09-10 17:19:06 +0000 | [diff] [blame] | 14 | #include "SkGraphics.h" |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 15 | #include "SkImageDecoder.h" |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 16 | #include "SkImageEncoder.h" |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 17 | #include "SkMath.h" |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 18 | #include "SkOSFile.h" |
| 19 | #include "SkPicture.h" |
| 20 | #include "SkStream.h" |
| 21 | #include "SkString.h" |
senorblanco@chromium.org | 3cbbb54 | 2012-07-13 18:55:53 +0000 | [diff] [blame] | 22 | #include "SkTArray.h" |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 23 | #include "PictureRenderer.h" |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 24 | #include "PictureRenderingFlags.h" |
twiz@google.com | a31b8bb | 2012-06-22 18:24:56 +0000 | [diff] [blame] | 25 | #include "picture_utils.h" |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 26 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 27 | // Flags used by this file, alphabetically: |
| 28 | DEFINE_int32(clone, 0, "Clone the picture n times before rendering."); |
| 29 | DECLARE_bool(deferImageDecoding); |
| 30 | DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Components that differ " |
| 31 | "by more than this amount are considered errors, though all diffs are reported. " |
| 32 | "Requires --validate."); |
| 33 | DECLARE_string(r); |
| 34 | DEFINE_string(w, "", "Directory to write the rendered images."); |
| 35 | DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered image to a " |
| 36 | "file, instead of an image for each tile."); |
| 37 | DEFINE_bool(validate, false, "Verify that the rendered image contains the same pixels as " |
| 38 | "the picture rendered in simple mode."); |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 39 | |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 40 | static void make_output_filepath(SkString* path, const SkString& dir, |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 41 | const SkString& name) { |
twiz@google.com | a31b8bb | 2012-06-22 18:24:56 +0000 | [diff] [blame] | 42 | sk_tools::make_filepath(path, dir, name); |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 43 | // Remove ".skp" |
| 44 | path->remove(path->size() - 4, 4); |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 45 | } |
| 46 | |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 47 | #include "SkData.h" |
| 48 | #include "SkLruImageCache.h" |
| 49 | |
| 50 | static SkLruImageCache gLruImageCache(1024*1024); |
| 51 | |
| 52 | #ifdef SK_BUILD_FOR_ANDROID |
| 53 | #include "SkAshmemImageCache.h" |
| 54 | #include "SkImage.h" |
| 55 | |
| 56 | static SkImageCache* cache_selector(const SkImage::Info& info) { |
| 57 | if (info.fWidth * info.fHeight > 32 * 1024) { |
| 58 | return SkAshmemImageCache::GetAshmemImageCache(); |
| 59 | } |
| 60 | return &gLruImageCache; |
| 61 | } |
| 62 | |
| 63 | #endif |
| 64 | |
| 65 | static bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap) { |
| 66 | void* copiedBuffer = sk_malloc_throw(size); |
| 67 | memcpy(copiedBuffer, buffer, size); |
| 68 | SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size)); |
| 69 | SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); |
| 70 | #ifdef SK_BUILD_FOR_ANDROID |
| 71 | factory.setCacheSelector(&cache_selector); |
| 72 | #else |
| 73 | factory.setImageCache(&gLruImageCache); |
| 74 | #endif |
| 75 | return factory.installPixelRef(data, bitmap); |
| 76 | } |
| 77 | |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame] | 78 | static bool render_picture(const SkString& inputPath, const SkString* outputDir, |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 79 | sk_tools::PictureRenderer& renderer, |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 80 | SkBitmap** out) { |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 81 | SkString inputFilename; |
| 82 | sk_tools::get_basename(&inputFilename, inputPath); |
twiz@google.com | a31b8bb | 2012-06-22 18:24:56 +0000 | [diff] [blame] | 83 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 84 | SkFILEStream inputStream; |
twiz@google.com | a31b8bb | 2012-06-22 18:24:56 +0000 | [diff] [blame] | 85 | inputStream.setPath(inputPath.c_str()); |
| 86 | if (!inputStream.isValid()) { |
| 87 | SkDebugf("Could not open file %s\n", inputPath.c_str()); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 88 | return false; |
twiz@google.com | a31b8bb | 2012-06-22 18:24:56 +0000 | [diff] [blame] | 89 | } |
| 90 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 91 | bool success = false; |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 92 | SkPicture* picture; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 93 | if (FLAGS_deferImageDecoding) { |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 94 | picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bitmap)); |
| 95 | } else { |
| 96 | picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder::DecodeMemory)); |
| 97 | } |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 98 | if (!success) { |
| 99 | SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str()); |
| 100 | return false; |
| 101 | } |
keyar@chromium.org | 451bb9f | 2012-07-26 17:27:57 +0000 | [diff] [blame] | 102 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 103 | for (int i = 0; i < FLAGS_clone; ++i) { |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 104 | SkPicture* clone = picture->clone(); |
| 105 | SkDELETE(picture); |
| 106 | picture = clone; |
| 107 | } |
| 108 | |
| 109 | SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(), |
borenet@google.com | 03fcee8 | 2012-09-10 18:18:38 +0000 | [diff] [blame] | 110 | inputPath.c_str()); |
skia.committer@gmail.com | 1d225f2 | 2012-09-14 02:01:10 +0000 | [diff] [blame] | 111 | |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 112 | renderer.init(picture); |
scroggo@google.com | b4773b4 | 2012-10-01 20:06:09 +0000 | [diff] [blame] | 113 | renderer.setup(); |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 114 | |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame] | 115 | SkString* outputPath = NULL; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 116 | if (NULL != outputDir && outputDir->size() > 0) { |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame] | 117 | outputPath = SkNEW(SkString); |
| 118 | make_output_filepath(outputPath, *outputDir, inputFilename); |
| 119 | } |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 120 | |
| 121 | success = renderer.render(outputPath, out); |
borenet@google.com | 070d354 | 2012-10-26 13:26:55 +0000 | [diff] [blame] | 122 | if (outputPath) { |
| 123 | if (!success) { |
| 124 | SkDebugf("Could not write to file %s\n", outputPath->c_str()); |
| 125 | } |
| 126 | SkDELETE(outputPath); |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 127 | } |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 128 | |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 129 | renderer.end(); |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 130 | |
| 131 | SkDELETE(picture); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 132 | return success; |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 133 | } |
| 134 | |
edisonn@google.com | ca1b3ff | 2013-01-16 18:18:48 +0000 | [diff] [blame] | 135 | static inline int getByte(uint32_t value, int index) { |
| 136 | SkASSERT(0 <= index && index < 4); |
| 137 | return (value >> (index * 8)) & 0xFF; |
| 138 | } |
| 139 | |
| 140 | static int MaxByteDiff(uint32_t v1, uint32_t v2) { |
| 141 | return SkMax32(SkMax32(abs(getByte(v1, 0) - getByte(v2, 0)), abs(getByte(v1, 1) - getByte(v2, 1))), |
| 142 | SkMax32(abs(getByte(v1, 2) - getByte(v2, 2)), abs(getByte(v1, 3) - getByte(v2, 3)))); |
| 143 | } |
| 144 | |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 145 | static bool render_picture(const SkString& inputPath, const SkString* outputDir, |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 146 | sk_tools::PictureRenderer& renderer) { |
edisonn@google.com | ca1b3ff | 2013-01-16 18:18:48 +0000 | [diff] [blame] | 147 | int diffs[256] = {0}; |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 148 | SkBitmap* bitmap = NULL; |
| 149 | bool success = render_picture(inputPath, |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 150 | FLAGS_writeWholeImage ? NULL : outputDir, |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 151 | renderer, |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 152 | FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL); |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 153 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 154 | if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL)) { |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 155 | SkDebugf("Failed to draw the picture.\n"); |
| 156 | SkDELETE(bitmap); |
| 157 | return false; |
| 158 | } |
| 159 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 160 | if (FLAGS_validate) { |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 161 | SkBitmap* referenceBitmap = NULL; |
| 162 | sk_tools::SimplePictureRenderer referenceRenderer; |
| 163 | success = render_picture(inputPath, NULL, referenceRenderer, |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 164 | &referenceBitmap); |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 165 | |
| 166 | if (!success || !referenceBitmap) { |
| 167 | SkDebugf("Failed to draw the reference picture.\n"); |
| 168 | SkDELETE(bitmap); |
| 169 | SkDELETE(referenceBitmap); |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | if (success && (bitmap->width() != referenceBitmap->width())) { |
| 174 | SkDebugf("Expected image width: %i, actual image width %i.\n", |
| 175 | referenceBitmap->width(), bitmap->width()); |
| 176 | SkDELETE(bitmap); |
| 177 | SkDELETE(referenceBitmap); |
| 178 | return false; |
| 179 | } |
| 180 | if (success && (bitmap->height() != referenceBitmap->height())) { |
| 181 | SkDebugf("Expected image height: %i, actual image height %i", |
| 182 | referenceBitmap->height(), bitmap->height()); |
| 183 | SkDELETE(bitmap); |
| 184 | SkDELETE(referenceBitmap); |
| 185 | return false; |
| 186 | } |
skia.committer@gmail.com | a7d8e3e | 2012-12-19 02:01:38 +0000 | [diff] [blame] | 187 | |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 188 | for (int y = 0; success && y < bitmap->height(); y++) { |
| 189 | for (int x = 0; success && x < bitmap->width(); x++) { |
edisonn@google.com | ca1b3ff | 2013-01-16 18:18:48 +0000 | [diff] [blame] | 190 | int diff = MaxByteDiff(*referenceBitmap->getAddr32(x, y), |
| 191 | *bitmap->getAddr32(x, y)); |
| 192 | SkASSERT(diff >= 0 && diff <= 255); |
| 193 | diffs[diff]++; |
skia.committer@gmail.com | 4d28d98 | 2013-01-17 07:06:06 +0000 | [diff] [blame] | 194 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 195 | if (diff > FLAGS_maxComponentDiff) { |
edisonn@google.com | ca1b3ff | 2013-01-16 18:18:48 +0000 | [diff] [blame] | 196 | SkDebugf("Expected pixel at (%i %i) exceedds maximum " |
| 197 | "component diff of %i: 0x%x, actual 0x%x\n", |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 198 | x, y, FLAGS_maxComponentDiff, |
edisonn@google.com | 01754bf | 2013-01-11 16:08:07 +0000 | [diff] [blame] | 199 | *referenceBitmap->getAddr32(x, y), |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 200 | *bitmap->getAddr32(x, y)); |
| 201 | SkDELETE(bitmap); |
| 202 | SkDELETE(referenceBitmap); |
| 203 | return false; |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | SkDELETE(referenceBitmap); |
edisonn@google.com | ca1b3ff | 2013-01-16 18:18:48 +0000 | [diff] [blame] | 208 | |
| 209 | for (int i = 1; i <= 255; ++i) { |
| 210 | if(diffs[i] > 0) { |
| 211 | SkDebugf("Number of pixels with max diff of %i is %i\n", i, diffs[i]); |
| 212 | } |
| 213 | } |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 214 | } |
| 215 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 216 | if (FLAGS_writeWholeImage) { |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 217 | sk_tools::force_all_opaque(*bitmap); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 218 | if (NULL != outputDir && FLAGS_writeWholeImage) { |
edisonn@google.com | 84f548c | 2012-12-18 22:24:03 +0000 | [diff] [blame] | 219 | SkString inputFilename; |
| 220 | sk_tools::get_basename(&inputFilename, inputPath); |
| 221 | SkString outputPath; |
| 222 | make_output_filepath(&outputPath, *outputDir, inputFilename); |
| 223 | outputPath.append(".png"); |
| 224 | if (!SkImageEncoder::EncodeFile(outputPath.c_str(), *bitmap, |
| 225 | SkImageEncoder::kPNG_Type, 100)) { |
| 226 | SkDebugf("Failed to draw the picture.\n"); |
| 227 | success = false; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | SkDELETE(bitmap); |
| 232 | |
| 233 | return success; |
| 234 | } |
| 235 | |
| 236 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 237 | static int process_input(const char* input, const SkString* outputDir, |
| 238 | sk_tools::PictureRenderer& renderer) { |
| 239 | SkOSFile::Iter iter(input, "skp"); |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 240 | SkString inputFilename; |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 241 | int failures = 0; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 242 | SkDebugf("process_input, %s\n", input); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 243 | if (iter.next(&inputFilename)) { |
| 244 | do { |
| 245 | SkString inputPath; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 246 | SkString inputAsSkString(input); |
| 247 | sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename); |
| 248 | if (!render_picture(inputPath, outputDir, renderer)) { |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 249 | ++failures; |
| 250 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 251 | } while(iter.next(&inputFilename)); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 252 | } else if (SkStrEndsWith(input, ".skp")) { |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 253 | SkString inputPath(input); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 254 | if (!render_picture(inputPath, outputDir, renderer)) { |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 255 | ++failures; |
| 256 | } |
| 257 | } else { |
| 258 | SkString warning; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 259 | warning.printf("Warning: skipping %s\n", input); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 260 | SkDebugf(warning.c_str()); |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 261 | } |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 262 | return failures; |
keyar@chromium.org | 1cbd47c | 2012-07-13 18:22:59 +0000 | [diff] [blame] | 263 | } |
| 264 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 265 | int tool_main(int argc, char** argv); |
| 266 | int tool_main(int argc, char** argv) { |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 267 | SkFlags::SetUsage("Render .skp files."); |
| 268 | SkFlags::ParseCommandLine(argc, argv); |
| 269 | |
| 270 | if (FLAGS_r.isEmpty()) { |
| 271 | SkDebugf(".skp files or directories are required.\n"); |
| 272 | exit(-1); |
| 273 | } |
| 274 | |
| 275 | if (FLAGS_maxComponentDiff < 0 || FLAGS_maxComponentDiff > 256) { |
| 276 | SkDebugf("--maxComponentDiff must be between 0 and 256\n"); |
| 277 | exit(-1); |
| 278 | } |
| 279 | |
| 280 | if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) { |
| 281 | SkDebugf("--maxComponentDiff requires --validate\n"); |
| 282 | exit(-1); |
| 283 | } |
| 284 | |
| 285 | if (FLAGS_clone < 0) { |
| 286 | SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone); |
| 287 | exit(-1); |
| 288 | } |
| 289 | |
| 290 | SkString errorString; |
| 291 | SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString, |
| 292 | kRender_PictureTool)); |
| 293 | if (errorString.size() > 0) { |
| 294 | SkDebugf("%s\n", errorString.c_str()); |
| 295 | } |
| 296 | |
| 297 | if (renderer.get() == NULL) { |
| 298 | exit(-1); |
| 299 | } |
| 300 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 301 | SkAutoGraphics ag; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 302 | |
| 303 | SkString outputDir; |
| 304 | if (FLAGS_w.count() == 1) { |
| 305 | outputDir.set(FLAGS_w[0]); |
| 306 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 307 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 308 | int failures = 0; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 309 | for (int i = 0; i < FLAGS_r.count(); i ++) { |
| 310 | failures += process_input(FLAGS_r[i], &outputDir, *renderer.get()); |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 311 | } |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 312 | if (failures != 0) { |
| 313 | SkDebugf("Failed to render %i pictures.\n", failures); |
| 314 | return 1; |
| 315 | } |
robertphillips@google.com | 163c84b | 2012-09-13 15:40:37 +0000 | [diff] [blame] | 316 | #if SK_SUPPORT_GPU |
| 317 | #if GR_CACHE_STATS |
| 318 | if (renderer->isUsingGpuDevice()) { |
| 319 | GrContext* ctx = renderer->getGrContext(); |
| 320 | |
| 321 | ctx->printCacheStats(); |
| 322 | } |
| 323 | #endif |
| 324 | #endif |
caryclark@google.com | 868e1f6 | 2012-10-02 20:00:03 +0000 | [diff] [blame] | 325 | return 0; |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 326 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 327 | |
| 328 | #if !defined SK_BUILD_FOR_IOS |
| 329 | int main(int argc, char * const argv[]) { |
| 330 | return tool_main(argc, (char**) argv); |
| 331 | } |
| 332 | #endif |