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

Unified Diff: src/core/SkStream.cpp

Issue 2333713002: change SkStreams to work with sk_sp<SkData> instead of SkData* (Closed)
Patch Set: fix xpsdevice Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/codec/SkCodecImageGenerator.cpp ('k') | src/images/SkImageEncoder.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkStream.cpp
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp
index e2b3e6454c96c13f6e78da3d720b3dafc7daa8b8..48eb92cae5c5631c1e4546f95e471040fa2297e9 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -306,6 +306,7 @@ SkMemoryStream::SkMemoryStream(sk_sp<SkData> data) : fData(std::move(data)) {
fOffset = 0;
}
+#ifdef SK_SUPPORT_LEGACY_STREAM_DATA
SkMemoryStream::SkMemoryStream(SkData* data) {
if (nullptr == data) {
fData = SkData::MakeEmpty();
@@ -314,6 +315,7 @@ SkMemoryStream::SkMemoryStream(SkData* data) {
}
fOffset = 0;
}
+#endif
void SkMemoryStream::setMemoryOwned(const void* src, size_t size) {
fData = SkData::MakeFromMalloc(src, size);
@@ -325,18 +327,13 @@ void SkMemoryStream::setMemory(const void* src, size_t size, bool copyData) {
fOffset = 0;
}
-SkData* SkMemoryStream::copyToData() const {
- return SkSafeRef(fData.get());
-}
-
-SkData* SkMemoryStream::setData(SkData* data) {
+void SkMemoryStream::setData(sk_sp<SkData> data) {
if (nullptr == data) {
fData = SkData::MakeEmpty();
} else {
- fData = sk_ref_sp(data);
+ fData = data;
}
fOffset = 0;
- return data;
}
void SkMemoryStream::skipToAlign4() {
@@ -642,14 +639,20 @@ void SkDynamicMemoryWStream::padToAlign4()
write(&zero, padBytes);
}
-SkData* SkDynamicMemoryWStream::copyToData() const {
+sk_sp<SkData> SkDynamicMemoryWStream::snapshotAsData() const {
if (nullptr == fCopy) {
auto data = SkData::MakeUninitialized(fBytesWritten);
// be sure to call copyTo() before we assign to fCopy
this->copyTo(data->writable_data());
fCopy = std::move(data);
}
- return SkRef(fCopy.get());
+ return fCopy;
+}
+
+sk_sp<SkData> SkDynamicMemoryWStream::detachAsData() {
+ sk_sp<SkData> data = this->snapshotAsData();
+ this->reset();
+ return data;
}
void SkDynamicMemoryWStream::invalidateCopy() {
@@ -882,7 +885,7 @@ sk_sp<SkData> SkCopyStreamToData(SkStream* stream) {
size_t bytesRead = stream->read(buffer, bufferSize);
tempStream.write(buffer, bytesRead);
} while (!stream->isAtEnd());
- return sk_sp<SkData>(tempStream.copyToData());
+ return tempStream.detachAsData();
}
bool SkStreamCopy(SkWStream* out, SkStream* input) {
« no previous file with comments | « src/codec/SkCodecImageGenerator.cpp ('k') | src/images/SkImageEncoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698