diff options
-rw-r--r-- | gm/gm_expectations.cpp | 30 | ||||
-rw-r--r-- | gm/gm_expectations.h | 43 | ||||
-rw-r--r-- | gyp/tools.gyp | 7 | ||||
-rw-r--r-- | tools/PictureRenderer.cpp | 67 | ||||
-rw-r--r-- | tools/PictureRenderer.h | 41 | ||||
-rw-r--r-- | tools/image_expectations.cpp | 80 | ||||
-rw-r--r-- | tools/image_expectations.h | 56 | ||||
-rw-r--r-- | tools/render_pictures_main.cpp | 2 |
8 files changed, 153 insertions, 173 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. diff --git a/gyp/tools.gyp b/gyp/tools.gyp index 769cf6cd2f..340f20766b 100644 --- a/gyp/tools.gyp +++ b/gyp/tools.gyp @@ -182,7 +182,6 @@ 'gm.gyp:gm_expectations', 'jsoncpp.gyp:jsoncpp', 'skia_lib.gyp:skia_lib', - 'utils.gyp:utils', ], }, { @@ -237,7 +236,6 @@ 'pdf.gyp:pdf', 'ports.gyp:ports', 'skia_lib.gyp:skia_lib', - 'utils.gyp:utils', ], }, { @@ -263,7 +261,6 @@ 'pdf.gyp:pdf', 'ports.gyp:ports', 'skia_lib.gyp:skia_lib', - 'utils.gyp:utils', ], }, { @@ -369,6 +366,8 @@ 'target_name': 'picture_renderer', 'type': 'static_library', 'sources': [ + '../tools/image_expectations.h', + '../tools/image_expectations.cpp', '../tools/LazyDecodeBitmap.cpp', '../tools/PictureRenderer.h', '../tools/PictureRenderer.cpp', @@ -388,7 +387,7 @@ ], 'direct_dependent_settings': { 'include_dirs': [ - # needed for JSON headers used within PictureRenderer.h + # needed for JSON headers used within image_expectations.h '../third_party/externals/jsoncpp-chromium/overrides/include/', '../third_party/externals/jsoncpp/include/', ], diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp index c712ae672f..b5dc0fc93d 100644 --- a/tools/PictureRenderer.cpp +++ b/tools/PictureRenderer.cpp @@ -48,67 +48,6 @@ enum { kDefaultTileHeight = 256 }; -/* - * TODO(epoger): Make constant strings consistent instead of mixing hypenated and camel-caps. - * - * TODO(epoger): Similar constants are already maintained in 2 other places: - * gm/gm_json.py and gm/gm_expectations.cpp. We shouldn't add yet a third place. - * Figure out a way to share the definitions instead. - * - * Note that, as of https://codereview.chromium.org/226293002 , the JSON - * schema used here has started to differ from the one in gm_expectations.cpp . - * TODO(epoger): Consider getting GM and render_pictures to use the same JSON - * output module. - */ -const static char kJsonKey_ActualResults[] = "actual-results"; -const static char kJsonKey_Header[] = "header"; -const static char kJsonKey_Header_Type[] = "type"; -const static char kJsonKey_Header_Revision[] = "revision"; // unique within Type -const static char kJsonKey_Image_ChecksumAlgorithm[] = "checksumAlgorithm"; -const static char kJsonKey_Image_ChecksumValue[] = "checksumValue"; -const static char kJsonKey_Image_ComparisonResult[] = "comparisonResult"; -const static char kJsonKey_Image_Filepath[] = "filepath"; -const static char kJsonKey_Source_TiledImages[] = "tiled-images"; -const static char kJsonKey_Source_WholeImage[] = "whole-image"; -// Values (not keys) that are written out by this JSON generator -const static char kJsonValue_Header_Type[] = "ChecksummedImages"; -const static int kJsonValue_Header_Revision = 1; -const static char kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5[] = "bitmap-64bitMD5"; -const static char kJsonValue_Image_ComparisonResult_NoComparison[] = "no-comparison"; - -void ImageResultsSummary::add(const char *sourceName, const char *fileName, uint64_t hash, - const int *tileNumber) { - Json::Value image; - image[kJsonKey_Image_ChecksumAlgorithm] = kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5; - image[kJsonKey_Image_ChecksumValue] = Json::UInt64(hash); - image[kJsonKey_Image_ComparisonResult] = kJsonValue_Image_ComparisonResult_NoComparison; - image[kJsonKey_Image_Filepath] = fileName; - if (NULL == tileNumber) { - fActualResults[sourceName][kJsonKey_Source_WholeImage] = image; - } else { - fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber] = image; - } -} - -void ImageResultsSummary::add(const char *sourceName, const char *fileName, const SkBitmap& bitmap, - const int *tileNumber) { - uint64_t hash; - SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash)); - this->add(sourceName, fileName, hash, tileNumber); -} - -void ImageResultsSummary::writeToFile(const char *filename) { - Json::Value header; - header[kJsonKey_Header_Type] = kJsonValue_Header_Type; - header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision; - Json::Value root; - root[kJsonKey_Header] = header; - root[kJsonKey_ActualResults] = fActualResults; - std::string jsonStdString = root.toStyledString(); - SkFILEWStream stream(filename); - stream.write(jsonStdString.c_str(), jsonStdString.length()); -} - void PictureRenderer::init(SkPicture* pict, const SkString* outputDir, const SkString* inputFilename, bool useChecksumBasedFilenames) { this->CopyString(&fOutputDir, outputDir); @@ -367,8 +306,10 @@ static bool write(SkCanvas* canvas, const SkString& outputDir, const SkString& i generatedHash = true; outputSubdirPtr = escapedInputFilename.c_str(); - outputFilename.set(kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5); - outputFilename.append("_"); + // TODO(epoger): The string constant below will be removed when I land + // the second part of https://codereview.chromium.org/261313004/ + // ('add --readJsonSummaryPath to render_pictures') + outputFilename.set("bitmap-64bitMD5_"); outputFilename.appendU64(hash); } else { outputFilename.set(escapedInputFilename); diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h index 796162846b..445737e755 100644 --- a/tools/PictureRenderer.h +++ b/tools/PictureRenderer.h @@ -11,7 +11,6 @@ #include "SkCanvas.h" #include "SkCountdown.h" #include "SkDrawFilter.h" -#include "SkJSONCPP.h" #include "SkMath.h" #include "SkPaint.h" #include "SkPicture.h" @@ -29,6 +28,8 @@ #include "GrContext.h" #endif +#include "image_expectations.h" + class SkBitmap; class SkCanvas; class SkGLContextHelper; @@ -38,44 +39,6 @@ namespace sk_tools { class TiledPictureRenderer; -/** - * Class for collecting image results (checksums) as we go. - */ -class ImageResultsSummary { -public: - /** - * Adds this image to the summary of results. - * - * @param sourceName name of the source file that generated this result - * @param fileName relative path to the image output file on local disk - * @param hash hash to store - * @param tileNumber if not NULL, ptr to tile number - */ - void add(const char *sourceName, const char *fileName, uint64_t hash, - const int *tileNumber=NULL); - - /** - * Adds this image to the summary of results. - * - * @param sourceName name of the source file that generated this result - * @param fileName relative path to the image output file on local disk - * @param bitmap bitmap to store the hash of - * @param tileNumber if not NULL, ptr to tile number - */ - void add(const char *sourceName, const char *fileName, const SkBitmap& bitmap, - const int *tileNumber=NULL); - - /** - * Writes the summary (as constructed so far) to a file. - * - * @param filename path to write the summary to - */ - void writeToFile(const char *filename); - -private: - Json::Value fActualResults; -}; - class PictureRenderer : public SkRefCnt { public: diff --git a/tools/image_expectations.cpp b/tools/image_expectations.cpp new file mode 100644 index 0000000000..1ab53f24d3 --- /dev/null +++ b/tools/image_expectations.cpp @@ -0,0 +1,80 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkBitmap.h" +#include "SkBitmapHasher.h" +#include "SkJSONCPP.h" +#include "SkOSFile.h" +#include "SkStream.h" +#include "SkTypes.h" + +#include "image_expectations.h" + +/* + * TODO(epoger): Make constant strings consistent instead of mixing hypenated and camel-caps. + * + * TODO(epoger): Similar constants are already maintained in 2 other places: + * gm/gm_json.py and gm/gm_expectations.cpp. We shouldn't add yet a third place. + * Figure out a way to share the definitions instead. + * + * Note that, as of https://codereview.chromium.org/226293002 , the JSON + * schema used here has started to differ from the one in gm_expectations.cpp . + * TODO(epoger): Consider getting GM and render_pictures to use the same JSON + * output module. + */ +const static char kJsonKey_ActualResults[] = "actual-results"; +const static char kJsonKey_Header[] = "header"; +const static char kJsonKey_Header_Type[] = "type"; +const static char kJsonKey_Header_Revision[] = "revision"; // unique within Type +const static char kJsonKey_Image_ChecksumAlgorithm[] = "checksumAlgorithm"; +const static char kJsonKey_Image_ChecksumValue[] = "checksumValue"; +const static char kJsonKey_Image_ComparisonResult[] = "comparisonResult"; +const static char kJsonKey_Image_Filepath[] = "filepath"; +const static char kJsonKey_Source_TiledImages[] = "tiled-images"; +const static char kJsonKey_Source_WholeImage[] = "whole-image"; +// Values (not keys) that are written out by this JSON generator +const static char kJsonValue_Header_Type[] = "ChecksummedImages"; +const static int kJsonValue_Header_Revision = 1; +const static char kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5[] = "bitmap-64bitMD5"; +const static char kJsonValue_Image_ComparisonResult_NoComparison[] = "no-comparison"; + +namespace sk_tools { + + void ImageResultsSummary::add(const char *sourceName, const char *fileName, uint64_t hash, + const int *tileNumber) { + Json::Value image; + image[kJsonKey_Image_ChecksumAlgorithm] = kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5; + image[kJsonKey_Image_ChecksumValue] = Json::UInt64(hash); + image[kJsonKey_Image_ComparisonResult] = kJsonValue_Image_ComparisonResult_NoComparison; + image[kJsonKey_Image_Filepath] = fileName; + if (NULL == tileNumber) { + fActualResults[sourceName][kJsonKey_Source_WholeImage] = image; + } else { + fActualResults[sourceName][kJsonKey_Source_TiledImages][*tileNumber] = image; + } + } + + void ImageResultsSummary::add(const char *sourceName, const char *fileName, const SkBitmap& bitmap, + const int *tileNumber) { + uint64_t hash; + SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash)); + this->add(sourceName, fileName, hash, tileNumber); + } + + void ImageResultsSummary::writeToFile(const char *filename) { + Json::Value header; + header[kJsonKey_Header_Type] = kJsonValue_Header_Type; + header[kJsonKey_Header_Revision] = kJsonValue_Header_Revision; + Json::Value root; + root[kJsonKey_Header] = header; + root[kJsonKey_ActualResults] = fActualResults; + std::string jsonStdString = root.toStyledString(); + SkFILEWStream stream(filename); + stream.write(jsonStdString.c_str(), jsonStdString.length()); + } + +} // namespace sk_tools diff --git a/tools/image_expectations.h b/tools/image_expectations.h new file mode 100644 index 0000000000..432cf6d3a8 --- /dev/null +++ b/tools/image_expectations.h @@ -0,0 +1,56 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef image_expectations_DEFINED +#define image_expectations_DEFINED + +#include "SkBitmap.h" +#include "SkJSONCPP.h" + +namespace sk_tools { + + /** + * Class for collecting image results (checksums) as we go. + */ + class ImageResultsSummary { + public: + /** + * Adds this image to the summary of results. + * + * @param sourceName name of the source file that generated this result + * @param fileName relative path to the image output file on local disk + * @param hash hash to store + * @param tileNumber if not NULL, ptr to tile number + */ + void add(const char *sourceName, const char *fileName, uint64_t hash, + const int *tileNumber=NULL); + + /** + * Adds this image to the summary of results. + * + * @param sourceName name of the source file that generated this result + * @param fileName relative path to the image output file on local disk + * @param bitmap bitmap to store the hash of + * @param tileNumber if not NULL, ptr to tile number + */ + void add(const char *sourceName, const char *fileName, const SkBitmap& bitmap, + const int *tileNumber=NULL); + + /** + * Writes the summary (as constructed so far) to a file. + * + * @param filename path to write the summary to + */ + void writeToFile(const char *filename); + + private: + Json::Value fActualResults; + }; + +} // namespace sk_tools + +#endif // image_expectations_DEFINED diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp index f11eb0b80e..1bc4d21e33 100644 --- a/tools/render_pictures_main.cpp +++ b/tools/render_pictures_main.cpp @@ -19,6 +19,8 @@ #include "SkPictureRecorder.h" #include "SkStream.h" #include "SkString.h" + +#include "image_expectations.h" #include "PictureRenderer.h" #include "PictureRenderingFlags.h" #include "picture_utils.h" |