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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 SkASSERT(fData.get()); | 57 SkASSERT(fData.get()); |
58 SkASSERT(fData->unique()); | 58 SkASSERT(fData->unique()); |
59 } | 59 } |
60 | 60 |
61 void WriteTask::makeDirOrFail(SkString dir) { | 61 void WriteTask::makeDirOrFail(SkString dir) { |
62 if (!sk_mkdir(dir.c_str())) { | 62 if (!sk_mkdir(dir.c_str())) { |
63 this->fail(); | 63 this->fail(); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 static SkString get_md5(const void* ptr, size_t len) { | 67 static SkString get_md5_string(SkMD5* hasher) { |
68 SkMD5 hasher; | |
69 hasher.write(ptr, len); | |
70 SkMD5::Digest digest; | 68 SkMD5::Digest digest; |
71 hasher.finish(digest); | 69 hasher->finish(digest); |
72 | 70 |
73 SkString md5; | 71 SkString md5; |
74 for (int i = 0; i < 16; i++) { | 72 for (int i = 0; i < 16; i++) { |
75 md5.appendf("%02x", digest.data[i]); | 73 md5.appendf("%02x", digest.data[i]); |
76 } | 74 } |
77 return md5; | 75 return md5; |
78 } | 76 } |
79 | 77 |
78 static SkString get_md5(const void* ptr, size_t len) { | |
79 SkMD5 hasher; | |
80 hasher.write(ptr, len); | |
81 return get_md5_string(&hasher); | |
82 } | |
83 | |
84 static SkString get_md5(SkStreamAsset* stream) { | |
85 if (stream->getMemoryBase()) { | |
mtklein
2014/10/02 19:54:59
Let's skip the if and just always call writeStream
bungeman-skia
2014/10/02 20:00:11
Done.
| |
86 return get_md5(stream->getMemoryBase(), stream->getLength()); | |
87 } | |
88 | |
89 SkMD5 hasher; | |
90 hasher.writeStream(stream, stream->getLength()); | |
91 return get_md5_string(&hasher); | |
92 } | |
93 | |
80 struct JsonData { | 94 struct JsonData { |
81 SkString name; // E.g. "ninepatch-stretch", "desk-gws_skp" | 95 SkString name; // E.g. "ninepatch-stretch", "desk-gws_skp" |
82 SkString config; // "gpu", "8888" | 96 SkString config; // "gpu", "8888" |
83 SkString mode; // "direct", "default-tilegrid", "pipe" | 97 SkString mode; // "direct", "default-tilegrid", "pipe" |
84 SkString sourceType; // "GM", "SKP" | 98 SkString sourceType; // "GM", "SKP" |
85 SkString md5; // In ASCII, so 32 bytes long. | 99 SkString md5; // In ASCII, so 32 bytes long. |
86 }; | 100 }; |
87 SkTArray<JsonData> gJsonData; | 101 SkTArray<JsonData> gJsonData; |
88 SK_DECLARE_STATIC_MUTEX(gJsonDataLock); | 102 SK_DECLARE_STATIC_MUTEX(gJsonDataLock); |
89 | 103 |
90 void WriteTask::draw() { | 104 void WriteTask::draw() { |
91 SkString md5; | 105 SkString md5; |
92 { | 106 { |
93 SkAutoLockPixels lock(fBitmap); | 107 SkAutoLockPixels lock(fBitmap); |
94 md5 = fData ? get_md5(fData->getMemoryBase(), fData->getLength()) | 108 md5 = fData ? get_md5(fData) |
95 : get_md5(fBitmap.getPixels(), fBitmap.getSize()); | 109 : get_md5(fBitmap.getPixels(), fBitmap.getSize()); |
96 } | 110 } |
97 | 111 |
98 SkASSERT(fSuffixes.count() > 0); | 112 SkASSERT(fSuffixes.count() > 0); |
99 SkString config = fSuffixes.back(); | 113 SkString config = fSuffixes.back(); |
100 SkString mode("direct"); | 114 SkString mode("direct"); |
101 if (fSuffixes.count() > 1) { | 115 if (fSuffixes.count() > 1) { |
102 mode = fSuffixes.fromBack(1); | 116 mode = fSuffixes.fromBack(1); |
103 } | 117 } |
104 | 118 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 } | 206 } |
193 } | 207 } |
194 | 208 |
195 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); | 209 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); |
196 SkFILEWStream stream(path.c_str()); | 210 SkFILEWStream stream(path.c_str()); |
197 stream.writeText(Json::StyledWriter().write(root).c_str()); | 211 stream.writeText(Json::StyledWriter().write(root).c_str()); |
198 stream.flush(); | 212 stream.flush(); |
199 } | 213 } |
200 | 214 |
201 } // namespace DM | 215 } // namespace DM |
OLD | NEW |