Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(708)

Side by Side Diff: tools/render_pictures_main.cpp

Issue 12801002: Modifying the behavior of render_pictures --validate to test the effect of bbh. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/PictureRenderer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
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 "
38 "the picture rendered in simple mode."); 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 wi thout the bbh.");
39 40
40 static void make_output_filepath(SkString* path, const SkString& dir, 41 static void make_output_filepath(SkString* path, const SkString& dir,
41 const SkString& name) { 42 const SkString& name) {
42 sk_tools::make_filepath(path, dir, name); 43 sk_tools::make_filepath(path, dir, name);
43 // Remove ".skp" 44 // Remove ".skp"
44 path->remove(path->size() - 4, 4); 45 path->remove(path->size() - 4, 4);
45 } 46 }
46 47
47 #include "SkData.h" 48 #include "SkData.h"
48 #include "SkLruImageCache.h" 49 #include "SkLruImageCache.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 static inline int getByte(uint32_t value, int index) { 136 static inline int getByte(uint32_t value, int index) {
136 SkASSERT(0 <= index && index < 4); 137 SkASSERT(0 <= index && index < 4);
137 return (value >> (index * 8)) & 0xFF; 138 return (value >> (index * 8)) & 0xFF;
138 } 139 }
139 140
140 static int MaxByteDiff(uint32_t v1, uint32_t v2) { 141 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 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 SkMax32(abs(getByte(v1, 2) - getByte(v2, 2)), abs(getByte(v1, 3) - getByte(v2, 3))));
143 } 144 }
144 145
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
145 static bool render_picture(const SkString& inputPath, const SkString* outputDir, 172 static bool render_picture(const SkString& inputPath, const SkString* outputDir,
146 sk_tools::PictureRenderer& renderer) { 173 sk_tools::PictureRenderer& renderer) {
147 int diffs[256] = {0}; 174 int diffs[256] = {0};
148 SkBitmap* bitmap = NULL; 175 SkBitmap* bitmap = NULL;
149 bool success = render_picture(inputPath, 176 bool success = render_picture(inputPath,
150 FLAGS_writeWholeImage ? NULL : outputDir, 177 FLAGS_writeWholeImage ? NULL : outputDir,
151 renderer, 178 renderer,
152 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL); 179 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
153 180
154 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL )) { 181 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL )) {
155 SkDebugf("Failed to draw the picture.\n"); 182 SkDebugf("Failed to draw the picture.\n");
156 SkDELETE(bitmap); 183 SkDELETE(bitmap);
157 return false; 184 return false;
158 } 185 }
159 186
160 if (FLAGS_validate) { 187 if (FLAGS_validate) {
161 SkBitmap* referenceBitmap = NULL; 188 SkBitmap* referenceBitmap = NULL;
162 sk_tools::SimplePictureRenderer referenceRenderer; 189 sk_tools::PictureRenderer* referenceRenderer;
163 success = render_picture(inputPath, NULL, 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_BBoxHi erarchyType);
198 } else {
199 referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer);
200 }
201 SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRe nderer);
202
203 success = render_picture(inputPath, NULL, *referenceRenderer,
164 &referenceBitmap); 204 &referenceBitmap);
165 205
166 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getP ixels()) { 206 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getP ixels()) {
167 SkDebugf("Failed to draw the reference picture.\n"); 207 SkDebugf("Failed to draw the reference picture.\n");
168 SkDELETE(bitmap); 208 SkDELETE(bitmap);
169 SkDELETE(referenceBitmap); 209 SkDELETE(referenceBitmap);
170 return false; 210 return false;
171 } 211 }
172 212
173 if (success && (bitmap->width() != referenceBitmap->width())) { 213 if (success && (bitmap->width() != referenceBitmap->width())) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 #endif 363 #endif
324 #endif 364 #endif
325 return 0; 365 return 0;
326 } 366 }
327 367
328 #if !defined SK_BUILD_FOR_IOS 368 #if !defined SK_BUILD_FOR_IOS
329 int main(int argc, char * const argv[]) { 369 int main(int argc, char * const argv[]) {
330 return tool_main(argc, (char**) argv); 370 return tool_main(argc, (char**) argv);
331 } 371 }
332 #endif 372 #endif
OLDNEW
« no previous file with comments | « tools/PictureRenderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698