• 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(SkStream* stream, bool fDeleteOnRelease, 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     SkStream *fSkStream;
76     const bool fDeleteOnRelease;
77     ULARGE_INTEGER fLocation;
78 
79     SkIStream(SkStream* stream, bool fDeleteOnRelease);
80     ~SkIStream() override;
81 };
82 
83 /**
84  * A minimal write-only IStream implementation which wraps an SkWIStream.
85  */
86 class SkWIStream : public SkBaseIStream {
87 public:
88     HRESULT static CreateFromSkWStream(SkWStream* stream, IStream ** ppStream);
89 
90     SK_STDMETHODIMP Write(void const* pv, ULONG cb, ULONG* pcbWritten) override;
91     SK_STDMETHODIMP Commit(DWORD) override;
92     SK_STDMETHODIMP Stat(STATSTG* pStatstg, DWORD grfStatFlag) override;
93 
94 private:
95     SkWStream *fSkWStream;
96 
97     SkWIStream(SkWStream* stream);
98     ~SkWIStream() override;
99 };
100 
101 #endif  // SK_BUILD_FOR_WIN
102 #endif  // SkIStream_DEFINED
103