Leaked source code of windows server 2003
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.

250 lines
8.8 KiB

  1. /*
  2. *
  3. * Copyright (c) Microsoft Corp. 1997
  4. *
  5. * All rights reserved.
  6. *
  7. * This file contains private, unpublished information and may not be
  8. * copied in part or in whole without express permission of
  9. * Microsoft Corp.
  10. *
  11. */
  12. #include "pch.cpp"
  13. #pragma hdrstop
  14. #include <hwprov.h>
  15. #define nullPrimCaps { \
  16. sizeof(D3DPRIMCAPS), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  17. } \
  18. #define nullLightCaps { \
  19. sizeof(D3DLIGHTINGCAPS), 0, 0, 0 \
  20. }
  21. #define transformCaps { sizeof(D3DTRANSFORMCAPS), D3DTRANSFORMCAPS_CLIP }
  22. #define THIS_MODEL D3DLIGHTINGMODEL_RGB
  23. #define lightingCaps { \
  24. sizeof(D3DLIGHTINGCAPS), \
  25. (D3DLIGHTCAPS_POINT \
  26. | D3DLIGHTCAPS_SPOT \
  27. | D3DLIGHTCAPS_DIRECTIONAL), \
  28. THIS_MODEL, /* dwLightingModel */ \
  29. 0, /* dwNumLights (infinite) */ \
  30. }
  31. /*
  32. * Software Driver caps
  33. */
  34. static D3DDEVICEDESC7 devDesc =
  35. {
  36. D3DDEVCAPS_FLOATTLVERTEX, /* devCaps */
  37. nullPrimCaps, /* lineCaps */
  38. nullPrimCaps, /* triCaps */
  39. 0, /* dwDeviceRenderBitDepth */
  40. 0 /* dwDeviceZBufferBitDepth */
  41. };
  42. //----------------------------------------------------------------------------
  43. //
  44. // HwHalProvider::QueryInterface
  45. //
  46. // Internal interface, no need to implement.
  47. //
  48. //----------------------------------------------------------------------------
  49. STDMETHODIMP HwHalProvider::QueryInterface(THIS_ REFIID riid, LPVOID* ppvObj)
  50. {
  51. *ppvObj = NULL;
  52. return E_NOINTERFACE;
  53. }
  54. //----------------------------------------------------------------------------
  55. //
  56. // HwHalProvider::AddRef
  57. //
  58. // Static implementation, no real refcount.
  59. //
  60. //----------------------------------------------------------------------------
  61. STDMETHODIMP_(ULONG) HwHalProvider::AddRef(THIS)
  62. {
  63. return 1;
  64. }
  65. //----------------------------------------------------------------------------
  66. //
  67. // HwHalProvider::Release
  68. //
  69. // Static implementation, no real refcount.
  70. //
  71. //----------------------------------------------------------------------------
  72. STDMETHODIMP_(ULONG) HwHalProvider::Release(THIS)
  73. {
  74. return 0;
  75. }
  76. //----------------------------------------------------------------------------
  77. //
  78. // HwHalProvider::GetCaps
  79. //
  80. // Returns the HAL caps.
  81. //
  82. //----------------------------------------------------------------------------
  83. STDMETHODIMP
  84. HwHalProvider::GetCaps(LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  85. LPD3DDEVICEDESC7 pHwDesc,
  86. LPD3DDEVICEDESC7 pHelDesc,
  87. DWORD dwVersion)
  88. {
  89. D3DDeviceDescConvert(pHwDesc,
  90. &pDdGbl->lpD3DGlobalDriverData->hwCaps,
  91. pDdGbl->lpD3DExtendedCaps);
  92. *pHelDesc = devDesc;
  93. // Since this is HAL, it can atleast rasterize in HW
  94. pHwDesc->dwDevCaps |= D3DDEVCAPS_HWRASTERIZATION;
  95. // Set D3DPRASTERCAPS_WFOG, texture op caps and texture stage caps
  96. // for legacy hal drivers off device7.
  97. LPD3DHAL_CALLBACKS3 lpD3DHALCallbacks3 =
  98. (LPD3DHAL_CALLBACKS3)pDdGbl->lpD3DHALCallbacks3;
  99. if (dwVersion >= 3 &&
  100. (lpD3DHALCallbacks3 == NULL || lpD3DHALCallbacks3->DrawPrimitives2 == NULL))
  101. {
  102. pHwDesc->dpcTriCaps.dwRasterCaps |= D3DPRASTERCAPS_WFOG;
  103. D3D_INFO(2, "Setting D3DPRASTERCAPS_WFOG for legacy HAL driver off Device7");
  104. pHwDesc->dwMaxAnisotropy = 1;
  105. pHwDesc->wMaxTextureBlendStages = 1;
  106. pHwDesc->wMaxSimultaneousTextures = 1;
  107. D3D_INFO(2, "Setting texture stage state info for legacy HAL driver off Device7");
  108. pHwDesc->dwTextureOpCaps = D3DTEXOPCAPS_DISABLE;
  109. if ((pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_DECAL) ||
  110. (pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_COPY))
  111. {
  112. pHwDesc->dwTextureOpCaps |= D3DTEXOPCAPS_SELECTARG1;
  113. }
  114. if ((pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_MODULATE) ||
  115. (pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_MODULATEALPHA))
  116. {
  117. pHwDesc->dwTextureOpCaps |= D3DTEXOPCAPS_MODULATE;
  118. }
  119. if (pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_ADD)
  120. {
  121. pHwDesc->dwTextureOpCaps |= D3DTEXOPCAPS_ADD;
  122. }
  123. if (pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_DECALALPHA)
  124. {
  125. pHwDesc->dwTextureOpCaps |= D3DTEXOPCAPS_BLENDTEXTUREALPHA;
  126. }
  127. D3D_INFO(2, "Setting textureop caps for legacy HAL driver off Device7");
  128. // map texture filter operations to DX6 set
  129. if ((pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_NEAREST) ||
  130. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPNEAREST) ||
  131. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST))
  132. {
  133. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MINFPOINT;
  134. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MAGFPOINT;
  135. }
  136. if ((pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR) ||
  137. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR) ||
  138. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR))
  139. {
  140. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MINFLINEAR;
  141. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MAGFLINEAR;
  142. }
  143. if ((pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPNEAREST) ||
  144. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR))
  145. {
  146. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MIPFPOINT;
  147. }
  148. if ((pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST) ||
  149. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR))
  150. {
  151. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MIPFLINEAR;
  152. }
  153. D3D_INFO(2, "Setting texturefilter caps for legacy HAL driver off Device7");
  154. }
  155. #ifdef __POINTSPRITES // may need this for DX8
  156. // DX6 drivers will handle DrawPrim2 and will be setting extended caps, but
  157. // won't be setting dvMaxPointSize yet. Therefore, dvMaxPointSize will be 0
  158. // from DDraw's initial clear of lpD3DExtendedCaps.
  159. if ((dwVersion >= 3) && (pHwDesc->dvMaxPointSize == 0.0f))
  160. {
  161. // set max point size to pre-DX7 1.0f
  162. pHwDesc->dvMaxPointSize = 1.0f;
  163. D3D_INFO(2, "Setting dvMaxPointSize cap for legacy HAL driver off Device7");
  164. }
  165. #endif
  166. return D3D_OK;
  167. }
  168. //----------------------------------------------------------------------------
  169. //
  170. // HwHalProvider::GetCallbacks
  171. //
  172. // Returns the HAL callbacks in the given DDraw global.
  173. //
  174. //----------------------------------------------------------------------------
  175. STDMETHODIMP
  176. HwHalProvider::GetInterface(THIS_
  177. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  178. LPD3DHALPROVIDER_INTERFACEDATA pInterfaceData,
  179. DWORD dwVersion)
  180. {
  181. pInterfaceData->pGlobalData = pDdGbl->lpD3DGlobalDriverData;
  182. pInterfaceData->pExtCaps = pDdGbl->lpD3DExtendedCaps;
  183. pInterfaceData->pCallbacks = pDdGbl->lpD3DHALCallbacks;
  184. pInterfaceData->pCallbacks2 = pDdGbl->lpD3DHALCallbacks2;
  185. pInterfaceData->pCallbacks3 = pDdGbl->lpD3DHALCallbacks3;
  186. if( pDdGbl->lpDDCBtmp )
  187. pInterfaceData->pfnGetDriverState =
  188. pDdGbl->lpDDCBtmp->HALDDMiscellaneous2.GetDriverState;
  189. else
  190. pInterfaceData->pfnGetDriverState = NULL;
  191. return S_OK;
  192. }
  193. //----------------------------------------------------------------------------
  194. //
  195. // GetHwHalProvider
  196. //
  197. // Returns the hardware HAL provider.
  198. //
  199. //----------------------------------------------------------------------------
  200. static HwHalProvider g_HwHalProvider;
  201. STDAPI
  202. GetHwHalProvider(REFIID riid, IHalProvider **ppHalProvider, HINSTANCE *phDll, LPDDRAWI_DIRECTDRAW_GBL pDdGbl)
  203. {
  204. *phDll = NULL;
  205. if ( (IsEqualIID(riid,IID_IDirect3DHALDevice) ||
  206. IsEqualIID(riid,IID_IDirect3DTnLHalDevice)) &&
  207. D3DI_isHALValid(pDdGbl->lpD3DHALCallbacks))
  208. {
  209. *ppHalProvider = &g_HwHalProvider;
  210. }
  211. else
  212. {
  213. *ppHalProvider = NULL;
  214. return E_NOINTERFACE;
  215. }
  216. return S_OK;
  217. }