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.

317 lines
16 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_TextureCreate(LPDIRECT3DDEVICEI, LPD3DTEXTUREHANDLE, LPDIRECTDRAWSURFACE);
  200. HRESULT D3DHAL_TextureDestroy(LPD3DI_TEXTUREBLOCK);
  201. HRESULT D3DFE_SetViewportData(LPDIRECT3DDEVICEI, DWORD, LPD3DVIEWPORT2);
  202. HRESULT D3DHAL_MaterialGetData(LPDIRECT3DDEVICEI, D3DMATERIALHANDLE, LPD3DMATERIAL);
  203. HRESULT D3DHAL_LightSet(LPDIRECT3DDEVICEI, DWORD, LPD3DI_LIGHT);
  204. HRESULT D3DHAL_SceneCapture(LPDIRECT3DDEVICEI, BOOL);
  205. /*********************
  206. * HEL Calls
  207. *********************/
  208. extern HRESULT D3DFE_Create(LPDIRECT3DDEVICEI lpDevI,
  209. LPDIRECTDRAW lpDD,
  210. LPDIRECTDRAW7 lpDD7,
  211. LPDIRECTDRAWSURFACE lpDDS,
  212. LPDIRECTDRAWSURFACE lpZ,
  213. LPDIRECTDRAWPALETTE lpPal);
  214. extern void D3DFE_Destroy(LPDIRECT3DDEVICEI lpDevI);
  215. DWORD D3DFE_QueryTextureFormat (LPDIRECT3DDEVICEI, LPDDSURFACEDESC*);
  216. HRESULT D3DFE_UpdateTexture (LPDIRECT3DDEVICEI, DWORD, D3DTEXTUREHANDLE);
  217. HRESULT D3DFE_Clear2(LPDIRECT3DDEVICEI lpDevI, DWORD dwFlags,DWORD numRect, LPD3DRECT lpRect, D3DCOLOR dwColor, D3DVALUE dvZ, DWORD dwStencil);
  218. #ifndef WIN95
  219. __inline HRESULT CheckContextSurface(LPDIRECT3DDEVICEI lpDevI)
  220. {
  221. if(lpDevI->hSurfaceTarget != ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSTarget)->lpLcl->hDDSurface)
  222. {
  223. D3DHAL_SETRENDERTARGETDATA rtData;
  224. HRESULT ret;
  225. rtData.dwhContext = lpDevI->dwhContext;
  226. if (lpDevI->dwFEFlags & D3DFE_REALHAL)
  227. {
  228. if (lpDevI->lpDDSTarget)
  229. rtData.lpDDSLcl = ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSTarget)->lpLcl;
  230. else
  231. rtData.lpDDSLcl = NULL;
  232. if (lpDevI->lpDDSZBuffer)
  233. rtData.lpDDSZLcl = ((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSZBuffer)->lpLcl;
  234. else
  235. rtData.lpDDSZLcl = NULL;
  236. }
  237. else
  238. {
  239. rtData.lpDDS = lpDevI->lpDDSTarget;
  240. rtData.lpDDSZ = lpDevI->lpDDSZBuffer;
  241. }
  242. rtData.ddrval = 0;
  243. CALL_HAL2ONLY(ret, lpDevI, SetRenderTarget, &rtData);
  244. if (ret != DDHAL_DRIVER_HANDLED)
  245. {
  246. D3D_ERR ( "Driver did not handle SetRenderTarget" );
  247. // Need sensible return value in this case,
  248. // currently we return whatever the lpDevI stuck in here.
  249. return rtData.ddrval;
  250. }
  251. lpDevI->hSurfaceTarget = (DWORD)(((LPDDRAWI_DDRAWSURFACE_INT)lpDevI->lpDDSTarget)->lpLcl->hDDSurface);
  252. }
  253. return(D3D_OK);
  254. }
  255. #endif //WIN95
  256. // This struct is used for FindLightingRange RampService
  257. typedef struct tagRAMP_RANGE_INFO
  258. {
  259. DWORD base;
  260. DWORD size;
  261. LPVOID pTexRampMap;
  262. BOOL specular;
  263. }RAMP_RANGE_INFO;
  264. // This inline is for calling RastService when nothing special is required.
  265. inline HRESULT CallRastService(LPDIRECT3DDEVICEI lpDevI,
  266. RastServiceType ServiceType,
  267. DWORD arg1,
  268. LPVOID arg2)
  269. {
  270. if (lpDevI->pfnRastService != NULL)
  271. {
  272. return lpDevI->pfnRastService(lpDevI->dwhContext,
  273. ServiceType, arg1, arg2);
  274. }
  275. else
  276. {
  277. return D3D_OK;
  278. }
  279. }
  280. #endif /* _HALDRV_H_ */