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>
This commit is contained in:
parent
226e2032e8
commit
49f1f34438
@ -53,7 +53,11 @@ 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);
|
||||
|
@ -101,10 +101,29 @@ 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. */
|
||||
@ -124,11 +143,6 @@ 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; }
|
||||
@ -139,44 +153,97 @@ 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:
|
||||
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 @@ 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;
|
||||
|
||||
@ -291,6 +370,11 @@ 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;
|
||||
@ -346,18 +430,35 @@ 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;
|
||||
|
||||
|
@ -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 @@ public:
|
||||
* 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
|
||||
|
@ -315,7 +315,9 @@ 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;
|
||||
@ -341,14 +343,24 @@ 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
|
||||
|
||||
sk_sp<SkROBuffer> fBuffer;
|
||||
SkROBuffer::Iter fIter;
|
||||
size_t fLocalOffset;
|
||||
|
@ -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 @@ bool SkFILEStream::rewind() {
|
||||
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 @@ bool SkFILEStream::move(long offset) {
|
||||
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 @@ bool SkMemoryStream::rewind() {
|
||||
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 @@ bool SkMemoryStream::move(long offset) {
|
||||
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 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
SkBlockMemoryStream* duplicate() const override {
|
||||
SkBlockMemoryStream* DUP_NAME() const override {
|
||||
return new SkBlockMemoryStream(fBlockMemory, fSize);
|
||||
}
|
||||
|
||||
@ -760,12 +775,12 @@ public:
|
||||
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 {
|
||||
|
@ -26,7 +26,11 @@ 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());
|
||||
|
@ -129,7 +129,11 @@ 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 {
|
||||
|
@ -60,7 +60,11 @@ 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 {
|
||||
|
@ -435,7 +435,11 @@ 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 {
|
||||
|
@ -86,7 +86,7 @@ HRESULT StreamFontFileLoader::CreateStreamFromKey(
|
||||
IDWriteFontFileStream** fontFileStream)
|
||||
{
|
||||
SkTScopedComPtr<SkDWriteFontFileStreamWrapper> stream;
|
||||
HR(SkDWriteFontFileStreamWrapper::Create(fStream->duplicate(), &stream));
|
||||
HR(SkDWriteFontFileStreamWrapper::Create(fStream->duplicate().release(), &stream));
|
||||
*fontFileStream = stream.release();
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -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 @@ 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;
|
||||
@ -61,17 +67,19 @@ private:
|
||||
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)
|
||||
|
@ -86,7 +86,12 @@ bool SkDWriteFontFileStream::rewind() {
|
||||
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 @@ bool SkDWriteFontFileStream::move(long offset) {
|
||||
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();
|
||||
|
@ -28,15 +28,31 @@ 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;
|
||||
|
@ -442,10 +442,10 @@ static void check(skiatest::Reporter* r,
|
||||
|
||||
#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);
|
||||
|
@ -54,9 +54,10 @@ 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 = 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_incremental_buffering(skiatest::Reporter* reporter, size_t buff
|
||||
}
|
||||
|
||||
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_perfectly_sized_buffer(skiatest::Reporter* reporter, size_t buf
|
||||
}
|
||||
|
||||
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 @@ 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.
|
||||
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 @@ 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));
|
||||
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 @@ static void test_initial_offset(skiatest::Reporter* reporter, size_t bufferSize)
|
||||
// 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 @@ private:
|
||||
|
||||
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.
|
||||
|
@ -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) {
|
||||
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 @@ 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;
|
||||
|
Loading…
Reference in New Issue
Block a user