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 13 #include "SkStream.h" 14 #include "SkTScopedComPtr.h" 15 16 #include <dwrite.h> 17 18 /** 19 * An SkStream backed by an IDWriteFontFileStream. 20 * This allows Skia code to read an IDWriteFontFileStream. 21 */ 22 class SkDWriteFontFileStream : public SkStreamMemory { 23 public: 24 explicit SkDWriteFontFileStream(IDWriteFontFileStream* fontFileStream); 25 virtual ~SkDWriteFontFileStream(); 26 27 virtual size_t read(void* buffer, size_t size) SK_OVERRIDE; 28 virtual bool isAtEnd() const SK_OVERRIDE; 29 virtual bool rewind() SK_OVERRIDE; 30 virtual SkDWriteFontFileStream* duplicate() const SK_OVERRIDE; 31 virtual size_t getPosition() const SK_OVERRIDE; 32 virtual bool seek(size_t position) SK_OVERRIDE; 33 virtual bool move(long offset) SK_OVERRIDE; 34 virtual SkDWriteFontFileStream* fork() const SK_OVERRIDE; 35 virtual size_t getLength() const SK_OVERRIDE; 36 virtual const void* getMemoryBase() SK_OVERRIDE; 37 38 private: 39 SkTScopedComPtr<IDWriteFontFileStream> fFontFileStream; 40 size_t fPos; 41 const void* fLockedMemory; 42 void* fFragmentLock; 43 }; 44 45 /** 46 * An IDWriteFontFileStream backed by an SkStream. 47 * This allows DirectWrite to read an SkStream. 48 */ 49 class SkDWriteFontFileStreamWrapper : public IDWriteFontFileStream { 50 public: 51 // IUnknown methods 52 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObject); 53 virtual ULONG STDMETHODCALLTYPE AddRef(); 54 virtual ULONG STDMETHODCALLTYPE Release(); 55 56 // IDWriteFontFileStream methods 57 virtual HRESULT STDMETHODCALLTYPE ReadFileFragment( 58 void const** fragmentStart, 59 UINT64 fileOffset, 60 UINT64 fragmentSize, 61 void** fragmentContext); 62 63 virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext); 64 virtual HRESULT STDMETHODCALLTYPE GetFileSize(UINT64* fileSize); 65 virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(UINT64* lastWriteTime); 66 67 static HRESULT Create(SkStream* stream, SkDWriteFontFileStreamWrapper** streamFontFileStream); 68 69 private: 70 explicit SkDWriteFontFileStreamWrapper(SkStream* stream); 71 72 ULONG fRefCount; 73 SkAutoTUnref<SkStream> fStream; 74 SkMutex fStreamMutex; 75 }; 76 #endif 77