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

Side by Side Diff: gm/gm_expectations.cpp

Issue 274463004: Revert of extract some common code from PictureRenderer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 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
« no previous file with comments | « gm/gm_expectations.h ('k') | gyp/gm.gyp » ('j') | 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 2013 Google Inc. 2 * Copyright 2013 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 *
7 * TODO(epoger): Combine this with tools/image_expectations.cpp, or eliminate on e of the two.
8 */ 6 */
9 7
10 #include "gm_expectations.h" 8 #include "gm_expectations.h"
11 #include "SkBitmapHasher.h" 9 #include "SkBitmapHasher.h"
12 #include "SkData.h"
13 #include "SkDataUtils.h"
14 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
15 11
16 #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message") 12 #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
17 13
18 // See gm_json.py for descriptions of each of these JSON keys. 14 // See gm_json.py for descriptions of each of these JSON keys.
19 // These constants must be kept in sync with the ones in that Python file! 15 // These constants must be kept in sync with the ones in that Python file!
20 const static char kJsonKey_ActualResults[] = "actual-results"; 16 const static char kJsonKey_ActualResults[] = "actual-results";
21 const static char kJsonKey_ActualResults_Failed[] = "failed"; 17 const static char kJsonKey_ActualResults_Failed[] = "failed";
22 const static char kJsonKey_ActualResults_FailureIgnored[]= "failure-ignored"; 18 const static char kJsonKey_ActualResults_FailureIgnored[]= "failure-ignored";
23 const static char kJsonKey_ActualResults_NoComparison[] = "no-comparison"; 19 const static char kJsonKey_ActualResults_NoComparison[] = "no-comparison";
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 212
217 JsonExpectationsSource::JsonExpectationsSource(const char *jsonPath) { 213 JsonExpectationsSource::JsonExpectationsSource(const char *jsonPath) {
218 Parse(jsonPath, &fJsonRoot); 214 Parse(jsonPath, &fJsonRoot);
219 fJsonExpectedResults = fJsonRoot[kJsonKey_ExpectedResults]; 215 fJsonExpectedResults = fJsonRoot[kJsonKey_ExpectedResults];
220 } 216 }
221 217
222 Expectations JsonExpectationsSource::get(const char *testName) const { 218 Expectations JsonExpectationsSource::get(const char *testName) const {
223 return Expectations(fJsonExpectedResults[testName]); 219 return Expectations(fJsonExpectedResults[testName]);
224 } 220 }
225 221
222 /*static*/ SkData* JsonExpectationsSource::ReadIntoSkData(SkStream &stream, size_t maxBytes) {
223 if (0 == maxBytes) {
224 return SkData::NewEmpty();
225 }
226 char* bufStart = reinterpret_cast<char *>(sk_malloc_throw(maxBytes));
227 char* bufPtr = bufStart;
228 size_t bytesRemaining = maxBytes;
229 while (bytesRemaining > 0) {
230 size_t bytesReadThisTime = stream.read(bufPtr, bytesRemaining);
231 if (0 == bytesReadThisTime) {
232 break;
233 }
234 bytesRemaining -= bytesReadThisTime;
235 bufPtr += bytesReadThisTime;
236 }
237 return SkData::NewFromMalloc(bufStart, maxBytes - bytesRemaining);
238 }
239
226 /*static*/ bool JsonExpectationsSource::Parse(const char *jsonPath, Json::Va lue *jsonRoot) { 240 /*static*/ bool JsonExpectationsSource::Parse(const char *jsonPath, Json::Va lue *jsonRoot) {
227 SkFILEStream inFile(jsonPath); 241 SkFILEStream inFile(jsonPath);
228 if (!inFile.isValid()) { 242 if (!inFile.isValid()) {
229 SkDebugf("unable to read JSON file %s\n", jsonPath); 243 SkDebugf("unable to read JSON file %s\n", jsonPath);
230 DEBUGFAIL_SEE_STDERR; 244 DEBUGFAIL_SEE_STDERR;
231 return false; 245 return false;
232 } 246 }
233 247
234 SkAutoDataUnref dataRef(SkDataUtils::ReadFileIntoSkData(inFile)); 248 SkAutoDataUnref dataRef(ReadFileIntoSkData(inFile));
235 if (NULL == dataRef.get()) { 249 if (NULL == dataRef.get()) {
236 SkDebugf("error reading JSON file %s\n", jsonPath); 250 SkDebugf("error reading JSON file %s\n", jsonPath);
237 DEBUGFAIL_SEE_STDERR; 251 DEBUGFAIL_SEE_STDERR;
238 return false; 252 return false;
239 } 253 }
240 254
241 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data() ); 255 const char *bytes = reinterpret_cast<const char *>(dataRef.get()->data() );
242 size_t size = dataRef.get()->size(); 256 size_t size = dataRef.get()->size();
243 Json::Reader reader; 257 Json::Reader reader;
244 if (!reader.parse(bytes, bytes+size, *jsonRoot)) { 258 if (!reader.parse(bytes, bytes+size, *jsonRoot)) {
245 SkDebugf("error parsing JSON file %s\n", jsonPath); 259 SkDebugf("error parsing JSON file %s\n", jsonPath);
246 DEBUGFAIL_SEE_STDERR; 260 DEBUGFAIL_SEE_STDERR;
247 return false; 261 return false;
248 } 262 }
249 return true; 263 return true;
250 } 264 }
251 265
252 } 266 }
OLDNEW
« no previous file with comments | « gm/gm_expectations.h ('k') | gyp/gm.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698