OLD | NEW |
1 #include "DMWriteTask.h" | 1 #include "DMWriteTask.h" |
2 | 2 |
3 #include "DMUtil.h" | 3 #include "DMUtil.h" |
4 #include "SkColorPriv.h" | 4 #include "SkColorPriv.h" |
5 #include "SkCommandLineFlags.h" | 5 #include "SkCommandLineFlags.h" |
6 #include "SkImageEncoder.h" | 6 #include "SkImageEncoder.h" |
7 #include "SkMallocPixelRef.h" | 7 #include "SkMallocPixelRef.h" |
8 #include "SkStream.h" | 8 #include "SkStream.h" |
9 #include "SkString.h" | 9 #include "SkString.h" |
10 | 10 |
11 DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs."); | 11 DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs."); |
12 | 12 |
13 namespace DM { | 13 namespace DM { |
14 | 14 |
15 // Splits off the last N suffixes of name (splitting on _) and appends them to o
ut. | 15 // Splits off the last N suffixes of name (splitting on _) and appends them to o
ut. |
16 // Returns the total number of characters consumed. | 16 // Returns the total number of characters consumed. |
17 static int split_suffixes(int N, const char* name, SkTArray<SkString>* out) { | 17 static int split_suffixes(int N, const char* name, SkTArray<SkString>* out) { |
18 SkTArray<SkString> split; | 18 SkTArray<SkString> split; |
19 SkStrSplit(name, "_", &split); | 19 SkStrSplit(name, "_", &split); |
20 int consumed = 0; | 20 int consumed = 0; |
21 for (int i = 0; i < N; i++) { | 21 for (int i = 0; i < N; i++) { |
22 // We're splitting off suffixes from the back to front. | 22 // We're splitting off suffixes from the back to front. |
23 out->push_back(split[split.count()-i-1]); | 23 out->push_back(split[split.count()-i-1]); |
24 consumed += out->back().size() + 1; // Add one for the _. | 24 consumed += out->back().size() + 1; // Add one for the _. |
25 } | 25 } |
26 return consumed; | 26 return consumed; |
27 } | 27 } |
28 | 28 |
29 WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) : CpuTask(parent), fBi
tmap(bitmap) { | 29 WriteTask::WriteTask(const Task& parent, SkBitmap bitmap, Mode mode) |
30 const int suffixes = parent.depth() + 1; | 30 : CpuTask(parent), fBitmap(bitmap) { |
31 const SkString& name = parent.name(); | 31 if (mode == kVerbatim_Mode) { |
32 const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), &fSuffi
xes); | 32 fGmName.set(parent.name()); |
33 fGmName.set(name.c_str(), name.size()-totalSuffixLength); | 33 } else { |
| 34 const int suffixes = parent.depth() + 1; |
| 35 const SkString& name = parent.name(); |
| 36 const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), &fS
uffixes); |
| 37 fGmName.set(name.c_str(), name.size()-totalSuffixLength); |
| 38 } |
34 } | 39 } |
35 | 40 |
36 void WriteTask::makeDirOrFail(SkString dir) { | 41 void WriteTask::makeDirOrFail(SkString dir) { |
37 if (!sk_mkdir(dir.c_str())) { | 42 if (!sk_mkdir(dir.c_str())) { |
38 this->fail(); | 43 this->fail(); |
39 } | 44 } |
40 } | 45 } |
41 | 46 |
42 namespace { | 47 namespace { |
43 | 48 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 const SkString path = path_to_expected_image(fRoot, task); | 159 const SkString path = path_to_expected_image(fRoot, task); |
155 SkBitmap expected; | 160 SkBitmap expected; |
156 if (!PngAndRaw::Decode(path.c_str(), bitmap.info(), &expected)) { | 161 if (!PngAndRaw::Decode(path.c_str(), bitmap.info(), &expected)) { |
157 return false; | 162 return false; |
158 } | 163 } |
159 | 164 |
160 return BitmapsEqual(expected, bitmap); | 165 return BitmapsEqual(expected, bitmap); |
161 } | 166 } |
162 | 167 |
163 } // namespace DM | 168 } // namespace DM |
OLD | NEW |