1b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com/* 2b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com * Copyright 2011 Google Inc. 3b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com * 4b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com * Use of this source code is governed by a BSD-style license that can be 5b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com * found in the LICENSE file. 6b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com */ 7b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com 8b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#ifndef SkHRESULT_DEFINED 9b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#define SkHRESULT_DEFINED 10b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com 11b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#include "SkTypes.h" 120cbe7ee765cf72f15e6ca10b308676aa077fb3e2halcanary#ifdef SK_BUILD_FOR_WIN 13b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com 14b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.comvoid SkTraceHR(const char* file, unsigned long line, 15b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com HRESULT hr, const char* msg); 16b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com 17b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#ifdef SK_DEBUG 18b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#define SK_TRACEHR(_hr, _msg) SkTraceHR(__FILE__, __LINE__, _hr, _msg) 19b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#else 20573ce20f4298e0a83c36a106cde78f5442801f50thakis#define SK_TRACEHR(_hr, _msg) sk_ignore_unused_variable(_hr) 21b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#endif 22b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com 23b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#define HR_GENERAL(_ex, _msg, _ret) {\ 24b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com HRESULT _hr = _ex;\ 25b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com if (FAILED(_hr)) {\ 26b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com SK_TRACEHR(_hr, _msg);\ 27b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com return _ret;\ 28b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com }\ 29b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com} 30b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com 31b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com//@{ 32b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com/** 33b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.comThese macros are for reporting HRESULT errors. 34b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.comThe expression will be evaluated. 35b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.comIf the resulting HRESULT SUCCEEDED then execution will continue normally. 36b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.comIf the HRESULT FAILED then the macro will return from the current function. 37b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.comIn variants ending with 'M' the given message will be traced when FAILED. 38b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.comThe HR variants will return the HRESULT when FAILED. 39b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.comThe HRB variants will return false when FAILED. 40e8f0592ae8b37e94d99f49816eb22e9fafde6d86bungeman@google.comThe HRN variants will return NULL when FAILED. 41b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.comThe HRV variants will simply return when FAILED. 4227f74aab32123e6f021359061149966fa4ca5a62bungeman@google.comThe HRZ variants will return 0 when FAILED. 43b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com*/ 44b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#define HR(ex) HR_GENERAL(ex, NULL, _hr) 45b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#define HRM(ex, msg) HR_GENERAL(ex, msg, _hr) 46b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com 47b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#define HRB(ex) HR_GENERAL(ex, NULL, false) 48b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#define HRBM(ex, msg) HR_GENERAL(ex, msg, false) 49b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com 50e8f0592ae8b37e94d99f49816eb22e9fafde6d86bungeman@google.com#define HRN(ex) HR_GENERAL(ex, NULL, NULL) 51e8f0592ae8b37e94d99f49816eb22e9fafde6d86bungeman@google.com#define HRNM(ex, msg) HR_GENERAL(ex, msg, NULL) 52e8f0592ae8b37e94d99f49816eb22e9fafde6d86bungeman@google.com 53b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#define HRV(ex) HR_GENERAL(ex, NULL, ) 54b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com#define HRVM(ex, msg) HR_GENERAL(ex, msg, ) 5527f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com 5627f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com#define HRZ(ex) HR_GENERAL(ex, NULL, 0) 5727f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com#define HRZM(ex, msg) HR_GENERAL(ex, msg, 0) 58b29c883fb46ac6099440d82ac57b86d25386daedbungeman@google.com//@} 590cbe7ee765cf72f15e6ca10b308676aa077fb3e2halcanary#endif // SK_BUILD_FOR_WIN 600cbe7ee765cf72f15e6ca10b308676aa077fb3e2halcanary#endif // SkHRESULT_DEFINED 61