Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1427)

Unified Diff: dm/DMWriteTask.cpp

Issue 88773002: DM: write failed comparison mode .pngs one more level deep in the tree. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: depth() instead Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/DMWriteTask.h ('k') | include/core/SkString.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMWriteTask.cpp
diff --git a/dm/DMWriteTask.cpp b/dm/DMWriteTask.cpp
index 011b3395407fb69f7d193c8cba23f5152abbd0f1..c86381f78af12485fcd1bf4d1dcbc4cc08acb119 100644
--- a/dm/DMWriteTask.cpp
+++ b/dm/DMWriteTask.cpp
@@ -3,41 +3,54 @@
#include "DMUtil.h"
#include "SkCommandLineFlags.h"
#include "SkImageEncoder.h"
-
-#include <string.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) {
- // Split parent's name <gmName>_<config> into gmName and config.
- const char* parentName = parent.name().c_str();
- const char* fromLastUnderscore = strrchr(parentName, '_');
- const ptrdiff_t gmNameLength = fromLastUnderscore - parentName;
+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);
+}
- fConfig.set(fromLastUnderscore+1);
- fGmName.set(parentName, gmNameLength);
+void WriteTask::makeDirOrFail(SkString dir) {
+ if (!sk_mkdir(dir.c_str())) {
+ this->fail();
+ }
}
void WriteTask::draw() {
- const char* root = FLAGS_writePath[0];
- const SkString dir = SkOSPath::SkPathJoin(root, fConfig.c_str());
- if (!sk_mkdir(root) ||
- !sk_mkdir(dir.c_str()) ||
- !SkImageEncoder::EncodeFile(Png(SkOSPath::SkPathJoin(dir.c_str(), fGmName.c_str())).c_str(),
+ 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*/))
- {
+ 100/*quality*/)) {
this->fail();
}
}
SkString WriteTask::name() const {
- return SkStringPrintf("writing %s/%s.png", fConfig.c_str(), fGmName.c_str());
+ 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 {
« no previous file with comments | « dm/DMWriteTask.h ('k') | include/core/SkString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698