diff options
author | 2011-10-10 13:19:10 +0000 | |
---|---|---|
committer | 2011-10-10 13:19:10 +0000 | |
commit | b29c883fb46ac6099440d82ac57b86d25386daed (patch) | |
tree | 2782e96a58d3dea8b2299d8d980eeeedbf08c0a8 /include/utils/win | |
parent | 1c04bf97b6245b55ac58c2f3902f8ca95ca91c3d (diff) |
Add xps device to skia.
http://codereview.appspot.com/5076041/
git-svn-id: http://skia.googlecode.com/svn/trunk@2437 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/utils/win')
-rw-r--r-- | include/utils/win/SkHRESULT.h | 50 | ||||
-rw-r--r-- | include/utils/win/SkTScopedComPtr.h | 25 |
2 files changed, 73 insertions, 2 deletions
diff --git a/include/utils/win/SkHRESULT.h b/include/utils/win/SkHRESULT.h new file mode 100644 index 0000000000..ff596c71a9 --- /dev/null +++ b/include/utils/win/SkHRESULT.h @@ -0,0 +1,50 @@ +/* + * 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" + +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) _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 HRV variants will simply return when FAILED. +*/ +#define HR(ex) HR_GENERAL(ex, NULL, _hr) +#define HRM(ex, msg) HR_GENERAL(ex, msg, _hr) + +#define HRB(ex) HR_GENERAL(ex, NULL, false) +#define HRBM(ex, msg) HR_GENERAL(ex, msg, false) + +#define HRV(ex) HR_GENERAL(ex, NULL, ) +#define HRVM(ex, msg) HR_GENERAL(ex, msg, ) +//@} +#endif diff --git a/include/utils/win/SkTScopedComPtr.h b/include/utils/win/SkTScopedComPtr.h index e0d1634cb8..b9be037d8b 100644 --- a/include/utils/win/SkTScopedComPtr.h +++ b/include/utils/win/SkTScopedComPtr.h @@ -6,13 +6,20 @@ * found in the LICENSE file. */ - #ifndef SkSkTScopedPtr_DEFINED #define SkSkTScopedPtr_DEFINED +#include "SkTypes.h" #include "SkTemplates.h" template<typename T> +class SkBlockComRef : public T { +private: + virtual ULONG STDMETHODCALLTYPE AddRef(void) = 0; + virtual ULONG STDMETHODCALLTYPE Release(void) = 0; +}; + +template<typename T> class SkTScopedComPtr : SkNoncopyable { private: T *fPtr; @@ -23,7 +30,9 @@ public: this->reset(); } T &operator*() const { return *fPtr; } - T *operator->() const { return fPtr; } + 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. @@ -38,6 +47,18 @@ public: this->fPtr = NULL; } } + + void swap(SkTScopedComPtr<T>& that) { + T* temp = this->fPtr; + this->fPtr = that.fPtr; + that.fPtr = temp; + } + + T* release() { + T* temp = this->fPtr; + this->fPtr = NULL; + return temp; + } }; #endif |