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.

571 lines
21 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 void D3DI_RemoveMaterialBlock(LPD3DI_MATERIALBLOCK);
  31. extern DWORD BitDepthToDDBD(int bpp);
  32. extern BOOL D3DI_isHALValid(LPD3DHAL_CALLBACKS pCallbacks);
  33. extern void FreeDeviceI(LPDIRECT3DDEVICEI pDevI);
  34. extern HRESULT D3DBufFreeBufferMemory(LPDIRECT3DEXECUTEBUFFERI lpBuf, DWORD dwWhere);
  35. extern HRESULT D3DBufAllocateBufferMemory(LPDIRECT3DEXECUTEBUFFERI lpBuf, DWORD dwWhere);
  36. extern HRESULT D3DBufHookBufferToDevice(LPDIRECT3DDEVICEI lpDev, LPDIRECT3DEXECUTEBUFFERI lpBuf);
  37. extern HRESULT HookD3DDeviceToSurface(LPDIRECT3DDEVICEI,LPDDRAWI_DDRAWSURFACE_LCL);
  38. extern void UnHookD3DDeviceFromSurface(LPDIRECT3DDEVICEI,LPDDRAWI_DDRAWSURFACE_LCL);
  39. #define D3DBUCKETBUFFERSIZE 32 //make buffer byte size 2*D3DBUCKETBUFFERSIZE*4
  40. extern HRESULT D3DMallocBucket(LPDIRECT3DI, LPD3DBUCKET *);
  41. extern void D3DFreeBucket(LPDIRECT3DI, LPD3DBUCKET);
  42. extern LPD3DI_TEXTUREBLOCK D3DI_FindTextureBlock(LPDIRECT3DTEXTUREI,LPDIRECT3DDEVICEI);
  43. extern HRESULT CopySurface(LPDIRECTDRAWSURFACE4,LPDIRECTDRAWSURFACE4,LPDIRECTDRAWCLIPPER);
  44. extern HRESULT GetTextureDDIHandle(LPDIRECT3DTEXTUREI,LPDIRECT3DDEVICEI,LPD3DI_TEXTUREBLOCK*);
  45. __inline void
  46. BatchTextureToDevice(LPDIRECT3DDEVICEI lpDevI, LPDDRAWI_DDRAWSURFACE_LCL lpLcl) {
  47. LPD3DBUCKET lpTextureBatched;
  48. if ( D3D_OK != HookD3DDeviceToSurface(lpDevI,lpLcl)) {
  49. return;
  50. }
  51. if (D3DMallocBucket(lpDevI->lpDirect3DI,&lpTextureBatched) != D3D_OK)
  52. { //this is left often to happen
  53. UnHookD3DDeviceFromSurface(lpDevI, lpLcl);
  54. return;
  55. }
  56. lpTextureBatched->lpLcl=lpLcl;
  57. lpTextureBatched->next=lpDevI->lpTextureBatched;
  58. lpDevI->lpTextureBatched=lpTextureBatched;
  59. return;
  60. }
  61. __inline void
  62. FlushTextureFromDevice(LPDIRECT3DDEVICEI lpDevI)
  63. {
  64. LPD3DBUCKET current=lpDevI->lpTextureBatched;
  65. DWORD dwStage;
  66. while(current)
  67. {
  68. LPD3DBUCKET temp;
  69. temp=current->next;
  70. UnHookD3DDeviceFromSurface(lpDevI,current->lpLcl);
  71. D3DFreeBucket(lpDevI->lpDirect3DI,current);
  72. current=temp;
  73. }
  74. lpDevI->lpTextureBatched=NULL;
  75. if (lpDevI->lpDDSZBuffer && (1==lpDevI->dwVersion))
  76. {
  77. if (!lpDevI->lpDDSZBuffer_DDS4) // DDRAW zeroed it ?
  78. {
  79. UnHookD3DDeviceFromSurface(lpDevI,((LPDDRAWI_DDRAWSURFACE_INT) lpDevI->lpDDSZBuffer)->lpLcl);
  80. lpDevI->lpDDSZBuffer=NULL;
  81. }
  82. }
  83. for (dwStage=0;dwStage < lpDevI->dwMaxTextureBlendStages; dwStage++)
  84. {
  85. LPD3DI_TEXTUREBLOCK lpBlock = lpDevI->lpD3DMappedBlock[dwStage];
  86. LPDIRECT3DTEXTUREI lpTexI = lpDevI->lpD3DMappedTexI[dwStage];
  87. if (NULL != lpTexI
  88. && NULL != lpBlock
  89. && 0 != lpBlock->hTex)
  90. {
  91. if(lpTexI->lpDDS != NULL)
  92. {
  93. BatchTextureToDevice(lpDevI, ((LPDDRAWI_DDRAWSURFACE_INT) lpTexI->lpDDS)->lpLcl);
  94. }
  95. else
  96. {
  97. BatchTextureToDevice(lpDevI, ((LPDDRAWI_DDRAWSURFACE_INT) lpTexI->lpDDSSys)->lpLcl);
  98. }
  99. }
  100. }
  101. return;
  102. }
  103. #undef DPF_MODNAME
  104. #define DPF_MODNAME "VerifyTextureCaps"
  105. __inline HRESULT
  106. VerifyTextureCaps(LPDIRECT3DDEVICEI lpDev, LPDDRAWI_DDRAWSURFACE_INT lpDDS)
  107. {
  108. DWORD texcap;
  109. WORD width, height;
  110. DDASSERT(lpDDS != NULL);
  111. /* first verify the dimensions */
  112. if (lpDev->d3dHWDevDesc.dwFlags & D3DDD_TRICAPS)
  113. texcap = lpDev->d3dHWDevDesc.dpcTriCaps.dwTextureCaps;
  114. else
  115. texcap = lpDev->d3dHELDevDesc.dpcTriCaps.dwTextureCaps;
  116. width = lpDDS->lpLcl->lpGbl->wWidth;
  117. height = lpDDS->lpLcl->lpGbl->wHeight;
  118. if (texcap & D3DPTEXTURECAPS_POW2)
  119. {
  120. if (width & (width - 1)) // Clear the right most set bit
  121. {
  122. if (texcap & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
  123. {
  124. D3D_INFO( 3, "Texture width not a power of two");
  125. D3D_INFO( 3, " with D3DPTEXTURECAPS_NONPOW2CONDITIONAL");
  126. }
  127. else
  128. {
  129. D3D_ERR("Texture width not a power of two");
  130. return D3DERR_TEXTURE_BADSIZE;
  131. }
  132. }
  133. if (height & (height - 1)) // Clear the right most set bit
  134. {
  135. if (texcap & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
  136. {
  137. D3D_INFO( 3, "Texture height not a power of two");
  138. D3D_INFO( 3, " with D3DPTEXTURECAPS_NONPOW2CONDITIONAL");
  139. }
  140. else
  141. {
  142. D3D_ERR("Texture height not a power of two");
  143. return D3DERR_TEXTURE_BADSIZE;
  144. }
  145. }
  146. }
  147. if (texcap & D3DPTEXTURECAPS_SQUAREONLY)
  148. {
  149. if (width != height)
  150. {
  151. D3D_ERR("Texture not square");
  152. return D3DERR_TEXTURE_BADSIZE;
  153. }
  154. }
  155. return D3D_OK;
  156. }
  157. #if _D3D_FORCEDOUBLE
  158. class CD3DForceFPUDouble
  159. {
  160. private:
  161. WORD wFPUCW;
  162. WORD wSaved;
  163. public:
  164. __inline
  165. CD3DForceFPUDouble(CDirect3DDeviceIHW * lpDevI)
  166. {
  167. wSaved=FALSE;
  168. if (lpDevI->dwDebugFlags & D3DDEBUG_FORCEDOUBLE)
  169. {
  170. WORD wTemp;
  171. __asm fstcw wTemp
  172. if (!(wTemp & 0x0200))
  173. {
  174. wSaved=TRUE;
  175. wFPUCW=wTemp;
  176. wTemp=wFPUCW | 0x0200; //Enforce Double Precision bit
  177. __asm fldcw wTemp
  178. }
  179. }
  180. }
  181. __inline
  182. ~CD3DForceFPUDouble()
  183. {
  184. if (wSaved)
  185. {
  186. WORD wTemp = wFPUCW;
  187. __asm fldcw wTemp
  188. }
  189. }
  190. };
  191. #endif //_D3D_FORCEDOUBLE
  192. //---------------------------------------------------------------------
  193. // The CSetD3DFPstate is used to facilitate the changing of FPU settings.
  194. // In the constructor the optimal FPU state is set. In the destructor the
  195. // old state is restored.
  196. //
  197. class CD3DFPstate
  198. {
  199. public:
  200. CD3DFPstate()
  201. {
  202. #ifdef _X86_
  203. WORD wTemp, wSave;
  204. wSavedFP = FALSE;
  205. // Disable floating point exceptions and go to single mode
  206. __asm fstcw wSave
  207. if (wSave & 0x300 || // Not single mode
  208. 0x3f != (wSave & 0x3f) || // Exceptions enabled
  209. wSave & 0xC00) // Not round to nearest mode
  210. {
  211. __asm {
  212. mov ax, wSave
  213. and ax, not 300h ;; single mode
  214. or ax, 3fh ;; disable all exceptions
  215. and ax, not 0xC00 ;; round to nearest mode
  216. mov wTemp, ax
  217. fldcw wTemp
  218. }
  219. wSavedFP = TRUE;
  220. }
  221. wSaveFP = wSave;
  222. #endif
  223. }
  224. ~CD3DFPstate()
  225. {
  226. #ifdef _X86_
  227. WORD wSave = wSaveFP;
  228. if (wSavedFP)
  229. __asm {
  230. fnclex
  231. fldcw wSave
  232. }
  233. #endif
  234. }
  235. protected:
  236. #ifdef _X86_
  237. WORD wSaveFP;
  238. WORD wSavedFP; // WORD-sized to make the data an even DWORD
  239. #endif
  240. };
  241. /*
  242. * State flushing functions
  243. */
  244. extern HRESULT FlushStatesHW(LPDIRECT3DDEVICEI);
  245. extern HRESULT FlushStatesDP(LPDIRECT3DDEVICEI);
  246. extern HRESULT FlushStatesCB(LPDIRECT3DDEVICEI);
  247. /*
  248. * These are used to draw primitives which come out of the clipper
  249. */
  250. extern HRESULT DrawPrimitivesDP(LPDIRECT3DDEVICEI, LPD3DTLVERTEX lpTLBuf, LPVOID lpTBuf, LPD3DINSTRUCTION ins, DWORD dwNumVertices, D3DVERTEXTYPE VtxType);
  251. extern HRESULT DrawPrimitiveLegacyHalCall(LPDIRECT3DDEVICEI, LPD3DTLVERTEX lpVertices, LPVOID lpvData, LPD3DINSTRUCTION ins, DWORD dwNumVertices, D3DVERTEXTYPE VtxType);
  252. extern HRESULT DrawPrimitivesCB(LPDIRECT3DDEVICEI, LPD3DTLVERTEX lpVertices, LPVOID lpvData, LPD3DINSTRUCTION ins, DWORD dwNumVertices, D3DVERTEXTYPE VtxType);
  253. /*
  254. * Critical section code.
  255. * Coarse locking. All actions require this section.
  256. * Defined in d3dcreat.c
  257. */
  258. /*
  259. * On WINNT critical sections can't be used because synchronization must
  260. * occur cross process. DDraw and D3D must share this synchronization so
  261. * DDraw exports private functions for synchronization that NT D3D must use.
  262. */
  263. #ifdef WIN95
  264. extern LPCRITICAL_SECTION lpD3DCSect;
  265. #endif
  266. extern "C" {
  267. #define this _this
  268. #include "ddrawpr.h"
  269. #undef this
  270. };
  271. #if DBG
  272. extern int iD3DCSCnt;
  273. #define INCD3DCSCNT() iD3DCSCnt++;
  274. #define INITD3DCSCNT() iD3DCSCnt = 0;
  275. #define DECD3DCSCNT() iD3DCSCnt--;
  276. #else
  277. #define INCD3DCSCNT()
  278. #define INITD3DCSCNT()
  279. #define DECD3DCSCNT()
  280. #endif
  281. #ifdef WIN95
  282. #define ENTER_D3D() \
  283. EnterCriticalSection( lpD3DCSect ); \
  284. INCD3DCSCNT(); \
  285. #define LEAVE_D3D() \
  286. DECD3DCSCNT() \
  287. LeaveCriticalSection( lpD3DCSect );
  288. #else
  289. #define ENTER_D3D() \
  290. AcquireDDThreadLock(); \
  291. INCD3DCSCNT(); \
  292. #define LEAVE_D3D() \
  293. DECD3DCSCNT() \
  294. ReleaseDDThreadLock();
  295. #endif
  296. // This class is designed to simplify ENTER_D3D() LEAVE_D3D() logic
  297. // If object of this class is instantiated, then internal lock will be taken.
  298. // As soon as object is destroyed lock will be released
  299. //
  300. class CLockD3D
  301. {
  302. public:
  303. CLockD3D(char *moduleName, char *fileName)
  304. {
  305. ENTER_D3D();
  306. #if DBG // Required to eliminate use of moduleName and fileName in retail builds
  307. D3D_INFO( 6, "*** LOCK_D3D: CNT = %ld %s %s", iD3DCSCnt, moduleName, fileName );
  308. #endif
  309. }
  310. ~CLockD3D()
  311. {
  312. LEAVE_D3D();
  313. D3D_INFO( 6, "*** UNLOCK_D3D: CNT = %ld", iD3DCSCnt);
  314. }
  315. };
  316. class CLockD3DST
  317. {
  318. private:
  319. bool bEnter;
  320. public:
  321. CLockD3DST(LPDIRECT3DDEVICEI lpDevI, char *moduleName, char *fileName)
  322. {
  323. if (! IS_MT_DEVICE(lpDevI) )
  324. {
  325. ENTER_D3D();
  326. #if DBG // Required to eliminate use of moduleName and fileName in retail builds
  327. D3D_INFO( 6, "*** LOCK_D3D: CNT = %ld %s %s", iD3DCSCnt, moduleName, fileName );
  328. #endif
  329. bEnter = true;
  330. }
  331. else
  332. bEnter = false;
  333. }
  334. ~CLockD3DST()
  335. {
  336. if (bEnter)
  337. {
  338. LEAVE_D3D();
  339. D3D_INFO( 6, "*** UNLOCK_D3D: CNT = %ld", iD3DCSCnt);
  340. }
  341. }
  342. };
  343. class CLockD3DMT
  344. {
  345. private:
  346. bool bEnter;
  347. public:
  348. CLockD3DMT(LPDIRECT3DDEVICEI lpDevI, char *moduleName, char *fileName)
  349. {
  350. if ( IS_MT_DEVICE(lpDevI) )
  351. {
  352. ENTER_D3D();
  353. #if DBG // Required to eliminate use of moduleName and fileName in retail builds
  354. D3D_INFO( 6, "*** LOCK_D3D: CNT = %ld %s %s", iD3DCSCnt, moduleName, fileName );
  355. #endif
  356. bEnter = true;
  357. }
  358. else
  359. bEnter = false;
  360. }
  361. ~CLockD3DMT()
  362. {
  363. if (bEnter)
  364. {
  365. LEAVE_D3D();
  366. D3D_INFO( 6, "*** UNLOCK_D3D: CNT = %ld", iD3DCSCnt);
  367. }
  368. }
  369. };
  370. #define ENTER_CBCSECT(device) EnterCriticalSection(&(device)->CommandBufferCSect)
  371. #define LEAVE_CBCSECT(device) LeaveCriticalSection(&(device)->CommandBufferCSect)
  372. /*
  373. * Legacy structure sizes
  374. */
  375. #define D3DFINDDEVICERESULTSIZE_V1 (sizeof(D3DFINDDEVICERESULT)-2*(D3DDEVICEDESCSIZE-D3DDEVICEDESCSIZE_V1) )
  376. #define D3DFINDDEVICERESULTSIZE_V2 (sizeof(D3DFINDDEVICERESULT)-2*(D3DDEVICEDESCSIZE-D3DDEVICEDESCSIZE_V2) )
  377. /*
  378. * Macros for validating parameters.
  379. * Only implement those not available in ddrawpr.h.
  380. */
  381. #define VALID_OUTPTR(x) ((x) && VALID_PTR_PTR(x))
  382. // FAST_CHECKING macro is defined in ddrawpr.h
  383. // so in make sure that ddrawpr.h is always included
  384. // before this header.
  385. #ifndef FAST_CHECKING
  386. #define VALID_DIRECT3D_PTR( ptr ) \
  387. (!IsBadWritePtr( ptr, sizeof( DIRECT3DI )))
  388. #define VALID_DIRECT3D2_PTR( ptr ) \
  389. (!IsBadWritePtr( ptr, sizeof( DIRECT3DI )))
  390. #define VALID_DIRECT3D3_PTR( ptr ) \
  391. (!IsBadWritePtr( ptr, sizeof( DIRECT3DI )))
  392. #define VALID_DIRECT3DDEVICE_PTR( ptr ) \
  393. (!IsBadWritePtr( ptr, sizeof( DIRECT3DDEVICEI )))
  394. #define VALID_DIRECT3DDEVICE2_PTR( ptr ) \
  395. (!IsBadWritePtr( ptr, sizeof( DIRECT3DDEVICEI )))
  396. #define VALID_DIRECT3DDEVICE3_PTR( ptr ) \
  397. (!IsBadWritePtr( ptr, sizeof( DIRECT3DDEVICEI )))
  398. #define VALID_DIRECT3DVIEWPORT_PTR( ptr ) \
  399. (!IsBadWritePtr( ptr, sizeof( DIRECT3DVIEWPORTI )))
  400. #define VALID_DIRECT3DVIEWPORT2_PTR( ptr ) \
  401. (!IsBadWritePtr( ptr, sizeof( DIRECT3DVIEWPORTI )))
  402. #define VALID_DIRECT3DVIEWPORT3_PTR( ptr ) \
  403. (!IsBadWritePtr( ptr, sizeof( DIRECT3DVIEWPORTI )))
  404. #define VALID_DIRECT3DMATERIAL_PTR( ptr ) \
  405. (!IsBadWritePtr( ptr, sizeof( DIRECT3DMATERIALI )))
  406. #define VALID_DIRECT3DMATERIAL2_PTR( ptr ) \
  407. (!IsBadWritePtr( ptr, sizeof( DIRECT3DMATERIALI )))
  408. #define VALID_DIRECT3DTEXTURE_PTR( ptr ) \
  409. (!IsBadWritePtr( ptr, sizeof( DIRECT3DTEXTUREI )))
  410. #define VALID_DIRECT3DTEXTURE2_PTR( ptr ) \
  411. (!IsBadWritePtr( ptr, sizeof( DIRECT3DTEXTUREI )))
  412. #define VALID_DIRECT3DLIGHT_PTR( ptr ) \
  413. (!IsBadWritePtr( ptr, sizeof( DIRECT3DLIGHTI )))
  414. #define VALID_DIRECT3DEXECUTEBUFFER_PTR( ptr ) \
  415. (!IsBadWritePtr( ptr, sizeof( DIRECT3DEXECUTEBUFFERI )))
  416. #define VALID_DIRECT3DVERTEXBUFFER_PTR( ptr ) \
  417. (!IsBadWritePtr( ptr, sizeof( CDirect3DVertexBuffer )))
  418. #define VALID_D3DEXECUTEBUFFERDESC_PTR( ptr ) \
  419. (!IsBadWritePtr( ptr, sizeof( D3DEXECUTEBUFFERDESC ) ) && \
  420. (ptr->dwSize == sizeof( D3DEXECUTEBUFFERDESC )) )
  421. #define VALID_D3DVERTEXBUFFERDESC_PTR( ptr ) \
  422. (!IsBadWritePtr( ptr, sizeof( D3DVERTEXBUFFERDESC ) ) && \
  423. (ptr->dwSize == sizeof( D3DVERTEXBUFFERDESC )) )
  424. #define VALID_D3DEXECUTEDATA_PTR( ptr ) \
  425. (!IsBadWritePtr( ptr, sizeof( D3DEXECUTEDATA ) ) && \
  426. (ptr->dwSize == sizeof( D3DEXECUTEDATA )) )
  427. #define VALID_D3DMATERIALHANDLE_PTR( ptr ) \
  428. (!IsBadWritePtr( ptr, sizeof( D3DMATERIALHANDLE ) ) )
  429. #define VALID_D3DSTATS_PTR( ptr ) \
  430. (!IsBadWritePtr( ptr, sizeof( D3DSTATS ) ) && \
  431. (ptr->dwSize == sizeof( D3DSTATS )) )
  432. #define VALID_D3DDEVICEDESC_PTR( ptr ) \
  433. ( (! IsBadWritePtr(ptr, 4) ) && \
  434. (ptr->dwSize == D3DDEVICEDESCSIZE || \
  435. ptr->dwSize == D3DDEVICEDESCSIZE_V1 || \
  436. ptr->dwSize == D3DDEVICEDESCSIZE_V2) && \
  437. (! IsBadWritePtr(ptr, ptr->dwSize) ) )
  438. #define VALID_D3DMATRIXHANDLE_PTR( ptr ) \
  439. (!IsBadWritePtr( ptr, sizeof( D3DMATRIXHANDLE ) ))
  440. #define VALID_D3DPICKRECORD_PTR( ptr ) \
  441. (!IsBadWritePtr( ptr, sizeof( D3DPICKRECORD ) ))
  442. #define VALID_D3DRECT_PTR( ptr ) \
  443. (!IsBadWritePtr( ptr, sizeof( D3DRECT ) ))
  444. #define VALID_D3DMATRIX_PTR( ptr ) \
  445. (!IsBadWritePtr( ptr, sizeof( D3DMATRIX ) ))
  446. #define VALID_D3DLIGHT_PTR( ptr ) \
  447. (!IsBadWritePtr( ptr, sizeof( D3DLIGHT ) ) && \
  448. (ptr->dwSize == sizeof( D3DLIGHT )) )
  449. #define VALID_D3DLIGHT2_PTR( ptr ) \
  450. (!IsBadWritePtr( ptr, sizeof( D3DLIGHT2 ) ) && \
  451. (ptr->dwSize == sizeof( D3DLIGHT2 )) )
  452. #define VALID_D3DMATERIAL_PTR( ptr ) \
  453. (!IsBadWritePtr( ptr, sizeof( D3DMATERIAL ) ) && \
  454. (ptr->dwSize == sizeof( D3DMATERIAL )) )
  455. #define VALID_D3DTEXTUREHANDLE_PTR( ptr ) \
  456. (!IsBadWritePtr( ptr, sizeof( D3DTEXTUREHANDLE ) ) )
  457. #define VALID_D3DLIGHTDATA_PTR( ptr ) \
  458. (!IsBadWritePtr( ptr, sizeof( D3DLIGHTDATA ) ) && \
  459. (ptr->dwSize == sizeof( D3DLIGHTDATA )) )
  460. #define VALID_D3DVIEWPORT_PTR( ptr ) \
  461. (!IsBadWritePtr( ptr, sizeof( D3DVIEWPORT ) ) && \
  462. (ptr->dwSize == sizeof( D3DVIEWPORT )) )
  463. #define VALID_D3DVIEWPORT2_PTR( ptr ) \
  464. (!IsBadWritePtr( ptr, sizeof( D3DVIEWPORT2 ) ) && \
  465. (ptr->dwSize == sizeof( D3DVIEWPORT2 )) )
  466. #define VALID_D3DTRANSFORMDATA_PTR( ptr ) \
  467. (!IsBadWritePtr( ptr, sizeof( D3DTRANSFORMDATA ) ) && \
  468. (ptr->dwSize == sizeof( D3DTRANSFORMDATA )) )
  469. #define VALID_D3DFINDDEVICESEARCH_PTR( ptr ) \
  470. (!IsBadWritePtr( ptr, sizeof( D3DFINDDEVICESEARCH ) ) && \
  471. (ptr->dwSize == sizeof( D3DFINDDEVICESEARCH ) ) )
  472. #define VALID_D3DFINDDEVICERESULT_PTR( ptr ) \
  473. ( (! IsBadWritePtr( ptr, 4)) && \
  474. (ptr->dwSize == sizeof(D3DFINDDEVICERESULT) || \
  475. ptr->dwSize == D3DFINDDEVICERESULTSIZE_V1 || \
  476. ptr->dwSize == D3DFINDDEVICERESULTSIZE_V2) && \
  477. (! IsBadWritePtr( ptr, ptr->dwSize) ) )
  478. // Note: these macros are replacements for the VALID_DIRECTDRAWSURFACE_PTR ddraw macros
  479. // because those macros need access to the ddCallbacks ddraw globals.
  480. // At some point these could be replaced with a ddraw exported fn that actually
  481. // verifies the callback table type
  482. #define VALID_D3D_DIRECTDRAWSURFACE_PTR(ptr) (!IsBadWritePtr(ptr, sizeof(DDRAWI_DDRAWSURFACE_INT)))
  483. #define VALID_D3D_DIRECTDRAWSURFACE4_PTR(ptr) (!IsBadWritePtr(ptr, sizeof(DDRAWI_DDRAWSURFACE_INT)))
  484. #else /* !FAST_CHECKING */
  485. #define VALID_DIRECT3D_PTR( ptr ) (ptr)
  486. #define VALID_DIRECT3D2_PTR( ptr ) (ptr)
  487. #define VALID_DIRECT3D3_PTR( ptr ) (ptr)
  488. #define VALID_DIRECT3DDEVICE_PTR( ptr ) (ptr)
  489. #define VALID_DIRECT3DDEVICE2_PTR( ptr ) (ptr)
  490. #define VALID_DIRECT3DDEVICE3_PTR( ptr ) (ptr)
  491. #define VALID_DIRECT3DVIEWPORT_PTR( ptr ) (ptr)
  492. #define VALID_DIRECT3DVIEWPORT2_PTR( ptr ) (ptr)
  493. #define VALID_DIRECT3DVIEWPORT3_PTR( ptr ) (ptr)
  494. #define VALID_DIRECT3DMATERIAL_PTR( ptr ) (ptr)
  495. #define VALID_DIRECT3DMATERIAL2_PTR( ptr ) (ptr)
  496. #define VALID_DIRECT3DTEXTURE_PTR( ptr ) (ptr)
  497. #define VALID_DIRECT3DTEXTURE2_PTR( ptr ) (ptr)
  498. #define VALID_DIRECT3DTEXTURE3_PTR( ptr ) (ptr)
  499. #define VALID_DIRECT3DLIGHT_PTR( ptr ) (ptr)
  500. #define VALID_DIRECT3DEXECUTEBUFFER_PTR( ptr ) (ptr)
  501. #define VALID_DIRECT3DVERTEXBUFFER_PTR( ptr ) (ptr)
  502. #define VALID_D3DEXECUTEBUFFERDESC_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DEXECUTEBUFFERDESC ))
  503. #define VALID_D3DVERTEXBUFFERDESC_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DVERTEXBUFFERDESC ))
  504. #define VALID_D3DEXECUTEDATA_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DEXECUTEDATA ))
  505. #define VALID_D3DMATERIALHANDLE_PTR( ptr ) (ptr)
  506. #define VALID_D3DSTATS_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DSTATS ))
  507. #define VALID_D3DDEVICEDESC_PTR( ptr ) ((ptr) && \
  508. (ptr->dwSize == D3DDEVICEDESCSIZE || \
  509. ptr->dwSize == D3DDEVICEDESCSIZE_V1 || \
  510. ptr->dwSize == D3DDEVICEDESCSIZE_V2))
  511. #define VALID_D3DMATRIXHANDLE_PTR( ptr ) (ptr)
  512. #define VALID_D3DPICKRECORD_PTR( ptr ) (ptr)
  513. #define VALID_D3DRECT_PTR( ptr ) (ptr)
  514. #define VALID_D3DMATRIX_PTR( ptr ) (ptr)
  515. #define VALID_D3DLIGHT_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DLIGHT ))
  516. #define VALID_D3DLIGHT2_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DLIGHT2 ))
  517. #define VALID_D3DMATERIAL_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DMATERIAL ))
  518. #define VALID_D3DTEXTUREHANDLE_PTR( ptr ) (ptr)
  519. #define VALID_D3DLIGHTDATA_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DLIGHTDATA ))
  520. #define VALID_D3DVIEWPORT_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DVIEWPORT ))
  521. #define VALID_D3DVIEWPORT2_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DVIEWPORT2 ))
  522. #define VALID_D3DTRANSFORMDATA_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DTRANSFORMDATA ))
  523. #define VALID_D3DFINDDEVICESEARCH_PTR( ptr ) ((ptr) && ptr->dwSize == sizeof( D3DFINDDEVICESEARCH ))
  524. #define VALID_D3DFINDDEVICERESULT_PTR( ptr ) \
  525. ((ptr) && (ptr->dwSize == sizeof( D3DFINDDEVICERESULT ) || \
  526. ptr->dwSize == D3DFINDDEVICERESULTSIZE_V1 || \
  527. ptr->dwSize == D3DFINDDEVICERESULTSIZE_V2 ) )
  528. #define VALID_D3D_DIRECTDRAWSURFACE_PTR(ptr) (ptr) // see comment above
  529. #define VALID_D3D_DIRECTDRAWSURFACE4_PTR(ptr) (ptr)
  530. #endif /* !FAST_CHECKING */
  531. #define CVAL_TO_RGBA(rgb) RGBA_MAKE((DWORD)(255.0 * (rgb).r), \
  532. (DWORD)(255.0 * (rgb).g), \
  533. (DWORD)(255.0 * (rgb).b), \
  534. (DWORD)(255.0 * (rgb).a))
  535. #endif /* _D3DPR_H_ */