OLD | NEW |
1 #include "DMWriteTask.h" | 1 #include "DMWriteTask.h" |
2 | 2 |
| 3 #include "DMJsonWriter.h" |
3 #include "DMUtil.h" | 4 #include "DMUtil.h" |
4 #include "SkColorPriv.h" | 5 #include "SkColorPriv.h" |
5 #include "SkCommonFlags.h" | 6 #include "SkCommonFlags.h" |
6 #include "SkData.h" | 7 #include "SkData.h" |
7 #include "SkImageEncoder.h" | 8 #include "SkImageEncoder.h" |
8 #include "SkMD5.h" | 9 #include "SkMD5.h" |
9 #include "SkMallocPixelRef.h" | 10 #include "SkMallocPixelRef.h" |
10 #include "SkOSFile.h" | 11 #include "SkOSFile.h" |
11 #include "SkStream.h" | 12 #include "SkStream.h" |
12 #include "SkString.h" | 13 #include "SkString.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 static bool write_asset(SkStreamAsset* input, SkWStream* output) { | 85 static bool write_asset(SkStreamAsset* input, SkWStream* output) { |
85 return input->rewind() && output->writeStream(input, input->getLength()); | 86 return input->rewind() && output->writeStream(input, input->getLength()); |
86 } | 87 } |
87 | 88 |
88 static SkString get_md5(SkStreamAsset* stream) { | 89 static SkString get_md5(SkStreamAsset* stream) { |
89 SkMD5 hasher; | 90 SkMD5 hasher; |
90 write_asset(stream, &hasher); | 91 write_asset(stream, &hasher); |
91 return get_md5_string(&hasher); | 92 return get_md5_string(&hasher); |
92 } | 93 } |
93 | 94 |
94 struct JsonData { | |
95 SkString name; // E.g. "ninepatch-stretch", "desk-gws_skp" | |
96 SkString config; // "gpu", "8888" | |
97 SkString mode; // "direct", "default-tilegrid", "pipe" | |
98 SkString sourceType; // "GM", "SKP" | |
99 SkString md5; // In ASCII, so 32 bytes long. | |
100 }; | |
101 SkTArray<JsonData> gJsonData; | |
102 SK_DECLARE_STATIC_MUTEX(gJsonDataLock); | |
103 | |
104 void WriteTask::draw() { | 95 void WriteTask::draw() { |
105 SkString md5; | 96 SkString md5; |
106 { | 97 { |
107 SkAutoLockPixels lock(fBitmap); | 98 SkAutoLockPixels lock(fBitmap); |
108 md5 = fData ? get_md5(fData) | 99 md5 = fData ? get_md5(fData) |
109 : get_md5(fBitmap.getPixels(), fBitmap.getSize()); | 100 : get_md5(fBitmap.getPixels(), fBitmap.getSize()); |
110 } | 101 } |
111 | 102 |
112 SkASSERT(fSuffixes.count() > 0); | 103 SkASSERT(fSuffixes.count() > 0); |
113 SkString config = fSuffixes.back(); | 104 SkString config = fSuffixes.back(); |
114 SkString mode("direct"); | 105 SkString mode("direct"); |
115 if (fSuffixes.count() > 1) { | 106 if (fSuffixes.count() > 1) { |
116 mode = fSuffixes.fromBack(1); | 107 mode = fSuffixes.fromBack(1); |
117 } | 108 } |
118 | 109 |
119 JsonData entry = { fBaseName, config, mode, fSourceType, md5 }; | |
120 { | 110 { |
121 SkAutoMutexAcquire lock(&gJsonDataLock); | 111 const JsonWriter::BitmapResult entry = { fBaseName, |
122 gJsonData.push_back(entry); | 112 config, |
| 113 mode, |
| 114 fSourceType, |
| 115 md5 }; |
| 116 JsonWriter::AddBitmapResult(entry); |
123 } | 117 } |
124 | 118 |
125 SkString dir(FLAGS_writePath[0]); | 119 SkString dir(FLAGS_writePath[0]); |
126 #if defined(SK_BUILD_FOR_IOS) | 120 #if defined(SK_BUILD_FOR_IOS) |
127 if (dir.equals("@")) { | 121 if (dir.equals("@")) { |
128 dir.set(FLAGS_resourcePath[0]); | 122 dir.set(FLAGS_resourcePath[0]); |
129 } | 123 } |
130 #endif | 124 #endif |
131 this->makeDirOrFail(dir); | 125 this->makeDirOrFail(dir); |
132 | 126 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 name.appendf("%s/", fSuffixes[i].c_str()); | 165 name.appendf("%s/", fSuffixes[i].c_str()); |
172 } | 166 } |
173 name.append(fBaseName.c_str()); | 167 name.append(fBaseName.c_str()); |
174 return name; | 168 return name; |
175 } | 169 } |
176 | 170 |
177 bool WriteTask::shouldSkip() const { | 171 bool WriteTask::shouldSkip() const { |
178 return FLAGS_writePath.isEmpty(); | 172 return FLAGS_writePath.isEmpty(); |
179 } | 173 } |
180 | 174 |
181 void WriteTask::DumpJson() { | |
182 if (FLAGS_writePath.isEmpty()) { | |
183 return; | |
184 } | |
185 | |
186 Json::Value root; | |
187 | |
188 for (int i = 1; i < FLAGS_properties.count(); i += 2) { | |
189 root[FLAGS_properties[i-1]] = FLAGS_properties[i]; | |
190 } | |
191 for (int i = 1; i < FLAGS_key.count(); i += 2) { | |
192 root["key"][FLAGS_key[i-1]] = FLAGS_key[i]; | |
193 } | |
194 | |
195 { | |
196 SkAutoMutexAcquire lock(&gJsonDataLock); | |
197 for (int i = 0; i < gJsonData.count(); i++) { | |
198 Json::Value result; | |
199 result["key"]["name"] = gJsonData[i].name.c_str(); | |
200 result["key"]["config"] = gJsonData[i].config.c_str(); | |
201 result["key"]["mode"] = gJsonData[i].mode.c_str(); | |
202 result["options"]["source_type"] = gJsonData[i].sourceType.c_str(); | |
203 result["md5"] = gJsonData[i].md5.c_str(); | |
204 | |
205 root["results"].append(result); | |
206 } | |
207 } | |
208 | |
209 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); | |
210 SkFILEWStream stream(path.c_str()); | |
211 stream.writeText(Json::StyledWriter().write(root).c_str()); | |
212 stream.flush(); | |
213 } | |
214 | |
215 } // namespace DM | 175 } // namespace DM |
OLD | NEW |