Revert "Revert "use unique_ptr for stream api""
This reverts commit 7031b247c9fe0cb8fa32129f9bc24fea2043cee2.
Bug: skia:
Change-Id: I24c34bbee703f02994be8e206bcb9c10b5427d84
Reviewed-on: https://skia-review.googlesource.com/47541
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/gm/fontscalerdistortable.cpp b/gm/fontscalerdistortable.cpp
index 1823b50..30352e4 100644
--- a/gm/fontscalerdistortable.cpp
+++ b/gm/fontscalerdistortable.cpp
@@ -53,7 +53,11 @@
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 5ef8519..2d7a8c5 100644
--- a/include/core/SkStream.h
+++ b/include/core/SkStream.h
@@ -101,10 +101,29 @@
*/
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. */
@@ -124,11 +143,6 @@
*/
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; }
@@ -139,44 +153,97 @@
/** 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:
- SkStreamAsset* duplicate() const override = 0;
- SkStreamAsset* fork() const override = 0;
-
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
};
/** 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;
-
- const void* getMemoryBase() 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
};
class SK_API SkWStream : SkNoncopyable {
@@ -278,12 +345,24 @@
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;
@@ -291,6 +370,11 @@
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;
@@ -346,18 +430,35 @@
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 3532fc5..a47acf8 100644
--- a/include/utils/SkFrontBufferedStream.h
+++ b/include/utils/SkFrontBufferedStream.h
@@ -8,10 +8,7 @@
#ifndef SkFrontBufferedStream_DEFINED
#define SkFrontBufferedStream_DEFINED
-#include "SkTypes.h"
-
-class SkStream;
-class SkStreamRewindable;
+#include "SkStream.h"
/**
* Specialized stream that buffers the first X bytes of a stream,
@@ -36,6 +33,13 @@
* NULL on failure. The caller is required to delete when finished with
* this object.
*/
- static SkStreamRewindable* Create(SkStream* stream, size_t minBufferSize);
+ 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
};
#endif // SkFrontBufferedStream_DEFINED
diff --git a/src/core/SkRWBuffer.cpp b/src/core/SkRWBuffer.cpp
index 3ac9677..8ec2baa 100644
--- a/src/core/SkRWBuffer.cpp
+++ b/src/core/SkRWBuffer.cpp
@@ -315,7 +315,9 @@
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;
@@ -341,14 +343,24 @@
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
+
sk_sp<SkROBuffer> fBuffer;
SkROBuffer::Iter fIter;
size_t fLocalOffset;
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp
index 139a72f..bc638c2 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -15,6 +15,14 @@
#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
+
///////////////////////////////////////////////////////////////////////////////
@@ -216,7 +224,7 @@
return true;
}
-SkStreamAsset* SkFILEStream::duplicate() const {
+SkStreamAsset* SkFILEStream::DUP_NAME() const {
// TODO: fOriginalOffset instead of 0.
return new SkFILEStream(fFILE, fSize, 0, fOriginalOffset);
}
@@ -234,7 +242,7 @@
return this->seek(fOffset + offset);
}
-SkStreamAsset* SkFILEStream::fork() const {
+SkStreamAsset* SkFILEStream::FORK_NAME() const {
return new SkFILEStream(fFILE, fSize, fOffset, fOriginalOffset);
}
@@ -342,7 +350,14 @@
return true;
}
-SkMemoryStream* SkMemoryStream::duplicate() const { return new SkMemoryStream(fData); }
+#ifdef SK_SUPPORT_LEGACY_STREAM_API
+SkMemoryStream* SkMemoryStream::duplicate() const
+#else
+SkMemoryStream* SkMemoryStream::onDuplicate() const
+#endif
+{
+ return new SkMemoryStream(fData);
+}
size_t SkMemoryStream::getPosition() const {
return fOffset;
@@ -359,7 +374,7 @@
return this->seek(fOffset + offset);
}
-SkMemoryStream* SkMemoryStream::fork() const {
+SkMemoryStream* SkMemoryStream::FORK_NAME() const {
std::unique_ptr<SkMemoryStream> that(this->duplicate());
that->seek(fOffset);
return that.release();
@@ -731,7 +746,7 @@
return true;
}
- SkBlockMemoryStream* duplicate() const override {
+ SkBlockMemoryStream* DUP_NAME() const override {
return new SkBlockMemoryStream(fBlockMemory, fSize);
}
@@ -760,12 +775,12 @@
return seek(fOffset + offset);
}
- SkBlockMemoryStream* fork() const override {
- std::unique_ptr<SkBlockMemoryStream> that(this->duplicate());
+ SkBlockMemoryStream* FORK_NAME() const override {
+ SkBlockMemoryStream* that = this->DUP_NAME();
that->fCurrent = this->fCurrent;
that->fOffset = this->fOffset;
that->fCurrentOffset = this->fCurrentOffset;
- return that.release();
+ return that;
}
size_t getLength() const override {
diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp
index 99092b6..aec76af 100644
--- a/src/ports/SkFontMgr_FontConfigInterface.cpp
+++ b/src/ports/SkFontMgr_FontConfigInterface.cpp
@@ -26,7 +26,11 @@
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 2dd3221..0ec2edb 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -129,7 +129,11 @@
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 91a5908..b38f48c 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -60,7 +60,11 @@
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 95c963d..8b3a058 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -435,7 +435,11 @@
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 1fd300c..b349c83 100644
--- a/src/ports/SkFontMgr_win_dw.cpp
+++ b/src/ports/SkFontMgr_win_dw.cpp
@@ -86,7 +86,11 @@
IDWriteFontFileStream** fontFileStream)
{
SkTScopedComPtr<SkDWriteFontFileStreamWrapper> stream;
+#ifdef SK_SUPPORT_LEGACY_STREAM_API
HR(SkDWriteFontFileStreamWrapper::Create(fStream->duplicate(), &stream));
+#else
+ HR(SkDWriteFontFileStreamWrapper::Create(fStream->duplicate().release(), &stream));
+#endif
*fontFileStream = stream.release();
return S_OK;
}
diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp
index 42b86f0..77c484a 100644
--- a/src/utils/SkFrontBufferedStream.cpp
+++ b/src/utils/SkFrontBufferedStream.cpp
@@ -11,8 +11,8 @@
class FrontBufferedStream : public SkStreamRewindable {
public:
- // Called by Create.
- FrontBufferedStream(SkStream*, size_t bufferSize);
+ // Called by Make.
+ FrontBufferedStream(std::unique_ptr<SkStream>, size_t bufferSize);
size_t read(void* buffer, size_t size) override;
@@ -26,9 +26,15 @@
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;
@@ -61,17 +67,19 @@
typedef SkStream INHERITED;
};
-SkStreamRewindable* SkFrontBufferedStream::Create(SkStream* stream, size_t bufferSize) {
- if (nullptr == stream) {
+std::unique_ptr<SkStreamRewindable> SkFrontBufferedStream::Make(std::unique_ptr<SkStream> stream,
+ size_t bufferSize) {
+ if (!stream) {
return nullptr;
}
- return new FrontBufferedStream(stream, bufferSize);
+ return std::unique_ptr<SkStreamRewindable>(new FrontBufferedStream(std::move(stream),
+ bufferSize));
}
-FrontBufferedStream::FrontBufferedStream(SkStream* stream, size_t bufferSize)
- : fStream(stream)
- , fHasLength(stream->hasPosition() && stream->hasLength())
- , fLength(stream->getLength() - stream->getPosition())
+FrontBufferedStream::FrontBufferedStream(std::unique_ptr<SkStream> stream, size_t bufferSize)
+ : fStream(std::move(stream))
+ , fHasLength(fStream->hasPosition() && fStream->hasLength())
+ , fLength(fStream->getLength() - fStream->getPosition())
, fOffset(0)
, fBufferedSoFar(0)
, fBufferSize(bufferSize)
diff --git a/src/utils/win/SkDWriteFontFileStream.cpp b/src/utils/win/SkDWriteFontFileStream.cpp
index 2bb7d0f..a43e163 100644
--- a/src/utils/win/SkDWriteFontFileStream.cpp
+++ b/src/utils/win/SkDWriteFontFileStream.cpp
@@ -86,7 +86,12 @@
return true;
}
-SkDWriteFontFileStream* SkDWriteFontFileStream::duplicate() const {
+#ifdef SK_SUPPORT_LEGACY_STREAM_API
+SkDWriteFontFileStream* SkDWriteFontFileStream::duplicate() const
+#else
+SkDWriteFontFileStream* SkDWriteFontFileStream::onDuplicate() const
+#endif
+{
return new SkDWriteFontFileStream(fFontFileStream.get());
}
@@ -104,7 +109,12 @@
return seek(fPos + offset);
}
-SkDWriteFontFileStream* SkDWriteFontFileStream::fork() const {
+#ifdef SK_SUPPORT_LEGACY_STREAM_API
+SkDWriteFontFileStream* SkDWriteFontFileStream::fork() const
+#else
+SkDWriteFontFileStream* SkDWriteFontFileStream::onFork() const
+#endif
+{
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 25322c5..9b65752 100644
--- a/src/utils/win/SkDWriteFontFileStream.h
+++ b/src/utils/win/SkDWriteFontFileStream.h
@@ -28,15 +28,31 @@
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 baa2314..f2551d2 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -442,10 +442,10 @@
#ifndef SK_PNG_DISABLE_TESTS
// Test using SkFrontBufferedStream, as Android does
- SkStream* bufferedStream = SkFrontBufferedStream::Create(
- new SkMemoryStream(std::move(fullData)), SkCodec::MinBufferedBytesNeeded());
+ auto bufferedStream = SkFrontBufferedStream::Make(
+ SkMemoryStream::Make(std::move(fullData)), SkCodec::MinBufferedBytesNeeded());
REPORTER_ASSERT(r, bufferedStream);
- codec = SkCodec::MakeFromStream(std::unique_ptr<SkStream>(bufferedStream));
+ codec = SkCodec::MakeFromStream(std::move(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 aa2dc89..5452730 100644
--- a/tests/FrontBufferedStreamTest.cpp
+++ b/tests/FrontBufferedStreamTest.cpp
@@ -54,9 +54,10 @@
// 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 = new SkMemoryStream(gAbcs, strlen(gAbcs), false);
+ SkMemoryStream* memStream = SkMemoryStream::MakeDirect(gAbcs, strlen(gAbcs)).release();
- std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));
+ auto bufferedStream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(memStream),
+ bufferSize);
test_hasLength(reporter, *bufferedStream, *memStream);
// First, test reading less than the max buffer size.
@@ -82,8 +83,9 @@
}
static void test_perfectly_sized_buffer(skiatest::Reporter* reporter, size_t bufferSize) {
- SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false);
- std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));
+ SkMemoryStream* memStream = SkMemoryStream::MakeDirect(gAbcs, strlen(gAbcs)).release();
+ auto bufferedStream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(memStream),
+ bufferSize);
test_hasLength(reporter, *bufferedStream, *memStream);
// Read exactly the amount that fits in the buffer.
@@ -101,8 +103,9 @@
}
static void test_skipping(skiatest::Reporter* reporter, size_t bufferSize) {
- SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false);
- std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));
+ SkMemoryStream* memStream = SkMemoryStream::MakeDirect(gAbcs, strlen(gAbcs)).release();
+ auto bufferedStream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(memStream),
+ bufferSize);
test_hasLength(reporter, *bufferedStream, *memStream);
// Skip half the buffer.
@@ -156,7 +159,8 @@
new AndroidLikeMemoryStream((void*)gAbcs, bufferSize, false);
// Create a buffer that matches the length of the stream.
- std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));
+ auto bufferedStream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(memStream),
+ bufferSize);
test_hasLength(reporter, *bufferedStream.get(), *memStream);
// Attempt to read one more than the bufferSize
@@ -203,7 +207,8 @@
for (int hasPos = 0; hasPos <= 1; hasPos++) {
LengthOptionalStream* stream =
new LengthOptionalStream(SkToBool(hasLen), SkToBool(hasPos));
- std::unique_ptr<SkStream> buffered(SkFrontBufferedStream::Create(stream, bufferSize));
+ auto buffered = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(stream),
+ bufferSize);
test_hasLength(reporter, *buffered.get(), *stream);
}
}
@@ -217,7 +222,8 @@
// the stream it wraps.
const size_t arbitraryOffset = 17;
memStream->skip(arbitraryOffset);
- std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));
+ auto bufferedStream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(memStream),
+ bufferSize);
// Since SkMemoryStream has a length, bufferedStream must also.
REPORTER_ASSERT(reporter, bufferedStream->hasLength());
@@ -281,7 +287,7 @@
DEF_TEST(ShortFrontBufferedStream, reporter) {
FailingStream* failingStream = new FailingStream;
- std::unique_ptr<SkStreamRewindable> stream(SkFrontBufferedStream::Create(failingStream, 64));
+ auto stream = SkFrontBufferedStream::Make(std::unique_ptr<SkStream>(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 8b5b2ae..2e8078e 100644
--- a/tests/StreamTest.cpp
+++ b/tests/StreamTest.cpp
@@ -227,9 +227,9 @@
static void test_peeking_front_buffered_stream(skiatest::Reporter* r,
const SkStream& original,
size_t bufferSize) {
- SkStream* dupe = original.duplicate();
+ std::unique_ptr<SkStream> dupe(original.duplicate());
REPORTER_ASSERT(r, dupe != nullptr);
- std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(dupe, bufferSize));
+ auto bufferedStream = SkFrontBufferedStream::Make(std::move(dupe), bufferSize);
REPORTER_ASSERT(r, bufferedStream != nullptr);
size_t peeked = 0;
@@ -249,7 +249,11 @@
}
// 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;