diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-09 03:18:41 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-09 03:18:41 +0000 |
commit | 90c0fbd34947b6b644e90c5b2253752035f65b64 (patch) | |
tree | a6177a057e95bf3a67eea1dd4a9ac56b43cc52f5 /gm | |
parent | 8a1e688552e8bc6b70633a56ea4769ee168a5f49 (diff) |
reland "extract some common code from PictureRenderer"
re-lands https://codereview.chromium.org/273703006/
NOTRY=True
R=bungeman@google.com, djsollen@google.com
Author: epoger@google.com
Review URL: https://codereview.chromium.org/278633002
git-svn-id: http://skia.googlecode.com/svn/trunk@14662 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r-- | gm/gm_expectations.cpp | 30 | ||||
-rw-r--r-- | gm/gm_expectations.h | 43 |
2 files changed, 6 insertions, 67 deletions
diff --git a/gm/gm_expectations.cpp b/gm/gm_expectations.cpp index f46a572458..28493ddd9e 100644 --- a/gm/gm_expectations.cpp +++ b/gm/gm_expectations.cpp @@ -3,10 +3,13 @@ * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. + * + * TODO(epoger): Combine this with tools/image_expectations.cpp, or eliminate one of the two. */ #include "gm_expectations.h" #include "SkBitmapHasher.h" +#include "SkData.h" #include "SkImageDecoder.h" #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message") @@ -219,33 +222,8 @@ namespace skiagm { return Expectations(fJsonExpectedResults[testName]); } - /*static*/ SkData* JsonExpectationsSource::ReadIntoSkData(SkStream &stream, size_t maxBytes) { - if (0 == maxBytes) { - return SkData::NewEmpty(); - } - char* bufStart = reinterpret_cast<char *>(sk_malloc_throw(maxBytes)); - char* bufPtr = bufStart; - size_t bytesRemaining = maxBytes; - while (bytesRemaining > 0) { - size_t bytesReadThisTime = stream.read(bufPtr, bytesRemaining); - if (0 == bytesReadThisTime) { - break; - } - bytesRemaining -= bytesReadThisTime; - bufPtr += bytesReadThisTime; - } - return SkData::NewFromMalloc(bufStart, maxBytes - bytesRemaining); - } - /*static*/ bool JsonExpectationsSource::Parse(const char *jsonPath, Json::Value *jsonRoot) { - SkFILEStream inFile(jsonPath); - if (!inFile.isValid()) { - SkDebugf("unable to read JSON file %s\n", jsonPath); - DEBUGFAIL_SEE_STDERR; - return false; - } - - SkAutoDataUnref dataRef(ReadFileIntoSkData(inFile)); + SkAutoDataUnref dataRef(SkData::NewFromFileName(jsonPath)); if (NULL == dataRef.get()) { SkDebugf("error reading JSON file %s\n", jsonPath); DEBUGFAIL_SEE_STDERR; diff --git a/gm/gm_expectations.h b/gm/gm_expectations.h index d454732dad..7092127338 100644 --- a/gm/gm_expectations.h +++ b/gm/gm_expectations.h @@ -3,6 +3,8 @@ * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. + * + * TODO(epoger): Combine this with tools/image_expectations.h, or eliminate one of the two. */ #ifndef gm_expectations_DEFINED #define gm_expectations_DEFINED @@ -216,47 +218,6 @@ namespace skiagm { private: /** - * Read as many bytes as possible (up to maxBytes) from the stream into - * an SkData object. - * - * If the returned SkData contains fewer than maxBytes, then EOF has been - * reached and no more data would be available from subsequent calls. - * (If EOF has already been reached, then this call will return an empty - * SkData object immediately.) - * - * If there are fewer than maxBytes bytes available to read from the - * stream, but the stream has not been closed yet, this call will block - * until there are enough bytes to read or the stream has been closed. - * - * It is up to the caller to call unref() on the returned SkData object - * once the data is no longer needed, so that the underlying buffer will - * be freed. For example: - * - * { - * size_t maxBytes = 256; - * SkAutoDataUnref dataRef(readIntoSkData(stream, maxBytes)); - * if (NULL != dataRef.get()) { - * size_t bytesActuallyRead = dataRef.get()->size(); - * // use the data... - * } - * } - * // underlying buffer has been freed, thanks to auto unref - * - */ - // TODO(epoger): Move this, into SkStream.[cpp|h] as attempted in - // https://codereview.appspot.com/7300071 ? - // And maybe ReadFileIntoSkData() also? - static SkData* ReadIntoSkData(SkStream &stream, size_t maxBytes); - - /** - * Wrapper around ReadIntoSkData for files: reads the entire file into - * an SkData object. - */ - static SkData* ReadFileIntoSkData(SkFILEStream &stream) { - return ReadIntoSkData(stream, stream.getLength()); - } - - /** * Read the file contents from jsonPath and parse them into jsonRoot. * * Returns true if successful. |