diff options
author | Hal Canary <halcanary@google.com> | 2017-03-14 14:35:02 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-15 19:25:45 +0000 |
commit | 0b83319b7f301145b7fc89d7096ddcea91d4a56b (patch) | |
tree | 171b46c0446b312c325be0f935c67e3ce8931396 | |
parent | 81538ee611c7e12273496d0b33174254e9551749 (diff) |
SkDynamicMemoryWStream::detachAsStream() returns unique_ptr
https://crrev.com/2747183002 must land first.
Change-Id: I65d1285a24d63c2c2f18662d511dea1c399511e1
Reviewed-on: https://skia-review.googlesource.com/9682
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
-rw-r--r-- | dm/DM.cpp | 2 | ||||
-rw-r--r-- | include/core/SkStream.h | 2 | ||||
-rw-r--r-- | src/core/SkStream.cpp | 9 | ||||
-rw-r--r-- | src/pdf/SkPDFTypes.cpp | 2 | ||||
-rw-r--r-- | tests/PDFDeflateWStreamTest.cpp | 2 | ||||
-rw-r--r-- | tools/skiaserve/urlhandlers/PostHandler.cpp | 3 |
6 files changed, 11 insertions, 9 deletions
@@ -1089,7 +1089,7 @@ struct Task { } // We're likely switching threads here, so we must capture by value, [=] or [foo,bar]. - SkStreamAsset* data = stream.detachAsStream(); + SkStreamAsset* data = stream.detachAsStream().release(); gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{ std::unique_ptr<SkStreamAsset> ownedData(data); diff --git a/include/core/SkStream.h b/include/core/SkStream.h index 8df59afaf3..0a53d47cf2 100644 --- a/include/core/SkStream.h +++ b/include/core/SkStream.h @@ -383,7 +383,7 @@ public: sk_sp<SkData> detachAsData(); /** Reset, returning a reader stream with the current content. */ - SkStreamAsset* detachAsStream(); + std::unique_ptr<SkStreamAsset> detachAsStream(); /** Reset the stream to its original, empty, state. */ void reset(); diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index 133df83078..f0e16a6ff6 100644 --- a/src/core/SkStream.cpp +++ b/src/core/SkStream.cpp @@ -759,12 +759,13 @@ private: size_t fCurrentOffset; }; -SkStreamAsset* SkDynamicMemoryWStream::detachAsStream() { - auto stream = skstd::make_unique<SkBlockMemoryStream>(sk_make_sp<SkBlockMemoryRefCnt>(fHead), - this->bytesWritten()); +std::unique_ptr<SkStreamAsset> SkDynamicMemoryWStream::detachAsStream() { + std::unique_ptr<SkStreamAsset> stream + = skstd::make_unique<SkBlockMemoryStream>(sk_make_sp<SkBlockMemoryRefCnt>(fHead), + this->bytesWritten()); fHead = nullptr; // signal reset() to not free anything this->reset(); - return stream.release(); + return stream; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp index 7a1e0a48f5..42b4ed4953 100644 --- a/src/pdf/SkPDFTypes.cpp +++ b/src/pdf/SkPDFTypes.cpp @@ -568,7 +568,7 @@ void SkPDFStream::setData(std::unique_ptr<SkStreamAsset> stream) { fDict.insertInt("Length", originalLength); return; } - fCompressedData.reset(compressedData.detachAsStream()); + fCompressedData = compressedData.detachAsStream(); fDict.insertName("Filter", "FlateDecode"); fDict.insertInt("Length", compressedLength); #endif diff --git a/tests/PDFDeflateWStreamTest.cpp b/tests/PDFDeflateWStreamTest.cpp index dcb7547495..3d734c81a1 100644 --- a/tests/PDFDeflateWStreamTest.cpp +++ b/tests/PDFDeflateWStreamTest.cpp @@ -28,7 +28,7 @@ void skia_free_func(void*, void* address) { sk_free(address); } * Use the un-deflate compression algorithm to decompress the data in src, * returning the result. Returns nullptr if an error occurs. */ -SkStreamAsset* stream_inflate(skiatest::Reporter* reporter, SkStream* src) { +std::unique_ptr<SkStreamAsset> stream_inflate(skiatest::Reporter* reporter, SkStream* src) { SkDynamicMemoryWStream decompressedDynamicMemoryWStream; SkWStream* dst = &decompressedDynamicMemoryWStream; diff --git a/tools/skiaserve/urlhandlers/PostHandler.cpp b/tools/skiaserve/urlhandlers/PostHandler.cpp index 34beefae11..634a2e5da2 100644 --- a/tools/skiaserve/urlhandlers/PostHandler.cpp +++ b/tools/skiaserve/urlhandlers/PostHandler.cpp @@ -62,7 +62,8 @@ int PostHandler::handle(Request* request, MHD_Connection* connection, MHD_destroy_post_processor(uc->fPostProcessor); uc->fPostProcessor = nullptr; - if (!request->initPictureFromStream(request->fUploadContext->fStream.detachAsStream())) { + std::unique_ptr<SkStreamAsset> stream(request->fUploadContext->fStream.detachAsStream()); + if (!request->initPictureFromStream(stream.get())) { fprintf(stderr, "Could not create picture from stream.\n"); return MHD_NO; } |