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

Side by Side Diff: gm/gm_expectations.cpp

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

Powered by Google App Engine
This is Rietveld 408576698