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

Side by Side Diff: dm/DMWriteTask.cpp

Issue 627473002: Handle getMemoryBase returning NULL in WriteTask. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comment. Created 6 years, 2 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 | « no previous file | no next file » | 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698