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 "PictureRenderer.h" | 8 #include "PictureRenderer.h" |
9 #include "picture_utils.h" | 9 #include "picture_utils.h" |
10 #include "SamplePipeControllers.h" | 10 #include "SamplePipeControllers.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 return SkScalarLog(x) * log2_conversion_factor; | 41 return SkScalarLog(x) * log2_conversion_factor; |
42 } | 42 } |
43 | 43 |
44 namespace sk_tools { | 44 namespace sk_tools { |
45 | 45 |
46 enum { | 46 enum { |
47 kDefaultTileWidth = 256, | 47 kDefaultTileWidth = 256, |
48 kDefaultTileHeight = 256 | 48 kDefaultTileHeight = 256 |
49 }; | 49 }; |
50 | 50 |
51 /* | |
epoger
2014/05/07 22:10:42
moved to image_expectations.cpp
| |
52 * TODO(epoger): Make constant strings consistent instead of mixing hypenated an d camel-caps. | |
53 * | |
54 * TODO(epoger): Similar constants are already maintained in 2 other places: | |
55 * gm/gm_json.py and gm/gm_expectations.cpp. We shouldn't add yet a third place. | |
56 * Figure out a way to share the definitions instead. | |
57 * | |
58 * Note that, as of https://codereview.chromium.org/226293002 , the JSON | |
59 * schema used here has started to differ from the one in gm_expectations.cpp . | |
60 * TODO(epoger): Consider getting GM and render_pictures to use the same JSON | |
61 * output module. | |
62 */ | |
63 const static char kJsonKey_ActualResults[] = "actual-results"; | |
64 const static char kJsonKey_Header[] = "header"; | |
65 const static char kJsonKey_Header_Type[] = "type"; | |
66 const static char kJsonKey_Header_Revision[] = "revision"; // unique within Typ e | |
67 const static char kJsonKey_Image_ChecksumAlgorithm[] = "checksumAlgorithm"; | |
68 const static char kJsonKey_Image_ChecksumValue[] = "checksumValue"; | |
69 const static char kJsonKey_Image_ComparisonResult[] = "comparisonResult"; | |
70 const static char kJsonKey_Image_Filepath[] = "filepath"; | |
71 const static char kJsonKey_Source_TiledImages[] = "tiled-images"; | |
72 const static char kJsonKey_Source_WholeImage[] = "whole-image"; | |
73 // Values (not keys) that are written out by this JSON generator | |
74 const static char kJsonValue_Header_Type[] = "ChecksummedImages"; | |
75 const static int kJsonValue_Header_Revision = 1; | |
76 const static char kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5[] = "bitmap- 64bitMD5"; | |
77 const static char kJsonValue_Image_ComparisonResult_NoComparison[] = "no-compari son"; | |
78 | |
79 void ImageResultsSummary::add(const char *sourceName, const char *fileName, uint 64_t hash, | |
80 const int *tileNumber) { | |
81 Json::Value image; | |
82 image[kJsonKey_Image_ChecksumAlgorithm] = kJsonValue_Image_ChecksumAlgorithm _Bitmap64bitMD5; | |
83 image[kJsonKey_Image_ChecksumValue] = Json::UInt64(hash); | |
84 image[kJsonKey_Image_ComparisonResult] = kJsonValue_Image_ComparisonResult_N oComparison; | |
85 image[kJsonKey_Image_Filepath] = fileName; | |
86 if (NULL == tileNumber) { | |
87 fActualResults[sourceName][kJsonKey_Source_WholeImage] = image; | |
88 } else { | |
89 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber] = i mage; | |
90 } | |
91 } | |
92 | |
93 void ImageResultsSummary::add(const char *sourceName, const char *fileName, cons t SkBitmap& bitmap, | |
94 const int *tileNumber) { | |
95 uint64_t hash; | |
96 SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash)); | |
97 this->add(sourceName, fileName, hash, tileNumber); | |
98 } | |
99 | |
100 void ImageResultsSummary::writeToFile(const char *filename) { | |
101 Json::Value header; | |
102 header[kJsonKey_Header_Type] = kJsonValue_Header_Type; | |
103 header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision; | |
104 Json::Value root; | |
105 root[kJsonKey_Header] = header; | |
106 root[kJsonKey_ActualResults] = fActualResults; | |
107 std::string jsonStdString = root.toStyledString(); | |
108 SkFILEWStream stream(filename); | |
109 stream.write(jsonStdString.c_str(), jsonStdString.length()); | |
110 } | |
111 | |
112 void PictureRenderer::init(SkPicture* pict, const SkString* outputDir, | 51 void PictureRenderer::init(SkPicture* pict, const SkString* outputDir, |
113 const SkString* inputFilename, bool useChecksumBasedF ilenames) { | 52 const SkString* inputFilename, bool useChecksumBasedF ilenames) { |
114 this->CopyString(&fOutputDir, outputDir); | 53 this->CopyString(&fOutputDir, outputDir); |
115 this->CopyString(&fInputFilename, inputFilename); | 54 this->CopyString(&fInputFilename, inputFilename); |
116 fUseChecksumBasedFilenames = useChecksumBasedFilenames; | 55 fUseChecksumBasedFilenames = useChecksumBasedFilenames; |
117 | 56 |
118 SkASSERT(NULL == fPicture); | 57 SkASSERT(NULL == fPicture); |
119 SkASSERT(NULL == fCanvas.get()); | 58 SkASSERT(NULL == fCanvas.get()); |
120 if (NULL != fPicture || NULL != fCanvas.get()) { | 59 if (NULL != fPicture || NULL != fCanvas.get()) { |
121 return; | 60 return; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 // TODO(epoger): what about including the config type within outputFilename? That way, | 299 // TODO(epoger): what about including the config type within outputFilename? That way, |
361 // we could combine results of different config types without conflicting fi lenames. | 300 // we could combine results of different config types without conflicting fi lenames. |
362 SkString outputFilename; | 301 SkString outputFilename; |
363 const char *outputSubdirPtr = NULL; | 302 const char *outputSubdirPtr = NULL; |
364 if (useChecksumBasedFilenames) { | 303 if (useChecksumBasedFilenames) { |
365 SkASSERT(!generatedHash); | 304 SkASSERT(!generatedHash); |
366 SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash)); | 305 SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash)); |
367 generatedHash = true; | 306 generatedHash = true; |
368 | 307 |
369 outputSubdirPtr = escapedInputFilename.c_str(); | 308 outputSubdirPtr = escapedInputFilename.c_str(); |
370 outputFilename.set(kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5); | 309 outputFilename.set("bitmap-64bitMD5_"); |
borenet
2014/05/08 12:05:53
Why the change to the literal? Couldn't the varia
epoger
2014/05/08 14:40:24
Damn you and your sharp eyes. I have added a TODO
| |
371 outputFilename.append("_"); | |
372 outputFilename.appendU64(hash); | 310 outputFilename.appendU64(hash); |
373 } else { | 311 } else { |
374 outputFilename.set(escapedInputFilename); | 312 outputFilename.set(escapedInputFilename); |
375 if (NULL != tileNumberPtr) { | 313 if (NULL != tileNumberPtr) { |
376 outputFilename.append("-tile"); | 314 outputFilename.append("-tile"); |
377 outputFilename.appendS32(*tileNumberPtr); | 315 outputFilename.appendS32(*tileNumberPtr); |
378 } | 316 } |
379 } | 317 } |
380 outputFilename.append(".png"); | 318 outputFilename.append(".png"); |
381 | 319 |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1012 virtual SkString getConfigNameInternal() SK_OVERRIDE { | 950 virtual SkString getConfigNameInternal() SK_OVERRIDE { |
1013 return SkString("picture_clone"); | 951 return SkString("picture_clone"); |
1014 } | 952 } |
1015 }; | 953 }; |
1016 | 954 |
1017 PictureRenderer* CreatePictureCloneRenderer() { | 955 PictureRenderer* CreatePictureCloneRenderer() { |
1018 return SkNEW(PictureCloneRenderer); | 956 return SkNEW(PictureCloneRenderer); |
1019 } | 957 } |
1020 | 958 |
1021 } // namespace sk_tools | 959 } // namespace sk_tools |
OLD | NEW |