blob: 80d046dfdc51137b582c724afd0b4f4f1ab52d42 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkTypes.h"
halcanary0cbe7ee2015-12-01 09:02:49 -080012#ifdef SK_BUILD_FOR_WIN
bungeman@google.comb29c8832011-10-10 13:19:10 +000013
Ben Wagnerab6eefe2019-05-20 11:02:49 -040014#include "src/core/SkLeanWindows.h"
halcanary4dbbd042016-06-07 17:21:10 -070015
bungeman@google.comb29c8832011-10-10 13:19:10 +000016void 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
thakis573ce202015-12-07 10:41:36 -080022#define SK_TRACEHR(_hr, _msg) sk_ignore_unused_variable(_hr)
bungeman@google.comb29c8832011-10-10 13:19:10 +000023#endif
24
Ben Wagner0b46a392019-02-04 13:50:02 -050025#define HR_GENERAL(_ex, _msg, _ret) do {\
bungeman@google.comb29c8832011-10-10 13:19:10 +000026 HRESULT _hr = _ex;\
27 if (FAILED(_hr)) {\
28 SK_TRACEHR(_hr, _msg);\
29 return _ret;\
30 }\
Ben Wagner0b46a392019-02-04 13:50:02 -050031} while(false)
bungeman@google.comb29c8832011-10-10 13:19:10 +000032
33//@{
34/**
35These macros are for reporting HRESULT errors.
36The expression will be evaluated.
37If the resulting HRESULT SUCCEEDED then execution will continue normally.
38If the HRESULT FAILED then the macro will return from the current function.
39In variants ending with 'M' the given message will be traced when FAILED.
40The HR variants will return the HRESULT when FAILED.
41The HRB variants will return false when FAILED.
bungeman2853f002016-06-16 15:31:42 -070042The HRN variants will return nullptr when FAILED.
bungeman@google.comb29c8832011-10-10 13:19:10 +000043The HRV variants will simply return when FAILED.
bungeman@google.com27f74aa2013-10-08 21:32:15 +000044The HRZ variants will return 0 when FAILED.
bungeman@google.comb29c8832011-10-10 13:19:10 +000045*/
bungeman2853f002016-06-16 15:31:42 -070046#define HR(ex) HR_GENERAL(ex, nullptr, _hr)
bungeman@google.comb29c8832011-10-10 13:19:10 +000047#define HRM(ex, msg) HR_GENERAL(ex, msg, _hr)
48
bungeman2853f002016-06-16 15:31:42 -070049#define HRB(ex) HR_GENERAL(ex, nullptr, false)
bungeman@google.comb29c8832011-10-10 13:19:10 +000050#define HRBM(ex, msg) HR_GENERAL(ex, msg, false)
51
bungeman2853f002016-06-16 15:31:42 -070052#define HRN(ex) HR_GENERAL(ex, nullptr, nullptr)
53#define HRNM(ex, msg) HR_GENERAL(ex, msg, nullptr)
bungeman@google.come8f05922012-08-16 16:13:40 +000054
bungeman2853f002016-06-16 15:31:42 -070055#define HRV(ex) HR_GENERAL(ex, nullptr, )
bungeman@google.comb29c8832011-10-10 13:19:10 +000056#define HRVM(ex, msg) HR_GENERAL(ex, msg, )
bungeman@google.com27f74aa2013-10-08 21:32:15 +000057
bungeman2853f002016-06-16 15:31:42 -070058#define HRZ(ex) HR_GENERAL(ex, nullptr, 0)
bungeman@google.com27f74aa2013-10-08 21:32:15 +000059#define HRZM(ex, msg) HR_GENERAL(ex, msg, 0)
bungeman@google.comb29c8832011-10-10 13:19:10 +000060//@}
halcanary0cbe7ee2015-12-01 09:02:49 -080061#endif // SK_BUILD_FOR_WIN
62#endif // SkHRESULT_DEFINED