Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

389 lines
12 KiB

  1. #ifndef __DXGINT_H__
  2. #define __DXGINT_H__
  3. // COM interface stuff to allow functions such as CoCreateInstance and the like
  4. #include <unknwn.h>
  5. #include "d3d8p.h"
  6. #include "d3d8ddi.h"
  7. #include "enum.hpp"
  8. // Forward decls
  9. class CResource;
  10. class CResourceManager;
  11. class CBaseTexture;
  12. class CBaseSurface;
  13. class CSwapChain;
  14. class CEnum;
  15. #undef DPF_MODNAME
  16. #define DPF_MODNAME "CBaseDevice"
  17. class CBaseDevice : public CLockOwner, public IDirect3DDevice8
  18. {
  19. public:
  20. // IUnknown methods
  21. STDMETHODIMP QueryInterface(REFIID, LPVOID FAR*); // 0
  22. STDMETHODIMP_(ULONG) AddRef(void); // 1
  23. STDMETHODIMP_(ULONG) Release(void); // 2
  24. // IDirectGraphicsDevice methods
  25. STDMETHODIMP TestCooperativeLevel(); // 3
  26. STDMETHODIMP_(UINT) GetAvailableTextureMem(void); // 4
  27. // ResourceManagerDiscardBytes is declared in d3di.hpp = 5
  28. STDMETHODIMP GetDirect3D(LPDIRECT3D8 *pD3D8); // 6
  29. STDMETHODIMP GetDeviceCaps(D3DCAPS8 *pCaps); // 7
  30. STDMETHODIMP GetDisplayMode(D3DDISPLAYMODE *pMode); // 8
  31. STDMETHODIMP GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *pParameters); // 9
  32. STDMETHODIMP SetCursorProperties(
  33. UINT xHotSpot,UINT yHotSpot,
  34. IDirect3DSurface8 *pCursorBitmap); // 10
  35. STDMETHODIMP_(void) SetCursorPosition(UINT xScreenSpace,UINT yScreenSpace,DWORD Flags); // 11
  36. STDMETHODIMP_(INT) ShowCursor(BOOL bShow); // 12
  37. // Swap Chain stuff
  38. STDMETHODIMP CreateAdditionalSwapChain(
  39. D3DPRESENT_PARAMETERS *pPresentationParameters,
  40. IDirect3DSwapChain8 **pSwapChain); // 13
  41. STDMETHODIMP Reset( D3DPRESENT_PARAMETERS *pPresentationParameters); // 14
  42. STDMETHODIMP Present( CONST RECT *pSourceRect,
  43. CONST RECT *pDestRect,
  44. HWND hTargetWindow,
  45. CONST RGNDATA *pDestinationRegion); // 15
  46. STDMETHODIMP GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer); // 16
  47. STDMETHODIMP GetRasterStatus(D3DRASTER_STATUS *pRasterStatus); // 17
  48. STDMETHODIMP_(void) SetGammaRamp(DWORD dwFlags, CONST D3DGAMMARAMP *pRamp); // 18
  49. STDMETHODIMP_(void) GetGammaRamp(D3DGAMMARAMP *pRamp); // 19
  50. STDMETHODIMP CreateTexture(UINT cpWidth,UINT cpHeight,UINT cLevels,DWORD dwUsage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture8 **ppTexture); // 20
  51. STDMETHODIMP CreateVolumeTexture(UINT cpWidth,UINT cpHeight,UINT cpDepth,UINT cLevels,DWORD dwUsage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture8 **ppVolumeTexture); // 21
  52. STDMETHODIMP CreateCubeTexture(UINT cpEdge,UINT cLevels,DWORD dwUsage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture8 **ppCubeTexture); // 22
  53. STDMETHODIMP CreateVertexBuffer(UINT cbLength,DWORD Usage,DWORD dwFVF,D3DPOOL Pool,IDirect3DVertexBuffer8 **ppVertexBuffer); // 23
  54. STDMETHODIMP CreateIndexBuffer(UINT cbLength,DWORD dwUsage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer8 **ppIndexBuffer); // 24
  55. STDMETHODIMP CreateRenderTarget(UINT cpWidth,UINT cpHeight,D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8 **ppSurface); // 25
  56. STDMETHODIMP CreateDepthStencilSurface(UINT cpWidth,UINT cpHeight,D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8 **ppSurface); // 26
  57. STDMETHODIMP CreateImageSurface(UINT cpWidth,UINT cpHeight,D3DFORMAT Format, IDirect3DSurface8 **ppSurface); // 27
  58. STDMETHODIMP CopyRects(IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRectsArray,UINT cRects,IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPointsArray); // 28
  59. STDMETHODIMP UpdateTexture(IDirect3DBaseTexture8 *pSourceTexture,IDirect3DBaseTexture8 *pDestinationTexture); // 29
  60. STDMETHODIMP GetFrontBuffer(IDirect3DSurface8 *pDestSurface); // 30
  61. // Constructor/deconstructor
  62. CBaseDevice();
  63. virtual ~CBaseDevice();
  64. HRESULT Init(
  65. PD3D8_DEVICEDATA pDeviceData,
  66. D3DDEVTYPE DeviceType,
  67. HWND hwndFocusWindow,
  68. DWORD dwBehaviorFlags,
  69. D3DPRESENT_PARAMETERS *pPresentationParameters,
  70. UINT AdapterIndex,
  71. CEnum* Parent);
  72. PD3D8_CALLBACKS GetHalCallbacks(void)
  73. {
  74. return &m_DeviceData.Callbacks;
  75. } // GetHalCallbacks
  76. // Get a handle for the device; used for kernel calls
  77. HANDLE GetHandle(void) const
  78. {
  79. return m_DeviceData.hDD;
  80. } // GetHandle
  81. BOOL CanTexBlt(void) const
  82. {
  83. if (GetDeviceType() == D3DDEVTYPE_SW ||
  84. GetDeviceType() == D3DDEVTYPE_REF)
  85. {
  86. // TexBlt is not supported for software
  87. // devices
  88. return FALSE;
  89. }
  90. // DX7 and above
  91. return (m_ddiType >= D3DDDITYPE_DX7);
  92. } // CanTexBlt
  93. BOOL CanBufBlt(void) const
  94. {
  95. if (GetDeviceType() == D3DDEVTYPE_SW ||
  96. GetDeviceType() == D3DDEVTYPE_REF)
  97. {
  98. // BufBlt is not supported for software
  99. // devices
  100. return FALSE;
  101. }
  102. // DX8 and above
  103. return (m_ddiType >= D3DDDITYPE_DX8);
  104. } // CanBufBlt
  105. BOOL CanDriverManageResource(void) const
  106. {
  107. if (m_dwBehaviorFlags & D3DCREATE_DISABLE_DRIVER_MANAGEMENT)
  108. {
  109. return FALSE;
  110. }
  111. else if (GetD3DCaps()->Caps2 & DDCAPS2_CANMANAGERESOURCE)
  112. {
  113. DDASSERT(m_ddiType >= D3DDDITYPE_DX8);
  114. return TRUE;
  115. }
  116. else
  117. {
  118. return FALSE;
  119. }
  120. } // CanDriverManage
  121. D3DDDITYPE GetDDIType(void) const
  122. {
  123. return m_ddiType;
  124. } // GetDDIType
  125. const D3D8_DRIVERCAPS* GetCoreCaps() const
  126. {
  127. return &m_DeviceData.DriverData;
  128. } // GetCoreCaps
  129. const D3DCAPS8* GetD3DCaps() const
  130. {
  131. return &m_DeviceData.DriverData.D3DCaps;
  132. } // GetD3DCaps
  133. D3DDISPLAYMODE* GetModeTable() const
  134. {
  135. return m_pD3DClass->GetModeTable(m_AdapterIndex);
  136. } // GetModeTable
  137. VOID* GetInitFunction() const
  138. {
  139. if (m_DeviceType == D3DDEVTYPE_SW)
  140. {
  141. return m_pD3DClass->GetInitFunction();
  142. }
  143. return NULL;
  144. } // GetModeTable
  145. const DWORD GetNumModes() const
  146. {
  147. return m_pD3DClass->GetNumModes(m_AdapterIndex);
  148. } // GetNumModes
  149. D3D8_DEVICEDATA* GetDeviceData()
  150. {
  151. return &m_DeviceData;
  152. } // GetDeviceData
  153. CBaseSurface *ZBuffer() const
  154. {
  155. return m_pZBuffer;
  156. } // ZBuffer
  157. CBaseSurface *RenderTarget() const
  158. {
  159. return m_pRenderTarget;
  160. } // RenderTarget
  161. void UpdateRenderTarget(CBaseSurface *pRenderTarget, CBaseSurface *pZStencil);
  162. CResourceManager* ResourceManager() const
  163. {
  164. // return the ResourceManager
  165. return m_pResourceManager;
  166. } // ResourceManager
  167. CEnum * Enum() const
  168. {
  169. // return the enumerator that created us
  170. return m_pD3DClass;
  171. } // Enum
  172. // Internal version of CopyRects (no parameter validation)
  173. HRESULT InternalCopyRects(CBaseSurface *pSourceSurface,
  174. CONST RECT *pSourceRectsArray,
  175. UINT cRects,
  176. CBaseSurface *pDestinationSurface,
  177. CONST POINT *pDestPointsArray);
  178. // Internal function for format validation
  179. HRESULT CheckDeviceFormat(DWORD Usage,
  180. D3DRESOURCETYPE RType,
  181. D3DFORMAT CheckFormat)
  182. {
  183. return Enum()->CheckDeviceFormat(AdapterIndex(),
  184. GetDeviceType(),
  185. DisplayFormat(),
  186. Usage,
  187. RType,
  188. CheckFormat);
  189. } // CheckDeviceFormats
  190. HRESULT CheckDepthStencilMatch(D3DFORMAT RTFormat, D3DFORMAT DSFormat)
  191. {
  192. return Enum()->CheckDepthStencilMatch(AdapterIndex(),
  193. GetDeviceType(),
  194. DisplayFormat(),
  195. RTFormat,
  196. DSFormat);
  197. } // CheckDepthStencilMatch
  198. // Internal function for multi-sample validation
  199. HRESULT CheckDeviceMultiSampleType(D3DFORMAT RenderTargetFormat,
  200. BOOL Windowed,
  201. D3DMULTISAMPLE_TYPE MultiSampleType)
  202. {
  203. return Enum()->CheckDeviceMultiSampleType(
  204. AdapterIndex(),
  205. GetDeviceType(),
  206. RenderTargetFormat,
  207. Windowed,
  208. MultiSampleType);
  209. } // CheckDeviceMultiSampleType
  210. D3DFORMAT MapDepthStencilFormat(D3DFORMAT Format) const
  211. {
  212. return Enum()->MapDepthStencilFormat(
  213. AdapterIndex(),
  214. GetDeviceType(),
  215. Format);
  216. } // MapDepthStencilFormat
  217. UINT DisplayWidth() const { return m_DeviceData.DriverData.DisplayWidth; }
  218. UINT DisplayHeight() const { return m_DeviceData.DriverData.DisplayHeight; }
  219. D3DFORMAT DisplayFormat() const { return m_DeviceData.DriverData.DisplayFormatWithoutAlpha; }
  220. UINT DisplayRate() const { return m_DeviceData.DriverData.DisplayFrequency; }
  221. D3DDEVTYPE GetDeviceType() const
  222. {
  223. // Check this value is correct; pure types shouldn't happen
  224. // and other values are wrong. Users of this method
  225. // assume that these three are the only possible values.
  226. DDASSERT(m_DeviceType == D3DDEVTYPE_REF ||
  227. m_DeviceType == D3DDEVTYPE_SW ||
  228. m_DeviceType == D3DDEVTYPE_HAL);
  229. return m_DeviceType;
  230. }
  231. HWND FocusWindow()
  232. {
  233. return m_hwndFocusWindow;
  234. } // FocusWindow
  235. CSwapChain* SwapChain() const
  236. {
  237. DDASSERT(m_pSwapChain);
  238. return m_pSwapChain;
  239. }
  240. D3DDISPLAYMODE DesktopMode() const
  241. {
  242. return m_DesktopMode;
  243. }
  244. UINT AdapterIndex() const
  245. {
  246. return m_AdapterIndex;
  247. }
  248. DWORD BehaviorFlags() const
  249. {
  250. return m_dwBehaviorFlags;
  251. }
  252. void ResetZStencil()
  253. {
  254. m_pAutoZStencil = NULL;
  255. }
  256. CBaseSurface* GetZStencil() const
  257. {
  258. return m_pAutoZStencil;
  259. }
  260. void EnableVidmemVBs()
  261. {
  262. m_DeviceData.DriverData.D3DCaps.DevCaps |= (D3DDEVCAPS_HWVERTEXBUFFER);
  263. }
  264. void DisableVidmemVBs()
  265. {
  266. m_DeviceData.DriverData.D3DCaps.DevCaps &= ~(D3DDEVCAPS_HWVERTEXBUFFER);
  267. }
  268. BOOL DriverSupportsVidmemVBs() const
  269. {
  270. return (GetD3DCaps()->DevCaps & D3DDEVCAPS_HWVERTEXBUFFER);
  271. }
  272. BOOL DriverSupportsVidmemIBs() const
  273. {
  274. return (GetD3DCaps()->DevCaps & D3DDEVCAPS_HWINDEXBUFFER);
  275. }
  276. BOOL VBFailOversDisabled() const
  277. {
  278. return m_bVBFailOversDisabled;
  279. }
  280. CResource* GetResourceList() const
  281. {
  282. return m_pResourceList;
  283. }
  284. void SetResourceList(CResource *pRes)
  285. {
  286. m_pResourceList = pRes;
  287. }
  288. #ifdef DEBUG
  289. // debugging helper
  290. UINT RefCount() const
  291. {
  292. return m_cRef;
  293. } // RefCount
  294. #endif // DEBUG
  295. protected:
  296. // This is the section for access to things that
  297. // the derived versions of the base device need.
  298. D3DDDITYPE m_ddiType;
  299. private:
  300. // We mark "main" as a friend so that gensym can
  301. // access everything it wants to
  302. friend int main(void);
  303. DWORD m_cRef;
  304. BOOL m_fullscreen; // should be a flag?
  305. BOOL m_bVBFailOversDisabled;
  306. CResource *m_pResourceList;
  307. CResourceManager *m_pResourceManager;
  308. D3D8_DEVICEDATA m_DeviceData;
  309. HWND m_hwndFocusWindow;
  310. DWORD m_dwBehaviorFlags;
  311. DWORD m_dwOriginalBehaviorFlags;
  312. CBaseSurface *m_pZBuffer;
  313. CSwapChain *m_pSwapChain;
  314. CBaseSurface *m_pRenderTarget;
  315. CBaseSurface *m_pAutoZStencil;
  316. D3DDEVTYPE m_DeviceType;
  317. UINT m_AdapterIndex;
  318. CEnum *m_pD3DClass;
  319. D3DDISPLAYMODE m_DesktopMode;
  320. };
  321. #endif // define __DXGINT_H__