aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-09-15 11:37:15 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-15 18:46:45 +0000
commit49f1f34438d3431f6d7e32847accd2ba96948a73 (patch)
treec4e0342c3350c546573fb2add99597e92c9ca66c /src
parent226e2032e8e37068a409aeb37aac79608fbd315d (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkRWBuffer.cpp14
-rw-r--r--src/core/SkStream.cpp31
-rw-r--r--src/ports/SkFontMgr_FontConfigInterface.cpp4
-rw-r--r--src/ports/SkFontMgr_android.cpp4
-rw-r--r--src/ports/SkFontMgr_custom.cpp4
-rw-r--r--src/ports/SkFontMgr_fontconfig.cpp4
-rw-r--r--src/ports/SkFontMgr_win_dw.cpp2
-rw-r--r--src/utils/SkFrontBufferedStream.cpp26
-rw-r--r--src/utils/win/SkDWriteFontFileStream.cpp14
-rw-r--r--src/utils/win/SkDWriteFontFileStream.h20
10 files changed, 100 insertions, 23 deletions
diff --git a/src/core/SkRWBuffer.cpp b/src/core/SkRWBuffer.cpp
index 3ac9677793..8ec2baafac 100644
--- a/src/core/SkRWBuffer.cpp
+++ b/src/core/SkRWBuffer.cpp
@@ -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;
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp
index 139a72f7ca..bc638c249a 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 @@ 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 {
diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp
index 99092b6b98..aec76af685 100644
--- a/src/ports/SkFontMgr_FontConfigInterface.cpp
+++ b/src/ports/SkFontMgr_FontConfigInterface.cpp
@@ -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());
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 2dd3221466..0ec2edba6a 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -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 {
diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp
index 91a590827c..b38f48c322 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -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 {
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 95c963d69f..8b3a058e9e 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -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 {
diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp
index 1fd300ca1d..eca20d94b7 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(), &stream));
+ HR(SkDWriteFontFileStreamWrapper::Create(fStream->duplicate().release(), &stream));
*fontFileStream = stream.release();
return S_OK;
}
diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp
index 42b86f09e3..77c484af64 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 @@ 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)
diff --git a/src/utils/win/SkDWriteFontFileStream.cpp b/src/utils/win/SkDWriteFontFileStream.cpp
index 2bb7d0fb4e..a43e163481 100644
--- a/src/utils/win/SkDWriteFontFileStream.cpp
+++ b/src/utils/win/SkDWriteFontFileStream.cpp
@@ -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();
diff --git a/src/utils/win/SkDWriteFontFileStream.h b/src/utils/win/SkDWriteFontFileStream.h
index 25322c5657..9b65752382 100644
--- a/src/utils/win/SkDWriteFontFileStream.h
+++ b/src/utils/win/SkDWriteFontFileStream.h
@@ -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;