1 /******************************************************************************
2     QtAV:  Multimedia framework based on Qt and FFmpeg
3     Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
4 
5 *   This file is part of QtAV (from 2015)
6 
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public
9     License as published by the Free Software Foundation; either
10     version 2.1 of the License, or (at your option) any later version.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Lesser General Public License for more details.
16 
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 ******************************************************************************/
21 
22 #ifndef QTAV_DIRECTXHELPER_H
23 #define QTAV_DIRECTXHELPER_H
24 
25 #include <QtCore/qglobal.h>
26 #ifndef Q_OS_WINRT
27 #include <d3d9.h>
28 #endif
29 
30 namespace QtAV {
31 
32 #ifndef DX_LOG_COMPONENT
33 #define DX_LOG_COMPONENT "DirectX"
34 #endif //DX_LOG_COMPONENT
35 #define DX_ENSURE(f, ...) DX_CHECK(f, return __VA_ARGS__;)
36 #define DX_WARN(f) DX_CHECK(f)
37 #define DX_ENSURE_OK(f, ...) DX_CHECK(f, return __VA_ARGS__;)
38 #define DX_CHECK(f, ...) \
39     do { \
40         HRESULT hr = f; \
41         if (FAILED(hr)) { \
42             qWarning() << QString::fromLatin1(DX_LOG_COMPONENT " error@%1. " #f ": (0x%2) %3").arg(__LINE__).arg(hr, 0, 16).arg(qt_error_string(hr)); \
43             __VA_ARGS__ \
44         } \
45     } while (0)
46 
47 
SafeRelease(T ** ppT)48 template <class T> void SafeRelease(T **ppT) {
49   if (*ppT) {
50     (*ppT)->Release();
51     *ppT = NULL;
52   }
53 }
54 
55 namespace DXHelper {
56 const char* vendorName(unsigned id);
57 
58 #ifndef Q_OS_WINRT
59 IDirect3DDevice9* CreateDevice9Ex(HINSTANCE dll, IDirect3D9Ex **d3d9ex, D3DADAPTER_IDENTIFIER9* d3dai = NULL);
60 IDirect3DDevice9* CreateDevice9(HINSTANCE dll, IDirect3D9 **d3d9, D3DADAPTER_IDENTIFIER9* d3dai = NULL);
61 #endif //Q_OS_WINRT
62 } //namespace DXHelper
63 
64 } //namespace QtAV
65 #endif //QTAV_DIRECTXHELPER_H
66