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.

325 lines
11 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995-1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: d3dpr.h
  6. * Content: Direct3D private include file
  7. *@@BEGIN_MSINTERNAL
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 05/11/95 stevela Initial rev with this header.
  13. * 23/11/95 colinmc Made various Direct3D interfaces queryable off
  14. * DirectDraw.
  15. * 07/12/95 stevela Merged Colin's changes.
  16. * 10/12/95 stevela Removed AGGREGATE_D3D.
  17. * 17/04/96 colinmc Bug 17008: DirectDraw/Direct3D deadlock
  18. *@@END_MSINTERNAL
  19. *
  20. ***************************************************************************/
  21. #ifndef _D3DPR_H_
  22. #define _D3DPR_H_
  23. #include "d3di.hpp"
  24. #include "texman.hpp"
  25. #include "dpf.h"
  26. /*
  27. * Texture Manipulation Utils
  28. */
  29. extern void D3DI_RemoveTextureHandle(LPD3DI_TEXTUREBLOCK);
  30. extern "C" void WINAPI D3DTextureUpdate(IUnknown FAR * pD3DIUnknown);
  31. extern DWORD BitDepthToDDBD(int bpp);
  32. extern BOOL D3DI_isHALValid(LPD3DHAL_CALLBACKS pCallbacks);
  33. extern void FreeDeviceI(LPDIRECT3DDEVICEI pDevI);
  34. #define D3DBUCKETBUFFERSIZE 32 //make buffer byte size 2*D3DBUCKETBUFFERSIZE*4
  35. extern HRESULT D3DMallocBucket(LPDIRECT3DI, LPD3DBUCKET *);
  36. extern void D3DFreeBucket(LPDIRECT3DI, LPD3DBUCKET);
  37. extern LPD3DI_TEXTUREBLOCK D3DI_FindTextureBlock(LPDIRECT3DTEXTUREI,LPDIRECT3DDEVICEI);
  38. inline bool MatchDDPIXELFORMAT( DDPIXELFORMAT* pddpfA, DDPIXELFORMAT* pddpfB )
  39. {
  40. return ( pddpfA->dwFlags == pddpfB->dwFlags ) &&
  41. ( pddpfA->dwRGBBitCount == pddpfB->dwRGBBitCount ) &&
  42. ( pddpfA->dwRBitMask == pddpfB->dwRBitMask ) &&
  43. ( pddpfA->dwGBitMask == pddpfB->dwGBitMask ) &&
  44. ( pddpfA->dwBBitMask == pddpfB->dwBBitMask ) &&
  45. ( pddpfA->dwRGBAlphaBitMask == pddpfB->dwRGBAlphaBitMask ) &&
  46. ( pddpfA->dwFourCC == pddpfB->dwFourCC );
  47. }
  48. inline DDPIXELFORMAT& PixelFormat(LPDDRAWI_DDRAWSURFACE_LCL lpLcl)
  49. {
  50. return (lpLcl->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? lpLcl->lpGbl->ddpfSurface : lpLcl->lpGbl->lpDD->vmiData.ddpfDisplay;
  51. }
  52. #if _D3D_FORCEDOUBLE
  53. class CD3DForceFPUDouble
  54. {
  55. private:
  56. WORD wFPUCW;
  57. WORD wSaved;
  58. public:
  59. __inline
  60. CD3DForceFPUDouble(CDirect3DDeviceIHW * lpDevI)
  61. {
  62. wSaved=FALSE;
  63. if (lpDevI->dwDebugFlags & D3DDEBUG_FORCEDOUBLE)
  64. {
  65. WORD wTemp;
  66. __asm fstcw wTemp
  67. if (!(wTemp & 0x0200))
  68. {
  69. wSaved=TRUE;
  70. wFPUCW=wTemp;
  71. wTemp=wFPUCW | 0x0200; //Enforce Double Precision bit
  72. __asm fldcw wTemp
  73. }
  74. }
  75. }
  76. __inline
  77. ~CD3DForceFPUDouble()
  78. {
  79. if (wSaved)
  80. {
  81. WORD wTemp = wFPUCW;
  82. __asm fldcw wTemp
  83. }
  84. }
  85. };
  86. #endif //_D3D_FORCEDOUBLE
  87. /*
  88. * Critical section code.
  89. * Coarse locking. All actions require this section.
  90. * Defined in d3dcreat.c
  91. */
  92. /*
  93. * On WINNT critical sections can't be used because synchronization must
  94. * occur cross process. DDraw and D3D must share this synchronization so
  95. * DDraw exports private functions for synchronization that NT D3D must use.
  96. */
  97. #ifdef WIN95
  98. extern LPCRITICAL_SECTION lpD3DCSect;
  99. #endif
  100. extern "C" {
  101. #define this _this
  102. #include "ddrawpr.h"
  103. #undef this
  104. };
  105. #if DBG
  106. extern int iD3DCSCnt;
  107. #define INCD3DCSCNT() iD3DCSCnt++;
  108. #define INITD3DCSCNT() iD3DCSCnt = 0;
  109. #define DECD3DCSCNT() iD3DCSCnt--;
  110. #else
  111. #define INCD3DCSCNT()
  112. #define INITD3DCSCNT()
  113. #define DECD3DCSCNT()
  114. #endif
  115. #ifdef WIN95
  116. #define ENTER_D3D() \
  117. EnterCriticalSection( lpD3DCSect ); \
  118. INCD3DCSCNT(); \
  119. #define LEAVE_D3D() \
  120. DECD3DCSCNT() \
  121. LeaveCriticalSection( lpD3DCSect );
  122. #else
  123. #define ENTER_D3D() \
  124. AcquireDDThreadLock(); \
  125. INCD3DCSCNT(); \
  126. #define LEAVE_D3D() \
  127. DECD3DCSCNT() \
  128. ReleaseDDThreadLock();
  129. #endif
  130. // This class is designed to simplify ENTER_D3D() LEAVE_D3D() logic
  131. // If object of this class is instantiated, then internal lock will be taken.
  132. // As soon as object is destroyed lock will be released
  133. //
  134. class CLockD3D
  135. {
  136. public:
  137. CLockD3D(char *moduleName, char *fileName)
  138. {
  139. ENTER_D3D();
  140. #if DBG // Required to eliminate use of moduleName and fileName in retail builds
  141. D3D_INFO( 6, "*** LOCK_D3D: CNT = %ld %s %s", iD3DCSCnt, moduleName, fileName );
  142. #endif
  143. }
  144. ~CLockD3D()
  145. {
  146. LEAVE_D3D();
  147. D3D_INFO( 6, "*** UNLOCK_D3D: CNT = %ld", iD3DCSCnt);
  148. }
  149. };
  150. class CLockD3DST
  151. {
  152. private:
  153. bool bEnter;
  154. public:
  155. CLockD3DST(LPDIRECT3DDEVICEI lpDevI, char *moduleName, char *fileName)
  156. {
  157. if (! IS_MT_DEVICE(lpDevI) )
  158. {
  159. ENTER_D3D();
  160. #if DBG // Required to eliminate use of moduleName and fileName in retail builds
  161. D3D_INFO( 6, "*** LOCK_D3D: CNT = %ld %s %s", iD3DCSCnt, moduleName, fileName );
  162. #endif
  163. bEnter = true;
  164. }
  165. else
  166. bEnter = false;
  167. }
  168. ~CLockD3DST()
  169. {
  170. if (bEnter)
  171. {
  172. LEAVE_D3D();
  173. D3D_INFO( 6, "*** UNLOCK_D3D: CNT = %ld", iD3DCSCnt);
  174. }
  175. }
  176. };
  177. class CLockD3DMT
  178. {
  179. private:
  180. bool bEnter;
  181. public:
  182. CLockD3DMT(LPDIRECT3DDEVICEI lpDevI, char *moduleName, char *fileName)
  183. {
  184. if ( IS_MT_DEVICE(lpDevI) )
  185. {
  186. ENTER_D3D();
  187. #if DBG // Required to eliminate use of moduleName and fileName in retail builds
  188. D3D_INFO( 6, "*** LOCK_D3D: CNT = %ld %s %s", iD3DCSCnt, moduleName, fileName );
  189. #endif
  190. bEnter = true;
  191. }
  192. else
  193. bEnter = false;
  194. }
  195. ~CLockD3DMT()
  196. {
  197. if (bEnter)
  198. {
  199. LEAVE_D3D();
  200. D3D_INFO( 6, "*** UNLOCK_D3D: CNT = %ld", iD3DCSCnt);
  201. }
  202. }
  203. };
  204. #define ENTER_CBCSECT(device) EnterCriticalSection(&(device)->CommandBufferCSect)
  205. #define LEAVE_CBCSECT(device) LeaveCriticalSection(&(device)->CommandBufferCSect)
  206. // Macro used to access DDRAW GBL from a given LPDIRECT3DI
  207. #define DDGBL(lpD3DI) ((LPDDRAWI_DIRECTDRAW_INT)lpD3DI->lpDD)->lpLcl->lpGbl
  208. // Macro used to access DDRAW SURF LCL from a given surface
  209. #define DDSLCL(lpDDS) (((LPDDRAWI_DDRAWSURFACE_INT)lpDDS)->lpLcl)
  210. // Macro used to access DDRAW SURF GBL from a given surface
  211. #define DDSGBL(lpDDS) (((LPDDRAWI_DDRAWSURFACE_INT)lpDDS)->lpLcl->lpGbl)
  212. /*
  213. * Macros for validating parameters.
  214. * Only implement those not available in ddrawpr.h.
  215. */
  216. #define VALID_OUTPTR(x) ((x) && VALID_PTR_PTR(x))
  217. // FAST_CHECKING macro is defined in ddrawpr.h
  218. // so in make sure that ddrawpr.h is always included
  219. // before this header.
  220. #ifndef FAST_CHECKING
  221. #define VALID_DIRECT3D_PTR( ptr ) \
  222. (!IsBadWritePtr( ptr, sizeof( DIRECT3DI )))
  223. #define VALID_DIRECT3DTEXTUREM_PTR( ptr ) \
  224. (!IsBadWritePtr( ptr, sizeof( DIRECT3DTEXTUREM )))
  225. #define VALID_DIRECT3DTEXTURED3DM_PTR( ptr ) \
  226. (!IsBadWritePtr( ptr, sizeof( DIRECT3DTEXTURED3DM )))
  227. #define VALID_DIRECT3DDEVICE_PTR( ptr ) \
  228. (!IsBadWritePtr( ptr, sizeof( DIRECT3DDEVICEI )))
  229. #define VALID_DDSURF_PTR( ptr ) \
  230. (!IsBadWritePtr( ptr, sizeof( DDRAWI_DDRAWSURFACE_INT )))
  231. #define VALID_DIRECT3DVERTEXBUFFER_PTR( ptr ) \
  232. (!IsBadWritePtr( ptr, sizeof( CDirect3DVertexBuffer )))
  233. #define VALID_D3DVERTEXBUFFERDESC_PTR( ptr ) \
  234. (!IsBadWritePtr( ptr, sizeof( D3DVERTEXBUFFERDESC ) ) && \
  235. (ptr->dwSize == sizeof( D3DVERTEXBUFFERDESC )) )
  236. #define VALID_D3DDEVICEDESC7_PTR( ptr ) \
  237. (! IsBadWritePtr(ptr, sizeof( D3DDEVICEDESC7 )) )
  238. #define VALID_D3DRECT_PTR( ptr ) \
  239. (!IsBadWritePtr( ptr, sizeof( D3DRECT ) ))
  240. #define VALID_GDIRECT_PTR( ptr ) \
  241. (!IsBadWritePtr( ptr, sizeof( RECT ) ))
  242. #define VALID_GDIPOINT_PTR( ptr ) \
  243. (!IsBadWritePtr( ptr, sizeof( POINT ) ))
  244. #define VALID_D3DVIEWPORT_PTR( ptr ) (!IsBadWritePtr(ptr, sizeof(D3DVIEWPORT7)))
  245. #define VALID_D3DMATRIX_PTR( ptr ) (!IsBadWritePtr(ptr, sizeof(D3DMATRIX)))
  246. #define VALID_D3DLIGHT_PTR( ptr ) (!IsBadWritePtr(ptr, sizeof(D3DLIGHT7)))
  247. #define VALID_D3DMATERIAL_PTR( ptr ) (!IsBadWritePtr( ptr, sizeof(D3DMATERIAL7)))
  248. #define VALID_D3DTEXTUREHANDLE_PTR( ptr ) \
  249. (!IsBadWritePtr( ptr, sizeof( D3DTEXTUREHANDLE ) ) )
  250. #define VALID_D3DLIGHTDATA_PTR( ptr ) \
  251. (!IsBadWritePtr( ptr, sizeof( D3DLIGHTDATA ) ) && \
  252. (ptr->dwSize == sizeof( D3DLIGHTDATA )) )
  253. #define VALID_D3DFINDDEVICESEARCH_PTR( ptr ) \
  254. (!IsBadWritePtr( ptr, sizeof( D3DFINDDEVICESEARCH ) ) && \
  255. (ptr->dwSize == sizeof( D3DFINDDEVICESEARCH ) ) )
  256. #define VALID_D3DFINDDEVICERESULT7_PTR( ptr ) \
  257. ( (! IsBadWritePtr( ptr, 4)) && \
  258. (ptr->dwSize == sizeof(D3DFINDDEVICERESULT7)) && \
  259. (! IsBadWritePtr( ptr, ptr->dwSize) ) )
  260. #define VALID_D3DDEVINFOSTRUCT_PTR( ptr, size ) \
  261. (!IsBadWritePtr( ptr, size ) )
  262. // Note: these macros are replacements for the VALID_DIRECTDRAWSURFACE_PTR ddraw macros
  263. // because those macros need access to the ddCallbacks ddraw globals.
  264. // At some point these could be replaced with a ddraw exported fn that actually
  265. // verifies the callback table type
  266. #define VALID_D3D_DIRECTDRAWSURFACE_PTR(ptr) (!IsBadWritePtr(ptr, sizeof(DDRAWI_DDRAWSURFACE_INT)))
  267. #define VALID_D3D_DIRECTDRAWSURFACE7_PTR(ptr) (!IsBadWritePtr(ptr, sizeof(DDRAWI_DDRAWSURFACE_INT)))
  268. #else /* !FAST_CHECKING */
  269. #define VALID_DIRECT3D_PTR( ptr ) (ptr)
  270. #define VALID_DIRECT3DTEXTUREM_PTR( ptr ) (ptr)
  271. #define VALID_DIRECT3DTEXTURED3DM_PTR( ptr ) (ptr)
  272. #define VALID_DIRECT3DDEVICE_PTR( ptr ) (ptr)
  273. #define VALID_DDSURF_PTR( ptr ) (ptr)
  274. #define VALID_DIRECT3DVERTEXBUFFER_PTR( ptr ) (ptr)
  275. #define VALID_D3DVERTEXBUFFERDESC_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DVERTEXBUFFERDESC ))
  276. #define VALID_D3DDEVICEDESC7_PTR( ptr ) (ptr)
  277. #define VALID_D3DVIEWPORT_PTR( ptr ) (ptr)
  278. #define VALID_D3DRECT_PTR( ptr ) (ptr)
  279. #define VALID_GDIRECT_PTR( ptr ) (ptr)
  280. #define VALID_GDIPOINT_PTR( ptr ) (ptr)
  281. #define VALID_D3DMATRIX_PTR( ptr ) (ptr)
  282. #define VALID_D3DLIGHT_PTR( ptr ) (ptr)
  283. #define VALID_D3DMATERIAL_PTR( ptr ) (ptr)
  284. #define VALID_D3DTEXTUREHANDLE_PTR( ptr ) (ptr)
  285. #define VALID_D3DLIGHTDATA_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DLIGHTDATA ))
  286. #define VALID_D3DFINDDEVICESEARCH_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DFINDDEVICESEARCH ))
  287. #define VALID_D3DFINDDEVICERESULT7_PTR( ptr ) \
  288. ((ptr) && (ptr->dwSize == sizeof( D3DFINDDEVICERESULT7 )) )
  289. #define VALID_D3D_DIRECTDRAWSURFACE_PTR(ptr) (ptr) // see comment above
  290. #define VALID_D3D_DIRECTDRAWSURFACE7_PTR(ptr) (ptr)
  291. #define VALID_D3DDEVINFOSTRUCT_PTR( ptr, size ) (ptr)
  292. #endif /* !FAST_CHECKING */
  293. #endif /* _D3DPR_H_ */