99589af4e3
DM writes out its images in a hierarchy that's a little different than GM, so this can't read GM's output. But it can read its own, written with -w. Example usage: $ out/Release/dm -w /tmp/baseline $ out/Release/dm -r /tmp/baseline -w /tmp/new (and optionally) $ mkdir /tmp/diff; out/Release/skdiff /tmp/baseline /tmp/new /tmp/diff GM's IndividualImageExpectationsSource and Expectations are a little too eager about decoding and hashing the expected images, so I took the opportunity to add DM::Expectations that mostly replaces skiagm::ExpectationsSource and skiagm::Expectations in DM. It mainly exists to move the image decoding and comparison off the main thread, which would otherwise be a major speed bottleneck. I tried to use skiagm code where possible. One notable place where I differed is in this new feature. When -r is a directory of images, DM does no hashing. It considerably faster to read the expected file into an SkBitmap and do a byte-for-byte comparison than to hash the two bitmaps and check those. The example usage above isn't quite working 100% yet. Expectations on some GMs fail, even with no binary change. I haven't pinned down whether this is due to - a bug in DM - flaky GMs - unthreadsafe GMs - flaky image decoding - unthreadsafe image decoding - something else but I intend to. Leon, Derek and I have suspected PNG decoding isn't threadsafe, but are as yet unable to prove it. I also seem to be able to cause malloc to fail on my laptop if I run too many configs at once, though I never seem to be using more than ~1G of RAM. Will track that down too. BUG= R=reed@google.com, bsalomon@google.com Author: mtklein@google.com Review URL: https://codereview.chromium.org/108963002 git-svn-id: http://skia.googlecode.com/svn/trunk@12596 2bbb7eff-a529-9590-31e7-b0007b416f81
111 lines
3.6 KiB
C++
111 lines
3.6 KiB
C++
#include "DMWriteTask.h"
|
|
|
|
#include "DMUtil.h"
|
|
#include "SkCommandLineFlags.h"
|
|
#include "SkImageDecoder.h"
|
|
#include "SkImageEncoder.h"
|
|
#include "SkString.h"
|
|
|
|
DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs.");
|
|
|
|
namespace DM {
|
|
|
|
// Splits off the last N suffixes of name (splitting on _) and appends them to out.
|
|
// Returns the total number of characters consumed.
|
|
static int split_suffixes(int N, const char* name, SkTArray<SkString>* out) {
|
|
SkTArray<SkString> split;
|
|
SkStrSplit(name, "_", &split);
|
|
int consumed = 0;
|
|
for (int i = 0; i < N; i++) {
|
|
// We're splitting off suffixes from the back to front.
|
|
out->push_back(split[split.count()-i-1]);
|
|
consumed += out->back().size() + 1; // Add one for the _.
|
|
}
|
|
return consumed;
|
|
}
|
|
|
|
WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) : Task(parent), fBitmap(bitmap) {
|
|
const int suffixes = parent.depth() + 1;
|
|
const SkString& name = parent.name();
|
|
const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), &fSuffixes);
|
|
fGmName.set(name.c_str(), name.size()-totalSuffixLength);
|
|
}
|
|
|
|
void WriteTask::makeDirOrFail(SkString dir) {
|
|
if (!sk_mkdir(dir.c_str())) {
|
|
this->fail();
|
|
}
|
|
}
|
|
|
|
void WriteTask::draw() {
|
|
SkString dir(FLAGS_writePath[0]);
|
|
this->makeDirOrFail(dir);
|
|
for (int i = 0; i < fSuffixes.count(); i++) {
|
|
dir = SkOSPath::SkPathJoin(dir.c_str(), fSuffixes[i].c_str());
|
|
this->makeDirOrFail(dir);
|
|
}
|
|
SkString path = SkOSPath::SkPathJoin(dir.c_str(), fGmName.c_str());
|
|
path.append(".png");
|
|
if (!SkImageEncoder::EncodeFile(path.c_str(),
|
|
fBitmap,
|
|
SkImageEncoder::kPNG_Type,
|
|
100/*quality*/)) {
|
|
this->fail();
|
|
}
|
|
}
|
|
|
|
SkString WriteTask::name() const {
|
|
SkString name("writing ");
|
|
for (int i = 0; i < fSuffixes.count(); i++) {
|
|
name.appendf("%s/", fSuffixes[i].c_str());
|
|
}
|
|
name.append(fGmName.c_str());
|
|
return name;
|
|
}
|
|
|
|
bool WriteTask::shouldSkip() const {
|
|
return FLAGS_writePath.isEmpty();
|
|
}
|
|
|
|
static SkString path_to_expected_image(const char* root, const Task& task) {
|
|
SkString filename = task.name();
|
|
|
|
// We know that all names passed in here belong to top-level Tasks, which have a single suffix
|
|
// (8888, 565, gpu, etc.) indicating what subdirectory to look in.
|
|
SkTArray<SkString> suffixes;
|
|
const int suffixLength = split_suffixes(1, filename.c_str(), &suffixes);
|
|
SkASSERT(1 == suffixes.count());
|
|
|
|
// We'll look in root/suffix for images.
|
|
const SkString dir = SkOSPath::SkPathJoin(root, suffixes[0].c_str());
|
|
|
|
// Remove the suffix and tack on a .png.
|
|
filename.remove(filename.size() - suffixLength, suffixLength);
|
|
filename.append(".png");
|
|
|
|
//SkDebugf("dir %s, filename %s\n", dir.c_str(), filename.c_str());
|
|
|
|
return SkOSPath::SkPathJoin(dir.c_str(), filename.c_str());
|
|
}
|
|
|
|
bool WriteTask::Expectations::check(const Task& task, SkBitmap bitmap) const {
|
|
const SkString path = path_to_expected_image(fRoot, task);
|
|
|
|
SkBitmap expected;
|
|
if (SkImageDecoder::DecodeFile(path.c_str(), &expected)) {
|
|
if (expected.config() != bitmap.config()) {
|
|
SkBitmap converted;
|
|
SkAssertResult(expected.copyTo(&converted, bitmap.config()));
|
|
expected.swap(converted);
|
|
}
|
|
SkASSERT(expected.config() == bitmap.config());
|
|
return BitmapsEqual(expected, bitmap);
|
|
}
|
|
|
|
// Couldn't read the file, etc.
|
|
SkDebugf("Problem decoding %s to SkBitmap.\n", path.c_str());
|
|
return false;
|
|
}
|
|
|
|
} // namespace DM
|