epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 10 | #ifndef SkIStream_DEFINED |
| 11 | #define SkIStream_DEFINED |
| 12 | |
| 13 | #define WIN32_LEAN_AND_MEAN |
| 14 | #include <Windows.h> |
| 15 | #include <ole2.h> |
| 16 | |
| 17 | class SkStream; |
| 18 | class SkWStream; |
| 19 | |
| 20 | /** |
| 21 | * A bare IStream implementation which properly reference counts |
| 22 | * but returns E_NOTIMPL for all ISequentialStream and IStream methods. |
| 23 | */ |
| 24 | class SkBaseIStream : public IStream { |
| 25 | private: |
| 26 | LONG _refcount; |
| 27 | |
| 28 | protected: |
| 29 | explicit SkBaseIStream(); |
| 30 | virtual ~SkBaseIStream(); |
| 31 | |
| 32 | public: |
| 33 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid |
| 34 | , void ** ppvObject); |
| 35 | virtual ULONG STDMETHODCALLTYPE AddRef(void); |
| 36 | virtual ULONG STDMETHODCALLTYPE Release(void); |
| 37 | |
| 38 | // ISequentialStream Interface |
| 39 | public: |
| 40 | virtual HRESULT STDMETHODCALLTYPE Read(void* pv, ULONG cb, ULONG* pcbRead); |
| 41 | |
| 42 | virtual HRESULT STDMETHODCALLTYPE Write(void const* pv |
| 43 | , ULONG cb |
| 44 | , ULONG* pcbWritten); |
| 45 | |
| 46 | // IStream Interface |
| 47 | public: |
| 48 | virtual HRESULT STDMETHODCALLTYPE SetSize(ULARGE_INTEGER); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 49 | |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 50 | virtual HRESULT STDMETHODCALLTYPE CopyTo(IStream* |
| 51 | , ULARGE_INTEGER |
| 52 | , ULARGE_INTEGER* |
| 53 | , ULARGE_INTEGER*); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 54 | |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 55 | virtual HRESULT STDMETHODCALLTYPE Commit(DWORD); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 56 | |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 57 | virtual HRESULT STDMETHODCALLTYPE Revert(void); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 58 | |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 59 | virtual HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER |
| 60 | , ULARGE_INTEGER |
| 61 | , DWORD); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 62 | |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 63 | virtual HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER |
| 64 | , ULARGE_INTEGER |
| 65 | , DWORD); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 66 | |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 67 | virtual HRESULT STDMETHODCALLTYPE Clone(IStream **); |
| 68 | |
| 69 | virtual HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove |
| 70 | , DWORD dwOrigin |
| 71 | , ULARGE_INTEGER* lpNewFilePointer); |
| 72 | |
| 73 | virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg |
| 74 | , DWORD grfStatFlag); |
| 75 | }; |
| 76 | |
| 77 | /** |
| 78 | * A minimal read-only IStream implementation which wraps an SkIStream. |
| 79 | */ |
| 80 | class SkIStream : public SkBaseIStream { |
| 81 | private: |
| 82 | SkStream *fSkStream; |
| 83 | bool fUnrefOnRelease; |
bungeman@google.com | 6015792 | 2011-08-13 00:06:17 +0000 | [diff] [blame] | 84 | ULARGE_INTEGER fLocation; |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 85 | |
| 86 | SkIStream(SkStream* stream, bool unrefOnRelease); |
| 87 | virtual ~SkIStream(); |
| 88 | |
| 89 | public: |
| 90 | HRESULT static CreateFromSkStream(SkStream* stream |
| 91 | , bool unrefOnRelease |
| 92 | , IStream ** ppStream); |
| 93 | |
| 94 | virtual HRESULT STDMETHODCALLTYPE Read(void* pv, ULONG cb, ULONG* pcbRead); |
| 95 | |
| 96 | virtual HRESULT STDMETHODCALLTYPE Write(void const* pv |
| 97 | , ULONG cb |
| 98 | , ULONG* pcbWritten); |
| 99 | |
| 100 | virtual HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove |
| 101 | , DWORD dwOrigin |
| 102 | , ULARGE_INTEGER* lpNewFilePointer); |
| 103 | |
| 104 | virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg |
| 105 | , DWORD grfStatFlag); |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * A minimal write-only IStream implementation which wraps an SkWIStream. |
| 110 | */ |
| 111 | class SkWIStream : public SkBaseIStream { |
| 112 | private: |
| 113 | SkWStream *fSkWStream; |
| 114 | |
| 115 | SkWIStream(SkWStream* stream); |
| 116 | virtual ~SkWIStream(); |
| 117 | |
| 118 | public: |
| 119 | HRESULT static CreateFromSkWStream(SkWStream* stream, IStream ** ppStream); |
| 120 | |
| 121 | virtual HRESULT STDMETHODCALLTYPE Write(void const* pv |
| 122 | , ULONG cb |
| 123 | , ULONG* pcbWritten); |
| 124 | |
bungeman@google.com | 14fc321 | 2011-08-01 20:41:53 +0000 | [diff] [blame] | 125 | virtual HRESULT STDMETHODCALLTYPE Commit(DWORD); |
| 126 | |
bungeman@google.com | 9df621d | 2011-06-23 21:43:52 +0000 | [diff] [blame] | 127 | virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg |
| 128 | , DWORD grfStatFlag); |
| 129 | }; |
| 130 | |
| 131 | #endif |