2012-06-12 14:56:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2013-07-16 18:21:46 +00:00
|
|
|
#include "LazyDecodeBitmap.h"
|
2012-11-07 18:01:46 +00:00
|
|
|
#include "CopyTilesRenderer.h"
|
2012-06-12 14:56:36 +00:00
|
|
|
#include "SkBitmap.h"
|
2012-07-20 22:34:27 +00:00
|
|
|
#include "SkDevice.h"
|
2013-03-21 19:43:15 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
2012-09-10 17:19:06 +00:00
|
|
|
#include "SkGraphics.h"
|
Add the ability to provide function pointers to SkPicture serialization
and deserialization for encoding and decoding bitmaps.
Remove kForceFlattenBitmapPixels_Flag, which is no longer used.
When an SkOrderedReadBuffer needs to read a bitmap, if it does not
have an image decoder, use a dummy bitmap.
In GM, add a tolerance option for color differences, used when
testing picture serialization, so it can assume two images are the
same even though PNG encoding/decoding may have resulted in small
differences.
Create dummy implementations for SkImageDecoder and SkImageEncoder
functions in SkImageDecoder_empty so that a project that does not
want to include the images project it can still build.
Allow ports to build without images project.
In Mac's image encoder, copy 4444 to 8888 before encoding.
Add SkWriter32::reservePad, to provide a pointer to write non 4 byte
aligned data, padded with zeroes.
In bench_ and render_ pictures, pass decode function to SkPicture
creation from a stream.
BUG=https://code.google.com/p/skia/issues/detail?id=842
Review URL: https://codereview.appspot.com/6551071
git-svn-id: http://skia.googlecode.com/svn/trunk@5818 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-10-04 21:46:08 +00:00
|
|
|
#include "SkImageDecoder.h"
|
2012-12-18 22:24:03 +00:00
|
|
|
#include "SkImageEncoder.h"
|
2012-08-23 20:53:25 +00:00
|
|
|
#include "SkMath.h"
|
2012-06-12 14:56:36 +00:00
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2012-06-12 14:56:36 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkString.h"
|
2014-05-09 03:18:41 +00:00
|
|
|
|
|
|
|
#include "image_expectations.h"
|
2012-07-26 17:27:57 +00:00
|
|
|
#include "PictureRenderer.h"
|
2013-03-04 16:41:06 +00:00
|
|
|
#include "PictureRenderingFlags.h"
|
2012-06-22 18:24:56 +00:00
|
|
|
#include "picture_utils.h"
|
2012-06-12 14:56:36 +00:00
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
// Flags used by this file, alphabetically:
|
2014-08-14 14:32:49 +00:00
|
|
|
DEFINE_bool(bench_record, false, "If true, drop into an infinite loop of recording the picture.");
|
2013-03-04 16:41:06 +00:00
|
|
|
DECLARE_bool(deferImageDecoding);
|
2014-08-14 14:32:49 +00:00
|
|
|
DEFINE_string(descriptions, "", "one or more key=value pairs to add to the descriptions section "
|
|
|
|
"of the JSON summary.");
|
2014-08-22 11:46:30 +00:00
|
|
|
DEFINE_string(imageBaseGSUrl, "", "The Google Storage image base URL the images are stored in.");
|
2013-03-04 16:41:06 +00:00
|
|
|
DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Components that differ "
|
|
|
|
"by more than this amount are considered errors, though all diffs are reported. "
|
|
|
|
"Requires --validate.");
|
2014-05-15 15:10:48 +00:00
|
|
|
DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
|
|
|
|
"pixel mismatches into this directory.");
|
2014-09-18 20:52:08 +00:00
|
|
|
#if GR_GPU_STATS
|
|
|
|
DEFINE_bool(gpuStats, false, "Only meaningful with gpu configurations. "
|
|
|
|
"Report some GPU call statistics.");
|
|
|
|
#endif
|
2014-10-09 11:59:19 +00:00
|
|
|
DEFINE_bool(mpd, false, "If true, use MultiPictureDraw for rendering.");
|
2014-05-12 15:37:20 +00:00
|
|
|
DEFINE_string(readJsonSummaryPath, "", "JSON file to read image expectations from.");
|
2013-04-09 21:25:46 +00:00
|
|
|
DECLARE_string(readPath);
|
2014-03-19 17:26:07 +00:00
|
|
|
DEFINE_bool(writeChecksumBasedFilenames, false,
|
|
|
|
"When writing out images, use checksum-based filenames.");
|
2013-05-03 20:43:37 +00:00
|
|
|
DEFINE_bool(writeEncodedImages, false, "Any time the skp contains an encoded image, write it to a "
|
|
|
|
"file rather than decoding it. Requires writePath to be set. Skips drawing the full "
|
|
|
|
"skp to a file. Not compatible with deferImageDecoding.");
|
2014-04-29 19:39:22 +00:00
|
|
|
DEFINE_string(writeJsonSummaryPath, "", "File to write a JSON summary of image results to.");
|
|
|
|
DEFINE_string2(writePath, w, "", "Directory to write the rendered images into.");
|
2013-03-04 16:41:06 +00:00
|
|
|
DEFINE_bool(writeWholeImage, false, "In tile mode, write the entire rendered image to a "
|
|
|
|
"file, instead of an image for each tile.");
|
|
|
|
DEFINE_bool(validate, false, "Verify that the rendered image contains the same pixels as "
|
2013-03-13 17:27:16 +00:00
|
|
|
"the picture rendered in simple mode. When used in conjunction with --bbh, results "
|
|
|
|
"are validated against the picture rendered in the same mode, but without the bbh.");
|
2012-06-12 14:56:36 +00:00
|
|
|
|
2013-05-03 20:43:37 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Table for translating from format of data to a suffix.
|
|
|
|
*/
|
|
|
|
struct Format {
|
|
|
|
SkImageDecoder::Format fFormat;
|
|
|
|
const char* fSuffix;
|
|
|
|
};
|
|
|
|
static const Format gFormats[] = {
|
|
|
|
{ SkImageDecoder::kBMP_Format, ".bmp" },
|
|
|
|
{ SkImageDecoder::kGIF_Format, ".gif" },
|
|
|
|
{ SkImageDecoder::kICO_Format, ".ico" },
|
|
|
|
{ SkImageDecoder::kJPEG_Format, ".jpg" },
|
|
|
|
{ SkImageDecoder::kPNG_Format, ".png" },
|
|
|
|
{ SkImageDecoder::kWBMP_Format, ".wbmp" },
|
|
|
|
{ SkImageDecoder::kWEBP_Format, ".webp" },
|
|
|
|
{ SkImageDecoder::kUnknown_Format, "" },
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an appropriate suffix for an image format.
|
|
|
|
*/
|
|
|
|
static const char* get_suffix_from_format(SkImageDecoder::Format format) {
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
|
|
|
|
if (gFormats[i].fFormat == format) {
|
|
|
|
return gFormats[i].fSuffix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base name for an image file created from the encoded data in an skp.
|
|
|
|
*/
|
|
|
|
static SkString gInputFileName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number to be appended to the image file name so that it is unique.
|
|
|
|
*/
|
|
|
|
static uint32_t gImageNo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up the name for writing encoded data to a file.
|
|
|
|
* Sets gInputFileName to name, minus any extension ".*"
|
|
|
|
* Sets gImageNo to 0, so images from file "X.skp" will
|
|
|
|
* look like "X_<gImageNo>.<suffix>", beginning with 0
|
|
|
|
* for each new skp.
|
|
|
|
*/
|
|
|
|
static void reset_image_file_base_name(const SkString& name) {
|
|
|
|
gImageNo = 0;
|
|
|
|
// Remove ".skp"
|
|
|
|
const char* cName = name.c_str();
|
|
|
|
const char* dot = strrchr(cName, '.');
|
|
|
|
if (dot != NULL) {
|
|
|
|
gInputFileName.set(cName, dot - cName);
|
|
|
|
} else {
|
|
|
|
gInputFileName.set(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the raw encoded bitmap data to a file.
|
|
|
|
*/
|
|
|
|
static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitmap) {
|
|
|
|
SkASSERT(!FLAGS_writePath.isEmpty());
|
|
|
|
SkMemoryStream memStream(buffer, size);
|
|
|
|
SkString outPath;
|
|
|
|
SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&memStream);
|
|
|
|
SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++,
|
|
|
|
get_suffix_from_format(format));
|
|
|
|
SkString dir(FLAGS_writePath[0]);
|
2014-07-29 02:26:58 +00:00
|
|
|
outPath = SkOSPath::Join(dir.c_str(), name.c_str());
|
2013-05-03 20:43:37 +00:00
|
|
|
SkFILEWStream fileStream(outPath.c_str());
|
|
|
|
if (!(fileStream.isValid() && fileStream.write(buffer, size))) {
|
|
|
|
SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str());
|
|
|
|
}
|
|
|
|
// Put in a dummy bitmap.
|
2014-06-13 00:40:00 +00:00
|
|
|
return SkImageDecoder::DecodeStream(&memStream, bitmap, kUnknown_SkColorType,
|
2013-05-03 20:43:37 +00:00
|
|
|
SkImageDecoder::kDecodeBounds_Mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-12-13 20:52:36 +00:00
|
|
|
/**
|
|
|
|
* Called only by render_picture().
|
|
|
|
*/
|
2014-05-15 15:10:48 +00:00
|
|
|
static bool render_picture_internal(const SkString& inputPath, const SkString* writePath,
|
|
|
|
const SkString* mismatchPath,
|
2013-12-13 20:52:36 +00:00
|
|
|
sk_tools::PictureRenderer& renderer,
|
|
|
|
SkBitmap** out) {
|
2014-07-29 02:26:58 +00:00
|
|
|
SkString inputFilename = SkOSPath::Basename(inputPath.c_str());
|
2014-05-15 15:10:48 +00:00
|
|
|
SkString writePathString;
|
2014-09-05 20:34:00 +00:00
|
|
|
if (writePath && writePath->size() > 0 && !FLAGS_writeEncodedImages) {
|
2014-05-15 15:10:48 +00:00
|
|
|
writePathString.set(*writePath);
|
|
|
|
}
|
|
|
|
SkString mismatchPathString;
|
2014-09-05 20:34:00 +00:00
|
|
|
if (mismatchPath && mismatchPath->size() > 0) {
|
2014-05-15 15:10:48 +00:00
|
|
|
mismatchPathString.set(*mismatchPath);
|
2014-03-19 17:26:07 +00:00
|
|
|
}
|
2012-06-22 18:24:56 +00:00
|
|
|
|
2012-07-09 18:32:08 +00:00
|
|
|
SkFILEStream inputStream;
|
2012-06-22 18:24:56 +00:00
|
|
|
inputStream.setPath(inputPath.c_str());
|
|
|
|
if (!inputStream.isValid()) {
|
|
|
|
SkDebugf("Could not open file %s\n", inputPath.c_str());
|
2012-09-17 18:26:06 +00:00
|
|
|
return false;
|
2012-06-22 18:24:56 +00:00
|
|
|
}
|
|
|
|
|
2013-06-28 21:32:00 +00:00
|
|
|
SkPicture::InstallPixelRefProc proc;
|
2013-03-04 16:41:06 +00:00
|
|
|
if (FLAGS_deferImageDecoding) {
|
2013-07-16 18:21:46 +00:00
|
|
|
proc = &sk_tools::LazyDecodeBitmap;
|
2013-05-03 20:43:37 +00:00
|
|
|
} else if (FLAGS_writeEncodedImages) {
|
|
|
|
SkASSERT(!FLAGS_writePath.isEmpty());
|
|
|
|
reset_image_file_base_name(inputFilename);
|
2013-06-28 21:32:00 +00:00
|
|
|
proc = &write_image_to_file;
|
2013-02-22 21:38:35 +00:00
|
|
|
} else {
|
2013-06-28 21:32:00 +00:00
|
|
|
proc = &SkImageDecoder::DecodeMemory;
|
2013-02-22 21:38:35 +00:00
|
|
|
}
|
2013-05-03 20:43:37 +00:00
|
|
|
|
2013-06-28 21:32:00 +00:00
|
|
|
SkDebugf("deserializing... %s\n", inputPath.c_str());
|
|
|
|
|
2014-08-12 17:12:40 +00:00
|
|
|
SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, proc));
|
2013-06-28 21:32:00 +00:00
|
|
|
|
|
|
|
if (NULL == picture) {
|
2012-09-17 18:26:06 +00:00
|
|
|
SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-26 17:27:57 +00:00
|
|
|
|
2013-07-24 20:37:30 +00:00
|
|
|
while (FLAGS_bench_record) {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2014-09-04 15:42:50 +00:00
|
|
|
picture->playback(recorder.beginRecording(picture->cullRect().width(),
|
|
|
|
picture->cullRect().height(),
|
|
|
|
NULL, 0));
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> other(recorder.endRecording());
|
2013-07-24 20:37:30 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 15:03:56 +00:00
|
|
|
SkDebugf("drawing... [%f %f %f %f] %s\n",
|
|
|
|
picture->cullRect().fLeft, picture->cullRect().fTop,
|
|
|
|
picture->cullRect().fRight, picture->cullRect().fBottom,
|
2012-09-10 18:18:38 +00:00
|
|
|
inputPath.c_str());
|
2012-09-14 02:01:10 +00:00
|
|
|
|
2014-05-15 15:10:48 +00:00
|
|
|
renderer.init(picture, &writePathString, &mismatchPathString, &inputFilename,
|
2014-10-09 11:59:19 +00:00
|
|
|
FLAGS_writeChecksumBasedFilenames, FLAGS_mpd);
|
2014-03-16 19:46:36 +00:00
|
|
|
|
2012-10-01 20:06:09 +00:00
|
|
|
renderer.setup();
|
2014-05-22 00:36:05 +00:00
|
|
|
renderer.enableWrites();
|
2012-08-07 17:11:33 +00:00
|
|
|
|
2014-03-19 17:26:07 +00:00
|
|
|
bool success = renderer.render(out);
|
|
|
|
if (!success) {
|
|
|
|
SkDebugf("Failed to render %s\n", inputFilename.c_str());
|
2012-09-20 14:54:21 +00:00
|
|
|
}
|
2012-08-07 17:11:33 +00:00
|
|
|
|
|
|
|
renderer.end();
|
2012-12-18 22:24:03 +00:00
|
|
|
|
2012-09-17 18:26:06 +00:00
|
|
|
return success;
|
2012-06-12 14:56:36 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 18:18:48 +00:00
|
|
|
static inline int getByte(uint32_t value, int index) {
|
|
|
|
SkASSERT(0 <= index && index < 4);
|
|
|
|
return (value >> (index * 8)) & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MaxByteDiff(uint32_t v1, uint32_t v2) {
|
|
|
|
return SkMax32(SkMax32(abs(getByte(v1, 0) - getByte(v2, 0)), abs(getByte(v1, 1) - getByte(v2, 1))),
|
|
|
|
SkMax32(abs(getByte(v1, 2) - getByte(v2, 2)), abs(getByte(v1, 3) - getByte(v2, 3))));
|
|
|
|
}
|
|
|
|
|
2013-03-13 17:27:16 +00:00
|
|
|
class AutoRestoreBbhType {
|
|
|
|
public:
|
|
|
|
AutoRestoreBbhType() {
|
|
|
|
fRenderer = NULL;
|
2013-03-13 19:03:26 +00:00
|
|
|
fSavedBbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
|
2013-03-13 17:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set(sk_tools::PictureRenderer* renderer,
|
|
|
|
sk_tools::PictureRenderer::BBoxHierarchyType bbhType) {
|
|
|
|
fRenderer = renderer;
|
|
|
|
fSavedBbhType = renderer->getBBoxHierarchyType();
|
|
|
|
renderer->setBBoxHierarchyType(bbhType);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoRestoreBbhType() {
|
2014-09-05 20:34:00 +00:00
|
|
|
if (fRenderer) {
|
2013-03-13 17:27:16 +00:00
|
|
|
fRenderer->setBBoxHierarchyType(fSavedBbhType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
sk_tools::PictureRenderer* fRenderer;
|
|
|
|
sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType;
|
|
|
|
};
|
|
|
|
|
2013-12-13 20:52:36 +00:00
|
|
|
/**
|
2014-05-15 15:10:48 +00:00
|
|
|
* Render the SKP file(s) within inputPath.
|
2013-12-13 20:52:36 +00:00
|
|
|
*
|
|
|
|
* @param inputPath path to an individual SKP file, or a directory of SKP files
|
2014-05-15 15:10:48 +00:00
|
|
|
* @param writePath if not NULL, write all image(s) generated into this directory
|
|
|
|
* @param mismatchPath if not NULL, write any image(s) not matching expectations into this directory
|
2013-12-13 20:52:36 +00:00
|
|
|
* @param renderer PictureRenderer to use to render the SKPs
|
|
|
|
* @param jsonSummaryPtr if not NULL, add the image(s) generated to this summary
|
|
|
|
*/
|
2014-05-15 15:10:48 +00:00
|
|
|
static bool render_picture(const SkString& inputPath, const SkString* writePath,
|
|
|
|
const SkString* mismatchPath, sk_tools::PictureRenderer& renderer,
|
2014-05-12 15:37:20 +00:00
|
|
|
sk_tools::ImageResultsAndExpectations *jsonSummaryPtr) {
|
2013-01-16 18:18:48 +00:00
|
|
|
int diffs[256] = {0};
|
2012-12-18 22:24:03 +00:00
|
|
|
SkBitmap* bitmap = NULL;
|
2013-12-13 20:52:36 +00:00
|
|
|
renderer.setJsonSummaryPtr(jsonSummaryPtr);
|
|
|
|
bool success = render_picture_internal(inputPath,
|
2014-05-15 15:10:48 +00:00
|
|
|
FLAGS_writeWholeImage ? NULL : writePath,
|
|
|
|
FLAGS_writeWholeImage ? NULL : mismatchPath,
|
2012-12-18 22:24:03 +00:00
|
|
|
renderer,
|
2013-03-04 16:41:06 +00:00
|
|
|
FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL);
|
2012-12-18 22:24:03 +00:00
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL)) {
|
2012-12-18 22:24:03 +00:00
|
|
|
SkDebugf("Failed to draw the picture.\n");
|
|
|
|
SkDELETE(bitmap);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
if (FLAGS_validate) {
|
2012-12-18 22:24:03 +00:00
|
|
|
SkBitmap* referenceBitmap = NULL;
|
2013-03-13 17:27:16 +00:00
|
|
|
sk_tools::PictureRenderer* referenceRenderer;
|
|
|
|
// If the renderer uses a BBoxHierarchy, then the reference renderer
|
2013-03-14 07:02:51 +00:00
|
|
|
// will be the same renderer, without the bbh.
|
2013-03-13 17:27:16 +00:00
|
|
|
AutoRestoreBbhType arbbh;
|
|
|
|
if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
|
|
|
|
renderer.getBBoxHierarchyType()) {
|
|
|
|
referenceRenderer = &renderer;
|
|
|
|
referenceRenderer->ref(); // to match auto unref below
|
|
|
|
arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHierarchyType);
|
|
|
|
} else {
|
2014-08-18 14:52:17 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
referenceRenderer = SkNEW_ARGS(sk_tools::SimplePictureRenderer,
|
|
|
|
(renderer.getGrContextOptions()));
|
|
|
|
#else
|
2013-03-13 17:27:16 +00:00
|
|
|
referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer);
|
2014-08-18 14:52:17 +00:00
|
|
|
#endif
|
2013-03-13 17:27:16 +00:00
|
|
|
}
|
|
|
|
SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer);
|
|
|
|
|
2014-05-15 15:10:48 +00:00
|
|
|
success = render_picture_internal(inputPath, NULL, NULL, *referenceRenderer,
|
2013-12-13 20:52:36 +00:00
|
|
|
&referenceBitmap);
|
2012-12-18 22:24:03 +00:00
|
|
|
|
2013-03-12 19:56:49 +00:00
|
|
|
if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getPixels()) {
|
2012-12-18 22:24:03 +00:00
|
|
|
SkDebugf("Failed to draw the reference picture.\n");
|
|
|
|
SkDELETE(bitmap);
|
|
|
|
SkDELETE(referenceBitmap);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success && (bitmap->width() != referenceBitmap->width())) {
|
|
|
|
SkDebugf("Expected image width: %i, actual image width %i.\n",
|
|
|
|
referenceBitmap->width(), bitmap->width());
|
|
|
|
SkDELETE(bitmap);
|
|
|
|
SkDELETE(referenceBitmap);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (success && (bitmap->height() != referenceBitmap->height())) {
|
|
|
|
SkDebugf("Expected image height: %i, actual image height %i",
|
|
|
|
referenceBitmap->height(), bitmap->height());
|
|
|
|
SkDELETE(bitmap);
|
|
|
|
SkDELETE(referenceBitmap);
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-19 02:01:38 +00:00
|
|
|
|
2012-12-18 22:24:03 +00:00
|
|
|
for (int y = 0; success && y < bitmap->height(); y++) {
|
|
|
|
for (int x = 0; success && x < bitmap->width(); x++) {
|
2013-01-16 18:18:48 +00:00
|
|
|
int diff = MaxByteDiff(*referenceBitmap->getAddr32(x, y),
|
|
|
|
*bitmap->getAddr32(x, y));
|
|
|
|
SkASSERT(diff >= 0 && diff <= 255);
|
|
|
|
diffs[diff]++;
|
2013-01-17 07:06:06 +00:00
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
if (diff > FLAGS_maxComponentDiff) {
|
2013-01-16 18:18:48 +00:00
|
|
|
SkDebugf("Expected pixel at (%i %i) exceedds maximum "
|
|
|
|
"component diff of %i: 0x%x, actual 0x%x\n",
|
2013-03-04 16:41:06 +00:00
|
|
|
x, y, FLAGS_maxComponentDiff,
|
2013-01-11 16:08:07 +00:00
|
|
|
*referenceBitmap->getAddr32(x, y),
|
2012-12-18 22:24:03 +00:00
|
|
|
*bitmap->getAddr32(x, y));
|
|
|
|
SkDELETE(bitmap);
|
|
|
|
SkDELETE(referenceBitmap);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkDELETE(referenceBitmap);
|
2013-01-16 18:18:48 +00:00
|
|
|
|
|
|
|
for (int i = 1; i <= 255; ++i) {
|
|
|
|
if(diffs[i] > 0) {
|
|
|
|
SkDebugf("Number of pixels with max diff of %i is %i\n", i, diffs[i]);
|
|
|
|
}
|
|
|
|
}
|
2012-12-18 22:24:03 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
if (FLAGS_writeWholeImage) {
|
2012-12-18 22:24:03 +00:00
|
|
|
sk_tools::force_all_opaque(*bitmap);
|
2013-12-13 20:52:36 +00:00
|
|
|
|
2014-07-29 02:26:58 +00:00
|
|
|
SkString inputFilename = SkOSPath::Basename(inputPath.c_str());
|
2014-05-15 15:10:48 +00:00
|
|
|
SkString outputFilename(inputFilename);
|
|
|
|
sk_tools::replace_char(&outputFilename, '.', '_');
|
|
|
|
outputFilename.append(".png");
|
2014-04-10 15:39:02 +00:00
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
if (jsonSummaryPtr) {
|
2014-05-12 15:37:20 +00:00
|
|
|
sk_tools::ImageDigest imageDigest(*bitmap);
|
2014-05-15 15:10:48 +00:00
|
|
|
jsonSummaryPtr->add(inputFilename.c_str(), outputFilename.c_str(), imageDigest);
|
2014-09-05 20:34:00 +00:00
|
|
|
if ((mismatchPath) && !mismatchPath->isEmpty() &&
|
2014-08-22 06:21:32 +00:00
|
|
|
!jsonSummaryPtr->getExpectation(inputFilename.c_str()).matches(imageDigest)) {
|
2014-05-15 15:10:48 +00:00
|
|
|
success &= sk_tools::write_bitmap_to_disk(*bitmap, *mismatchPath, NULL,
|
|
|
|
outputFilename);
|
|
|
|
}
|
2013-12-13 20:52:36 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
if ((writePath) && !writePath->isEmpty()) {
|
2014-05-15 15:10:48 +00:00
|
|
|
success &= sk_tools::write_bitmap_to_disk(*bitmap, *writePath, NULL, outputFilename);
|
2012-12-18 22:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SkDELETE(bitmap);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-15 15:10:48 +00:00
|
|
|
static int process_input(const char* input, const SkString* writePath,
|
|
|
|
const SkString* mismatchPath, sk_tools::PictureRenderer& renderer,
|
2014-05-12 15:37:20 +00:00
|
|
|
sk_tools::ImageResultsAndExpectations *jsonSummaryPtr) {
|
2013-03-04 16:41:06 +00:00
|
|
|
SkOSFile::Iter iter(input, "skp");
|
2012-07-09 18:32:08 +00:00
|
|
|
SkString inputFilename;
|
2012-09-17 18:26:06 +00:00
|
|
|
int failures = 0;
|
2013-03-04 16:41:06 +00:00
|
|
|
SkDebugf("process_input, %s\n", input);
|
2012-07-09 18:32:08 +00:00
|
|
|
if (iter.next(&inputFilename)) {
|
|
|
|
do {
|
2014-07-29 02:26:58 +00:00
|
|
|
SkString inputPath = SkOSPath::Join(input, inputFilename.c_str());
|
2014-05-15 15:10:48 +00:00
|
|
|
if (!render_picture(inputPath, writePath, mismatchPath, renderer, jsonSummaryPtr)) {
|
2012-09-19 17:28:29 +00:00
|
|
|
++failures;
|
|
|
|
}
|
2012-07-09 18:32:08 +00:00
|
|
|
} while(iter.next(&inputFilename));
|
2013-03-04 16:41:06 +00:00
|
|
|
} else if (SkStrEndsWith(input, ".skp")) {
|
2012-07-09 18:32:08 +00:00
|
|
|
SkString inputPath(input);
|
2014-05-15 15:10:48 +00:00
|
|
|
if (!render_picture(inputPath, writePath, mismatchPath, renderer, jsonSummaryPtr)) {
|
2012-09-19 17:28:29 +00:00
|
|
|
++failures;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SkString warning;
|
2013-03-04 16:41:06 +00:00
|
|
|
warning.printf("Warning: skipping %s\n", input);
|
2012-09-19 17:28:29 +00:00
|
|
|
SkDebugf(warning.c_str());
|
2012-07-09 18:32:08 +00:00
|
|
|
}
|
2012-09-17 18:26:06 +00:00
|
|
|
return failures;
|
2012-07-09 18:32:08 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_main(int argc, char** argv) {
|
2013-03-21 19:43:15 +00:00
|
|
|
SkCommandLineFlags::SetUsage("Render .skp files.");
|
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
2012-07-20 22:34:27 +00:00
|
|
|
|
2013-04-09 21:25:46 +00:00
|
|
|
if (FLAGS_readPath.isEmpty()) {
|
2013-03-04 16:41:06 +00:00
|
|
|
SkDebugf(".skp files or directories are required.\n");
|
2012-10-03 17:32:33 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
if (FLAGS_maxComponentDiff < 0 || FLAGS_maxComponentDiff > 256) {
|
|
|
|
SkDebugf("--maxComponentDiff must be between 0 and 256\n");
|
2012-12-18 22:24:03 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
if (FLAGS_maxComponentDiff != 256 && !FLAGS_validate) {
|
|
|
|
SkDebugf("--maxComponentDiff requires --validate\n");
|
2012-12-18 22:24:03 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2013-05-03 20:43:37 +00:00
|
|
|
if (FLAGS_writeEncodedImages) {
|
|
|
|
if (FLAGS_writePath.isEmpty()) {
|
|
|
|
SkDebugf("--writeEncodedImages requires --writePath\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
if (FLAGS_deferImageDecoding) {
|
|
|
|
SkDebugf("--writeEncodedImages is not compatible with --deferImageDecoding\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
SkString errorString;
|
|
|
|
SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
|
|
|
|
kRender_PictureTool));
|
|
|
|
if (errorString.size() > 0) {
|
|
|
|
SkDebugf("%s\n", errorString.c_str());
|
2012-07-26 17:27:57 +00:00
|
|
|
}
|
2012-08-20 15:03:29 +00:00
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
if (renderer.get() == NULL) {
|
2013-02-08 19:38:21 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
2012-06-12 14:56:36 +00:00
|
|
|
|
2012-09-17 18:26:06 +00:00
|
|
|
SkAutoGraphics ag;
|
2013-03-04 16:41:06 +00:00
|
|
|
|
2014-05-15 15:10:48 +00:00
|
|
|
SkString writePath;
|
2013-04-09 21:25:46 +00:00
|
|
|
if (FLAGS_writePath.count() == 1) {
|
2014-05-15 15:10:48 +00:00
|
|
|
writePath.set(FLAGS_writePath[0]);
|
|
|
|
}
|
|
|
|
SkString mismatchPath;
|
|
|
|
if (FLAGS_mismatchPath.count() == 1) {
|
|
|
|
mismatchPath.set(FLAGS_mismatchPath[0]);
|
2013-03-04 16:41:06 +00:00
|
|
|
}
|
2014-05-12 15:37:20 +00:00
|
|
|
sk_tools::ImageResultsAndExpectations jsonSummary;
|
|
|
|
sk_tools::ImageResultsAndExpectations* jsonSummaryPtr = NULL;
|
2013-12-13 20:52:36 +00:00
|
|
|
if (FLAGS_writeJsonSummaryPath.count() == 1) {
|
|
|
|
jsonSummaryPtr = &jsonSummary;
|
2014-05-12 15:37:20 +00:00
|
|
|
if (FLAGS_readJsonSummaryPath.count() == 1) {
|
|
|
|
SkASSERT(jsonSummary.readExpectationsFile(FLAGS_readJsonSummaryPath[0]));
|
|
|
|
}
|
2013-12-13 20:52:36 +00:00
|
|
|
}
|
2012-06-12 14:56:36 +00:00
|
|
|
|
2012-09-17 18:26:06 +00:00
|
|
|
int failures = 0;
|
2013-04-09 21:25:46 +00:00
|
|
|
for (int i = 0; i < FLAGS_readPath.count(); i ++) {
|
2014-05-15 15:10:48 +00:00
|
|
|
failures += process_input(FLAGS_readPath[i], &writePath, &mismatchPath, *renderer.get(),
|
|
|
|
jsonSummaryPtr);
|
2012-09-17 18:26:06 +00:00
|
|
|
}
|
|
|
|
if (failures != 0) {
|
|
|
|
SkDebugf("Failed to render %i pictures.\n", failures);
|
|
|
|
return 1;
|
2012-06-12 14:56:36 +00:00
|
|
|
}
|
2012-09-13 15:40:37 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#if GR_CACHE_STATS
|
|
|
|
if (renderer->isUsingGpuDevice()) {
|
|
|
|
GrContext* ctx = renderer->getGrContext();
|
|
|
|
ctx->printCacheStats();
|
2013-10-02 18:19:17 +00:00
|
|
|
#ifdef SK_DEVELOPER
|
|
|
|
ctx->dumpFontCache();
|
|
|
|
#endif
|
2012-09-13 15:40:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-09-18 20:52:08 +00:00
|
|
|
#if GR_GPU_STATS
|
|
|
|
if (FLAGS_gpuStats && renderer->isUsingGpuDevice()) {
|
|
|
|
GrContext* ctx = renderer->getGrContext();
|
|
|
|
SkDebugf("RenderTarget Binds: %d\n", ctx->gpuStats()->renderTargetBinds());
|
|
|
|
SkDebugf("Shader Compilations: %d\n", ctx->gpuStats()->shaderCompilations());
|
|
|
|
}
|
|
|
|
#endif
|
2012-09-13 15:40:37 +00:00
|
|
|
#endif
|
2013-12-13 20:52:36 +00:00
|
|
|
if (FLAGS_writeJsonSummaryPath.count() == 1) {
|
2014-08-14 14:32:49 +00:00
|
|
|
// If there were any descriptions on the command line, insert them now.
|
|
|
|
for (int i=0; i<FLAGS_descriptions.count(); i++) {
|
|
|
|
SkTArray<SkString> tokens;
|
|
|
|
SkStrSplit(FLAGS_descriptions[i], "=", &tokens);
|
|
|
|
SkASSERT(tokens.count() == 2);
|
|
|
|
jsonSummary.addDescription(tokens[0].c_str(), tokens[1].c_str());
|
|
|
|
}
|
2014-08-22 11:46:30 +00:00
|
|
|
if (FLAGS_imageBaseGSUrl.count() == 1) {
|
|
|
|
jsonSummary.setImageBaseGSUrl(FLAGS_imageBaseGSUrl[0]);
|
|
|
|
}
|
2013-12-13 20:52:36 +00:00
|
|
|
jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]);
|
|
|
|
}
|
2012-10-02 20:00:03 +00:00
|
|
|
return 0;
|
2012-06-12 14:56:36 +00:00
|
|
|
}
|
2012-10-02 18:33:14 +00:00
|
|
|
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
|
|
int main(int argc, char * const argv[]) {
|
|
|
|
return tool_main(argc, (char**) argv);
|
|
|
|
}
|
|
|
|
#endif
|