• 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 "SkTypes.h"
14 
15 #ifdef SK_BUILD_FOR_WIN
16 
17 #define WIN32_LEAN_AND_MEAN
18 #include <windows.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 private:
30     LONG _refcount;
31 
32 protected:
33     explicit SkBaseIStream();
34     virtual ~SkBaseIStream();
35 
36 public:
37     virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid
38                                                    , void ** ppvObject);
39     virtual ULONG STDMETHODCALLTYPE AddRef(void);
40     virtual ULONG STDMETHODCALLTYPE Release(void);
41 
42     // ISequentialStream Interface
43 public:
44     virtual HRESULT STDMETHODCALLTYPE Read(void* pv, ULONG cb, ULONG* pcbRead);
45 
46     virtual HRESULT STDMETHODCALLTYPE Write(void const* pv
47                                           , ULONG cb
48                                           , ULONG* pcbWritten);
49 
50     // IStream Interface
51 public:
52     virtual HRESULT STDMETHODCALLTYPE SetSize(ULARGE_INTEGER);
53 
54     virtual HRESULT STDMETHODCALLTYPE CopyTo(IStream*
55                                            , ULARGE_INTEGER
56                                            , ULARGE_INTEGER*
57                                            , ULARGE_INTEGER*);
58 
59     virtual HRESULT STDMETHODCALLTYPE Commit(DWORD);
60 
61     virtual HRESULT STDMETHODCALLTYPE Revert(void);
62 
63     virtual HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER
64                                                , ULARGE_INTEGER
65                                                , DWORD);
66 
67     virtual HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER
68                                                  , ULARGE_INTEGER
69                                                  , DWORD);
70 
71     virtual HRESULT STDMETHODCALLTYPE Clone(IStream **);
72 
73     virtual HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove
74                                          , DWORD dwOrigin
75                                          , ULARGE_INTEGER* lpNewFilePointer);
76 
77     virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg
78                                          , DWORD grfStatFlag);
79 };
80 
81 /**
82  * A minimal read-only IStream implementation which wraps an SkStream.
83  */
84 class SkIStream : public SkBaseIStream {
85 private:
86     SkStream *fSkStream;
87     const bool fDeleteOnRelease;
88     ULARGE_INTEGER fLocation;
89 
90     SkIStream(SkStream* stream, bool fDeleteOnRelease);
91     virtual ~SkIStream();
92 
93 public:
94     HRESULT static CreateFromSkStream(SkStream* stream
95                                     , bool fDeleteOnRelease
96                                     , IStream ** ppStream);
97 
98     virtual HRESULT STDMETHODCALLTYPE Read(void* pv, ULONG cb, ULONG* pcbRead);
99 
100     virtual HRESULT STDMETHODCALLTYPE Write(void const* pv
101                                           , ULONG cb
102                                           , ULONG* pcbWritten);
103 
104     virtual HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove
105                                          , DWORD dwOrigin
106                                          , ULARGE_INTEGER* lpNewFilePointer);
107 
108     virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg
109                                          , DWORD grfStatFlag);
110 };
111 
112 /**
113  * A minimal write-only IStream implementation which wraps an SkWIStream.
114  */
115 class SkWIStream : public SkBaseIStream {
116 private:
117     SkWStream *fSkWStream;
118 
119     SkWIStream(SkWStream* stream);
120     virtual ~SkWIStream();
121 
122 public:
123     HRESULT static CreateFromSkWStream(SkWStream* stream, IStream ** ppStream);
124 
125     virtual HRESULT STDMETHODCALLTYPE Write(void const* pv
126                                           , ULONG cb
127                                           , ULONG* pcbWritten);
128 
129     virtual HRESULT STDMETHODCALLTYPE Commit(DWORD);
130 
131     virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg
132                                          , DWORD grfStatFlag);
133 };
134 
135 #endif  // SK_BUILD_FOR_WIN
136 #endif  // SkIStream_DEFINED
137