Flutter Engine
The Flutter Engine
SkIStream.h
Go to the documentation of this file.
1
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef SkIStream_DEFINED
11#define SkIStream_DEFINED
12
14
15#ifdef SK_BUILD_FOR_WIN
16
19#include <ole2.h>
20
21class SkStream;
22class SkWStream;
23
24/**
25 * A bare IStream implementation which properly reference counts
26 * but returns E_NOTIMPL for all ISequentialStream and IStream methods.
27 */
28class SkBaseIStream : public IStream {
29public:
30 // IUnknown methods
31 SK_STDMETHODIMP QueryInterface(REFIID iid, void ** ppvObject) override;
32 SK_STDMETHODIMP_(ULONG) AddRef() override;
33 SK_STDMETHODIMP_(ULONG) Release() override;
34
35 // ISequentialStream methods
36 SK_STDMETHODIMP Read(void* pv, ULONG cb, ULONG* pcbRead) override;
37 SK_STDMETHODIMP Write(void const* pv, ULONG cb, ULONG* pcbWritten) override;
38
39 // IStream methods
40 SK_STDMETHODIMP SetSize(ULARGE_INTEGER) override;
41 SK_STDMETHODIMP CopyTo(IStream*, ULARGE_INTEGER, ULARGE_INTEGER*, ULARGE_INTEGER*) override;
42 SK_STDMETHODIMP Commit(DWORD) override;
43 SK_STDMETHODIMP Revert() override;
44 SK_STDMETHODIMP LockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD) override;
45 SK_STDMETHODIMP UnlockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD) override;
46 SK_STDMETHODIMP Clone(IStream**) override;
47 SK_STDMETHODIMP Seek(LARGE_INTEGER liDistanceToMove,
48 DWORD dwOrigin,
49 ULARGE_INTEGER* lpNewFilePointer) override;
50 SK_STDMETHODIMP Stat(STATSTG* pStatstg, DWORD grfStatFlag) override;
51
52protected:
53 explicit SkBaseIStream();
54 virtual ~SkBaseIStream();
55
56private:
57 LONG _refcount;
58};
59
60/**
61 * A minimal read-only IStream implementation which wraps an SkStream.
62 */
63class SkIStream : public SkBaseIStream {
64public:
65 HRESULT static CreateFromSkStream(std::unique_ptr<SkStreamAsset>, IStream** ppStream);
66
67 SK_STDMETHODIMP Read(void* pv, ULONG cb, ULONG* pcbRead) override;
68 SK_STDMETHODIMP Write(void const* pv, ULONG cb, ULONG* pcbWritten) override;
69 SK_STDMETHODIMP Seek(LARGE_INTEGER liDistanceToMove,
70 DWORD dwOrigin,
71 ULARGE_INTEGER* lpNewFilePointer) override;
72 SK_STDMETHODIMP Stat(STATSTG* pStatstg, DWORD grfStatFlag) override;
73
74private:
75 const std::unique_ptr<SkStream> fSkStream;
76 ULARGE_INTEGER fLocation;
77
78 explicit SkIStream(std::unique_ptr<SkStreamAsset>);
79 ~SkIStream() override;
80};
81
82/**
83 * A minimal write-only IStream implementation which wraps an SkWIStream.
84 */
85class SkWIStream : public SkBaseIStream {
86public:
87 HRESULT static CreateFromSkWStream(SkWStream* stream, IStream ** ppStream);
88
89 SK_STDMETHODIMP Write(void const* pv, ULONG cb, ULONG* pcbWritten) override;
90 SK_STDMETHODIMP Commit(DWORD) override;
91 SK_STDMETHODIMP Stat(STATSTG* pStatstg, DWORD grfStatFlag) override;
92
93private:
94 SkWStream *fSkWStream;
95
96 SkWIStream(SkWStream* stream);
97 ~SkWIStream() override;
98};
99
100#endif // SK_BUILD_FOR_WIN
101#endif // SkIStream_DEFINED
#define SK_STDMETHODIMP_(type)
Definition: SkObjBase.h:23
#define SK_STDMETHODIMP
Definition: SkObjBase.h:22
SK_API bool Read(SkStreamSeekable *src, SkDocumentPage *dstArray, int dstArrayCount, const SkDeserialProcs *=nullptr)
long LONG
Definition: windows_types.h:23
DWORD ULONG
Definition: windows_types.h:40
unsigned long DWORD
Definition: windows_types.h:22