bungeman@google.com | e8f0592 | 2012-08-16 16:13:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkDWriteFontFileStream_DEFINED |
| 9 | #define SkDWriteFontFileStream_DEFINED |
| 10 | |
| 11 | #include "SkTypes.h" |
| 12 | |
mtklein | 7b274c7 | 2015-02-03 13:38:58 -0800 | [diff] [blame] | 13 | #include "SkMutex.h" |
bungeman@google.com | e8f0592 | 2012-08-16 16:13:40 +0000 | [diff] [blame] | 14 | #include "SkStream.h" |
| 15 | #include "SkTScopedComPtr.h" |
| 16 | |
| 17 | #include <dwrite.h> |
| 18 | |
| 19 | /** |
| 20 | * An SkStream backed by an IDWriteFontFileStream. |
| 21 | * This allows Skia code to read an IDWriteFontFileStream. |
| 22 | */ |
bungeman@google.com | 6cab1a4 | 2013-05-29 13:43:31 +0000 | [diff] [blame] | 23 | class SkDWriteFontFileStream : public SkStreamMemory { |
bungeman@google.com | e8f0592 | 2012-08-16 16:13:40 +0000 | [diff] [blame] | 24 | public: |
| 25 | explicit SkDWriteFontFileStream(IDWriteFontFileStream* fontFileStream); |
| 26 | virtual ~SkDWriteFontFileStream(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 27 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 28 | size_t read(void* buffer, size_t size) override; |
| 29 | bool isAtEnd() const override; |
| 30 | bool rewind() override; |
| 31 | SkDWriteFontFileStream* duplicate() const override; |
| 32 | size_t getPosition() const override; |
| 33 | bool seek(size_t position) override; |
| 34 | bool move(long offset) override; |
| 35 | SkDWriteFontFileStream* fork() const override; |
| 36 | size_t getLength() const override; |
| 37 | const void* getMemoryBase() override; |
bungeman@google.com | e8f0592 | 2012-08-16 16:13:40 +0000 | [diff] [blame] | 38 | |
| 39 | private: |
| 40 | SkTScopedComPtr<IDWriteFontFileStream> fFontFileStream; |
| 41 | size_t fPos; |
| 42 | const void* fLockedMemory; |
| 43 | void* fFragmentLock; |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * An IDWriteFontFileStream backed by an SkStream. |
| 48 | * This allows DirectWrite to read an SkStream. |
| 49 | */ |
| 50 | class SkDWriteFontFileStreamWrapper : public IDWriteFontFileStream { |
| 51 | public: |
| 52 | // IUnknown methods |
| 53 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObject); |
| 54 | virtual ULONG STDMETHODCALLTYPE AddRef(); |
| 55 | virtual ULONG STDMETHODCALLTYPE Release(); |
| 56 | |
| 57 | // IDWriteFontFileStream methods |
| 58 | virtual HRESULT STDMETHODCALLTYPE ReadFileFragment( |
| 59 | void const** fragmentStart, |
| 60 | UINT64 fileOffset, |
| 61 | UINT64 fragmentSize, |
| 62 | void** fragmentContext); |
| 63 | |
| 64 | virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext); |
| 65 | virtual HRESULT STDMETHODCALLTYPE GetFileSize(UINT64* fileSize); |
| 66 | virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(UINT64* lastWriteTime); |
| 67 | |
bungeman | 0babd3c | 2015-02-18 11:01:05 -0800 | [diff] [blame] | 68 | static HRESULT Create(SkStreamAsset* stream, |
| 69 | SkDWriteFontFileStreamWrapper** streamFontFileStream); |
bungeman@google.com | e8f0592 | 2012-08-16 16:13:40 +0000 | [diff] [blame] | 70 | |
| 71 | private: |
bungeman | 0babd3c | 2015-02-18 11:01:05 -0800 | [diff] [blame] | 72 | explicit SkDWriteFontFileStreamWrapper(SkStreamAsset* stream); |
bungeman | d7f846b | 2014-06-19 11:26:59 -0700 | [diff] [blame] | 73 | virtual ~SkDWriteFontFileStreamWrapper() { } |
bungeman@google.com | e8f0592 | 2012-08-16 16:13:40 +0000 | [diff] [blame] | 74 | |
| 75 | ULONG fRefCount; |
bungeman | 0babd3c | 2015-02-18 11:01:05 -0800 | [diff] [blame] | 76 | SkAutoTDelete<SkStreamAsset> fStream; |
bungeman@google.com | e8f0592 | 2012-08-16 16:13:40 +0000 | [diff] [blame] | 77 | SkMutex fStreamMutex; |
| 78 | }; |
| 79 | #endif |