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

Unified Diff: tools/PictureRenderer.cpp

Issue 261313004: add --readJsonSummaryPath to render_pictures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: split out SkDataUtils.[h,cpp] 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 side-by-side diff with in-line comments
Download patch
Index: tools/PictureRenderer.cpp
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index c712ae672fbfae196bc16504fef214b9d3bcbdd2..496853603428c263ad09df32d1bb5f2e0cf3d149 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.
epoger 2014/05/07 03:15:16 moved to image_expectations
- *
- * 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);
@@ -345,14 +284,11 @@ static bool write(SkCanvas* canvas, const SkString& outputDir, const SkString& i
SkBitmap bitmap;
SkISize size = canvas->getDeviceSize();
- sk_tools::setup_bitmap(&bitmap, size.width(), size.height());
-
- // Make sure we only compute the bitmap hash once (at most).
- uint64_t hash;
- bool generatedHash = false;
+ setup_bitmap(&bitmap, size.width(), size.height());
canvas->readPixels(&bitmap, 0, 0);
- sk_tools::force_all_opaque(bitmap);
+ force_all_opaque(bitmap);
+ BitmapAndDigest bitmapAndDigest(bitmap);
SkString escapedInputFilename(inputFilename);
replace_char(&escapedInputFilename, '.', '_');
@@ -360,16 +296,13 @@ static bool write(SkCanvas* canvas, const SkString& outputDir, const SkString& i
// TODO(epoger): what about including the config type within outputFilename? That way,
// we could combine results of different config types without conflicting filenames.
SkString outputFilename;
+ const ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr();
const char *outputSubdirPtr = NULL;
if (useChecksumBasedFilenames) {
- SkASSERT(!generatedHash);
- SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash));
- generatedHash = true;
-
outputSubdirPtr = escapedInputFilename.c_str();
- outputFilename.set(kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5);
+ outputFilename.set(imageDigestPtr->getHashType());
outputFilename.append("_");
- outputFilename.appendU64(hash);
+ outputFilename.appendU64(imageDigestPtr->getHashValue());
} else {
outputFilename.set(escapedInputFilename);
if (NULL != tileNumberPtr) {
@@ -380,11 +313,7 @@ static bool write(SkCanvas* canvas, const SkString& outputDir, const SkString& i
outputFilename.append(".png");
if (NULL != jsonSummaryPtr) {
- if (!generatedHash) {
- SkAssertResult(SkBitmapHasher::ComputeDigest(bitmap, &hash));
- generatedHash = true;
- }
-
+ const ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr();
SkString outputRelativePath;
if (outputSubdirPtr) {
outputRelativePath.set(outputSubdirPtr);
@@ -395,7 +324,7 @@ static bool write(SkCanvas* canvas, const SkString& outputDir, const SkString& i
}
jsonSummaryPtr->add(inputFilename.c_str(), outputRelativePath.c_str(),
- hash, tileNumberPtr);
+ *imageDigestPtr, tileNumberPtr);
}
if (outputDir.isEmpty()) {

Powered by Google App Engine
This is Rietveld 408576698