aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/gm_expectations.cpp24
-rw-r--r--gm/gm_expectations.h43
-rw-r--r--gyp/gm.gyp1
-rw-r--r--gyp/tools.gyp5
-rw-r--r--gyp/utils.gyp2
-rw-r--r--src/utils/SkDataUtils.cpp28
-rw-r--r--src/utils/SkDataUtils.h63
-rw-r--r--tools/PictureRenderer.cpp67
-rw-r--r--tools/PictureRenderer.h41
-rw-r--r--tools/image_expectations.cpp82
-rw-r--r--tools/image_expectations.h56
-rw-r--r--tools/render_pictures_main.cpp2
12 files changed, 163 insertions, 251 deletions
diff --git a/gm/gm_expectations.cpp b/gm/gm_expectations.cpp
index 40bb2b4f90..f46a572458 100644
--- a/gm/gm_expectations.cpp
+++ b/gm/gm_expectations.cpp
@@ -3,14 +3,10 @@
*
* 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 "SkDataUtils.h"
#include "SkImageDecoder.h"
#define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
@@ -223,6 +219,24 @@ 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()) {
@@ -231,7 +245,7 @@ namespace skiagm {
return false;
}
- SkAutoDataUnref dataRef(SkDataUtils::ReadFileIntoSkData(inFile));
+ SkAutoDataUnref dataRef(ReadFileIntoSkData(inFile));
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 7092127338..d454732dad 100644
--- a/gm/gm_expectations.h
+++ b/gm/gm_expectations.h
@@ -3,8 +3,6 @@
*
* 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
@@ -218,6 +216,47 @@ 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/gm.gyp b/gyp/gm.gyp
index 546052569c..3533aa5ce9 100644
--- a/gyp/gm.gyp
+++ b/gyp/gm.gyp
@@ -17,7 +17,6 @@
'dependencies': [
'skia_lib.gyp:skia_lib',
'jsoncpp.gyp:jsoncpp',
- 'utils.gyp:utils',
],
'direct_dependent_settings': {
'include_dirs': [
diff --git a/gyp/tools.gyp b/gyp/tools.gyp
index e3ed7d5d41..769cf6cd2f 100644
--- a/gyp/tools.gyp
+++ b/gyp/tools.gyp
@@ -369,8 +369,6 @@
'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',
@@ -390,7 +388,7 @@
],
'direct_dependent_settings': {
'include_dirs': [
- # needed for JSON headers used within image_expectations.h
+ # needed for JSON headers used within PictureRenderer.h
'../third_party/externals/jsoncpp-chromium/overrides/include/',
'../third_party/externals/jsoncpp/include/',
],
@@ -400,7 +398,6 @@
'jsoncpp.gyp:jsoncpp',
'skia_lib.gyp:skia_lib',
'tools.gyp:picture_utils',
- 'utils.gyp:utils',
],
'conditions': [
['skia_gpu == 1',
diff --git a/gyp/utils.gyp b/gyp/utils.gyp
index b61a1069f7..5b3d9ea98c 100644
--- a/gyp/utils.gyp
+++ b/gyp/utils.gyp
@@ -73,8 +73,6 @@
'../src/utils/SkCanvasStateUtils.cpp',
'../src/utils/SkCubicInterval.cpp',
'../src/utils/SkCullPoints.cpp',
- '../src/utils/SkDataUtils.cpp',
- '../src/utils/SkDataUtils.h',
'../src/utils/SkDeferredCanvas.cpp',
'../src/utils/SkDumpCanvas.cpp',
'../src/utils/SkEventTracer.cpp',
diff --git a/src/utils/SkDataUtils.cpp b/src/utils/SkDataUtils.cpp
deleted file mode 100644
index c5544f71ba..0000000000
--- a/src/utils/SkDataUtils.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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 "SkData.h"
-#include "SkDataUtils.h"
-#include "SkStream.h"
-
-/*static*/ SkData* SkDataUtils::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);
-}
diff --git a/src/utils/SkDataUtils.h b/src/utils/SkDataUtils.h
deleted file mode 100644
index fc237f7b1a..0000000000
--- a/src/utils/SkDataUtils.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 SkDataUtils_DEFINED
-#define SkDataUtils_DEFINED
-
-#include "SkData.h"
-#include "SkStream.h"
-
-/**
- * Static class that performs various operations on SkData objects.
- *
- * EPOGER: Before committing, add unittests for these methods.
- *
- * TODO(epoger): Move these methods into SkStream.[cpp|h], as attempted in
- * https://codereview.appspot.com/7300071 ?
- */
-class SkDataUtils {
-public:
- /**
- * 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
- */
- 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());
- }
-
-};
-
-#endif
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index b5dc0fc93d..c712ae672f 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -48,6 +48,67 @@ 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);
@@ -306,10 +367,8 @@ static bool write(SkCanvas* canvas, const SkString& outputDir, const SkString& i
generatedHash = true;
outputSubdirPtr = escapedInputFilename.c_str();
- // 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.set(kJsonValue_Image_ChecksumAlgorithm_Bitmap64bitMD5);
+ outputFilename.append("_");
outputFilename.appendU64(hash);
} else {
outputFilename.set(escapedInputFilename);
diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h
index 445737e755..796162846b 100644
--- a/tools/PictureRenderer.h
+++ b/tools/PictureRenderer.h
@@ -11,6 +11,7 @@
#include "SkCanvas.h"
#include "SkCountdown.h"
#include "SkDrawFilter.h"
+#include "SkJSONCPP.h"
#include "SkMath.h"
#include "SkPaint.h"
#include "SkPicture.h"
@@ -28,8 +29,6 @@
#include "GrContext.h"
#endif
-#include "image_expectations.h"
-
class SkBitmap;
class SkCanvas;
class SkGLContextHelper;
@@ -39,6 +38,44 @@ 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
deleted file mode 100644
index a1fa589a2f..0000000000
--- a/tools/image_expectations.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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 "SkData.h"
-#include "SkDataUtils.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
deleted file mode 100644
index 432cf6d3a8..0000000000
--- a/tools/image_expectations.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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 1bc4d21e33..f11eb0b80e 100644
--- a/tools/render_pictures_main.cpp
+++ b/tools/render_pictures_main.cpp
@@ -19,8 +19,6 @@
#include "SkPictureRecorder.h"
#include "SkStream.h"
#include "SkString.h"
-
-#include "image_expectations.h"
#include "PictureRenderer.h"
#include "PictureRenderingFlags.h"
#include "picture_utils.h"