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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dm/DMWriteTask.h ('k') | include/core/SkString.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "DMWriteTask.h" 1 #include "DMWriteTask.h"
2 2
3 #include "DMUtil.h" 3 #include "DMUtil.h"
4 #include "SkCommandLineFlags.h" 4 #include "SkCommandLineFlags.h"
5 #include "SkImageEncoder.h" 5 #include "SkImageEncoder.h"
6 6 #include "SkString.h"
7 #include <string.h>
8 7
9 DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs."); 8 DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs.");
10 9
11 namespace DM { 10 namespace DM {
12 11
13 WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) 12 WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) : Task(parent), fBitma p(bitmap) {
14 : Task(parent) 13 const int suffixes = parent.depth() + 1;
15 , fBitmap(bitmap) { 14 const char* name = parent.name().c_str();
16 // Split parent's name <gmName>_<config> into gmName and config. 15 SkTArray<SkString> split;
17 const char* parentName = parent.name().c_str(); 16 SkStrSplit(name, "_", &split);
18 const char* fromLastUnderscore = strrchr(parentName, '_'); 17 int totalSuffixLength = 0;
19 const ptrdiff_t gmNameLength = fromLastUnderscore - parentName; 18 for (int i = 0; i < suffixes; i++) {
19 // We're splitting off suffixes from the back to front.
20 fSuffixes.push_back(split[split.count()-i-1]);
21 totalSuffixLength += fSuffixes.back().size() + 1;
22 }
23 fGmName.set(name, strlen(name)-totalSuffixLength);
24 }
20 25
21 fConfig.set(fromLastUnderscore+1); 26 void WriteTask::makeDirOrFail(SkString dir) {
22 fGmName.set(parentName, gmNameLength); 27 if (!sk_mkdir(dir.c_str())) {
28 this->fail();
29 }
23 } 30 }
24 31
25 void WriteTask::draw() { 32 void WriteTask::draw() {
26 const char* root = FLAGS_writePath[0]; 33 SkString dir(FLAGS_writePath[0]);
27 const SkString dir = SkOSPath::SkPathJoin(root, fConfig.c_str()); 34 this->makeDirOrFail(dir);
28 if (!sk_mkdir(root) || 35 for (int i = 0; i < fSuffixes.count(); i++) {
29 !sk_mkdir(dir.c_str()) || 36 dir = SkOSPath::SkPathJoin(dir.c_str(), fSuffixes[i].c_str());
30 !SkImageEncoder::EncodeFile(Png(SkOSPath::SkPathJoin(dir.c_str(), fGmNam e.c_str())).c_str(), 37 this->makeDirOrFail(dir);
38 }
39 if (!SkImageEncoder::EncodeFile(Png(SkOSPath::SkPathJoin(dir.c_str(), fGmNam e.c_str())).c_str(),
31 fBitmap, 40 fBitmap,
32 SkImageEncoder::kPNG_Type, 41 SkImageEncoder::kPNG_Type,
33 100/*quality*/)) 42 100/*quality*/)) {
34 {
35 this->fail(); 43 this->fail();
36 } 44 }
37 } 45 }
38 46
39 SkString WriteTask::name() const { 47 SkString WriteTask::name() const {
40 return SkStringPrintf("writing %s/%s.png", fConfig.c_str(), fGmName.c_str()) ; 48 SkString name("writing ");
49 for (int i = 0; i < fSuffixes.count(); i++) {
50 name.appendf("%s/", fSuffixes[i].c_str());
51 }
52 name.append(fGmName.c_str());
53 return name;
41 } 54 }
42 55
43 bool WriteTask::shouldSkip() const { 56 bool WriteTask::shouldSkip() const {
44 return FLAGS_writePath.isEmpty(); 57 return FLAGS_writePath.isEmpty();
45 } 58 }
46 59
47 } // namespace DM 60 } // namespace DM
OLDNEW
« 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