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

Side by Side Diff: dm/DMWriteTask.cpp

Issue 551873003: Update DM JSON format. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « dm/DMWriteTask.h ('k') | tools/flags/SkCommonFlags.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 "SkColorPriv.h" 4 #include "SkColorPriv.h"
5 #include "SkCommonFlags.h" 5 #include "SkCommonFlags.h"
6 #include "SkData.h" 6 #include "SkData.h"
7 #include "SkImageEncoder.h" 7 #include "SkImageEncoder.h"
8 #include "SkMD5.h" 8 #include "SkMD5.h"
9 #include "SkMallocPixelRef.h" 9 #include "SkMallocPixelRef.h"
10 #include "SkOSFile.h" 10 #include "SkOSFile.h"
(...skipping 18 matching lines...) Expand all
29 return consumed; 29 return consumed;
30 } 30 }
31 31
32 inline static SkString find_base_name(const Task& parent, SkTArray<SkString>* su ffixList) { 32 inline static SkString find_base_name(const Task& parent, SkTArray<SkString>* su ffixList) {
33 const int suffixes = parent.depth() + 1; 33 const int suffixes = parent.depth() + 1;
34 const SkString& name = parent.name(); 34 const SkString& name = parent.name();
35 const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), suffixL ist); 35 const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), suffixL ist);
36 return SkString(name.c_str(), name.size() - totalSuffixLength); 36 return SkString(name.c_str(), name.size() - totalSuffixLength);
37 } 37 }
38 38
39 struct JsonData { 39 WriteTask::WriteTask(const Task& parent, const char* sourceType, SkBitmap bitmap )
40 SkString name;
41 SkString md5; // In ASCII, so 32 bytes long.
42 };
43 SkTArray<JsonData> gJsonData;
44 SK_DECLARE_STATIC_MUTEX(gJsonDataLock);
45
46 WriteTask::WriteTask(const Task& parent, SkBitmap bitmap)
47 : CpuTask(parent) 40 : CpuTask(parent)
48 , fFullName(parent.name())
49 , fBaseName(find_base_name(parent, &fSuffixes)) 41 , fBaseName(find_base_name(parent, &fSuffixes))
42 , fSourceType(sourceType)
50 , fBitmap(bitmap) 43 , fBitmap(bitmap)
51 , fData(NULL) 44 , fData(NULL)
52 , fExtension(".png") { 45 , fExtension(".png") {
53 } 46 }
54 47
55 WriteTask::WriteTask(const Task& parent, SkStreamAsset *data, const char* ext) 48 WriteTask::WriteTask(const Task& parent,
49 const char* sourceType,
50 SkStreamAsset *data,
51 const char* ext)
56 : CpuTask(parent) 52 : CpuTask(parent)
57 , fFullName(parent.name())
58 , fBaseName(find_base_name(parent, &fSuffixes)) 53 , fBaseName(find_base_name(parent, &fSuffixes))
54 , fSourceType(sourceType)
59 , fData(data) 55 , fData(data)
60 , fExtension(ext) { 56 , fExtension(ext) {
61 SkASSERT(fData.get()); 57 SkASSERT(fData.get());
62 SkASSERT(fData->unique()); 58 SkASSERT(fData->unique());
63 } 59 }
64 60
65 void WriteTask::makeDirOrFail(SkString dir) { 61 void WriteTask::makeDirOrFail(SkString dir) {
66 if (!sk_mkdir(dir.c_str())) { 62 if (!sk_mkdir(dir.c_str())) {
67 this->fail(); 63 this->fail();
68 } 64 }
(...skipping 14 matching lines...) Expand all
83 SkMD5::Digest digest; 79 SkMD5::Digest digest;
84 hasher.finish(digest); 80 hasher.finish(digest);
85 81
86 SkString md5; 82 SkString md5;
87 for (int i = 0; i < 16; i++) { 83 for (int i = 0; i < 16; i++) {
88 md5.appendf("%02x", digest.data[i]); 84 md5.appendf("%02x", digest.data[i]);
89 } 85 }
90 return md5; 86 return md5;
91 } 87 }
92 88
89 struct JsonData {
90 SkString name; // E.g. "ninepatch-stretch", "desk-gws_skp"
91 SkString config; // "gpu", "8888"
92 SkString sourceType; // "GM", "SKP"
93 SkString md5; // In ASCII, so 32 bytes long.
94 };
95 SkTArray<JsonData> gJsonData;
96 SK_DECLARE_STATIC_MUTEX(gJsonDataLock);
97
93 void WriteTask::draw() { 98 void WriteTask::draw() {
94 if (!fData.get()) { 99 if (!fData.get()) {
95 fData.reset(encode_to_png(fBitmap)); 100 fData.reset(encode_to_png(fBitmap));
96 if (!fData.get()) { 101 if (!fData.get()) {
97 this->fail("Can't encode to PNG."); 102 this->fail("Can't encode to PNG.");
98 } 103 }
99 } 104 }
100 105
101 JsonData entry = { fFullName, get_md5(fData) }; 106 JsonData entry = { fBaseName, fSuffixes[0], fSourceType, get_md5(fData) };
102 { 107 {
103 SkAutoMutexAcquire lock(&gJsonDataLock); 108 SkAutoMutexAcquire lock(&gJsonDataLock);
104 gJsonData.push_back(entry); 109 gJsonData.push_back(entry);
105 } 110 }
106 111
107 SkString dir(FLAGS_writePath[0]); 112 SkString dir(FLAGS_writePath[0]);
108 #if SK_BUILD_FOR_IOS 113 #if SK_BUILD_FOR_IOS
109 if (dir.equals("@")) { 114 if (dir.equals("@")) {
110 dir.set(FLAGS_resourcePath[0]); 115 dir.set(FLAGS_resourcePath[0]);
111 } 116 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 162
158 bool WriteTask::shouldSkip() const { 163 bool WriteTask::shouldSkip() const {
159 return FLAGS_writePath.isEmpty(); 164 return FLAGS_writePath.isEmpty();
160 } 165 }
161 166
162 void WriteTask::DumpJson() { 167 void WriteTask::DumpJson() {
163 if (FLAGS_writePath.isEmpty()) { 168 if (FLAGS_writePath.isEmpty()) {
164 return; 169 return;
165 } 170 }
166 171
167 // FIXME: This JSON format is a complete MVP strawman.
168 Json::Value root; 172 Json::Value root;
173
174 for (int i = 1; i < FLAGS_properties.count(); i += 2) {
175 root[FLAGS_properties[i-1]] = FLAGS_properties[i];
176 }
177 for (int i = 1; i < FLAGS_key.count(); i += 2) {
178 root["key"][FLAGS_key[i-1]] = FLAGS_key[i];
179 }
180
169 { 181 {
170 SkAutoMutexAcquire lock(&gJsonDataLock); 182 SkAutoMutexAcquire lock(&gJsonDataLock);
171 for (int i = 0; i < gJsonData.count(); i++) { 183 for (int i = 0; i < gJsonData.count(); i++) {
172 root[gJsonData[i].name.c_str()] = gJsonData[i].md5.c_str(); 184 Json::Value result;
185 result["key"]["name"] = gJsonData[i].name.c_str();
186 result["key"]["config"] = gJsonData[i].config.c_str();
187 result["options"]["source_type"] = gJsonData[i].sourceType.c_str();
188 result["md5"] = gJsonData[i].md5.c_str();
189
190 root["results"].append(result);
173 } 191 }
174 } 192 }
175 193
176 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); 194 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json");
177 SkFILEWStream stream(path.c_str()); 195 SkFILEWStream stream(path.c_str());
178 stream.writeText(Json::StyledWriter().write(root).c_str()); 196 stream.writeText(Json::StyledWriter().write(root).c_str());
179 stream.flush(); 197 stream.flush();
180 } 198 }
181 199
182 } // namespace DM 200 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMWriteTask.h ('k') | tools/flags/SkCommonFlags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698