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 { |