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 { 96 public: 97 CSurfaceWrapper(); 98 virtual ~CSurfaceWrapper(); 99 }; 100 101 #if defined(_WIN32) 102 //windows specific wrappers 103 class CD3D9Wrapper: public CDeviceWrapper { 104 public: 105 CD3D9Wrapper(); 106 ~CD3D9Wrapper(); 107 108 virtual bool AdapterNext(); 109 virtual unsigned int AdapterIdx() const; 110 virtual void *Device() const; 111 virtual TDeviceStatus Status() const; 112 virtual void *D3D() const; 113 114 private: 115 LPDIRECT3D9 _d3d9; 116 LPDIRECT3DDEVICE9 _d3dDevice; 117 D3DDISPLAYMODE _d3ddm; 118 D3DADAPTER_IDENTIFIER9 _adapter; 119 TDeviceStatus _status; 120 unsigned int _adapterIdx; 121 bool _adapterFound; 122 123 D3DFORMAT Format(); 124 D3DADAPTER_IDENTIFIER9 Adapter(); 125 int Init(); 126 void Destroy(); 127 }; 128 129 class CD3D9ExWrapper: public CDeviceWrapper { 130 public: 131 CD3D9ExWrapper(); 132 ~CD3D9ExWrapper(); 133 134 virtual bool AdapterNext(); 135 virtual unsigned int AdapterIdx() const; 136 virtual void *Device() const; 137 virtual TDeviceStatus Status() const; 138 virtual void *D3D() const; 139 140 private: 141 LPDIRECT3D9EX _d3d9Ex; 142 LPDIRECT3DDEVICE9EX _d3dDeviceEx; 143 D3DDISPLAYMODEEX _d3ddmEx; 144 D3DADAPTER_IDENTIFIER9 _adapter; 145 TDeviceStatus _status; 146 unsigned int _adapterIdx; 147 bool _adapterFound; 148 149 D3DFORMAT Format(); 150 D3DADAPTER_IDENTIFIER9 Adapter(); 151 int Init(); 152 void Destroy(); 153 }; 154 155 class CDXVAWrapper: public CDeviceWrapper { 156 public: 157 CDXVAWrapper(); 158 ~CDXVAWrapper(); 159 160 virtual bool AdapterNext(); 161 virtual unsigned int AdapterIdx() const; 162 virtual void *Device() const; 163 virtual TDeviceStatus Status() const; 164 virtual void *D3D() const; 165 const CD3D9ExWrapper &D3D9() const; 166 167 private: 168 CD3D9ExWrapper _d3d9; 169 IDXVAHD_Device *_dxvaDevice; 170 TDeviceStatus _status; 171 bool _adapterFound; 172 173 static const D3DFORMAT RENDER_TARGET_FORMAT; 174 static const D3DFORMAT VIDEO_FORMAT; 175 static const unsigned int VIDEO_FPS; 176 177 TDeviceStatus DXVAHDInit(); 178 void DXVAHDDestroy(); 179 }; 180 181 class CD3D9SurfaceWrapper: public CSurfaceWrapper 182 { 183 public: 184 CD3D9SurfaceWrapper(); 185 CD3D9SurfaceWrapper( IDirect3DSurface9* mem ); 186 ~CD3D9SurfaceWrapper(); 187 188 operator IDirect3DSurface9*() { return mMem; } 189 IDirect3DSurface9* * operator&() { return &mMem; } 190 IDirect3DSurface9* operator->() const { return mMem; } 191 192 private: 193 IDirect3DSurface9* mMem; 194 }; 195 #endif 196 197 #endif // __D3D_WRAPPERS 198