OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "CopyTilesRenderer.h" | 8 #include "CopyTilesRenderer.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkBitmapFactory.h" | 10 #include "SkBitmapFactory.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 // Flags used by this file, alphabetically: | 27 // Flags used by this file, alphabetically: |
28 DEFINE_int32(clone, 0, "Clone the picture n times before rendering."); | 28 DEFINE_int32(clone, 0, "Clone the picture n times before rendering."); |
29 DECLARE_bool(deferImageDecoding); | 29 DECLARE_bool(deferImageDecoding); |
30 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Compo nents that differ " | 30 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Compo nents that differ " |
31 "by more than this amount are considered errors, though all diffs a re reported. " | 31 "by more than this amount are considered errors, though all diffs a re reported. " |
32 "Requires --validate."); | 32 "Requires --validate."); |
33 DECLARE_string(r); | 33 DECLARE_string(r); |
34 DEFINE_string(w, "", "Directory to write the rendered images."); | 34 DEFINE_string(w, "", "Directory to write the rendered images."); |
35 DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered ima ge to a " | 35 DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered ima ge to a " |
36 "file, instead of an image for each tile."); | 36 "file, instead of an image for each tile."); |
37 DEFINE_bool(validate, false, "Verify that the rendered image contains the same p ixels as " | 37 DEFINE_bool(validate, false, "Verify that the rendered image contains the same p ixels as " |
edisonn
2013/03/13 15:25:34
update validate description
| |
38 "the picture rendered in simple mode."); | 38 "the picture rendered in simple mode."); |
39 | 39 |
40 static void make_output_filepath(SkString* path, const SkString& dir, | 40 static void make_output_filepath(SkString* path, const SkString& dir, |
41 const SkString& name) { | 41 const SkString& name) { |
42 sk_tools::make_filepath(path, dir, name); | 42 sk_tools::make_filepath(path, dir, name); |
43 // Remove ".skp" | 43 // Remove ".skp" |
44 path->remove(path->size() - 4, 4); | 44 path->remove(path->size() - 4, 4); |
45 } | 45 } |
46 | 46 |
47 #include "SkData.h" | 47 #include "SkData.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 static inline int getByte(uint32_t value, int index) { | 135 static inline int getByte(uint32_t value, int index) { |
136 SkASSERT(0 <= index && index < 4); | 136 SkASSERT(0 <= index && index < 4); |
137 return (value >> (index * 8)) & 0xFF; | 137 return (value >> (index * 8)) & 0xFF; |
138 } | 138 } |
139 | 139 |
140 static int MaxByteDiff(uint32_t v1, uint32_t v2) { | 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))), | 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)))); | 142 SkMax32(abs(getByte(v1, 2) - getByte(v2, 2)), abs(getByte(v1, 3) - getByte(v2, 3)))); |
143 } | 143 } |
144 | 144 |
145 namespace { | |
146 class AutoRestoreBbhType { | |
147 public: | |
148 AutoRestoreBbhType() { | |
149 fRenderer = NULL; | |
150 } | |
151 | |
152 void set(sk_tools::PictureRenderer* renderer, | |
153 sk_tools::PictureRenderer::BBoxHierarchyType bbhType) { | |
154 fRenderer = renderer; | |
155 fSavedBbhType = renderer->getBBoxHierarchyType(); | |
156 renderer->setBBoxHierarchyType(bbhType); | |
157 } | |
158 | |
159 ~AutoRestoreBbhType() { | |
160 if (NULL != fRenderer) { | |
161 fRenderer->setBBoxHierarchyType(fSavedBbhType); | |
162 } | |
163 } | |
164 | |
165 private: | |
166 sk_tools::PictureRenderer* fRenderer; | |
167 sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType; | |
168 }; | |
169 } | |
170 | |
145 static bool render_picture(const SkString& inputPath, const SkString* outputDir, | 171 static bool render_picture(const SkString& inputPath, const SkString* outputDir, |
146 sk_tools::PictureRenderer& renderer) { | 172 sk_tools::PictureRenderer& renderer) { |
147 int diffs[256] = {0}; | 173 int diffs[256] = {0}; |
148 SkBitmap* bitmap = NULL; | 174 SkBitmap* bitmap = NULL; |
149 bool success = render_picture(inputPath, | 175 bool success = render_picture(inputPath, |
150 FLAGS_writeWholeImage ? NULL : outputDir, | 176 FLAGS_writeWholeImage ? NULL : outputDir, |
151 renderer, | 177 renderer, |
152 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL); | 178 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL); |
153 | 179 |
154 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL )) { | 180 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL )) { |
155 SkDebugf("Failed to draw the picture.\n"); | 181 SkDebugf("Failed to draw the picture.\n"); |
156 SkDELETE(bitmap); | 182 SkDELETE(bitmap); |
157 return false; | 183 return false; |
158 } | 184 } |
159 | 185 |
160 if (FLAGS_validate) { | 186 if (FLAGS_validate) { |
161 SkBitmap* referenceBitmap = NULL; | 187 SkBitmap* referenceBitmap = NULL; |
162 sk_tools::SimplePictureRenderer referenceRenderer; | 188 sk_tools::PictureRenderer* referenceRenderer; |
163 success = render_picture(inputPath, NULL, referenceRenderer, | 189 // If the renderer uses a BBoxHierarchy, then the reference renderer |
edisonn
2013/03/13 15:25:34
you can simplify the comment, and include this exc
| |
190 // will be the same renderer, without the bbh. This allows us to | |
191 // validate the effect of the bbh in isolation. In all other cases, | |
192 // the reference renderer is a SimplePictureRenderer. | |
193 AutoRestoreBbhType arbbh; | |
194 if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType != | |
195 renderer.getBBoxHierarchyType()) { | |
196 referenceRenderer = &renderer; | |
197 referenceRenderer->ref(); // to match auto unref below | |
198 arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHi erarchyType); | |
199 } else { | |
200 referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer); | |
201 } | |
202 SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRe nderer); | |
203 | |
204 success = render_picture(inputPath, NULL, *referenceRenderer, | |
164 &referenceBitmap); | 205 &referenceBitmap); |
165 | 206 |
166 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getP ixels()) { | 207 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getP ixels()) { |
167 SkDebugf("Failed to draw the reference picture.\n"); | 208 SkDebugf("Failed to draw the reference picture.\n"); |
168 SkDELETE(bitmap); | 209 SkDELETE(bitmap); |
169 SkDELETE(referenceBitmap); | 210 SkDELETE(referenceBitmap); |
170 return false; | 211 return false; |
171 } | 212 } |
172 | 213 |
173 if (success && (bitmap->width() != referenceBitmap->width())) { | 214 if (success && (bitmap->width() != referenceBitmap->width())) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 #endif | 364 #endif |
324 #endif | 365 #endif |
325 return 0; | 366 return 0; |
326 } | 367 } |
327 | 368 |
328 #if !defined SK_BUILD_FOR_IOS | 369 #if !defined SK_BUILD_FOR_IOS |
329 int main(int argc, char * const argv[]) { | 370 int main(int argc, char * const argv[]) { |
330 return tool_main(argc, (char**) argv); | 371 return tool_main(argc, (char**) argv); |
331 } | 372 } |
332 #endif | 373 #endif |
OLD | NEW |