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.

436 lines
21 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995 - 1998 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: d3di.h
  6. * Content: Direct3D HAL driver include file
  7. *
  8. ***************************************************************************/
  9. #ifndef _HALDRV_H_
  10. #define _HALDRV_H_
  11. #undef DPF_MODNAME
  12. #define DPF_MODNAME "Direct3D HAL"
  13. #define SURFACE_MEMORY(surf) \
  14. (LPVOID)(((LPDDRAWI_DDRAWSURFACE_INT)(surf))->lpLcl->lpGbl->fpVidMem)
  15. #ifdef TRACK_HAL_CALLS
  16. #define RESET_HAL_CALLS(lpDevI) ((lpDevI)->hal_calls = 0)
  17. #define TRACK_HAL_CALL(lpDevI) ((lpDevI)->hal_calls++)
  18. #else
  19. #define RESET_HAL_CALLS(lpDevI)
  20. #define TRACK_HAL_CALL(lpDevI)
  21. #endif
  22. #define QUOTE(x) #x
  23. #define QQUOTE(y) QUOTE(y)
  24. #define REMIND(str) __FILE__ "(" QQUOTE(__LINE__) "):" str
  25. #ifdef WIN95
  26. extern void _stdcall GetpWin16Lock( LPVOID FAR *);
  27. extern void _stdcall _EnterSysLevel( LPVOID );
  28. extern void _stdcall _LeaveSysLevel( LPVOID );
  29. extern LPVOID lpWin16Lock;
  30. #define LOCK_HAL(ret, lpDevI) \
  31. { \
  32. if (lpDevI->dwFEFlags & D3DFE_REALHAL) { \
  33. _EnterSysLevel(lpWin16Lock); \
  34. } \
  35. ret = D3D_OK; \
  36. }
  37. #define UNLOCK_HAL(lpDevI) \
  38. { \
  39. if (lpDevI->dwFEFlags & D3DFE_REALHAL) { \
  40. _LeaveSysLevel(lpWin16Lock); \
  41. } \
  42. }
  43. HRESULT D3DHAL_LockDibEngine(LPDIRECT3DDEVICEI lpDevI);
  44. void D3DHAL_UnlockDibEngine(LPDIRECT3DDEVICEI lpDevI);
  45. #define LOCK_DIBENGINE(ret, lpDevI) \
  46. { \
  47. if (lpDevI->dwFEFlags & D3DFE_REALHAL) { \
  48. ret = D3DHAL_LockDibEngine(lpDevI); \
  49. } \
  50. else { \
  51. ret = D3D_OK; \
  52. } \
  53. }
  54. #define UNLOCK_DIBENGINE(lpDevI) \
  55. { \
  56. if (lpDevI->dwFEFlags & D3DFE_REALHAL) { \
  57. D3DHAL_UnlockDibEngine(lpDevI); \
  58. } \
  59. }
  60. #else // WIN95
  61. #define LOCK_HAL(ret, lpDevI) ret = DD_OK
  62. #define UNLOCK_HAL(lpDevI)
  63. #define LOCK_DIBENGINE(ret, lpDevI) ret = DD_OK
  64. #define UNLOCK_DIBENGINE(lpDevI)
  65. #endif // WIN95
  66. #define CALL_HALONLY_NOLOCK(ret, lpDevI, call, data) \
  67. { \
  68. if (lpDevI->lpD3DHALCallbacks->call) { \
  69. LOCK_DIBENGINE(ret, lpDevI); \
  70. if (ret != DD_OK) { \
  71. D3D_ERR("dibengine was busy, not calling HAL"); \
  72. } else { \
  73. ret = (*lpDevI->lpD3DHALCallbacks->call)(data); \
  74. TRACK_HAL_CALL(lpDevI) \
  75. UNLOCK_DIBENGINE(lpDevI); \
  76. } \
  77. } else { \
  78. D3D_ERR("No HAL call available"); \
  79. ret = DDHAL_DRIVER_NOTHANDLED; \
  80. } \
  81. }
  82. #define CALL_HAL2ONLY_NOLOCK(ret, lpDevI, call, data) \
  83. { \
  84. if (lpDevI->lpD3DHALCallbacks2->call) { \
  85. LOCK_DIBENGINE(ret, lpDevI); \
  86. if (ret != DD_OK) { \
  87. D3D_ERR("dibengine was busy, not calling HAL"); \
  88. } else { \
  89. ret = (*lpDevI->lpD3DHALCallbacks2->call)(data); \
  90. TRACK_HAL_CALL(lpDevI) \
  91. UNLOCK_DIBENGINE(lpDevI); \
  92. } \
  93. } else { \
  94. D3D_ERR("No HAL call available"); \
  95. ret = DDHAL_DRIVER_NOTHANDLED; \
  96. } \
  97. }
  98. #define CALL_HALCBONLY_NOLOCK(ret, lpDevI, call, data) \
  99. { \
  100. if (lpDevI->lpD3DHALCommandBufferCallbacks->call) { \
  101. LOCK_DIBENGINE(ret, lpDevI); \
  102. if (ret != DD_OK) { \
  103. D3D_ERR("dibengine was busy, not calling HAL"); \
  104. } else { \
  105. ret = (*lpDevI->lpD3DHALCommandBufferCallbacks->call)(data); \
  106. TRACK_HAL_CALL(lpDevI) \
  107. UNLOCK_DIBENGINE(lpDevI); \
  108. } \
  109. } else { \
  110. D3D_ERR("No HAL call available"); \
  111. ret = DDHAL_DRIVER_NOTHANDLED; \
  112. } \
  113. }
  114. #define CALL_HAL3ONLY_NOLOCK(ret, lpDevI, call, data) \
  115. { \
  116. if (lpDevI->lpD3DHALCallbacks3->call) { \
  117. LOCK_DIBENGINE(ret, lpDevI); \
  118. if (ret != DD_OK) { \
  119. D3D_ERR("dibengine was busy, not calling HAL"); \
  120. } else { \
  121. ret = (*lpDevI->lpD3DHALCallbacks3->call)(data); \
  122. TRACK_HAL_CALL(lpDevI) \
  123. UNLOCK_DIBENGINE(lpDevI); \
  124. } \
  125. } else { \
  126. D3D_ERR("No HAL call available"); \
  127. ret = DDHAL_DRIVER_NOTHANDLED; \
  128. } \
  129. }
  130. #define CALL_HALONLY(ret, lpDevI, call, data) \
  131. { \
  132. BOOL locked; \
  133. ret = DD_OK; \
  134. LOCK_HAL(ret, lpDevI); \
  135. if (ret == DD_OK) \
  136. locked = TRUE; \
  137. if (ret == DD_OK) { \
  138. CALL_HALONLY_NOLOCK(ret, lpDevI, call, data); \
  139. } \
  140. if (locked) { \
  141. UNLOCK_HAL(lpDevI); \
  142. } \
  143. }
  144. #define CALL_HALCBONLY(ret, lpDevI, call, data) \
  145. { \
  146. BOOL locked; \
  147. ret = DD_OK; \
  148. LOCK_HAL(ret, lpDevI); \
  149. if (ret == DD_OK) \
  150. locked = TRUE; \
  151. if (ret == DD_OK) { \
  152. CALL_HALCBONLY_NOLOCK(ret, lpDevI, call, data); \
  153. } \
  154. if (locked) { \
  155. UNLOCK_HAL(lpDevI); \
  156. } \
  157. }
  158. #define CALL_HAL2ONLY(ret, lpDevI, call, data) \
  159. { \
  160. BOOL locked; \
  161. ret = DD_OK; \
  162. LOCK_HAL(ret, lpDevI); \
  163. if (ret == DD_OK) \
  164. locked = TRUE; \
  165. if (ret == DD_OK) { \
  166. CALL_HAL2ONLY_NOLOCK(ret, lpDevI, call, data); \
  167. } \
  168. if (locked) { \
  169. UNLOCK_HAL(lpDevI); \
  170. } \
  171. }
  172. //-----------------------------------------------------------------------
  173. // Call for callbacks that are not required to be implemented
  174. //
  175. #define CALL_HAL3ONLY_OPTIONAL(ret, lpDevI, call, data) \
  176. { \
  177. BOOL locked; \
  178. ret = DD_OK; \
  179. if (lpDevI->lpD3DHALCallbacks3->call) \
  180. { \
  181. CALL_HAL3ONLY(ret, lpDevI, call, data); \
  182. } \
  183. }
  184. //-----------------------------------------------------------------------
  185. #define CALL_HAL3ONLY(ret, lpDevI, call, data) \
  186. { \
  187. BOOL locked; \
  188. ret = DD_OK; \
  189. LOCK_HAL(ret, lpDevI); \
  190. if (ret == DD_OK) \
  191. locked = TRUE; \
  192. if (ret == DD_OK) { \
  193. CALL_HAL3ONLY_NOLOCK(ret, lpDevI, call, data); \
  194. } \
  195. if (locked) { \
  196. UNLOCK_HAL(lpDevI); \
  197. } \
  198. }
  199. HRESULT D3DHAL_AllocateBuffer(LPDIRECT3DDEVICEI, LPD3DI_BUFFERHANDLE, LPD3DEXECUTEBUFFERDESC, LPDIRECTDRAWSURFACE*);
  200. HRESULT D3DHAL_DeallocateBuffer(LPDIRECT3DDEVICEI, D3DI_BUFFERHANDLE);
  201. HRESULT D3DHAL_DeallocateBuffers(LPDIRECT3DDEVICEI);
  202. HRESULT D3DHAL_LockBuffer(LPDIRECT3DDEVICEI, D3DI_BUFFERHANDLE, LPD3DEXECUTEBUFFERDESC, LPDIRECTDRAWSURFACE*);
  203. HRESULT D3DHAL_UnlockBuffer(LPDIRECT3DDEVICEI, D3DI_BUFFERHANDLE);
  204. HRESULT D3DHAL_ExecuteClipped(LPDIRECT3DDEVICEI, LPD3DI_EXECUTEDATA);
  205. HRESULT D3DHAL_ExecuteUnclipped(LPDIRECT3DDEVICEI, LPD3DI_EXECUTEDATA);
  206. HRESULT D3DHAL_ExecutePick(LPDIRECT3DDEVICEI, LPD3DI_PICKDATA);
  207. HRESULT D3DHAL_TextureCreate(LPDIRECT3DDEVICEI, LPD3DTEXTUREHANDLE, LPDIRECTDRAWSURFACE);
  208. HRESULT D3DHAL_TextureDestroy(LPD3DI_TEXTUREBLOCK);
  209. HRESULT D3DHAL_TextureSwap(LPDIRECT3DDEVICEI, D3DTEXTUREHANDLE, D3DTEXTUREHANDLE);
  210. __declspec(dllexport) HRESULT D3DHAL_TextureGetSurf(LPDIRECT3DDEVICEI, D3DTEXTUREHANDLE, LPDIRECTDRAWSURFACE*);
  211. HRESULT D3DHAL_MatrixCreate(LPDIRECT3DDEVICEI, LPD3DMATRIXHANDLE);
  212. HRESULT D3DHAL_MatrixDestroy(LPDIRECT3DDEVICEI, D3DMATRIXHANDLE);
  213. HRESULT D3DHAL_MatrixSetData(LPDIRECT3DDEVICEI, D3DMATRIXHANDLE, LPD3DMATRIX);
  214. HRESULT D3DHAL_MatrixGetData(LPDIRECT3DDEVICEI, D3DMATRIXHANDLE, LPD3DMATRIX);
  215. HRESULT D3DFE_SetViewportData(LPDIRECT3DDEVICEI, DWORD, LPD3DVIEWPORT2);
  216. HRESULT D3DHAL_MaterialCreate(LPDIRECT3DDEVICEI, LPD3DMATERIALHANDLE, LPD3DMATERIAL);
  217. HRESULT D3DHAL_MaterialDestroy(LPDIRECT3DDEVICEI, D3DMATERIALHANDLE);
  218. HRESULT D3DHAL_MaterialSetData(LPDIRECT3DDEVICEI, D3DMATERIALHANDLE, LPD3DMATERIAL);
  219. HRESULT D3DHAL_MaterialGetData(LPDIRECT3DDEVICEI, D3DMATERIALHANDLE, LPD3DMATERIAL);
  220. HRESULT D3DHAL_LightSet(LPDIRECT3DDEVICEI, DWORD, LPD3DI_LIGHT);
  221. HRESULT D3DHAL_SceneCapture(LPDIRECT3DDEVICEI, BOOL);
  222. HRESULT D3DHAL_GetState(LPDIRECT3DDEVICEI, DWORD, LPD3DSTATE);
  223. /*********************
  224. * HEL Calls
  225. *********************/
  226. /*
  227. * Calls to emulate instructions.
  228. */
  229. extern HRESULT D3DHELInst_D3DOP_STATELIGHT(LPDIRECT3DDEVICEI, DWORD, LPD3DSTATE);
  230. extern HRESULT D3DHELInst_D3DOP_TEXTURELOAD(LPDIRECT3DDEVICEI, DWORD, LPD3DTEXTURELOAD);
  231. extern HRESULT D3DFE_Create(LPDIRECT3DDEVICEI lpDevI,
  232. LPDIRECTDRAW lpDD,
  233. LPDIRECTDRAWSURFACE lpDDS,
  234. LPDIRECTDRAWSURFACE lpZ,
  235. LPDIRECTDRAWPALETTE lpPal);
  236. extern void D3DFE_Destroy(LPDIRECT3DDEVICEI lpDevI);
  237. /*
  238. * Transform calls.
  239. */
  240. extern HRESULT D3DFE_TransformUnclippedVp(D3DFE_PROCESSVERTICES*, DWORD, D3DTRANSFORMDATAI*);
  241. extern HRESULT D3DFE_TransformClippedVp(D3DFE_PROCESSVERTICES*, DWORD, D3DTRANSFORMDATAI*);
  242. /*
  243. * Lighting calls.
  244. */
  245. extern HRESULT D3DFE_InitRGBLighting(LPDIRECT3DDEVICEI);
  246. extern void D3DFE_DestroyRGBLighting(LPDIRECT3DDEVICEI);
  247. DWORD D3DFE_QueryTextureFormat (LPDIRECT3DDEVICEI, LPDDSURFACEDESC*);
  248. HRESULT D3DFE_UpdateTexture (LPDIRECT3DDEVICEI, DWORD, D3DTEXTUREHANDLE);
  249. HRESULT D3DFE_Clear(LPDIRECT3DDEVICEI lpDevI, DWORD dwFlags, DWORD numRect, LPD3DRECT lpRect, D3DCOLORVALUE *pFillColor, D3DTEXTUREHANDLE dwTexture);
  250. HRESULT D3DFE_Clear2(LPDIRECT3DDEVICEI lpDevI, DWORD dwFlags,DWORD numRect, LPD3DRECT lpRect, D3DCOLOR dwColor, D3DVALUE dvZ, DWORD dwStencil);
  251. HRESULT D3DFE_SetMatrixProj(LPDIRECT3DDEVICEI lpDevI, D3DMATRIX *mat);
  252. HRESULT D3DFE_SetMatrixView(LPDIRECT3DDEVICEI lpDevI, D3DMATRIX *mat);
  253. HRESULT D3DFE_SetMatrixWorld(LPDIRECT3DDEVICEI lpDevI, D3DMATRIX *mat);
  254. HRESULT D3DFE_MultMatrixProj(LPDIRECT3DDEVICEI lpDevI, D3DMATRIX *mat);
  255. HRESULT D3DFE_MultMatrixView(LPDIRECT3DDEVICEI lpDevI, D3DMATRIX *mat);
  256. HRESULT D3DFE_MultMatrixWorld(LPDIRECT3DDEVICEI lpDevI, D3DMATRIX *mat);
  257. //---------------------------------------------------------------------
  258. // This function is called from HALEXE.CPP and from device::SetRenderState
  259. // Always use this function to update RSTATES.
  260. //
  261. HRESULT
  262. SetDeviceRenderState(LPDIRECT3DDEVICEI lpDevI, D3DRENDERSTATETYPE type,
  263. DWORD value);
  264. #ifndef WIN95
  265. __inline HRESULT CheckContextSurface(LPDIRECT3DDEVICEI lpDevI)
  266. {
  267. if(lpDevI->hSurfaceTarget != ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSTarget)->lpLcl->hDDSurface)
  268. {
  269. D3DHAL_SETRENDERTARGETDATA rtData;
  270. HRESULT ret;
  271. rtData.dwhContext = lpDevI->dwhContext;
  272. if (lpDevI->dwFEFlags & D3DFE_REALHAL)
  273. {
  274. if (lpDevI->lpDDSTarget)
  275. rtData.lpDDSLcl = ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSTarget)->lpLcl;
  276. else
  277. rtData.lpDDSLcl = NULL;
  278. if (lpDevI->lpDDSZBuffer)
  279. rtData.lpDDSZLcl = ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSZBuffer)->lpLcl;
  280. else
  281. rtData.lpDDSZLcl = NULL;
  282. }
  283. else
  284. {
  285. rtData.lpDDS = lpDevI->lpDDSTarget;
  286. rtData.lpDDSZ = lpDevI->lpDDSZBuffer;
  287. }
  288. rtData.ddrval = 0;
  289. CALL_HAL2ONLY(ret, lpDevI, SetRenderTarget, &rtData);
  290. if (ret != DDHAL_DRIVER_HANDLED)
  291. {
  292. D3D_ERR ( "Driver did not handle SetRenderTarget" );
  293. // Need sensible return value in this case,
  294. // currently we return whatever the lpDevI stuck in here.
  295. return rtData.ddrval;
  296. }
  297. lpDevI->hSurfaceTarget = ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSTarget)->lpLcl->hDDSurface;
  298. }
  299. return(D3D_OK);
  300. }
  301. __inline HRESULT CheckContextSurfaceNOLOCK (LPDIRECT3DDEVICEI lpDevI)
  302. {
  303. if(lpDevI->hSurfaceTarget != ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSTarget)->lpLcl->hDDSurface)
  304. {
  305. D3DHAL_SETRENDERTARGETDATA rtData;
  306. HRESULT ret;
  307. rtData.dwhContext = lpDevI->dwhContext;
  308. if (lpDevI->dwFEFlags & D3DFE_REALHAL)
  309. {
  310. if (lpDevI->lpDDSTarget)
  311. rtData.lpDDSLcl = ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSTarget)->lpLcl;
  312. else
  313. rtData.lpDDSLcl = NULL;
  314. if (lpDevI->lpDDSZBuffer)
  315. rtData.lpDDSZLcl = ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSZBuffer)->lpLcl;
  316. else
  317. rtData.lpDDSZLcl = NULL;
  318. }
  319. else
  320. {
  321. rtData.lpDDS = lpDevI->lpDDSTarget;
  322. rtData.lpDDSZ = lpDevI->lpDDSZBuffer;
  323. }
  324. rtData.ddrval = 0;
  325. CALL_HAL2ONLY_NOLOCK(ret, lpDevI, SetRenderTarget, &rtData);
  326. if (ret != DDHAL_DRIVER_HANDLED)
  327. {
  328. D3D_ERR( "Driver did not handle SetRenderTarget" );
  329. // Need sensible return value in this case,
  330. // currently we return whatever the lpDevI stuck in here.
  331. return rtData.ddrval;
  332. }
  333. lpDevI->hSurfaceTarget = ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSTarget)->lpLcl->hDDSurface;
  334. }
  335. return(D3D_OK);
  336. }
  337. #endif //WIN95
  338. // This struct is used for FindLightingRange RampService
  339. typedef struct tagRAMP_RANGE_INFO
  340. {
  341. DWORD base;
  342. DWORD size;
  343. LPVOID pTexRampMap;
  344. BOOL specular;
  345. }RAMP_RANGE_INFO;
  346. // This inline is for calling RastService when nothing special is required.
  347. inline HRESULT CallRastService(LPDIRECT3DDEVICEI lpDevI,
  348. RastServiceType ServiceType,
  349. DWORD arg1,
  350. LPVOID arg2)
  351. {
  352. if (lpDevI->pfnRastService != NULL)
  353. {
  354. return lpDevI->pfnRastService(lpDevI->dwhContext,
  355. ServiceType, arg1, arg2);
  356. }
  357. else
  358. {
  359. return D3D_OK;
  360. }
  361. }
  362. // This inline is for calling RampService.
  363. // bFlush is set to TRUE when DrawPrims needs to be flushed.
  364. // Right now, it is set for SetMat and LightState-SetMat.
  365. inline HRESULT CallRampService(LPDIRECT3DDEVICEI lpDevI,
  366. RastRampServiceType ServiceType,
  367. ULONG_PTR arg1,
  368. LPVOID arg2,
  369. BOOL bFlush = FALSE)
  370. {
  371. if (lpDevI->pfnRampService != NULL)
  372. {
  373. if (bFlush)
  374. {
  375. //time to flush DrawPrimitives
  376. (*lpDevI->pfnFlushStates)( lpDevI );
  377. }
  378. // Call the service
  379. return lpDevI->pfnRampService(lpDevI->dwhContext,
  380. ServiceType, arg1, arg2);
  381. }
  382. else
  383. {
  384. return D3D_OK;
  385. }
  386. }
  387. #endif /* _HALDRV_H_ */