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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/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 | |
Ben Wagner | ab6eefe | 2019-05-20 11:02:49 -0400 | [diff] [blame] | 14 | #include "src/core/SkLeanWindows.h" |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 15 | |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 16 | void SkTraceHR(const char* file, unsigned long line, |
| 17 | HRESULT hr, const char* msg); |
| 18 | |
| 19 | #ifdef SK_DEBUG |
| 20 | #define SK_TRACEHR(_hr, _msg) SkTraceHR(__FILE__, __LINE__, _hr, _msg) |
| 21 | #else |
thakis | 573ce20 | 2015-12-07 10:41:36 -0800 | [diff] [blame] | 22 | #define SK_TRACEHR(_hr, _msg) sk_ignore_unused_variable(_hr) |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 23 | #endif |
| 24 | |
Ben Wagner | 0b46a39 | 2019-02-04 13:50:02 -0500 | [diff] [blame] | 25 | #define HR_GENERAL(_ex, _msg, _ret) do {\ |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 26 | HRESULT _hr = _ex;\ |
| 27 | if (FAILED(_hr)) {\ |
| 28 | SK_TRACEHR(_hr, _msg);\ |
| 29 | return _ret;\ |
| 30 | }\ |
Ben Wagner | 0b46a39 | 2019-02-04 13:50:02 -0500 | [diff] [blame] | 31 | } while(false) |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 32 | |
| 33 | //@{ |
| 34 | /** |
| 35 | These macros are for reporting HRESULT errors. |
| 36 | The expression will be evaluated. |
| 37 | If the resulting HRESULT SUCCEEDED then execution will continue normally. |
| 38 | If the HRESULT FAILED then the macro will return from the current function. |
| 39 | In variants ending with 'M' the given message will be traced when FAILED. |
| 40 | The HR variants will return the HRESULT when FAILED. |
| 41 | The HRB variants will return false when FAILED. |
bungeman | 2853f00 | 2016-06-16 15:31:42 -0700 | [diff] [blame] | 42 | The HRN variants will return nullptr when FAILED. |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 43 | The HRV variants will simply return when FAILED. |
bungeman@google.com | 27f74aa | 2013-10-08 21:32:15 +0000 | [diff] [blame] | 44 | The HRZ variants will return 0 when FAILED. |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 45 | */ |
bungeman | 2853f00 | 2016-06-16 15:31:42 -0700 | [diff] [blame] | 46 | #define HR(ex) HR_GENERAL(ex, nullptr, _hr) |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 47 | #define HRM(ex, msg) HR_GENERAL(ex, msg, _hr) |
| 48 | |
bungeman | 2853f00 | 2016-06-16 15:31:42 -0700 | [diff] [blame] | 49 | #define HRB(ex) HR_GENERAL(ex, nullptr, false) |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 50 | #define HRBM(ex, msg) HR_GENERAL(ex, msg, false) |
| 51 | |
bungeman | 2853f00 | 2016-06-16 15:31:42 -0700 | [diff] [blame] | 52 | #define HRN(ex) HR_GENERAL(ex, nullptr, nullptr) |
| 53 | #define HRNM(ex, msg) HR_GENERAL(ex, msg, nullptr) |
bungeman@google.com | e8f0592 | 2012-08-16 16:13:40 +0000 | [diff] [blame] | 54 | |
bungeman | 2853f00 | 2016-06-16 15:31:42 -0700 | [diff] [blame] | 55 | #define HRV(ex) HR_GENERAL(ex, nullptr, ) |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 56 | #define HRVM(ex, msg) HR_GENERAL(ex, msg, ) |
bungeman@google.com | 27f74aa | 2013-10-08 21:32:15 +0000 | [diff] [blame] | 57 | |
bungeman | 2853f00 | 2016-06-16 15:31:42 -0700 | [diff] [blame] | 58 | #define HRZ(ex) HR_GENERAL(ex, nullptr, 0) |
bungeman@google.com | 27f74aa | 2013-10-08 21:32:15 +0000 | [diff] [blame] | 59 | #define HRZM(ex, msg) HR_GENERAL(ex, msg, 0) |
bungeman@google.com | b29c883 | 2011-10-10 13:19:10 +0000 | [diff] [blame] | 60 | //@} |
halcanary | 0cbe7ee | 2015-12-01 09:02:49 -0800 | [diff] [blame] | 61 | #endif // SK_BUILD_FOR_WIN |
| 62 | #endif // SkHRESULT_DEFINED |