• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SkStream {
23 public:
24     explicit SkDWriteFontFileStream(IDWriteFontFileStream* fontFileStream);
25     virtual ~SkDWriteFontFileStream();
26 
27     virtual bool rewind() SK_OVERRIDE;
28     virtual size_t read(void* buffer, size_t size) SK_OVERRIDE;
29     virtual const void* getMemoryBase() SK_OVERRIDE;
30 
31 private:
32     SkTScopedComPtr<IDWriteFontFileStream> fFontFileStream;
33     size_t fPos;
34     const void* fLockedMemory;
35     void* fFragmentLock;
36 };
37 
38 /**
39  *  An IDWriteFontFileStream backed by an SkStream.
40  *  This allows DirectWrite to read an SkStream.
41  */
42 class SkDWriteFontFileStreamWrapper : public IDWriteFontFileStream {
43 public:
44     // IUnknown methods
45     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObject);
46     virtual ULONG STDMETHODCALLTYPE AddRef();
47     virtual ULONG STDMETHODCALLTYPE Release();
48 
49     // IDWriteFontFileStream methods
50     virtual HRESULT STDMETHODCALLTYPE ReadFileFragment(
51         void const** fragmentStart,
52         UINT64 fileOffset,
53         UINT64 fragmentSize,
54         void** fragmentContext);
55 
56     virtual void STDMETHODCALLTYPE ReleaseFileFragment(void* fragmentContext);
57     virtual HRESULT STDMETHODCALLTYPE GetFileSize(UINT64* fileSize);
58     virtual HRESULT STDMETHODCALLTYPE GetLastWriteTime(UINT64* lastWriteTime);
59 
60     static HRESULT Create(SkStream* stream, SkDWriteFontFileStreamWrapper** streamFontFileStream);
61 
62 private:
63     explicit SkDWriteFontFileStreamWrapper(SkStream* stream);
64 
65     ULONG fRefCount;
66     SkAutoTUnref<SkStream> fStream;
67     SkMutex fStreamMutex;
68 };
69 #endif
70