blob: 4f9d1bec796e11cd6612bd578f9fb2c143db8dd7 [file] [log] [blame]
bungeman@google.comb29c8832011-10-10 13:19:10 +00001/*
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
13void SkTraceHR(const char* file, unsigned long line,
14 HRESULT hr, const char* msg);
15
16#ifdef SK_DEBUG
17#define SK_TRACEHR(_hr, _msg) SkTraceHR(__FILE__, __LINE__, _hr, _msg)
18#else
19#define SK_TRACEHR(_hr, _msg) _hr
20#endif
21
22#define HR_GENERAL(_ex, _msg, _ret) {\
23 HRESULT _hr = _ex;\
24 if (FAILED(_hr)) {\
25 SK_TRACEHR(_hr, _msg);\
26 return _ret;\
27 }\
28}
29
30//@{
31/**
32These macros are for reporting HRESULT errors.
33The expression will be evaluated.
34If the resulting HRESULT SUCCEEDED then execution will continue normally.
35If the HRESULT FAILED then the macro will return from the current function.
36In variants ending with 'M' the given message will be traced when FAILED.
37The HR variants will return the HRESULT when FAILED.
38The HRB variants will return false when FAILED.
bungeman@google.come8f05922012-08-16 16:13:40 +000039The HRN variants will return NULL when FAILED.
bungeman@google.comb29c8832011-10-10 13:19:10 +000040The HRV variants will simply return when FAILED.
bungeman@google.com27f74aa2013-10-08 21:32:15 +000041The HRZ variants will return 0 when FAILED.
bungeman@google.comb29c8832011-10-10 13:19:10 +000042*/
43#define HR(ex) HR_GENERAL(ex, NULL, _hr)
44#define HRM(ex, msg) HR_GENERAL(ex, msg, _hr)
45
46#define HRB(ex) HR_GENERAL(ex, NULL, false)
47#define HRBM(ex, msg) HR_GENERAL(ex, msg, false)
48
bungeman@google.come8f05922012-08-16 16:13:40 +000049#define HRN(ex) HR_GENERAL(ex, NULL, NULL)
50#define HRNM(ex, msg) HR_GENERAL(ex, msg, NULL)
51
bungeman@google.comb29c8832011-10-10 13:19:10 +000052#define HRV(ex) HR_GENERAL(ex, NULL, )
53#define HRVM(ex, msg) HR_GENERAL(ex, msg, )
bungeman@google.com27f74aa2013-10-08 21:32:15 +000054
55#define HRZ(ex) HR_GENERAL(ex, NULL, 0)
56#define HRZM(ex, msg) HR_GENERAL(ex, msg, 0)
bungeman@google.comb29c8832011-10-10 13:19:10 +000057//@}
58#endif