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 "SkImageEncoder.h" | 6 #include "SkImageEncoder.h" |
7 #include "SkMallocPixelRef.h" | 7 #include "SkMallocPixelRef.h" |
8 #include "SkStream.h" | 8 #include "SkStream.h" |
9 #include "SkString.h" | 9 #include "SkString.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 return SkString(name.c_str(), name.size() - totalSuffixLength); | 34 return SkString(name.c_str(), name.size() - totalSuffixLength); |
35 } | 35 } |
36 | 36 |
37 WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) | 37 WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) |
38 : CpuTask(parent) | 38 : CpuTask(parent) |
39 , fGmName(find_gm_name(parent, &fSuffixes)) | 39 , fGmName(find_gm_name(parent, &fSuffixes)) |
40 , fBitmap(bitmap) | 40 , fBitmap(bitmap) |
41 , fData(NULL) | 41 , fData(NULL) |
42 , fExtension(".png") {} | 42 , fExtension(".png") {} |
43 | 43 |
44 WriteTask::WriteTask(const Task& parent, SkData *data, const char* ext) | 44 WriteTask::WriteTask(const Task& parent, SkStreamAsset *data, const char* ext) |
45 : CpuTask(parent) | 45 : CpuTask(parent) |
46 , fGmName(find_gm_name(parent, &fSuffixes)) | 46 , fGmName(find_gm_name(parent, &fSuffixes)) |
47 , fData(SkRef(data)) | 47 , fData(data) |
48 , fExtension(ext) {} | 48 , fExtension(ext) {} |
49 | 49 |
50 void WriteTask::makeDirOrFail(SkString dir) { | 50 void WriteTask::makeDirOrFail(SkString dir) { |
51 if (!sk_mkdir(dir.c_str())) { | 51 if (!sk_mkdir(dir.c_str())) { |
52 this->fail(); | 52 this->fail(); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 namespace { | 56 namespace { |
57 | 57 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 info, rowBytes, NULL/*ctable*/, subset)); | 108 info, rowBytes, NULL/*ctable*/, subset)); |
109 SkASSERT(pixels); | 109 SkASSERT(pixels); |
110 | 110 |
111 bitmap->setInfo(info, rowBytes); | 111 bitmap->setInfo(info, rowBytes); |
112 bitmap->setPixelRef(pixels); | 112 bitmap->setPixelRef(pixels); |
113 return true; | 113 return true; |
114 } | 114 } |
115 }; | 115 }; |
116 | 116 |
117 // Does not take ownership of data. | 117 // Does not take ownership of data. |
118 bool save_data_to_file(const SkData* data, const char* path) { | 118 bool save_data_to_file(SkStreamAsset* data, const char* path) { |
| 119 data->rewind(); |
119 SkFILEWStream stream(path); | 120 SkFILEWStream stream(path); |
120 if (!stream.isValid() || !stream.write(data->data(), data->size())) { | 121 if (!stream.isValid() || !stream.writeStream(data, data->getLength())) { |
121 SkDebugf("Can't write %s.\n", path); | 122 SkDebugf("Can't write %s.\n", path); |
122 return false; | 123 return false; |
123 } | 124 } |
124 return true; | 125 return true; |
125 } | 126 } |
126 | 127 |
127 } // namespace | 128 } // namespace |
128 | 129 |
129 void WriteTask::draw() { | 130 void WriteTask::draw() { |
130 SkString dir(FLAGS_writePath[0]); | 131 SkString dir(FLAGS_writePath[0]); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 const SkString path = path_to_expected_image(fRoot, task); | 191 const SkString path = path_to_expected_image(fRoot, task); |
191 SkBitmap expected; | 192 SkBitmap expected; |
192 if (!PngAndRaw::Decode(path.c_str(), bitmap.info(), &expected)) { | 193 if (!PngAndRaw::Decode(path.c_str(), bitmap.info(), &expected)) { |
193 return false; | 194 return false; |
194 } | 195 } |
195 | 196 |
196 return BitmapsEqual(expected, bitmap); | 197 return BitmapsEqual(expected, bitmap); |
197 } | 198 } |
198 | 199 |
199 } // namespace DM | 200 } // namespace DM |
OLD | NEW |