blob: e78b621c0230ffc1be47916079c9209867d3e0c4 [file] [log] [blame]
bungeman@google.come8f05922012-08-16 16:13:40 +00001/*
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
mtklein7b274c72015-02-03 13:38:58 -080013#include "SkMutex.h"
bungeman@google.come8f05922012-08-16 16:13:40 +000014#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.com6cab1a42013-05-29 13:43:31 +000023class SkDWriteFontFileStream : public SkStreamMemory {
bungeman@google.come8f05922012-08-16 16:13:40 +000024public:
25 explicit SkDWriteFontFileStream(IDWriteFontFileStream* fontFileStream);
26 virtual ~SkDWriteFontFileStream();
rmistry@google.comd6176b02012-08-23 18:14:13 +000027
mtklein36352bf2015-03-25 18:17:31 -070028 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.come8f05922012-08-16 16:13:40 +000038
39private:
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 */
50class SkDWriteFontFileStreamWrapper : public IDWriteFontFileStream {
51public:
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
bungeman0babd3c2015-02-18 11:01:05 -080068 static HRESULT Create(SkStreamAsset* stream,
69 SkDWriteFontFileStreamWrapper** streamFontFileStream);
bungeman@google.come8f05922012-08-16 16:13:40 +000070
71private:
bungeman0babd3c2015-02-18 11:01:05 -080072 explicit SkDWriteFontFileStreamWrapper(SkStreamAsset* stream);
bungemand7f846b2014-06-19 11:26:59 -070073 virtual ~SkDWriteFontFileStreamWrapper() { }
bungeman@google.come8f05922012-08-16 16:13:40 +000074
75 ULONG fRefCount;
bungeman0babd3c2015-02-18 11:01:05 -080076 SkAutoTDelete<SkStreamAsset> fStream;
bungeman@google.come8f05922012-08-16 16:13:40 +000077 SkMutex fStreamMutex;
78};
79#endif