Index: include/core/SkStream.h |
diff --git a/include/core/SkStream.h b/include/core/SkStream.h |
index 4bfaeda58793d7b25aa58319a52c8cc92503a14e..48ac577070b289a7ef31016b68c302fd32a5f6e8 100644 |
--- a/include/core/SkStream.h |
+++ b/include/core/SkStream.h |
@@ -291,11 +291,13 @@ public: |
/** If copyData is true, the stream makes a private copy of the data. */ |
SkMemoryStream(const void* data, size_t length, bool copyData = false); |
+#ifdef SK_SUPPORT_LEGACY_STREAM_DATA |
/** Use the specified data as the memory for this stream. |
* The stream will call ref() on the data (assuming it is not NULL). |
* DEPRECATED |
*/ |
SkMemoryStream(SkData*); |
+#endif |
/** Creates the stream to read from the specified data */ |
SkMemoryStream(sk_sp<SkData>); |
@@ -312,17 +314,24 @@ public: |
*/ |
void setMemoryOwned(const void* data, size_t length); |
+ sk_sp<SkData> asData() const { return fData; } |
+ void setData(sk_sp<SkData>); |
+#ifdef SK_SUPPORT_LEGACY_STREAM_DATA |
/** Return the stream's data in a SkData. |
* The caller must call unref() when it is finished using the data. |
*/ |
- SkData* copyToData() const; |
+ SkData* copyToData() const { return asData().release(); } |
/** |
* Use the specified data as the memory for this stream. |
* The stream will call ref() on the data (assuming it is not NULL). |
* The function returns the data parameter as a convenience. |
*/ |
- SkData* setData(SkData*); |
+ SkData* setData(SkData* data) { |
+ this->setData(sk_ref_sp(data)); |
+ return data; |
+ } |
+#endif |
void skipToAlign4(); |
const void* getAtPos(); |
@@ -404,11 +413,18 @@ public: |
void copyTo(void* dst) const; |
void writeToStream(SkWStream* dst) const; |
+ sk_sp<SkData> snapshotAsData() const; |
+ // Return the contents as SkData, and then reset the stream. |
+ sk_sp<SkData> detachAsData(); |
+#ifdef SK_SUPPORT_LEGACY_STREAM_DATA |
/** |
* Return a copy of the data written so far. This call is responsible for |
* calling unref() when they are finished with the data. |
*/ |
- SkData* copyToData() const; |
+ SkData* copyToData() const { |
+ return snapshotAsData().release(); |
+ } |
+#endif |
/** Reset, returning a reader stream with the current content. */ |
SkStreamAsset* detachAsStream(); |