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" 12 #ifdef SK_BUILD_FOR_WIN 13 14 #include "SkLeanWindows.h" 15 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 22 #define SK_TRACEHR(_hr, _msg) sk_ignore_unused_variable(_hr) 23 #endif 24 25 #define HR_GENERAL(_ex, _msg, _ret) {\ 26 HRESULT _hr = _ex;\ 27 if (FAILED(_hr)) {\ 28 SK_TRACEHR(_hr, _msg);\ 29 return _ret;\ 30 }\ 31 } 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. 42 The HRN variants will return nullptr when FAILED. 43 The HRV variants will simply return when FAILED. 44 The HRZ variants will return 0 when FAILED. 45 */ 46 #define HR(ex) HR_GENERAL(ex, nullptr, _hr) 47 #define HRM(ex, msg) HR_GENERAL(ex, msg, _hr) 48 49 #define HRB(ex) HR_GENERAL(ex, nullptr, false) 50 #define HRBM(ex, msg) HR_GENERAL(ex, msg, false) 51 52 #define HRN(ex) HR_GENERAL(ex, nullptr, nullptr) 53 #define HRNM(ex, msg) HR_GENERAL(ex, msg, nullptr) 54 55 #define HRV(ex) HR_GENERAL(ex, nullptr, ) 56 #define HRVM(ex, msg) HR_GENERAL(ex, msg, ) 57 58 #define HRZ(ex) HR_GENERAL(ex, nullptr, 0) 59 #define HRZM(ex, msg) HR_GENERAL(ex, msg, 0) 60 //@} 61 #endif // SK_BUILD_FOR_WIN 62 #endif // SkHRESULT_DEFINED 63