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

Unified Diff: dm/DMWriteTask.cpp

Issue 29293003: DM: add --writePath (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: directory per config Created 7 years, 2 months 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') | dm/README » ('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
new file mode 100644
index 0000000000000000000000000000000000000000..21a9b55bc33037d5aea527a9747aafc6d226a622
--- /dev/null
+++ b/dm/DMWriteTask.cpp
@@ -0,0 +1,47 @@
+#include "DMWriteTask.h"
+
+#include "DMUtil.h"
+#include "SkCommandLineFlags.h"
+#include "SkImageEncoder.h"
+
+#include <string.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;
+
+ fConfig.set(fromLastUnderscore+1);
+ fGmName.set(parentName, gmNameLength);
+}
+
+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(),
+ fBitmap,
+ SkImageEncoder::kPNG_Type,
+ 100/*quality*/))
+ {
+ this->fail();
+ }
+}
+
+SkString WriteTask::name() const {
+ return SkStringPrintf("writing %s/%s.png", fConfig.c_str(), fGmName.c_str());
+}
+
+bool WriteTask::shouldSkip() const {
+ return FLAGS_writePath.isEmpty();
+}
+
+} // namespace DM
« no previous file with comments | « dm/DMWriteTask.h ('k') | dm/README » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698