1 // 2 // Copyright (c) 2017 The Khronos Group Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 #ifndef __WRAPPERS_H 17 #define __WRAPPERS_H 18 19 #if defined(_WIN32) 20 #include <d3d9.h> 21 #if defined(__MINGW32__) 22 #include <rpcsal.h> 23 typedef unsigned char UINT8; 24 #define __out 25 #define __in 26 #define __inout 27 #define __out_bcount(size) 28 #define __out_bcount_opt(size) 29 #define __in_opt 30 #define __in_ecount(size) 31 #define __in_ecount_opt(size) 32 #define __out_opt 33 #define __out_ecount(size) 34 #define __out_ecount_opt(size) 35 #define __in_bcount_opt(size) 36 #define __inout_opt 37 #define __inout_bcount(size) 38 #define __in_bcount(size) 39 #define __deref_out 40 #endif 41 #include <dxvahd.h> 42 #include <tchar.h> 43 #endif 44 45 enum TDeviceStatus 46 { 47 DEVICE_NOTSUPPORTED, 48 DEVICE_PASS, 49 DEVICE_FAIL, 50 }; 51 52 class CDeviceWrapper { 53 public: 54 enum TAccelerationType 55 { 56 ACCELERATION_HW, 57 ACCELERATION_SW, 58 }; 59 60 CDeviceWrapper(); 61 virtual ~CDeviceWrapper(); 62 63 virtual bool AdapterNext() = 0; 64 virtual unsigned int AdapterIdx() const = 0; 65 virtual void *Device() const = 0; 66 virtual TDeviceStatus Status() const = 0; 67 virtual void *D3D() const = 0; 68 69 #if defined(_WIN32) 70 HWND WindowHandle() const; 71 #endif 72 int WindowWidth() const; 73 int WindowHeight() const; 74 void WindowInit(); 75 76 77 static TAccelerationType AccelerationType(); 78 static void AccelerationType(TAccelerationType accelerationTypeNew); 79 80 private: 81 static LPCTSTR WINDOW_TITLE; 82 static const int WINDOW_WIDTH; 83 static const int WINDOW_HEIGHT; 84 static TAccelerationType accelerationType; 85 86 #if defined(_WIN32) 87 HMODULE _hInstance; 88 HWND _hWnd; 89 #endif 90 91 void WindowDestroy(); 92 }; 93 94 class CSurfaceWrapper { 95 public: 96 CSurfaceWrapper(); 97 virtual ~CSurfaceWrapper(); 98 }; 99 100 #if defined(_WIN32) 101 // windows specific wrappers 102 class CD3D9Wrapper : public CDeviceWrapper { 103 public: 104 CD3D9Wrapper(); 105 ~CD3D9Wrapper(); 106 107 virtual bool AdapterNext(); 108 virtual unsigned int AdapterIdx() const; 109 virtual void *Device() const; 110 virtual TDeviceStatus Status() const; 111 virtual void *D3D() const; 112 113 private: 114 LPDIRECT3D9 _d3d9; 115 LPDIRECT3DDEVICE9 _d3dDevice; 116 D3DDISPLAYMODE _d3ddm; 117 D3DADAPTER_IDENTIFIER9 _adapter; 118 TDeviceStatus _status; 119 unsigned int _adapterIdx; 120 bool _adapterFound; 121 122 D3DFORMAT Format(); 123 D3DADAPTER_IDENTIFIER9 Adapter(); 124 int Init(); 125 void Destroy(); 126 }; 127 128 class CD3D9ExWrapper : public CDeviceWrapper { 129 public: 130 CD3D9ExWrapper(); 131 ~CD3D9ExWrapper(); 132 133 virtual bool AdapterNext(); 134 virtual unsigned int AdapterIdx() const; 135 virtual void *Device() const; 136 virtual TDeviceStatus Status() const; 137 virtual void *D3D() const; 138 139 private: 140 LPDIRECT3D9EX _d3d9Ex; 141 LPDIRECT3DDEVICE9EX _d3dDeviceEx; 142 D3DDISPLAYMODEEX _d3ddmEx; 143 D3DADAPTER_IDENTIFIER9 _adapter; 144 TDeviceStatus _status; 145 unsigned int _adapterIdx; 146 bool _adapterFound; 147 148 D3DFORMAT Format(); 149 D3DADAPTER_IDENTIFIER9 Adapter(); 150 int Init(); 151 void Destroy(); 152 }; 153 154 class CDXVAWrapper : public CDeviceWrapper { 155 public: 156 CDXVAWrapper(); 157 ~CDXVAWrapper(); 158 159 virtual bool AdapterNext(); 160 virtual unsigned int AdapterIdx() const; 161 virtual void *Device() const; 162 virtual TDeviceStatus Status() const; 163 virtual void *D3D() const; 164 const CD3D9ExWrapper &D3D9() const; 165 166 private: 167 CD3D9ExWrapper _d3d9; 168 IDXVAHD_Device *_dxvaDevice; 169 TDeviceStatus _status; 170 bool _adapterFound; 171 172 static const D3DFORMAT RENDER_TARGET_FORMAT; 173 static const D3DFORMAT VIDEO_FORMAT; 174 static const unsigned int VIDEO_FPS; 175 176 TDeviceStatus DXVAHDInit(); 177 void DXVAHDDestroy(); 178 }; 179 180 class CD3D9SurfaceWrapper : public CSurfaceWrapper { 181 public: 182 CD3D9SurfaceWrapper(); 183 CD3D9SurfaceWrapper(IDirect3DSurface9 *mem); 184 ~CD3D9SurfaceWrapper(); 185 186 operator IDirect3DSurface9 *() { return mMem; } 187 IDirect3DSurface9 **operator&() { return &mMem; } 188 IDirect3DSurface9 *operator->() const { return mMem; } 189 190 private: 191 IDirect3DSurface9 *mMem; 192 }; 193 #endif 194 195 #endif // __D3D_WRAPPERS 196