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