skia2/dm/DMWriteTask.cpp
mtklein@google.com ca5bb87a31 DM: write failed comparison mode .pngs one more level deep in the tree.
E.g.  instead of having to compare
    /tmp/dm/565/optimizations.png
vs.
    /tmp/dm/replay/optimizations_565.png

it's now

    /tmp/dm/565/optimizations.png
vs.
    /tmp/dm/replay/565/optimizations.png

This lets working with skdiff go a lot more smoothly.

BUG=
R=bsalomon@google.com

Review URL: https://codereview.chromium.org/88773002

git-svn-id: http://skia.googlecode.com/svn/trunk@12402 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-11-26 22:06:12 +00:00

61 lines
1.7 KiB
C++

#include "DMWriteTask.h"
#include "DMUtil.h"
#include "SkCommandLineFlags.h"
#include "SkImageEncoder.h"
#include "SkString.h"
DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs.");
namespace DM {
WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) : Task(parent), fBitmap(bitmap) {
const int suffixes = parent.depth() + 1;
const char* name = parent.name().c_str();
SkTArray<SkString> split;
SkStrSplit(name, "_", &split);
int totalSuffixLength = 0;
for (int i = 0; i < suffixes; i++) {
// We're splitting off suffixes from the back to front.
fSuffixes.push_back(split[split.count()-i-1]);
totalSuffixLength += fSuffixes.back().size() + 1;
}
fGmName.set(name, strlen(name)-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);
}
if (!SkImageEncoder::EncodeFile(Png(SkOSPath::SkPathJoin(dir.c_str(), fGmName.c_str())).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();
}
} // namespace DM