bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkHRESULT_DEFINED |
| 9 | #define SkHRESULT_DEFINED |
| 10 | |
| 11 | #include "SkTypes.h" |
halcanary | 0cbe7ee | 2015-12-01 09:02:49 -0800 | [diff] [blame^] | 12 | #ifdef SK_BUILD_FOR_WIN |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 13 | |
| 14 | void SkTraceHR(const char* file, unsigned long line, |
| 15 | HRESULT hr, const char* msg); |
| 16 | |
| 17 | #ifdef SK_DEBUG |
| 18 | #define SK_TRACEHR(_hr, _msg) SkTraceHR(__FILE__, __LINE__, _hr, _msg) |
| 19 | #else |
| 20 | #define SK_TRACEHR(_hr, _msg) _hr |
| 21 | #endif |
| 22 | |
| 23 | #define HR_GENERAL(_ex, _msg, _ret) {\ |
| 24 | HRESULT _hr = _ex;\ |
| 25 | if (FAILED(_hr)) {\ |
| 26 | SK_TRACEHR(_hr, _msg);\ |
| 27 | return _ret;\ |
| 28 | }\ |
| 29 | } |
| 30 | |
| 31 | //@{ |
| 32 | /** |
| 33 | These macros are for reporting HRESULT errors. |
| 34 | The expression will be evaluated. |
| 35 | If the resulting HRESULT SUCCEEDED then execution will continue normally. |
| 36 | If the HRESULT FAILED then the macro will return from the current function. |
| 37 | In variants ending with 'M' the given message will be traced when FAILED. |
| 38 | The HR variants will return the HRESULT when FAILED. |
| 39 | The HRB variants will return false when FAILED. |
bungeman@google.com | e8f0592 | 2012-08-16 16:13:40 +0000 | [diff] [blame] | 40 | The HRN variants will return NULL when FAILED. |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 41 | The HRV variants will simply return when FAILED. |
bungeman@google.com | 27f74aa | 2013-10-08 21:32:15 +0000 | [diff] [blame] | 42 | The HRZ variants will return 0 when FAILED. |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 43 | */ |
| 44 | #define HR(ex) HR_GENERAL(ex, NULL, _hr) |
| 45 | #define HRM(ex, msg) HR_GENERAL(ex, msg, _hr) |
| 46 | |
| 47 | #define HRB(ex) HR_GENERAL(ex, NULL, false) |
| 48 | #define HRBM(ex, msg) HR_GENERAL(ex, msg, false) |
| 49 | |
bungeman@google.com | e8f0592 | 2012-08-16 16:13:40 +0000 | [diff] [blame] | 50 | #define HRN(ex) HR_GENERAL(ex, NULL, NULL) |
| 51 | #define HRNM(ex, msg) HR_GENERAL(ex, msg, NULL) |
| 52 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 53 | #define HRV(ex) HR_GENERAL(ex, NULL, ) |
| 54 | #define HRVM(ex, msg) HR_GENERAL(ex, msg, ) |
bungeman@google.com | 27f74aa | 2013-10-08 21:32:15 +0000 | [diff] [blame] | 55 | |
| 56 | #define HRZ(ex) HR_GENERAL(ex, NULL, 0) |
| 57 | #define HRZM(ex, msg) HR_GENERAL(ex, msg, 0) |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 58 | //@} |
halcanary | 0cbe7ee | 2015-12-01 09:02:49 -0800 | [diff] [blame^] | 59 | #endif // SK_BUILD_FOR_WIN |
| 60 | #endif // SkHRESULT_DEFINED |