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 #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); 49 50 virtual HRESULT STDMETHODCALLTYPE CopyTo(IStream* 51 , ULARGE_INTEGER 52 , ULARGE_INTEGER* 53 , ULARGE_INTEGER*); 54 55 virtual HRESULT STDMETHODCALLTYPE Commit(DWORD); 56 57 virtual HRESULT STDMETHODCALLTYPE Revert(void); 58 59 virtual HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER 60 , ULARGE_INTEGER 61 , DWORD); 62 63 virtual HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER 64 , ULARGE_INTEGER 65 , DWORD); 66 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 SkStream. 79 */ 80 class SkIStream : public SkBaseIStream { 81 private: 82 SkStream *fSkStream; 83 const bool fDeleteOnRelease; 84 ULARGE_INTEGER fLocation; 85 86 SkIStream(SkStream* stream, bool fDeleteOnRelease); 87 virtual ~SkIStream(); 88 89 public: 90 HRESULT static CreateFromSkStream(SkStream* stream 91 , bool fDeleteOnRelease 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 125 virtual HRESULT STDMETHODCALLTYPE Commit(DWORD); 126 127 virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg 128 , DWORD grfStatFlag); 129 }; 130 131 #endif 132