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

Side by Side Diff: dm/DMWriteTask.cpp

Issue 502193002: SkData to SkStreamAsset to avoid unneeded copying (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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
« dm/DMPDFTask.cpp ('K') | « dm/DMWriteTask.h ('k') | 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 "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
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
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
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
OLDNEW
« dm/DMPDFTask.cpp ('K') | « dm/DMWriteTask.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698