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.

257 lines
9.1 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. | D3DLIGHTCAPS_PARALLELPOINT), \
  29. THIS_MODEL, /* dwLightingModel */ \
  30. 0, /* dwNumLights (infinite) */ \
  31. }
  32. /*
  33. * Software Driver caps
  34. */
  35. static D3DDEVICEDESC devDesc =
  36. {
  37. sizeof(D3DDEVICEDESC), /* dwSize */
  38. D3DDD_COLORMODEL | /* dwFlags */
  39. D3DDD_DEVCAPS |
  40. D3DDD_TRANSFORMCAPS |
  41. D3DDD_LIGHTINGCAPS |
  42. D3DDD_BCLIPPING,
  43. 0, /* dcmColorModel */
  44. D3DDEVCAPS_FLOATTLVERTEX, /* devCaps */
  45. transformCaps, /* dtcTransformCaps */
  46. TRUE, /* bClipping */
  47. lightingCaps, /* dlcLightingCaps */
  48. nullPrimCaps, /* lineCaps */
  49. nullPrimCaps, /* triCaps */
  50. 0, /* dwDeviceRenderBitDepth */
  51. 0, /* dwDeviceZBufferBitDepth */
  52. 0, /* dwMaxBufferSize */
  53. 0 /* dwMaxVertexCount */
  54. };
  55. //----------------------------------------------------------------------------
  56. //
  57. // HwHalProvider::QueryInterface
  58. //
  59. // Internal interface, no need to implement.
  60. //
  61. //----------------------------------------------------------------------------
  62. STDMETHODIMP HwHalProvider::QueryInterface(THIS_ REFIID riid, LPVOID* ppvObj)
  63. {
  64. *ppvObj = NULL;
  65. return E_NOINTERFACE;
  66. }
  67. //----------------------------------------------------------------------------
  68. //
  69. // HwHalProvider::AddRef
  70. //
  71. // Static implementation, no real refcount.
  72. //
  73. //----------------------------------------------------------------------------
  74. STDMETHODIMP_(ULONG) HwHalProvider::AddRef(THIS)
  75. {
  76. return 1;
  77. }
  78. //----------------------------------------------------------------------------
  79. //
  80. // HwHalProvider::Release
  81. //
  82. // Static implementation, no real refcount.
  83. //
  84. //----------------------------------------------------------------------------
  85. STDMETHODIMP_(ULONG) HwHalProvider::Release(THIS)
  86. {
  87. return 0;
  88. }
  89. //----------------------------------------------------------------------------
  90. //
  91. // HwHalProvider::GetCaps
  92. //
  93. // Returns the HAL caps.
  94. //
  95. //----------------------------------------------------------------------------
  96. STDMETHODIMP
  97. HwHalProvider::GetCaps(LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  98. LPD3DDEVICEDESC pHwDesc,
  99. LPD3DDEVICEDESC pHelDesc,
  100. DWORD dwVersion)
  101. {
  102. D3DDeviceDescConvert(pHwDesc,
  103. &pDdGbl->lpD3DGlobalDriverData->hwCaps,
  104. pDdGbl->lpD3DExtendedCaps);
  105. if (pHwDesc->dwMaxVertexCount == 0)
  106. {
  107. D3D_WARN(2, "Setting dwMaxVertexCount to %d", D3DHAL_DEFAULT_TL_NUM);
  108. pHwDesc->dwMaxVertexCount = D3DHAL_DEFAULT_TL_NUM;
  109. }
  110. else
  111. {
  112. D3D_INFO(2, "Hal driver has max vertices of %d", pHwDesc->dwMaxVertexCount);
  113. }
  114. *pHelDesc = devDesc;
  115. // Force HEL's vertex and buffer size to the HAL's.
  116. D3D_WARN(1, "Forcing HEL's vertex and buffer size to the HAL's v %d b %d",
  117. pHwDesc->dwMaxVertexCount, pHwDesc->dwMaxBufferSize);
  118. pHelDesc->dwMaxVertexCount = pHwDesc->dwMaxVertexCount;
  119. pHelDesc->dwMaxBufferSize = pHwDesc->dwMaxBufferSize;
  120. // Set D3DPRASTERCAPS_WFOG, texture op caps and texture stage caps
  121. // for legacy hal drivers off device3.
  122. LPD3DHAL_CALLBACKS3 lpD3DHALCallbacks3 =
  123. (LPD3DHAL_CALLBACKS3)pDdGbl->lpD3DHALCallbacks3;
  124. if (dwVersion >= 3 &&
  125. (lpD3DHALCallbacks3 == NULL || lpD3DHALCallbacks3->DrawPrimitives2 == NULL))
  126. {
  127. pHwDesc->dpcTriCaps.dwRasterCaps |= D3DPRASTERCAPS_WFOG;
  128. D3D_INFO(2, "Setting D3DPRASTERCAPS_WFOG for legacy HAL driver off Device3");
  129. pHwDesc->dwMaxAnisotropy = 1;
  130. pHwDesc->wMaxTextureBlendStages = 1;
  131. pHwDesc->wMaxSimultaneousTextures = 1;
  132. D3D_INFO(2, "Setting texture stage state info for legacy HAL driver off Device3");
  133. pHwDesc->dwTextureOpCaps = D3DTEXOPCAPS_DISABLE;
  134. if ((pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_DECAL) ||
  135. (pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_COPY))
  136. {
  137. pHwDesc->dwTextureOpCaps |= D3DTEXOPCAPS_SELECTARG1;
  138. }
  139. if ((pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_MODULATE) ||
  140. (pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_MODULATEALPHA))
  141. {
  142. pHwDesc->dwTextureOpCaps |= D3DTEXOPCAPS_MODULATE;
  143. }
  144. if (pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_ADD)
  145. {
  146. pHwDesc->dwTextureOpCaps |= D3DTEXOPCAPS_ADD;
  147. }
  148. if (pHwDesc->dpcTriCaps.dwTextureBlendCaps & D3DPTBLENDCAPS_DECALALPHA)
  149. {
  150. pHwDesc->dwTextureOpCaps |= D3DTEXOPCAPS_BLENDTEXTUREALPHA;
  151. }
  152. D3D_INFO(2, "Setting textureop caps for legacy HAL driver off Device3");
  153. // map texture filter operations to DX6 set
  154. if ((pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_NEAREST) ||
  155. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPNEAREST) ||
  156. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST))
  157. {
  158. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MINFPOINT;
  159. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MAGFPOINT;
  160. }
  161. if ((pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEAR) ||
  162. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR) ||
  163. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR))
  164. {
  165. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MINFLINEAR;
  166. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MAGFLINEAR;
  167. }
  168. if ((pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPNEAREST) ||
  169. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_MIPLINEAR))
  170. {
  171. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MIPFPOINT;
  172. }
  173. if ((pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPNEAREST) ||
  174. (pHwDesc->dpcTriCaps.dwTextureFilterCaps & D3DPTFILTERCAPS_LINEARMIPLINEAR))
  175. {
  176. pHwDesc->dpcTriCaps.dwTextureFilterCaps |= D3DPTFILTERCAPS_MIPFLINEAR;
  177. }
  178. D3D_INFO(2, "Setting texturefilter caps for legacy HAL driver off Device3");
  179. }
  180. return D3D_OK;
  181. }
  182. //----------------------------------------------------------------------------
  183. //
  184. // HwHalProvider::GetCallbacks
  185. //
  186. // Returns the HAL callbacks in the given DDraw global.
  187. //
  188. //----------------------------------------------------------------------------
  189. STDMETHODIMP
  190. HwHalProvider::GetInterface(THIS_
  191. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  192. LPD3DHALPROVIDER_INTERFACEDATA pInterfaceData,
  193. DWORD dwVersion)
  194. {
  195. pInterfaceData->pGlobalData = pDdGbl->lpD3DGlobalDriverData;
  196. pInterfaceData->pExtCaps = pDdGbl->lpD3DExtendedCaps;
  197. pInterfaceData->pCallbacks = pDdGbl->lpD3DHALCallbacks;
  198. pInterfaceData->pCallbacks2 = pDdGbl->lpD3DHALCallbacks2;
  199. pInterfaceData->pCallbacks3 = pDdGbl->lpD3DHALCallbacks3;
  200. pInterfaceData->pfnRampService = NULL;
  201. return S_OK;
  202. }
  203. //----------------------------------------------------------------------------
  204. //
  205. // GetHwHalProvider
  206. //
  207. // Returns the hardware HAL provider.
  208. //
  209. //----------------------------------------------------------------------------
  210. static HwHalProvider g_HwHalProvider;
  211. STDAPI
  212. GetHwHalProvider(REFIID riid, IHalProvider **ppHalProvider, HINSTANCE *phDll, LPDDRAWI_DIRECTDRAW_GBL pDdGbl)
  213. {
  214. *phDll = NULL;
  215. if (IsEqualIID(riid, IID_IDirect3DHALDevice) && D3DI_isHALValid(pDdGbl->lpD3DHALCallbacks))
  216. {
  217. *ppHalProvider = &g_HwHalProvider;
  218. }
  219. else
  220. {
  221. *ppHalProvider = NULL;
  222. return E_NOINTERFACE;
  223. }
  224. return S_OK;
  225. }