• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 #include "include/core/SkTypes.h"
14 
15 #ifdef SK_BUILD_FOR_WIN
16 
17 #include "src/core/SkLeanWindows.h"
18 #include "src/utils/win/SkObjBase.h"
19 #include <ole2.h>
20 
21 class SkStream;
22 class SkWStream;
23 
24 /**
25  * A bare IStream implementation which properly reference counts
26  * but returns E_NOTIMPL for all ISequentialStream and IStream methods.
27  */
28 class SkBaseIStream : public IStream {
29 public:
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 
52 protected:
53     explicit SkBaseIStream();
54     virtual ~SkBaseIStream();
55 
56 private:
57     LONG _refcount;
58 };
59 
60 /**
61  * A minimal read-only IStream implementation which wraps an SkStream.
62  */
63 class SkIStream : public SkBaseIStream {
64 public:
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 
74 private:
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  */
85 class SkWIStream : public SkBaseIStream {
86 public:
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 
93 private:
94     SkWStream *fSkWStream;
95 
96     SkWIStream(SkWStream* stream);
97     ~SkWIStream() override;
98 };
99 
100 #endif  // SK_BUILD_FOR_WIN
101 #endif  // SkIStream_DEFINED
102