OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapHasher.h" | 9 #include "SkBitmapHasher.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 * Figure out a way to share the definitions instead. | 23 * Figure out a way to share the definitions instead. |
24 * | 24 * |
25 * Note that, as of https://codereview.chromium.org/226293002 , the JSON | 25 * Note that, as of https://codereview.chromium.org/226293002 , the JSON |
26 * schema used here has started to differ from the one in gm_expectations.cpp . | 26 * schema used here has started to differ from the one in gm_expectations.cpp . |
27 * TODO(epoger): Consider getting GM and render_pictures to use the same JSON | 27 * TODO(epoger): Consider getting GM and render_pictures to use the same JSON |
28 * output module. | 28 * output module. |
29 */ | 29 */ |
30 const static char kJsonKey_ActualResults[] = "actual-results"; | 30 const static char kJsonKey_ActualResults[] = "actual-results"; |
31 const static char kJsonKey_Descriptions[] = "descriptions"; | 31 const static char kJsonKey_Descriptions[] = "descriptions"; |
32 const static char kJsonKey_ExpectedResults[] = "expected-results"; | 32 const static char kJsonKey_ExpectedResults[] = "expected-results"; |
| 33 const static char kJsonKey_ImageBaseGSUrl[] = "image-base-gs-url"; |
33 const static char kJsonKey_Header[] = "header"; | 34 const static char kJsonKey_Header[] = "header"; |
34 const static char kJsonKey_Header_Type[] = "type"; | 35 const static char kJsonKey_Header_Type[] = "type"; |
35 const static char kJsonKey_Header_Revision[] = "revision"; | 36 const static char kJsonKey_Header_Revision[] = "revision"; |
36 const static char kJsonKey_Image_ChecksumAlgorithm[] = "checksumAlgorithm"; | 37 const static char kJsonKey_Image_ChecksumAlgorithm[] = "checksumAlgorithm"; |
37 const static char kJsonKey_Image_ChecksumValue[] = "checksumValue"; | 38 const static char kJsonKey_Image_ChecksumValue[] = "checksumValue"; |
38 const static char kJsonKey_Image_ComparisonResult[] = "comparisonResult"; | 39 const static char kJsonKey_Image_ComparisonResult[] = "comparisonResult"; |
39 const static char kJsonKey_Image_Filepath[] = "filepath"; | 40 const static char kJsonKey_Image_Filepath[] = "filepath"; |
40 const static char kJsonKey_Image_IgnoreFailure[] = "ignoreFailure"; | 41 const static char kJsonKey_Image_IgnoreFailure[] = "ignoreFailure"; |
41 const static char kJsonKey_Source_TiledImages[] = "tiled-images"; | 42 const static char kJsonKey_Source_TiledImages[] = "tiled-images"; |
42 const static char kJsonKey_Source_WholeImage[] = "whole-image"; | 43 const static char kJsonKey_Source_WholeImage[] = "whole-image"; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 fActualResults[sourceName][kJsonKey_Source_WholeImage] = actualImage
; | 192 fActualResults[sourceName][kJsonKey_Source_WholeImage] = actualImage
; |
192 } else { | 193 } else { |
193 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber]
= actualImage; | 194 fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber]
= actualImage; |
194 } | 195 } |
195 } | 196 } |
196 | 197 |
197 void ImageResultsAndExpectations::addDescription(const char *key, const char
*value) { | 198 void ImageResultsAndExpectations::addDescription(const char *key, const char
*value) { |
198 fDescriptions[key] = value; | 199 fDescriptions[key] = value; |
199 } | 200 } |
200 | 201 |
| 202 void ImageResultsAndExpectations::setImageBaseGSUrl(const char *imageBaseGSU
rl) { |
| 203 fImageBaseGSUrl = imageBaseGSUrl; |
| 204 } |
| 205 |
201 Expectation ImageResultsAndExpectations::getExpectation(const char *sourceNa
me, | 206 Expectation ImageResultsAndExpectations::getExpectation(const char *sourceNa
me, |
202 const int *tileNumbe
r) { | 207 const int *tileNumbe
r) { |
203 if (fExpectedResults.isNull()) { | 208 if (fExpectedResults.isNull()) { |
204 return Expectation(); | 209 return Expectation(); |
205 } | 210 } |
206 | 211 |
207 Json::Value expectedImage; | 212 Json::Value expectedImage; |
208 if (NULL == tileNumber) { | 213 if (NULL == tileNumber) { |
209 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_WholeIm
age]; | 214 expectedImage = fExpectedResults[sourceName][kJsonKey_Source_WholeIm
age]; |
210 } else { | 215 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
221 } | 226 } |
222 | 227 |
223 void ImageResultsAndExpectations::writeToFile(const char *filename) const { | 228 void ImageResultsAndExpectations::writeToFile(const char *filename) const { |
224 Json::Value header; | 229 Json::Value header; |
225 header[kJsonKey_Header_Type] = kJsonValue_Header_Type; | 230 header[kJsonKey_Header_Type] = kJsonValue_Header_Type; |
226 header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision; | 231 header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision; |
227 Json::Value root; | 232 Json::Value root; |
228 root[kJsonKey_ActualResults] = fActualResults; | 233 root[kJsonKey_ActualResults] = fActualResults; |
229 root[kJsonKey_Descriptions] = fDescriptions; | 234 root[kJsonKey_Descriptions] = fDescriptions; |
230 root[kJsonKey_Header] = header; | 235 root[kJsonKey_Header] = header; |
| 236 root[kJsonKey_ImageBaseGSUrl] = fImageBaseGSUrl; |
231 std::string jsonStdString = root.toStyledString(); | 237 std::string jsonStdString = root.toStyledString(); |
232 SkFILEWStream stream(filename); | 238 SkFILEWStream stream(filename); |
233 stream.write(jsonStdString.c_str(), jsonStdString.length()); | 239 stream.write(jsonStdString.c_str(), jsonStdString.length()); |
234 } | 240 } |
235 | 241 |
236 /*static*/ bool ImageResultsAndExpectations::Parse(SkFILE *filePtr, | 242 /*static*/ bool ImageResultsAndExpectations::Parse(SkFILE *filePtr, |
237 Json::Value *jsonRoot) { | 243 Json::Value *jsonRoot) { |
238 SkAutoDataUnref dataRef(SkData::NewFromFILE(filePtr)); | 244 SkAutoDataUnref dataRef(SkData::NewFromFILE(filePtr)); |
239 if (NULL == dataRef.get()) { | 245 if (NULL == dataRef.get()) { |
240 return false; | 246 return false; |
241 } | 247 } |
242 | 248 |
243 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data()
); | 249 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data()
); |
244 size_t size = dataRef.get()->size(); | 250 size_t size = dataRef.get()->size(); |
245 Json::Reader reader; | 251 Json::Reader reader; |
246 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { | 252 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { |
247 return false; | 253 return false; |
248 } | 254 } |
249 | 255 |
250 return true; | 256 return true; |
251 } | 257 } |
252 | 258 |
253 } // namespace sk_tools | 259 } // namespace sk_tools |
OLD | NEW |