diff options
author | 2016-06-16 15:31:42 -0700 | |
---|---|---|
committer | 2016-06-16 15:31:43 -0700 | |
commit | 2853f007289997c27e736243913bfb43cf9b16bb (patch) | |
tree | aa2b073f16a2390176c0c46f218472216fd99b2b /src | |
parent | 73c7c3c2346033e0b5df123f1a6b488015443a55 (diff) |
Move headers in include/utils/win to src/utils/win.
These headers are not intended for external use and are only used in src.
Review-Url: https://codereview.chromium.org/2070983002
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/win/SkAutoCoInitialize.h | 31 | ||||
-rw-r--r-- | src/utils/win/SkHRESULT.h | 62 | ||||
-rw-r--r-- | src/utils/win/SkIStream.h | 135 | ||||
-rw-r--r-- | src/utils/win/SkTScopedComPtr.h | 81 |
4 files changed, 309 insertions, 0 deletions
diff --git a/src/utils/win/SkAutoCoInitialize.h b/src/utils/win/SkAutoCoInitialize.h new file mode 100644 index 0000000000..f11cf856c5 --- /dev/null +++ b/src/utils/win/SkAutoCoInitialize.h @@ -0,0 +1,31 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkAutoCo_DEFINED +#define SkAutoCo_DEFINED + +#include "SkTypes.h" + +#ifdef SK_BUILD_FOR_WIN + +#include "SkLeanWindows.h" + +/** + * An instance of this class initializes COM on creation + * and closes the COM library on destruction. + */ +class SkAutoCoInitialize : SkNoncopyable { +private: + HRESULT fHR; +public: + SkAutoCoInitialize(); + ~SkAutoCoInitialize(); + bool succeeded(); +}; + +#endif // SK_BUILD_FOR_WIN +#endif // SkAutoCo_DEFINED diff --git a/src/utils/win/SkHRESULT.h b/src/utils/win/SkHRESULT.h new file mode 100644 index 0000000000..a9cd8c408b --- /dev/null +++ b/src/utils/win/SkHRESULT.h @@ -0,0 +1,62 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkHRESULT_DEFINED +#define SkHRESULT_DEFINED + +#include "SkTypes.h" +#ifdef SK_BUILD_FOR_WIN + +#include "SkLeanWindows.h" + +void SkTraceHR(const char* file, unsigned long line, + HRESULT hr, const char* msg); + +#ifdef SK_DEBUG +#define SK_TRACEHR(_hr, _msg) SkTraceHR(__FILE__, __LINE__, _hr, _msg) +#else +#define SK_TRACEHR(_hr, _msg) sk_ignore_unused_variable(_hr) +#endif + +#define HR_GENERAL(_ex, _msg, _ret) {\ + HRESULT _hr = _ex;\ + if (FAILED(_hr)) {\ + SK_TRACEHR(_hr, _msg);\ + return _ret;\ + }\ +} + +//@{ +/** +These macros are for reporting HRESULT errors. +The expression will be evaluated. +If the resulting HRESULT SUCCEEDED then execution will continue normally. +If the HRESULT FAILED then the macro will return from the current function. +In variants ending with 'M' the given message will be traced when FAILED. +The HR variants will return the HRESULT when FAILED. +The HRB variants will return false when FAILED. +The HRN variants will return nullptr when FAILED. +The HRV variants will simply return when FAILED. +The HRZ variants will return 0 when FAILED. +*/ +#define HR(ex) HR_GENERAL(ex, nullptr, _hr) +#define HRM(ex, msg) HR_GENERAL(ex, msg, _hr) + +#define HRB(ex) HR_GENERAL(ex, nullptr, false) +#define HRBM(ex, msg) HR_GENERAL(ex, msg, false) + +#define HRN(ex) HR_GENERAL(ex, nullptr, nullptr) +#define HRNM(ex, msg) HR_GENERAL(ex, msg, nullptr) + +#define HRV(ex) HR_GENERAL(ex, nullptr, ) +#define HRVM(ex, msg) HR_GENERAL(ex, msg, ) + +#define HRZ(ex) HR_GENERAL(ex, nullptr, 0) +#define HRZM(ex, msg) HR_GENERAL(ex, msg, 0) +//@} +#endif // SK_BUILD_FOR_WIN +#endif // SkHRESULT_DEFINED diff --git a/src/utils/win/SkIStream.h b/src/utils/win/SkIStream.h new file mode 100644 index 0000000000..a3315c121d --- /dev/null +++ b/src/utils/win/SkIStream.h @@ -0,0 +1,135 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + + +#ifndef SkIStream_DEFINED +#define SkIStream_DEFINED + +#include "SkTypes.h" + +#ifdef SK_BUILD_FOR_WIN + +#include "SkLeanWindows.h" +#include <ole2.h> + +class SkStream; +class SkWStream; + +/** + * A bare IStream implementation which properly reference counts + * but returns E_NOTIMPL for all ISequentialStream and IStream methods. + */ +class SkBaseIStream : public IStream { +private: + LONG _refcount; + +protected: + explicit SkBaseIStream(); + virtual ~SkBaseIStream(); + +public: + virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid + , void ** ppvObject); + virtual ULONG STDMETHODCALLTYPE AddRef(void); + virtual ULONG STDMETHODCALLTYPE Release(void); + + // ISequentialStream Interface +public: + virtual HRESULT STDMETHODCALLTYPE Read(void* pv, ULONG cb, ULONG* pcbRead); + + virtual HRESULT STDMETHODCALLTYPE Write(void const* pv + , ULONG cb + , ULONG* pcbWritten); + + // IStream Interface +public: + virtual HRESULT STDMETHODCALLTYPE SetSize(ULARGE_INTEGER); + + virtual HRESULT STDMETHODCALLTYPE CopyTo(IStream* + , ULARGE_INTEGER + , ULARGE_INTEGER* + , ULARGE_INTEGER*); + + virtual HRESULT STDMETHODCALLTYPE Commit(DWORD); + + virtual HRESULT STDMETHODCALLTYPE Revert(void); + + virtual HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER + , ULARGE_INTEGER + , DWORD); + + virtual HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER + , ULARGE_INTEGER + , DWORD); + + virtual HRESULT STDMETHODCALLTYPE Clone(IStream **); + + virtual HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove + , DWORD dwOrigin + , ULARGE_INTEGER* lpNewFilePointer); + + virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg + , DWORD grfStatFlag); +}; + +/** + * A minimal read-only IStream implementation which wraps an SkStream. + */ +class SkIStream : public SkBaseIStream { +private: + SkStream *fSkStream; + const bool fDeleteOnRelease; + ULARGE_INTEGER fLocation; + + SkIStream(SkStream* stream, bool fDeleteOnRelease); + virtual ~SkIStream(); + +public: + HRESULT static CreateFromSkStream(SkStream* stream + , bool fDeleteOnRelease + , IStream ** ppStream); + + virtual HRESULT STDMETHODCALLTYPE Read(void* pv, ULONG cb, ULONG* pcbRead); + + virtual HRESULT STDMETHODCALLTYPE Write(void const* pv + , ULONG cb + , ULONG* pcbWritten); + + virtual HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove + , DWORD dwOrigin + , ULARGE_INTEGER* lpNewFilePointer); + + virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg + , DWORD grfStatFlag); +}; + +/** + * A minimal write-only IStream implementation which wraps an SkWIStream. + */ +class SkWIStream : public SkBaseIStream { +private: + SkWStream *fSkWStream; + + SkWIStream(SkWStream* stream); + virtual ~SkWIStream(); + +public: + HRESULT static CreateFromSkWStream(SkWStream* stream, IStream ** ppStream); + + virtual HRESULT STDMETHODCALLTYPE Write(void const* pv + , ULONG cb + , ULONG* pcbWritten); + + virtual HRESULT STDMETHODCALLTYPE Commit(DWORD); + + virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg + , DWORD grfStatFlag); +}; + +#endif // SK_BUILD_FOR_WIN +#endif // SkIStream_DEFINED diff --git a/src/utils/win/SkTScopedComPtr.h b/src/utils/win/SkTScopedComPtr.h new file mode 100644 index 0000000000..5410f5c992 --- /dev/null +++ b/src/utils/win/SkTScopedComPtr.h @@ -0,0 +1,81 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkTScopedComPtr_DEFINED +#define SkTScopedComPtr_DEFINED + +#include "SkLeanWindows.h" + +#ifdef SK_BUILD_FOR_WIN + +template<typename T> +class SkBlockComRef : public T { +private: + virtual ULONG STDMETHODCALLTYPE AddRef(void) = 0; + virtual ULONG STDMETHODCALLTYPE Release(void) = 0; +}; + +template<typename T> T* SkRefComPtr(T* ptr) { + ptr->AddRef(); + return ptr; +} + +template<typename T> T* SkSafeRefComPtr(T* ptr) { + if (ptr) { + ptr->AddRef(); + } + return ptr; +} + +template<typename T> +class SkTScopedComPtr : SkNoncopyable { +private: + T *fPtr; + +public: + explicit SkTScopedComPtr(T *ptr = nullptr) : fPtr(ptr) { } + + ~SkTScopedComPtr() { this->reset();} + + T &operator*() const { SkASSERT(fPtr != nullptr); return *fPtr; } + + explicit operator bool() const { return fPtr != nullptr; } + + SkBlockComRef<T> *operator->() const { return static_cast<SkBlockComRef<T>*>(fPtr); } + + /** + * Returns the address of the underlying pointer. + * This is dangerous -- it breaks encapsulation and the reference escapes. + * Must only be used on instances currently pointing to NULL, + * and only to initialize the instance. + */ + T **operator&() { SkASSERT(fPtr == nullptr); return &fPtr; } + + T *get() const { return fPtr; } + + void reset() { + if (this->fPtr) { + this->fPtr->Release(); + this->fPtr = nullptr; + } + } + + void swap(SkTScopedComPtr<T>& that) { + T* temp = this->fPtr; + this->fPtr = that.fPtr; + that.fPtr = temp; + } + + T* release() { + T* temp = this->fPtr; + this->fPtr = nullptr; + return temp; + } +}; + +#endif // SK_BUILD_FOR_WIN +#endif // SkTScopedComPtr_DEFINED |