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"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkString.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:
|
|
|
|
DEFINE_int32(clone, 0, "Clone the picture n times before rendering.");
|
|
|
|
DECLARE_bool(deferImageDecoding);
|
|
|
|
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.");
|
2013-04-09 21:25:46 +00:00
|
|
|
DECLARE_string(readPath);
|
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.");
|
2013-12-13 20:52:36 +00:00
|
|
|
DEFINE_string(writeJsonSummaryPath, "", "File to write a JSON summary of image results to. "
|
|
|
|
"TODO(epoger): Currently, this only works if --writePath is also specified.");
|
2013-04-09 21:25:46 +00:00
|
|
|
DEFINE_string2(writePath, w, "", "Directory to write the rendered images.");
|
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-07-24 20:37:30 +00:00
|
|
|
DEFINE_bool(bench_record, false, "If true, drop into an infinite loop of recording the picture.");
|
|
|
|
|
2012-07-13 18:22:59 +00:00
|
|
|
static void make_output_filepath(SkString* path, const SkString& dir,
|
2012-06-12 14:56:36 +00:00
|
|
|
const SkString& name) {
|
2012-06-22 18:24:56 +00:00
|
|
|
sk_tools::make_filepath(path, dir, name);
|
2012-09-20 14:54:21 +00:00
|
|
|
// Remove ".skp"
|
|
|
|
path->remove(path->size() - 4, 4);
|
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]);
|
|
|
|
sk_tools::make_filepath(&outPath, dir, name);
|
|
|
|
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.
|
|
|
|
return SkImageDecoder::DecodeStream(&memStream, bitmap, SkBitmap::kNo_Config,
|
|
|
|
SkImageDecoder::kDecodeBounds_Mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-12-13 20:52:36 +00:00
|
|
|
/**
|
|
|
|
* Called only by render_picture().
|
|
|
|
*/
|
|
|
|
static bool render_picture_internal(const SkString& inputPath, const SkString* outputDir,
|
|
|
|
sk_tools::PictureRenderer& renderer,
|
|
|
|
SkBitmap** out) {
|
2012-07-09 18:32:08 +00:00
|
|
|
SkString inputFilename;
|
|
|
|
sk_tools::get_basename(&inputFilename, inputPath);
|
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());
|
|
|
|
|
|
|
|
SkPicture* picture = SkPicture::CreateFromStream(&inputStream, proc);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
const int kRecordFlags = 0;
|
|
|
|
SkPicture other;
|
|
|
|
picture->draw(other.beginRecording(picture->width(), picture->height(), kRecordFlags));
|
|
|
|
other.endRecording();
|
|
|
|
}
|
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
for (int i = 0; i < FLAGS_clone; ++i) {
|
2012-12-18 22:24:03 +00:00
|
|
|
SkPicture* clone = picture->clone();
|
|
|
|
SkDELETE(picture);
|
|
|
|
picture = clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
|
2012-09-10 18:18:38 +00:00
|
|
|
inputPath.c_str());
|
2012-09-14 02:01:10 +00:00
|
|
|
|
2012-12-18 22:24:03 +00:00
|
|
|
renderer.init(picture);
|
2012-10-01 20:06:09 +00:00
|
|
|
renderer.setup();
|
2012-08-07 17:11:33 +00:00
|
|
|
|
2012-10-26 13:26:55 +00:00
|
|
|
SkString* outputPath = NULL;
|
2013-05-03 20:43:37 +00:00
|
|
|
if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages) {
|
2012-10-26 13:26:55 +00:00
|
|
|
outputPath = SkNEW(SkString);
|
|
|
|
make_output_filepath(outputPath, *outputDir, inputFilename);
|
|
|
|
}
|
2012-12-18 22:24:03 +00:00
|
|
|
|
2013-06-28 21:32:00 +00:00
|
|
|
bool success = renderer.render(outputPath, out);
|
2012-10-26 13:26:55 +00:00
|
|
|
if (outputPath) {
|
|
|
|
if (!success) {
|
|
|
|
SkDebugf("Could not write to file %s\n", outputPath->c_str());
|
|
|
|
}
|
|
|
|
SkDELETE(outputPath);
|
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
|
|
|
|
|
|
|
SkDELETE(picture);
|
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() {
|
|
|
|
if (NULL != fRenderer) {
|
|
|
|
fRenderer->setBBoxHierarchyType(fSavedBbhType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
sk_tools::PictureRenderer* fRenderer;
|
|
|
|
sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType;
|
|
|
|
};
|
|
|
|
|
2013-12-13 20:52:36 +00:00
|
|
|
/**
|
|
|
|
* Render the SKP file(s) within inputPath, writing their bitmap images into outputDir.
|
|
|
|
*
|
|
|
|
* @param inputPath path to an individual SKP file, or a directory of SKP files
|
|
|
|
* @param outputDir if not NULL, write the image(s) generated into this directory
|
|
|
|
* @param renderer PictureRenderer to use to render the SKPs
|
|
|
|
* @param jsonSummaryPtr if not NULL, add the image(s) generated to this summary
|
|
|
|
*/
|
2012-12-18 22:24:03 +00:00
|
|
|
static bool render_picture(const SkString& inputPath, const SkString* outputDir,
|
2013-12-13 20:52:36 +00:00
|
|
|
sk_tools::PictureRenderer& renderer,
|
|
|
|
sk_tools::ImageResultsSummary *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,
|
2013-03-04 16:41:06 +00:00
|
|
|
FLAGS_writeWholeImage ? NULL : outputDir,
|
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 {
|
|
|
|
referenceRenderer = SkNEW(sk_tools::SimplePictureRenderer);
|
|
|
|
}
|
|
|
|
SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRenderer);
|
|
|
|
|
2013-12-13 20:52:36 +00:00
|
|
|
success = render_picture_internal(inputPath, NULL, *referenceRenderer,
|
|
|
|
&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
|
|
|
|
|
|
|
if (NULL != jsonSummaryPtr) {
|
|
|
|
// EPOGER: This is a hacky way of constructing the filename associated with the
|
|
|
|
// image checksum; we basically are repeating the logic of make_output_filepath()
|
|
|
|
// and code below here, within here.
|
|
|
|
// It would be better for the filename (without outputDir) to be passed in here,
|
|
|
|
// and used both for the checksum file and writing into outputDir.
|
|
|
|
//
|
|
|
|
// EPOGER: what about including the config type within hashFilename? That way,
|
|
|
|
// we could combine results of different config types without conflicting filenames.
|
|
|
|
SkString hashFilename;
|
|
|
|
sk_tools::get_basename(&hashFilename, inputPath);
|
|
|
|
hashFilename.remove(hashFilename.size() - 4, 4); // Remove ".skp"
|
|
|
|
hashFilename.append(".png");
|
|
|
|
jsonSummaryPtr->add(hashFilename.c_str(), *bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != outputDir) {
|
2012-12-18 22:24:03 +00:00
|
|
|
SkString inputFilename;
|
|
|
|
sk_tools::get_basename(&inputFilename, inputPath);
|
|
|
|
SkString outputPath;
|
|
|
|
make_output_filepath(&outputPath, *outputDir, inputFilename);
|
|
|
|
outputPath.append(".png");
|
|
|
|
if (!SkImageEncoder::EncodeFile(outputPath.c_str(), *bitmap,
|
|
|
|
SkImageEncoder::kPNG_Type, 100)) {
|
|
|
|
SkDebugf("Failed to draw the picture.\n");
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkDELETE(bitmap);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 16:41:06 +00:00
|
|
|
static int process_input(const char* input, const SkString* outputDir,
|
2013-12-13 20:52:36 +00:00
|
|
|
sk_tools::PictureRenderer& renderer,
|
|
|
|
sk_tools::ImageResultsSummary *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 {
|
|
|
|
SkString inputPath;
|
2013-03-04 16:41:06 +00:00
|
|
|
SkString inputAsSkString(input);
|
|
|
|
sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename);
|
2013-12-13 20:52:36 +00:00
|
|
|
if (!render_picture(inputPath, outputDir, 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);
|
2013-12-13 20:52:36 +00:00
|
|
|
if (!render_picture(inputPath, outputDir, 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-03-04 16:41:06 +00:00
|
|
|
if (FLAGS_clone < 0) {
|
|
|
|
SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone);
|
2012-07-20 22:34:27 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
2012-07-26 17:27:57 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
SkString outputDir;
|
2013-04-09 21:25:46 +00:00
|
|
|
if (FLAGS_writePath.count() == 1) {
|
|
|
|
outputDir.set(FLAGS_writePath[0]);
|
2013-03-04 16:41:06 +00:00
|
|
|
}
|
2013-12-13 20:52:36 +00:00
|
|
|
sk_tools::ImageResultsSummary jsonSummary;
|
|
|
|
sk_tools::ImageResultsSummary* jsonSummaryPtr = NULL;
|
|
|
|
if (FLAGS_writeJsonSummaryPath.count() == 1) {
|
|
|
|
jsonSummaryPtr = &jsonSummary;
|
|
|
|
}
|
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 ++) {
|
2013-12-13 20:52:36 +00:00
|
|
|
failures += process_input(FLAGS_readPath[i], &outputDir, *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
|
|
|
|
#endif
|
2013-12-13 20:52:36 +00:00
|
|
|
if (FLAGS_writeJsonSummaryPath.count() == 1) {
|
|
|
|
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
|