From 42943c8aa9c611c18ad0f1a30a27669f3d82239c Mon Sep 17 00:00:00 2001 From: reed Date: Mon, 12 Sep 2016 12:01:44 -0700 Subject: change SkStreams to work with sk_sp instead of SkData* BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2333713002 Review-Url: https://codereview.chromium.org/2333713002 --- include/core/SkStream.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'include/core/SkStream.h') diff --git a/include/core/SkStream.h b/include/core/SkStream.h index 4bfaeda587..48ac577070 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); @@ -312,17 +314,24 @@ public: */ void setMemoryOwned(const void* data, size_t length); + sk_sp asData() const { return fData; } + void setData(sk_sp); +#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 snapshotAsData() const; + // Return the contents as SkData, and then reset the stream. + sk_sp 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(); -- cgit v1.2.3