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