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

Unified 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: Another Patch Set Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/DMWriteTask.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMWriteTask.cpp
diff --git a/dm/DMWriteTask.cpp b/dm/DMWriteTask.cpp
index b8ce3189a843ee6ce0be45d04d4b2ee37b917de8..5a07e4669d472dd05eb3d113f156fc9946a41982 100644
--- a/dm/DMWriteTask.cpp
+++ b/dm/DMWriteTask.cpp
@@ -41,11 +41,14 @@ WriteTask::WriteTask(const Task& parent, SkBitmap bitmap)
, fData(NULL)
, fExtension(".png") {}
-WriteTask::WriteTask(const Task& parent, SkData *data, const char* ext)
+WriteTask::WriteTask(const Task& parent, SkStreamAsset *data, const char* ext)
: CpuTask(parent)
, fGmName(find_gm_name(parent, &fSuffixes))
- , fData(SkRef(data))
- , fExtension(ext) {}
+ , fData(data)
+ , fExtension(ext) {
+ SkASSERT(fData.get());
+ SkASSERT(fData->unique());
+}
void WriteTask::makeDirOrFail(SkString dir) {
if (!sk_mkdir(dir.c_str())) {
@@ -115,9 +118,10 @@ struct PngAndRaw {
};
// Does not take ownership of data.
-bool save_data_to_file(const SkData* data, const char* path) {
+bool save_data_to_file(SkStreamAsset* data, const char* path) {
+ data->rewind();
SkFILEWStream stream(path);
- if (!stream.isValid() || !stream.write(data->data(), data->size())) {
+ if (!stream.isValid() || !stream.writeStream(data, data->getLength())) {
SkDebugf("Can't write %s.\n", path);
return false;
}
@@ -142,7 +146,7 @@ void WriteTask::draw() {
SkString path = SkOSPath::Join(dir.c_str(), fGmName.c_str());
path.append(fExtension);
- const bool ok = fData.get() ? save_data_to_file(fData, path.c_str())
+ const bool ok = fData.get() ? save_data_to_file(fData.get(), path.c_str())
: PngAndRaw::Encode(fBitmap, path.c_str());
if (!ok) {
this->fail();
« no previous file with comments | « dm/DMWriteTask.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698