diff options
author | Mike Reed <reed@google.com> | 2017-09-15 21:03:54 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-15 21:04:07 +0000 |
commit | 7031b247c9fe0cb8fa32129f9bc24fea2043cee2 (patch) | |
tree | 6ded4ad2071a03530ead08e4f5e1a41f4c42c563 | |
parent | f95352322496796ce4c99df9582dbc630fe8a327 (diff) |
Revert "use unique_ptr for stream api"
This reverts commit 49f1f34438d3431f6d7e32847accd2ba96948a73.
Reason for revert: broke win-chrome
../../third_party/skia/src/ports/SkFontMgr_win_dw.cpp(89): error C2228: left of '.release' must have class/struct/union
../../third_party/skia/src/ports/SkFontMgr_win_dw.cpp(89): note: type is 'SkStreamAsset *'
../../third_party/skia/src/ports/SkFontMgr_win_dw.cpp(89): note: did you intend to use '->' instead?
Original change's description:
> use unique_ptr for stream api
>
> Bug: skia:6888
> Change-Id: I3459b4913982a7cae1c0061697c82cc65ad9a2d8
> Reviewed-on: https://skia-review.googlesource.com/26740
> Reviewed-by: Mike Klein <mtklein@chromium.org>
> Commit-Queue: Mike Reed <reed@google.com>
TBR=mtklein@chromium.org,mtklein@google.com,bungeman@google.com,reed@google.com
Change-Id: Ic1e4af557317abd06b7f6b7f5056645df7e469f0
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:6888
Reviewed-on: https://skia-review.googlesource.com/47440
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
-rw-r--r-- | gm/fontscalerdistortable.cpp | 4 | ||||
-rw-r--r-- | include/core/SkStream.h | 121 | ||||
-rw-r--r-- | include/utils/SkFrontBufferedStream.h | 14 | ||||
-rw-r--r-- | src/core/SkRWBuffer.cpp | 14 | ||||
-rw-r--r-- | src/core/SkStream.cpp | 31 | ||||
-rw-r--r-- | src/ports/SkFontMgr_FontConfigInterface.cpp | 4 | ||||
-rw-r--r-- | src/ports/SkFontMgr_android.cpp | 4 | ||||
-rw-r--r-- | src/ports/SkFontMgr_custom.cpp | 4 | ||||
-rw-r--r-- | src/ports/SkFontMgr_fontconfig.cpp | 4 | ||||
-rw-r--r-- | src/ports/SkFontMgr_win_dw.cpp | 2 | ||||
-rw-r--r-- | src/utils/SkFrontBufferedStream.cpp | 26 | ||||
-rw-r--r-- | src/utils/win/SkDWriteFontFileStream.cpp | 14 | ||||
-rw-r--r-- | src/utils/win/SkDWriteFontFileStream.h | 20 | ||||
-rw-r--r-- | tests/CodecTest.cpp | 6 | ||||
-rw-r--r-- | tests/FrontBufferedStreamTest.cpp | 26 | ||||
-rw-r--r-- | tests/StreamTest.cpp | 8 |
16 files changed, 53 insertions, 249 deletions
diff --git a/gm/fontscalerdistortable.cpp b/gm/fontscalerdistortable.cpp index 30352e4b7d..1823b50efa 100644 --- a/gm/fontscalerdistortable.cpp +++ b/gm/fontscalerdistortable.cpp @@ -53,11 +53,7 @@ protected: SkFontArguments::VariationPosition position = { coordinates, SK_ARRAY_COUNT(coordinates) }; paint.setTypeface(sk_sp<SkTypeface>(fontMgr->createFromStream( -#ifdef SK_SUPPORT_LEGACY_STREAM_API distortable->duplicate(), -#else - distortable->duplicate().release(), -#endif SkFontArguments().setVariationDesignPosition(position)))); SkAutoCanvasRestore acr(canvas, true); diff --git a/include/core/SkStream.h b/include/core/SkStream.h index 2d7a8c529d..5ef8519245 100644 --- a/include/core/SkStream.h +++ b/include/core/SkStream.h @@ -101,29 +101,10 @@ public: */ virtual bool rewind() { return false; } -#ifdef SK_SUPPORT_LEGACY_STREAM_API /** Duplicates this stream. If this cannot be done, returns NULL. * The returned stream will be positioned at the beginning of its data. */ virtual SkStreamRewindable* duplicate() const { return nullptr; } - /** Duplicates this stream. If this cannot be done, returns NULL. - * The returned stream will be positioned the same as this stream. - */ - virtual SkStreamSeekable* fork() const { return nullptr; } -#else - /** Duplicates this stream. If this cannot be done, returns NULL. - * The returned stream will be positioned at the beginning of its data. - */ - std::unique_ptr<SkStream> duplicate() const { - return std::unique_ptr<SkStream>(this->onDuplicate()); - } - /** Duplicates this stream. If this cannot be done, returns NULL. - * The returned stream will be positioned the same as this stream. - */ - std::unique_ptr<SkStream> fork() const { - return std::unique_ptr<SkStream>(this->onFork()); - } -#endif //SkStreamSeekable /** Returns true if this stream can report it's current position. */ @@ -143,6 +124,11 @@ public: */ virtual bool move(long /*offset*/) { return false; } + /** Duplicates this stream. If this cannot be done, returns NULL. + * The returned stream will be positioned the same as this stream. + */ + virtual SkStreamSeekable* fork() const { return nullptr; } + //SkStreamAsset /** Returns true if this stream can report it's total length. */ virtual bool hasLength() const { return false; } @@ -153,97 +139,44 @@ public: /** Returns the starting address for the data. If this cannot be done, returns NULL. */ //TODO: replace with virtual const SkData* getData() virtual const void* getMemoryBase() { return nullptr; } - -private: -#ifndef SK_SUPPORT_LEGACY_STREAM_API - virtual SkStream* onDuplicate() const { return nullptr; } - virtual SkStream* onFork() const { return nullptr; } -#endif }; /** SkStreamRewindable is a SkStream for which rewind and duplicate are required. */ class SK_API SkStreamRewindable : public SkStream { public: bool rewind() override = 0; -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkStreamRewindable* duplicate() const override = 0; -#else - std::unique_ptr<SkStreamRewindable> duplicate() const { - return std::unique_ptr<SkStreamRewindable>(this->onDuplicate()); - } -private: - SkStreamRewindable* onDuplicate() const override = 0; -#endif }; /** SkStreamSeekable is a SkStreamRewindable for which position, seek, move, and fork are required. */ class SK_API SkStreamSeekable : public SkStreamRewindable { public: -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkStreamSeekable* duplicate() const override = 0; -#else - std::unique_ptr<SkStreamSeekable> duplicate() const { - return std::unique_ptr<SkStreamSeekable>(this->onDuplicate()); - } -#endif bool hasPosition() const override { return true; } size_t getPosition() const override = 0; bool seek(size_t position) override = 0; bool move(long offset) override = 0; -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkStreamSeekable* fork() const override = 0; -#else - std::unique_ptr<SkStreamSeekable> fork() const { - return std::unique_ptr<SkStreamSeekable>(this->onFork()); - } -private: - SkStreamSeekable* onDuplicate() const override = 0; - SkStreamSeekable* onFork() const override = 0; -#endif }; /** SkStreamAsset is a SkStreamSeekable for which getLength is required. */ class SK_API SkStreamAsset : public SkStreamSeekable { public: - bool hasLength() const override { return true; } - size_t getLength() const override = 0; - -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkStreamAsset* duplicate() const override = 0; SkStreamAsset* fork() const override = 0; -#else - std::unique_ptr<SkStreamAsset> duplicate() const { - return std::unique_ptr<SkStreamAsset>(this->onDuplicate()); - } - std::unique_ptr<SkStreamAsset> fork() const { - return std::unique_ptr<SkStreamAsset>(this->onFork()); - } -private: - SkStreamAsset* onDuplicate() const override = 0; - SkStreamAsset* onFork() const override = 0; -#endif + + bool hasLength() const override { return true; } + size_t getLength() const override = 0; }; /** SkStreamMemory is a SkStreamAsset for which getMemoryBase is required. */ class SK_API SkStreamMemory : public SkStreamAsset { public: - const void* getMemoryBase() override = 0; - -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkStreamMemory* duplicate() const override = 0; SkStreamMemory* fork() const override = 0; -#else - std::unique_ptr<SkStreamMemory> duplicate() const { - return std::unique_ptr<SkStreamMemory>(this->onDuplicate()); - } - std::unique_ptr<SkStreamMemory> fork() const { - return std::unique_ptr<SkStreamMemory>(this->onFork()); - } -private: - SkStreamMemory* onDuplicate() const override = 0; - SkStreamMemory* onFork() const override = 0; -#endif + + const void* getMemoryBase() override = 0; }; class SK_API SkWStream : SkNoncopyable { @@ -345,24 +278,12 @@ public: bool isAtEnd() const override; bool rewind() override; -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkStreamAsset* duplicate() const override; -#else - std::unique_ptr<SkStreamAsset> duplicate() const { - return std::unique_ptr<SkStreamAsset>(this->onDuplicate()); - } -#endif size_t getPosition() const override; bool seek(size_t position) override; bool move(long offset) override; -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkStreamAsset* fork() const override; -#else - std::unique_ptr<SkStreamAsset> fork() const { - return std::unique_ptr<SkStreamAsset>(this->onFork()); - } -#endif size_t getLength() const override; @@ -370,11 +291,6 @@ private: explicit SkFILEStream(std::shared_ptr<FILE>, size_t size, size_t offset); explicit SkFILEStream(std::shared_ptr<FILE>, size_t size, size_t offset, size_t originalOffset); -#ifndef SK_SUPPORT_LEGACY_STREAM_API - SkStreamAsset* onDuplicate() const override; - SkStreamAsset* onFork() const override; -#endif - std::shared_ptr<FILE> fFILE; // My own council will I keep on sizes and offsets. size_t fSize; @@ -430,35 +346,18 @@ public: size_t peek(void* buffer, size_t size) const override; bool rewind() override; -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkMemoryStream* duplicate() const override; -#else - std::unique_ptr<SkMemoryStream> duplicate() const { - return std::unique_ptr<SkMemoryStream>(this->onDuplicate()); - } -#endif size_t getPosition() const override; bool seek(size_t position) override; bool move(long offset) override; -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkMemoryStream* fork() const override; -#else - std::unique_ptr<SkMemoryStream> fork() const { - return std::unique_ptr<SkMemoryStream>(this->onFork()); - } -#endif size_t getLength() const override; const void* getMemoryBase() override; private: -#ifndef SK_SUPPORT_LEGACY_STREAM_API - SkMemoryStream* onDuplicate() const override; - SkMemoryStream* onFork() const override; -#endif - sk_sp<SkData> fData; size_t fOffset; diff --git a/include/utils/SkFrontBufferedStream.h b/include/utils/SkFrontBufferedStream.h index a47acf8a06..3532fc5259 100644 --- a/include/utils/SkFrontBufferedStream.h +++ b/include/utils/SkFrontBufferedStream.h @@ -8,7 +8,10 @@ #ifndef SkFrontBufferedStream_DEFINED #define SkFrontBufferedStream_DEFINED -#include "SkStream.h" +#include "SkTypes.h" + +class SkStream; +class SkStreamRewindable; /** * Specialized stream that buffers the first X bytes of a stream, @@ -33,13 +36,6 @@ public: * NULL on failure. The caller is required to delete when finished with * this object. */ - static std::unique_ptr<SkStreamRewindable> Make(std::unique_ptr<SkStream> stream, - size_t minBufferSize); - -#ifdef SK_SUPPORT_LEGACY_STREAM_API - static SkStreamRewindable* Create(SkStream* stream, size_t minBufferSize) { - return Make(std::unique_ptr<SkStream>(stream), minBufferSize).release(); - } -#endif + static SkStreamRewindable* Create(SkStream* stream, size_t minBufferSize); }; #endif // SkFrontBufferedStream_DEFINED diff --git a/src/core/SkRWBuffer.cpp b/src/core/SkRWBuffer.cpp index 8ec2baafac..3ac9677793 100644 --- a/src/core/SkRWBuffer.cpp +++ b/src/core/SkRWBuffer.cpp @@ -315,9 +315,7 @@ public: return fBuffer->size() == fGlobalOffset; } -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkStreamAsset* duplicate() const override { return new SkROBufferStreamAsset(fBuffer); } -#endif size_t getPosition() const override { return fGlobalOffset; @@ -343,24 +341,14 @@ public: return true; } -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkStreamAsset* fork() const override { SkStreamAsset* clone = this->duplicate(); clone->seek(this->getPosition()); return clone; } -#endif -private: -#ifndef SK_SUPPORT_LEGACY_STREAM_API - SkStreamAsset* onDuplicate() const override { return new SkROBufferStreamAsset(fBuffer); } - SkStreamAsset* onFork() const override { - auto clone = this->duplicate(); - clone->seek(this->getPosition()); - return clone.release(); - } -#endif +private: sk_sp<SkROBuffer> fBuffer; SkROBuffer::Iter fIter; size_t fLocalOffset; diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index bc638c249a..139a72f7ca 100644 --- a/src/core/SkStream.cpp +++ b/src/core/SkStream.cpp @@ -15,14 +15,6 @@ #include "SkOSFile.h" #include "SkTypes.h" -#ifdef SK_SUPPORT_LEGACY_STREAM_API -#define DUP_NAME duplicate -#define FORK_NAME fork -#else -#define DUP_NAME onDuplicate -#define FORK_NAME onFork -#endif - /////////////////////////////////////////////////////////////////////////////// @@ -224,7 +216,7 @@ bool SkFILEStream::rewind() { return true; } -SkStreamAsset* SkFILEStream::DUP_NAME() const { +SkStreamAsset* SkFILEStream::duplicate() const { // TODO: fOriginalOffset instead of 0. return new SkFILEStream(fFILE, fSize, 0, fOriginalOffset); } @@ -242,7 +234,7 @@ bool SkFILEStream::move(long offset) { return this->seek(fOffset + offset); } -SkStreamAsset* SkFILEStream::FORK_NAME() const { +SkStreamAsset* SkFILEStream::fork() const { return new SkFILEStream(fFILE, fSize, fOffset, fOriginalOffset); } @@ -350,14 +342,7 @@ bool SkMemoryStream::rewind() { return true; } -#ifdef SK_SUPPORT_LEGACY_STREAM_API -SkMemoryStream* SkMemoryStream::duplicate() const -#else -SkMemoryStream* SkMemoryStream::onDuplicate() const -#endif -{ - return new SkMemoryStream(fData); -} +SkMemoryStream* SkMemoryStream::duplicate() const { return new SkMemoryStream(fData); } size_t SkMemoryStream::getPosition() const { return fOffset; @@ -374,7 +359,7 @@ bool SkMemoryStream::move(long offset) { return this->seek(fOffset + offset); } -SkMemoryStream* SkMemoryStream::FORK_NAME() const { +SkMemoryStream* SkMemoryStream::fork() const { std::unique_ptr<SkMemoryStream> that(this->duplicate()); that->seek(fOffset); return that.release(); @@ -746,7 +731,7 @@ public: return true; } - SkBlockMemoryStream* DUP_NAME() const override { + SkBlockMemoryStream* duplicate() const override { return new SkBlockMemoryStream(fBlockMemory, fSize); } @@ -775,12 +760,12 @@ public: return seek(fOffset + offset); } - SkBlockMemoryStream* FORK_NAME() const override { - SkBlockMemoryStream* that = this->DUP_NAME(); + SkBlockMemoryStream* fork() const override { + std::unique_ptr<SkBlockMemoryStream> that(this->duplicate()); that->fCurrent = this->fCurrent; that->fOffset = this->fOffset; that->fCurrentOffset = this->fCurrentOffset; - return that; + return that.release(); } size_t getLength() const override { diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp index aec76af685..99092b6b98 100644 --- a/src/ports/SkFontMgr_FontConfigInterface.cpp +++ b/src/ports/SkFontMgr_FontConfigInterface.cpp @@ -26,11 +26,7 @@ SkStreamAsset* SkTypeface_FCI::onOpenStream(int* ttcIndex) const { if (!stream) { return nullptr; } -#ifdef SK_SUPPORT_LEGACY_STREAM_API return stream->duplicate(); -#else - return stream->duplicate().release(); -#endif } return fFCI->openStream(this->getIdentity()); diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index 0ec2edba6a..2dd3221466 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -129,11 +129,7 @@ public: SkStreamAsset* onOpenStream(int* ttcIndex) const override { *ttcIndex = fData->getIndex(); -#ifdef SK_SUPPORT_LEGACY_STREAM_API return fData->getStream()->duplicate(); -#else - return fData->getStream()->duplicate().release(); -#endif } std::unique_ptr<SkFontData> onMakeFontData() const override { diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp index b38f48c322..91a590827c 100644 --- a/src/ports/SkFontMgr_custom.cpp +++ b/src/ports/SkFontMgr_custom.cpp @@ -60,11 +60,7 @@ SkTypeface_Stream::SkTypeface_Stream(std::unique_ptr<SkFontData> fontData, SkStreamAsset* SkTypeface_Stream::onOpenStream(int* ttcIndex) const { *ttcIndex = fData->getIndex(); -#ifdef SK_SUPPORT_LEGACY_STREAM_API return fData->getStream()->duplicate(); -#else - return fData->getStream()->duplicate().release(); -#endif } std::unique_ptr<SkFontData> SkTypeface_Stream::onMakeFontData() const { diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp index 8b3a058e9e..95c963d69f 100644 --- a/src/ports/SkFontMgr_fontconfig.cpp +++ b/src/ports/SkFontMgr_fontconfig.cpp @@ -435,11 +435,7 @@ public: SkStreamAsset* onOpenStream(int* ttcIndex) const override { *ttcIndex = fData->getIndex(); -#ifdef SK_SUPPORT_LEGACY_STREAM_API return fData->getStream()->duplicate(); -#else - return fData->getStream()->duplicate().release(); -#endif } std::unique_ptr<SkFontData> onMakeFontData() const override { diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp index eca20d94b7..1fd300ca1d 100644 --- a/src/ports/SkFontMgr_win_dw.cpp +++ b/src/ports/SkFontMgr_win_dw.cpp @@ -86,7 +86,7 @@ HRESULT StreamFontFileLoader::CreateStreamFromKey( IDWriteFontFileStream** fontFileStream) { SkTScopedComPtr<SkDWriteFontFileStreamWrapper> stream; - HR(SkDWriteFontFileStreamWrapper::Create(fStream->duplicate().release(), &stream)); + HR(SkDWriteFontFileStreamWrapper::Create(fStream->duplicate(), &stream)); *fontFileStream = stream.release(); return S_OK; } diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp index 77c484af64..42b86f09e3 100644 --- a/src/utils/SkFrontBufferedStream.cpp +++ b/src/utils/SkFrontBufferedStream.cpp @@ -11,8 +11,8 @@ class FrontBufferedStream : public SkStreamRewindable { public: - // Called by Make. - FrontBufferedStream(std::unique_ptr<SkStream>, size_t bufferSize); + // Called by Create. + FrontBufferedStream(SkStream*, size_t bufferSize); size_t read(void* buffer, size_t size) override; @@ -26,15 +26,9 @@ public: size_t getLength() const override { return fLength; } -#ifdef SK_SUPPORT_LEGACY_STREAM_API SkStreamRewindable* duplicate() const override { return nullptr; } -#endif private: -#ifndef SK_SUPPORT_LEGACY_STREAM_API - SkStreamRewindable* onDuplicate() const override { return nullptr; } -#endif - std::unique_ptr<SkStream> fStream; const bool fHasLength; const size_t fLength; @@ -67,19 +61,17 @@ private: typedef SkStream INHERITED; }; -std::unique_ptr<SkStreamRewindable> SkFrontBufferedStream::Make(std::unique_ptr<SkStream> stream, - size_t bufferSize) { - if (!stream) { +SkStreamRewindable* SkFrontBufferedStream::Create(SkStream* stream, size_t bufferSize) { + if (nullptr == stream) { return nullptr; } - return std::unique_ptr<SkStreamRewindable>(new FrontBufferedStream(std::move(stream), - bufferSize)); + return new FrontBufferedStream(stream, bufferSize); } -FrontBufferedStream::FrontBufferedStream(std::unique_ptr<SkStream> stream, size_t bufferSize) - : fStream(std::move(stream)) - , fHasLength(fStream->hasPosition() && fStream->hasLength()) - , fLength(fStream->getLength() - fStream->getPosition()) +FrontBufferedStream::FrontBufferedStream(SkStream* stream, size_t bufferSize) + : fStream(stream) + , fHasLength(stream->hasPosition() && stream->hasLength()) + , fLength(stream->getLength() - stream->getPosition()) , fOffset(0) , fBufferedSoFar(0) , fBufferSize(bufferSize) diff --git a/src/utils/win/SkDWriteFontFileStream.cpp b/src/utils/win/SkDWriteFontFileStream.cpp index a43e163481..2bb7d0fb4e 100644 --- a/src/utils/win/SkDWriteFontFileStream.cpp +++ b/src/utils/win/SkDWriteFontFileStream.cpp @@ -86,12 +86,7 @@ bool SkDWriteFontFileStream::rewind() { return true; } -#ifdef SK_SUPPORT_LEGACY_STREAM_API -SkDWriteFontFileStream* SkDWriteFontFileStream::duplicate() const -#else -SkDWriteFontFileStream* SkDWriteFontFileStream::onDuplicate() const -#endif -{ +SkDWriteFontFileStream* SkDWriteFontFileStream::duplicate() const { return new SkDWriteFontFileStream(fFontFileStream.get()); } @@ -109,12 +104,7 @@ bool SkDWriteFontFileStream::move(long offset) { return seek(fPos + offset); } -#ifdef SK_SUPPORT_LEGACY_STREAM_API -SkDWriteFontFileStream* SkDWriteFontFileStream::fork() const -#else -SkDWriteFontFileStream* SkDWriteFontFileStream::onFork() const -#endif -{ +SkDWriteFontFileStream* SkDWriteFontFileStream::fork() const { std::unique_ptr<SkDWriteFontFileStream> that(this->duplicate()); that->seek(fPos); return that.release(); diff --git a/src/utils/win/SkDWriteFontFileStream.h b/src/utils/win/SkDWriteFontFileStream.h index 9b65752382..25322c5657 100644 --- a/src/utils/win/SkDWriteFontFileStream.h +++ b/src/utils/win/SkDWriteFontFileStream.h @@ -28,31 +28,15 @@ public: size_t read(void* buffer, size_t size) override; bool isAtEnd() const override; bool rewind() override; + SkDWriteFontFileStream* duplicate() const override; size_t getPosition() const override; bool seek(size_t position) override; bool move(long offset) override; + SkDWriteFontFileStream* fork() const override; size_t getLength() const override; const void* getMemoryBase() override; -#ifdef SK_SUPPORT_LEGACY_STREAM_API - SkDWriteFontFileStream* duplicate() const override; - SkDWriteFontFileStream* fork() const override; -#else - std::unique_ptr<SkDWriteFontFileStream> duplicate() const { - return std::unique_ptr<SkDWriteFontFileStream>(this->onDuplicate()); - } - std::unique_ptr<SkDWriteFontFileStream> fork() const { - return std::unique_ptr<SkDWriteFontFileStream>(this->onFork()); - } -#endif - - private: -#ifndef SK_SUPPORT_LEGACY_STREAM_API - SkDWriteFontFileStream* onDuplicate() const override; - SkDWriteFontFileStream* onFork() const override; -#endif - SkTScopedComPtr<IDWriteFontFileStream> fFontFileStream; size_t fPos; const void* fLockedMemory; diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp index f2551d2d95..baa231497f 100644 --- a/tests/CodecTest.cpp +++ b/tests/CodecTest.cpp @@ -442,10 +442,10 @@ static void check(skiatest::Reporter* r, #ifndef SK_PNG_DISABLE_TESTS // Test using SkFrontBufferedStream, as Android does - auto bufferedStream = SkFrontBufferedStream::Make( - SkMemoryStream::Make(std::move(fullData)), SkCodec::MinBufferedBytesNeeded()); + SkStream* bufferedStream = SkFrontBufferedStream::Create( + new SkMemoryStream(std::move(fullData)), SkCodec::MinBufferedBytesNeeded()); REPORTER_ASSERT(r, bufferedStream); - codec = SkCodec::MakeFromStream(std::move(bufferedStream)); + codec = SkCodec::MakeFromStream(std::unique_ptr<SkStream>(bufferedStream)); REPORTER_ASSERT(r, codec); if (codec) { test_info(r, codec.get(), info, SkCodec::kSuccess, &codecDigest); diff --git a/tests/FrontBufferedStreamTest.cpp b/tests/FrontBufferedStreamTest.cpp index 5452730ea4..aa2dc89a11 100644 --- a/tests/FrontBufferedStreamTest.cpp +++ b/tests/FrontBufferedStreamTest.cpp @@ -54,10 +54,9 @@ static void test_incremental_buffering(skiatest::Reporter* reporter, size_t buff // NOTE: For this and other tests in this file, we cheat and continue to refer to the // wrapped stream, but that's okay because we know the wrapping stream has not been // deleted yet (and we only call const methods in it). - SkMemoryStream* memStream = SkMemoryStream::MakeDirect(gAbcs, strlen(gAbcs)).release(); + SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false); - auto bufferedStream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(memStream), - bufferSize); + std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); test_hasLength(reporter, *bufferedStream, *memStream); // First, test reading less than the max buffer size. @@ -83,9 +82,8 @@ static void test_incremental_buffering(skiatest::Reporter* reporter, size_t buff } static void test_perfectly_sized_buffer(skiatest::Reporter* reporter, size_t bufferSize) { - SkMemoryStream* memStream = SkMemoryStream::MakeDirect(gAbcs, strlen(gAbcs)).release(); - auto bufferedStream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(memStream), - bufferSize); + SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false); + std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); test_hasLength(reporter, *bufferedStream, *memStream); // Read exactly the amount that fits in the buffer. @@ -103,9 +101,8 @@ static void test_perfectly_sized_buffer(skiatest::Reporter* reporter, size_t buf } static void test_skipping(skiatest::Reporter* reporter, size_t bufferSize) { - SkMemoryStream* memStream = SkMemoryStream::MakeDirect(gAbcs, strlen(gAbcs)).release(); - auto bufferedStream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(memStream), - bufferSize); + SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false); + std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); test_hasLength(reporter, *bufferedStream, *memStream); // Skip half the buffer. @@ -159,8 +156,7 @@ static void test_read_beyond_buffer(skiatest::Reporter* reporter, size_t bufferS new AndroidLikeMemoryStream((void*)gAbcs, bufferSize, false); // Create a buffer that matches the length of the stream. - auto bufferedStream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(memStream), - bufferSize); + std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); test_hasLength(reporter, *bufferedStream.get(), *memStream); // Attempt to read one more than the bufferSize @@ -207,8 +203,7 @@ static void test_length_combos(skiatest::Reporter* reporter, size_t bufferSize) for (int hasPos = 0; hasPos <= 1; hasPos++) { LengthOptionalStream* stream = new LengthOptionalStream(SkToBool(hasLen), SkToBool(hasPos)); - auto buffered = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(stream), - bufferSize); + std::unique_ptr<SkStream> buffered(SkFrontBufferedStream::Create(stream, bufferSize)); test_hasLength(reporter, *buffered.get(), *stream); } } @@ -222,8 +217,7 @@ static void test_initial_offset(skiatest::Reporter* reporter, size_t bufferSize) // the stream it wraps. const size_t arbitraryOffset = 17; memStream->skip(arbitraryOffset); - auto bufferedStream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(memStream), - bufferSize); + std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); // Since SkMemoryStream has a length, bufferedStream must also. REPORTER_ASSERT(reporter, bufferedStream->hasLength()); @@ -287,7 +281,7 @@ private: DEF_TEST(ShortFrontBufferedStream, reporter) { FailingStream* failingStream = new FailingStream; - auto stream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(failingStream), 64); + std::unique_ptr<SkStreamRewindable> stream(SkFrontBufferedStream::Create(failingStream, 64)); // This will fail to create a codec. However, what we really want to test is that we // won't read past the end of the stream. diff --git a/tests/StreamTest.cpp b/tests/StreamTest.cpp index 2e8078e337..8b5b2ae05a 100644 --- a/tests/StreamTest.cpp +++ b/tests/StreamTest.cpp @@ -227,9 +227,9 @@ static void test_fully_peekable_stream(skiatest::Reporter* r, SkStream* stream, static void test_peeking_front_buffered_stream(skiatest::Reporter* r, const SkStream& original, size_t bufferSize) { - std::unique_ptr<SkStream> dupe(original.duplicate()); + SkStream* dupe = original.duplicate(); REPORTER_ASSERT(r, dupe != nullptr); - auto bufferedStream = SkFrontBufferedStream::Make(std::move(dupe), bufferSize); + std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(dupe, bufferSize)); REPORTER_ASSERT(r, bufferedStream != nullptr); size_t peeked = 0; @@ -249,11 +249,7 @@ static void test_peeking_front_buffered_stream(skiatest::Reporter* r, } // Test that attempting to peek beyond the length of the buffer does not prevent rewinding. -#ifdef SK_SUPPORT_LEGACY_STREAM_API bufferedStream.reset(SkFrontBufferedStream::Create(original.duplicate(), bufferSize)); -#else - bufferedStream = SkFrontBufferedStream::Make(original.duplicate(), bufferSize); -#endif REPORTER_ASSERT(r, bufferedStream != nullptr); const size_t bytesToPeek = bufferSize + 1; |