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 SkMD5 hasher; |
| 86 hasher.writeStream(stream, stream->getLength()); |
| 87 return get_md5_string(&hasher); |
| 88 } |
| 89 |
80 struct JsonData { | 90 struct JsonData { |
81 SkString name; // E.g. "ninepatch-stretch", "desk-gws_skp" | 91 SkString name; // E.g. "ninepatch-stretch", "desk-gws_skp" |
82 SkString config; // "gpu", "8888" | 92 SkString config; // "gpu", "8888" |
83 SkString mode; // "direct", "default-tilegrid", "pipe" | 93 SkString mode; // "direct", "default-tilegrid", "pipe" |
84 SkString sourceType; // "GM", "SKP" | 94 SkString sourceType; // "GM", "SKP" |
85 SkString md5; // In ASCII, so 32 bytes long. | 95 SkString md5; // In ASCII, so 32 bytes long. |
86 }; | 96 }; |
87 SkTArray<JsonData> gJsonData; | 97 SkTArray<JsonData> gJsonData; |
88 SK_DECLARE_STATIC_MUTEX(gJsonDataLock); | 98 SK_DECLARE_STATIC_MUTEX(gJsonDataLock); |
89 | 99 |
90 void WriteTask::draw() { | 100 void WriteTask::draw() { |
91 SkString md5; | 101 SkString md5; |
92 { | 102 { |
93 SkAutoLockPixels lock(fBitmap); | 103 SkAutoLockPixels lock(fBitmap); |
94 md5 = fData ? get_md5(fData->getMemoryBase(), fData->getLength()) | 104 md5 = fData ? get_md5(fData) |
95 : get_md5(fBitmap.getPixels(), fBitmap.getSize()); | 105 : get_md5(fBitmap.getPixels(), fBitmap.getSize()); |
96 } | 106 } |
97 | 107 |
98 SkASSERT(fSuffixes.count() > 0); | 108 SkASSERT(fSuffixes.count() > 0); |
99 SkString config = fSuffixes.back(); | 109 SkString config = fSuffixes.back(); |
100 SkString mode("direct"); | 110 SkString mode("direct"); |
101 if (fSuffixes.count() > 1) { | 111 if (fSuffixes.count() > 1) { |
102 mode = fSuffixes.fromBack(1); | 112 mode = fSuffixes.fromBack(1); |
103 } | 113 } |
104 | 114 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 202 } |
193 } | 203 } |
194 | 204 |
195 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); | 205 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); |
196 SkFILEWStream stream(path.c_str()); | 206 SkFILEWStream stream(path.c_str()); |
197 stream.writeText(Json::StyledWriter().write(root).c_str()); | 207 stream.writeText(Json::StyledWriter().write(root).c_str()); |
198 stream.flush(); | 208 stream.flush(); |
199 } | 209 } |
200 | 210 |
201 } // namespace DM | 211 } // namespace DM |
OLD | NEW |