| 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 SkASSERT(fData.get()); |
| 50 SkASSERT(fData->unique()); |
| 51 } |
| 49 | 52 |
| 50 void WriteTask::makeDirOrFail(SkString dir) { | 53 void WriteTask::makeDirOrFail(SkString dir) { |
| 51 if (!sk_mkdir(dir.c_str())) { | 54 if (!sk_mkdir(dir.c_str())) { |
| 52 this->fail(); | 55 this->fail(); |
| 53 } | 56 } |
| 54 } | 57 } |
| 55 | 58 |
| 56 namespace { | 59 namespace { |
| 57 | 60 |
| 58 // One file that first contains a .png of an SkBitmap, then its raw pixels. | 61 // One file that first contains a .png of an SkBitmap, then its raw pixels. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 info, rowBytes, NULL/*ctable*/, subset)); | 111 info, rowBytes, NULL/*ctable*/, subset)); |
| 109 SkASSERT(pixels); | 112 SkASSERT(pixels); |
| 110 | 113 |
| 111 bitmap->setInfo(info, rowBytes); | 114 bitmap->setInfo(info, rowBytes); |
| 112 bitmap->setPixelRef(pixels); | 115 bitmap->setPixelRef(pixels); |
| 113 return true; | 116 return true; |
| 114 } | 117 } |
| 115 }; | 118 }; |
| 116 | 119 |
| 117 // Does not take ownership of data. | 120 // Does not take ownership of data. |
| 118 bool save_data_to_file(const SkData* data, const char* path) { | 121 bool save_data_to_file(SkStreamAsset* data, const char* path) { |
| 122 data->rewind(); |
| 119 SkFILEWStream stream(path); | 123 SkFILEWStream stream(path); |
| 120 if (!stream.isValid() || !stream.write(data->data(), data->size())) { | 124 if (!stream.isValid() || !stream.writeStream(data, data->getLength())) { |
| 121 SkDebugf("Can't write %s.\n", path); | 125 SkDebugf("Can't write %s.\n", path); |
| 122 return false; | 126 return false; |
| 123 } | 127 } |
| 124 return true; | 128 return true; |
| 125 } | 129 } |
| 126 | 130 |
| 127 } // namespace | 131 } // namespace |
| 128 | 132 |
| 129 void WriteTask::draw() { | 133 void WriteTask::draw() { |
| 130 SkString dir(FLAGS_writePath[0]); | 134 SkString dir(FLAGS_writePath[0]); |
| 131 #if SK_BUILD_FOR_IOS | 135 #if SK_BUILD_FOR_IOS |
| 132 if (dir.equals("@")) { | 136 if (dir.equals("@")) { |
| 133 dir.set(FLAGS_resourcePath[0]); | 137 dir.set(FLAGS_resourcePath[0]); |
| 134 } | 138 } |
| 135 #endif | 139 #endif |
| 136 this->makeDirOrFail(dir); | 140 this->makeDirOrFail(dir); |
| 137 for (int i = 0; i < fSuffixes.count(); i++) { | 141 for (int i = 0; i < fSuffixes.count(); i++) { |
| 138 dir = SkOSPath::Join(dir.c_str(), fSuffixes[i].c_str()); | 142 dir = SkOSPath::Join(dir.c_str(), fSuffixes[i].c_str()); |
| 139 this->makeDirOrFail(dir); | 143 this->makeDirOrFail(dir); |
| 140 } | 144 } |
| 141 | 145 |
| 142 SkString path = SkOSPath::Join(dir.c_str(), fGmName.c_str()); | 146 SkString path = SkOSPath::Join(dir.c_str(), fGmName.c_str()); |
| 143 path.append(fExtension); | 147 path.append(fExtension); |
| 144 | 148 |
| 145 const bool ok = fData.get() ? save_data_to_file(fData, path.c_str()) | 149 const bool ok = fData.get() ? save_data_to_file(fData.get(), path.c_str()) |
| 146 : PngAndRaw::Encode(fBitmap, path.c_str()); | 150 : PngAndRaw::Encode(fBitmap, path.c_str()); |
| 147 if (!ok) { | 151 if (!ok) { |
| 148 this->fail(); | 152 this->fail(); |
| 149 } | 153 } |
| 150 } | 154 } |
| 151 | 155 |
| 152 SkString WriteTask::name() const { | 156 SkString WriteTask::name() const { |
| 153 SkString name("writing "); | 157 SkString name("writing "); |
| 154 for (int i = 0; i < fSuffixes.count(); i++) { | 158 for (int i = 0; i < fSuffixes.count(); i++) { |
| 155 name.appendf("%s/", fSuffixes[i].c_str()); | 159 name.appendf("%s/", fSuffixes[i].c_str()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 const SkString path = path_to_expected_image(fRoot, task); | 194 const SkString path = path_to_expected_image(fRoot, task); |
| 191 SkBitmap expected; | 195 SkBitmap expected; |
| 192 if (!PngAndRaw::Decode(path.c_str(), bitmap.info(), &expected)) { | 196 if (!PngAndRaw::Decode(path.c_str(), bitmap.info(), &expected)) { |
| 193 return false; | 197 return false; |
| 194 } | 198 } |
| 195 | 199 |
| 196 return BitmapsEqual(expected, bitmap); | 200 return BitmapsEqual(expected, bitmap); |
| 197 } | 201 } |
| 198 | 202 |
| 199 } // namespace DM | 203 } // namespace DM |
| OLD | NEW |