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 "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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 return md5; | 75 return md5; |
76 } | 76 } |
77 | 77 |
78 static SkString get_md5(const void* ptr, size_t len) { | 78 static SkString get_md5(const void* ptr, size_t len) { |
79 SkMD5 hasher; | 79 SkMD5 hasher; |
80 hasher.write(ptr, len); | 80 hasher.write(ptr, len); |
81 return get_md5_string(&hasher); | 81 return get_md5_string(&hasher); |
82 } | 82 } |
83 | 83 |
| 84 static bool write_asset(SkStreamAsset* input, SkWStream* output) { |
| 85 return input->rewind() && output->writeStream(input, input->getLength()); |
| 86 } |
| 87 |
84 static SkString get_md5(SkStreamAsset* stream) { | 88 static SkString get_md5(SkStreamAsset* stream) { |
85 SkMD5 hasher; | 89 SkMD5 hasher; |
86 hasher.writeStream(stream, stream->getLength()); | 90 write_asset(stream, &hasher); |
87 return get_md5_string(&hasher); | 91 return get_md5_string(&hasher); |
88 } | 92 } |
89 | 93 |
90 struct JsonData { | 94 struct JsonData { |
91 SkString name; // E.g. "ninepatch-stretch", "desk-gws_skp" | 95 SkString name; // E.g. "ninepatch-stretch", "desk-gws_skp" |
92 SkString config; // "gpu", "8888" | 96 SkString config; // "gpu", "8888" |
93 SkString mode; // "direct", "default-tilegrid", "pipe" | 97 SkString mode; // "direct", "default-tilegrid", "pipe" |
94 SkString sourceType; // "GM", "SKP" | 98 SkString sourceType; // "GM", "SKP" |
95 SkString md5; // In ASCII, so 32 bytes long. | 99 SkString md5; // In ASCII, so 32 bytes long. |
96 }; | 100 }; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 path.append(fExtension); | 151 path.append(fExtension); |
148 // The path is unique, so two threads can't both write to the same file. | 152 // The path is unique, so two threads can't both write to the same file. |
149 // If already present we overwrite here, since the content may have chan
ged. | 153 // If already present we overwrite here, since the content may have chan
ged. |
150 } | 154 } |
151 | 155 |
152 SkFILEWStream file(path.c_str()); | 156 SkFILEWStream file(path.c_str()); |
153 if (!file.isValid()) { | 157 if (!file.isValid()) { |
154 return this->fail("Can't open file."); | 158 return this->fail("Can't open file."); |
155 } | 159 } |
156 | 160 |
157 bool ok = fData ? file.writeStream(fData, fData->getLength()) | 161 bool ok = fData ? write_asset(fData, &file) |
158 : SkImageEncoder::EncodeStream(&file, fBitmap, SkImageEncode
r::kPNG_Type, 100); | 162 : SkImageEncoder::EncodeStream(&file, fBitmap, SkImageEncode
r::kPNG_Type, 100); |
159 if (!ok) { | 163 if (!ok) { |
160 return this->fail("Can't write to file."); | 164 return this->fail("Can't write to file."); |
161 } | 165 } |
162 } | 166 } |
163 | 167 |
164 SkString WriteTask::name() const { | 168 SkString WriteTask::name() const { |
165 SkString name("writing "); | 169 SkString name("writing "); |
166 for (int i = 0; i < fSuffixes.count(); i++) { | 170 for (int i = 0; i < fSuffixes.count(); i++) { |
167 name.appendf("%s/", fSuffixes[i].c_str()); | 171 name.appendf("%s/", fSuffixes[i].c_str()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 206 } |
203 } | 207 } |
204 | 208 |
205 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); | 209 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); |
206 SkFILEWStream stream(path.c_str()); | 210 SkFILEWStream stream(path.c_str()); |
207 stream.writeText(Json::StyledWriter().write(root).c_str()); | 211 stream.writeText(Json::StyledWriter().write(root).c_str()); |
208 stream.flush(); | 212 stream.flush(); |
209 } | 213 } |
210 | 214 |
211 } // namespace DM | 215 } // namespace DM |
OLD | NEW |