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.

1183 lines
44 KiB

  1. /******************************Module*Header*******************************\
  2. *
  3. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4. * !! !!
  5. * !! WARNING: NOT DDK SAMPLE CODE !!
  6. * !! !!
  7. * !! This source code is provided for completeness only and should not be !!
  8. * !! used as sample code for display driver development. Only those sources !!
  9. * !! marked as sample code for a given driver component should be used for !!
  10. * !! development purposes. !!
  11. * !! !!
  12. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  13. *
  14. * Module Name: directx.h
  15. *
  16. * Content: DirectX macros and definitions
  17. *
  18. * Copyright (c) 1994-1999 3Dlabs Inc. Ltd. All rights reserved.
  19. * Copyright (c) 1995-2003 Microsoft Corporation
  20. \**************************************************************************/
  21. #ifndef __DIRECTX_H
  22. #define __DIRECTX_H
  23. #ifdef WNT_DDRAW
  24. #include "dx95type.h"
  25. #endif
  26. #ifndef __GLINTDEF
  27. #include "glintdef.h"
  28. #endif
  29. #include "pmdef.h"
  30. #ifndef __P3RXDEF
  31. #include "p3rxdef.h"
  32. #endif
  33. #include "surf_fmt.h"
  34. #include "ddover.h"
  35. //------------------------------------------------------------------
  36. //
  37. //------------------------------------------------------------------
  38. #define VTG_MEMORY_ADDRESS(a) (0x1000F | (((a >> 2) << 4) & 0xFFFF) )
  39. #define VTG_VIDEO_ADDRESS(a) (0x20000 | (((a >> 2) << 4) & 0xFFFF) )
  40. #define MEM_MEMORYSCRATCH 0x10
  41. #define VID_SCREENBASE 0x0
  42. #if DX7_STEREO
  43. #define VID_VIDEOCONTROL 0x58
  44. #define VID_SCREENBASERIGHT 0x80
  45. #define __VIDEO_STEREOENABLE 0x800
  46. #endif
  47. //------------------------------------------------------------------
  48. //
  49. //------------------------------------------------------------------
  50. #if !DBG
  51. #define STOP_SOFTWARE_CURSOR(pThisDisplay) \
  52. pThisDisplay->pGLInfo->dwFlags |= GMVF_GCOP
  53. #define START_SOFTWARE_CURSOR(pThisDisplay) \
  54. pThisDisplay->pGLInfo->dwFlags &= ~GMVF_GCOP
  55. #else
  56. #define STOP_SOFTWARE_CURSOR(pThisDisplay) \
  57. { \
  58. DISPDBG((DBGLVL, "STOP_SW_CURSOR %s %d", __FILE__, __LINE__ )); \
  59. if (pThisDisplay->pGLInfo->dwFlags & GMVF_GCOP) \
  60. DISPDBG((WRNLVL,"Stopping Cursor that is already stopped!"));\
  61. pThisDisplay->pGLInfo->dwFlags |= GMVF_GCOP; \
  62. }
  63. #define START_SOFTWARE_CURSOR(pThisDisplay) \
  64. { \
  65. DISPDBG((DBGLVL, "START_SW_CURSOR %s, %d", __FILE__, __LINE__ ));\
  66. if (!(pThisDisplay->pGLInfo->dwFlags & GMVF_GCOP)) \
  67. DISPDBG((WRNLVL,"Starting Cursor that is already started!"));\
  68. pThisDisplay->pGLInfo->dwFlags &= ~GMVF_GCOP; \
  69. }
  70. #endif // !DBG
  71. //------------------------------------------------------------------
  72. //
  73. //------------------------------------------------------------------
  74. // From MS, undocumented sharing flag
  75. #define HEAP_SHARED 0x04000000 // put heap in shared memory
  76. //------------------------------------------------------------------
  77. // Defines for video flipping, etc.
  78. //------------------------------------------------------------------
  79. #define IN_VBLANK \
  80. (pThisDisplay->pGlint->LineCount < pThisDisplay->pGlint->VbEnd)
  81. #define IN_DISPLAY (!IN_VBLANK)
  82. //------------------------------------------------------------------
  83. //
  84. //------------------------------------------------------------------
  85. #if WNT_DDRAW
  86. #define DXCONTEXT_IMMEDIATE(pThisDisplay) \
  87. vGlintSwitchContext(pThisDisplay->ppdev, \
  88. pThisDisplay->ppdev->DDContextID);
  89. #define IS_DXCONTEXT_CURRENT(pThisDisplay) \
  90. (((pThisDisplay->ppdev->currentCtxt) != \
  91. (pThisDisplay->ppdev->DDContextID)) ? FALSE : TRUE)
  92. #else // WNT_DDRAW
  93. #define DXCONTEXT_IMMEDIATE(pThisDisplay) \
  94. ChangeContext(pThisDisplay, \
  95. pThisDisplay->pGLInfo, \
  96. CONTEXT_DIRECTX_HANDLE);
  97. #define IS_DXCONTEXT_CURRENT(pThisDisplay) \
  98. ((pThisDisplay->pGLInfo->dwCurrentContext != CONTEXT_DIRECTX_HANDLE) ? \
  99. FALSE : TRUE)
  100. #endif // WNT_DDRAW
  101. //------------------------------------------------------------------
  102. // For comparing GUID's
  103. //------------------------------------------------------------------
  104. #ifdef __cplusplus
  105. #define MATCH_GUID(a, b) IsEqualIID((a), (b))
  106. #else
  107. #define MATCH_GUID(a, b) IsEqualIID(&(a), &(b))
  108. #endif
  109. //------------------------------------------------------------------
  110. // Registry
  111. //------------------------------------------------------------------
  112. #ifdef WNT_DDRAW
  113. #define GET_REGISTRY_ULONG_FROM_STRING(a, b) \
  114. bGlintQueryRegistryValueUlong(pThisDisplay->ppdev, L##a, (DWORD*)b)
  115. #define SET_REGISTRY_STRING_FROM_ULONG(a, b) \
  116. bGlintSetRegistryValueString(pThisDisplay->ppdev, L##a, b)
  117. #define GET_REGISTRY_STRING(a, b) \
  118. bGlintQueryRegistryValueString(pThisDisplay->ppdev, L##a, b, c)
  119. #else
  120. // Win95 calls the same registry call as it always did,
  121. // NT makes the call with an extra parameter - the ppdev
  122. BOOL bGlintQueryRegistryValueString(LPTSTR valueStr,
  123. char* pString,
  124. int StringLen);
  125. BOOL bGlintQueryRegistryValueUlong(LPTSTR valueStr,
  126. PULONG pData);
  127. BOOL bGlintQueryRegistryValueUlongAsUlong(LPTSTR valueStr,
  128. PULONG pData);
  129. BOOL bGlintSetRegistryValueString(LPTSTR valueStr,
  130. ULONG Data);
  131. #define GET_REGISTRY_ULONG_FROM_STRING(a, b) \
  132. bGlintQueryRegistryValueUlong(a, (DWORD*)b)
  133. #define GET_REGISTRY_STRING(a, b) \
  134. bGlintQueryRegistryValueString(a, b, strlen(a))
  135. #define SET_REGISTRY_STRING_FROM_ULONG(a, b) \
  136. bGlintSetRegistryValueString(a, b)
  137. #endif // WNT_DDRAW
  138. //------------------------------------------------------------------
  139. // Memory Allocation calls
  140. //------------------------------------------------------------------
  141. #ifdef WNT_DDRAW
  142. #define HEAP_ALLOC(flags, size, tag) ENGALLOCMEM(FL_ZERO_MEMORY, size, tag)
  143. #define HEAP_FREE(ptr) ENGFREEMEM(ptr)
  144. // Shared memory allocation calls. On NT , the 16 bit ptr is irrelevant and
  145. // the call is resolved as a normal call to HEAP_ALLOC/HEAP_FREE
  146. // The 16 bit ptrs are alwasy defined as DWORD and the 32 bit as ULONG_PTR
  147. __inline void SHARED_HEAP_ALLOC(DWORD *ppData16,
  148. ULONG_PTR* ppData32,
  149. DWORD size)
  150. {
  151. *ppData32 = (ULONG_PTR) HEAP_ALLOC(FL_ZERO_MEMORY,
  152. size ,
  153. ALLOC_TAG_DX(S));
  154. *ppData16 = (DWORD)(*ppData32);
  155. }
  156. __inline void SHARED_HEAP_FREE(DWORD *ppData16,
  157. ULONG_PTR * ppData32,
  158. BOOL bZero)
  159. {
  160. HEAP_FREE((PVOID)(*ppData32));
  161. if (bZero)
  162. {
  163. *ppData32 = 0;
  164. *ppData16 = 0;
  165. }
  166. }
  167. #else
  168. #define FL_ZERO_MEMORY HEAP_ZERO_MEMORY
  169. #define HEAP_ALLOC(flags, size, tag) \
  170. HeapAlloc((HANDLE)g_DXGlobals.hHeap32, flags, size)
  171. #define HEAP_FREE(ptr) \
  172. HeapFree((HANDLE)g_DXGlobals.hHeap32, 0, ptr)
  173. BOOL SharedHeapAlloc(DWORD* ppData16, ULONG_PTR* ppData32, DWORD size);
  174. void SharedHeapFree(DWORD ptr16, ULONG_PTR ptr32);
  175. // Shared memory allocation calls. On Win9x , the 16 bit ptr is important.
  176. // We map this calls to some Win9x specific code
  177. #define SHARED_HEAP_ALLOC( ppData16, ppData32, size) \
  178. SharedHeapAlloc(ppData16, ppData32, size);
  179. #define SHARED_HEAP_FREE( ppData16, ppData32, bZero) \
  180. { \
  181. SharedHeapFree(*(ppData16), *(ppData32)); \
  182. if (bZero) \
  183. { \
  184. *ppData32 = 0; \
  185. *ppData16 = 0; \
  186. } \
  187. }
  188. #endif // WNT_DDRAW
  189. //------------------------------------------------------------------
  190. // Display driver's DC
  191. //------------------------------------------------------------------
  192. // Allows us to get the display driver's DC at any point.
  193. // CREATE_DRIVER_DC must be matched by a DELETE_DRIVER_DC.
  194. #define CREATE_DRIVER_DC(pGLInfo) ( \
  195. ( ( (pGLInfo)->szDeviceName[7] == '\0' ) && \
  196. ( (pGLInfo)->szDeviceName[6] == 'Y' ) && \
  197. ( (pGLInfo)->szDeviceName[5] == 'A' ) && \
  198. ( (pGLInfo)->szDeviceName[4] == 'L' ) && \
  199. ( (pGLInfo)->szDeviceName[3] == 'P' ) && \
  200. ( (pGLInfo)->szDeviceName[2] == 'S' ) && \
  201. ( (pGLInfo)->szDeviceName[1] == 'I' ) && \
  202. ( (pGLInfo)->szDeviceName[0] == 'D' ) ) ? \
  203. /* The Win95 and NT4-compatible version */ \
  204. ( CreateDC ( "DISPLAY", NULL, NULL, NULL ) ) : \
  205. /* The Win98 and NT5-compatible multimon version */ \
  206. ( CreateDC ( NULL, (pGLInfo)->szDeviceName, NULL, NULL ) ) \
  207. )
  208. #define DELETE_DRIVER_DC(hDC) DeleteDC(hDC)
  209. //------------------------------------------------------------------
  210. // Macro to define a FOURCC.
  211. // Needed on NT builds. On Win9x it comes from the DDK.
  212. //------------------------------------------------------------------
  213. #ifndef MAKEFOURCC
  214. #define MAKEFOURCC(ch0, ch1, ch2, ch3) \
  215. ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
  216. ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))
  217. #endif //defined(MAKEFOURCC)
  218. // For the video
  219. #define FOURCC_YUV422 (MAKEFOURCC('Y','U','Y','2'))
  220. #define FOURCC_YUV411 (MAKEFOURCC('Y','4','1','1'))
  221. // Mediamatics private 4CC's
  222. #define FOURCC_MVCA (MAKEFOURCC('M','V','C','A'))
  223. #define FOURCC_MVSU (MAKEFOURCC('M','V','S','U'))
  224. #define FOURCC_MVSB (MAKEFOURCC('M','V','S','B'))
  225. //------------------------------------------------------------------
  226. //------------------------------------------------------------------
  227. #define PACKED_PP_LOOKUP(a) (pThisDisplay->PPCodes[(a) >> 5] & 0x1FF)
  228. #define PACKED_PP_LOOKUP4(a) (pThisDisplay->PPCodes[(a) >> 5])
  229. #define PP0_LOOKUP(a) (PACKED_PP_LOOKUP(a) & 0x7)
  230. #define PP1_LOOKUP(a) ((PACKED_PP_LOOKUP(a) >> 3) & 0x7)
  231. #define PP2_LOOKUP(a) ((PACKED_PP_LOOKUP(a) >> 6) & 0x7)
  232. #define PP3_LOOKUP(a) ((PACKED_PP_LOOKUP(a) >> 9) & 0x7)
  233. //------------------------------------------------------------------
  234. // Globals that are truly global across multiple displays
  235. //------------------------------------------------------------------
  236. typedef enum tagPixelCenterSetting
  237. {
  238. PIXELCENTER_ZERO,
  239. PIXELCENTER_NEARLY_HALF,
  240. PIXELCENTER_HALF,
  241. PIXELCENTER_FORCE_DWORD = 0xFFFFFFFF
  242. } PixelCenterSetting;
  243. typedef struct tagDirectXGlobals {
  244. // State
  245. HINSTANCE hInstance; // Instance handle for this DLL
  246. DWORD hHeap32; // Shared 32 bit heap
  247. } DirectXGlobals;
  248. // There is one global structure in the driver. This is shared across
  249. // all applications and all cards. It holds data such as the current
  250. // driver settings and a handle to the memory heap that is used within
  251. // the driver. There is also a global pointer that points at the current
  252. // primary display
  253. extern DirectXGlobals g_DXGlobals;
  254. //------------------------------------------------------------------
  255. // Driver thunked data
  256. //------------------------------------------------------------------
  257. #if W95_DDRAW
  258. extern P3_THUNKEDDATA* g_pDriverData;
  259. #endif
  260. extern struct tagThunkedData* g_pThisTemp;
  261. #if WNT_DDRAW
  262. #define GET_THUNKEDDATA(pThisDisplay,a) \
  263. { \
  264. pThisDisplay = (P3_THUNKEDDATA*)(((PPDEV) ((a)->dhpdev))->thunkData);\
  265. }
  266. #else // WNT_DDRAW
  267. #if !DBG
  268. #define GET_THUNKEDDATA(pThisDisplay,a) \
  269. { \
  270. if ((a)->dwReserved3) \
  271. { \
  272. pThisDisplay = (P3_THUNKEDDATA*)(a)->dwReserved3; \
  273. } \
  274. else \
  275. { \
  276. pThisDisplay = g_pDriverData; \
  277. } \
  278. }
  279. #else
  280. #define GET_THUNKEDDATA(pThisDisplay,a) \
  281. { \
  282. if ((a)->dwReserved3) \
  283. { \
  284. pThisDisplay = (P3_THUNKEDDATA*)(a)->dwReserved3; \
  285. DISPDBG((DBGLVL,"Secondary Display: DevHandle=0x%x", \
  286. pThisDisplay->pGLInfo->dwDeviceHandle)); \
  287. } \
  288. else \
  289. { \
  290. pThisDisplay = g_pDriverData; \
  291. DISPDBG((DBGLVL,"Primary Display DevHandle=0x%x", \
  292. pThisDisplay->pGLInfo->dwDeviceHandle)); \
  293. } \
  294. }
  295. #endif // !DBG
  296. #endif // WNT_DDRAW
  297. //------------------------------------------------------------------
  298. //
  299. //------------------------------------------------------------------
  300. #define PATCH_SELECTIVE 0
  301. #define PATCH_ALWAYS 1
  302. #define PATCH_NEVER 2
  303. //------------------------------------------------------------------
  304. // Color format conversion macros
  305. //------------------------------------------------------------------
  306. #define FORMAT_565_32BIT(val) \
  307. ( (((val & 0xF800) >> 8) << 16) | \
  308. (((val & 0x7E0) >> 3) << 8) | \
  309. (((val & 0x1F) << 3) ) )
  310. #define FORMAT_565_32BIT_BGR(val) \
  311. ( (((val & 0xF800) >> 8) ) | \
  312. (((val & 0x7E0) >> 3) << 8) | \
  313. (((val & 0x1F) << 19) ) )
  314. #define FORMAT_565_32BIT_ZEROEXTEND(val) \
  315. ( (((val & 0xF800) >> 11) ) | \
  316. (((val & 0x7E0) >> 3) << 6) | \
  317. (((val & 0x1F) << 16) ) )
  318. #define FORMAT_5551_32BIT(val) \
  319. ( (((val & 0x8000) >> 8) << 24) | \
  320. (((val & 0x7C00) >> 7) << 16) | \
  321. (((val & 0x3E0) >> 2) << 8 ) | \
  322. (((val & 0x1F) << 3) ) )
  323. #define FORMAT_5551_32BIT_BGR(val) \
  324. ( (((val & 0x8000) >> 8) << 24) | \
  325. (((val & 0x7C00) >> 7) ) | \
  326. (((val & 0x3E0) >> 2) << 8 ) | \
  327. (((val & 0x1F) <<19) ) )
  328. #define FORMAT_5551_32BIT_ZEROEXTEND(val) \
  329. ( (((val & 0x8000) << 9 ) ) | \
  330. (((val & 0x7C00) >> 10 ) ) | \
  331. (((val & 0x3E0) >> 2 ) << 5) | \
  332. (((val & 0x1F) << 16 ) ) )
  333. #define FORMAT_4444_32BIT(val) \
  334. ( (((val & 0xF000) << 16) ) | \
  335. (((val & 0xF00) >> 4) << 16) | \
  336. (((val & 0xF0) << 8) ) | \
  337. (((val & 0xF) << 4) ) )
  338. #define FORMAT_4444_32BIT_BGR(val) \
  339. ( ((val & 0xF000) << 16) | \
  340. ((val & 0xF00) >> 4) | \
  341. ((val & 0xF0) << 8) | \
  342. ((val & 0xF) << 20) )
  343. #define FORMAT_4444_32BIT_ZEROEXTEND(val) \
  344. ( ((val & 0xF000) << 12) | \
  345. ((val & 0xF00) >> 8) | \
  346. ((val & 0xF0) << 4) | \
  347. ((val & 0xF) << 16) )
  348. #define FORMAT_332_32BIT(val) \
  349. ( (((val & 0xE0) << 16) ) | \
  350. (((val & 0x1C) << 3) << 8) | \
  351. (((val & 0x3) << 6) ) )
  352. #define FORMAT_332_32BIT_BGR(val) \
  353. ( (((val & 0xE0) ) ) | \
  354. (((val & 0x1C) << 3) << 8) | \
  355. (((val & 0x3) << 22) ) )
  356. #define FORMAT_332_32BIT_ZEROEXTEND(val) \
  357. ( (((val & 0xE0) >> 5) ) | \
  358. (((val & 0x1C) << 3) << 3) | \
  359. (((val & 0x3) << 16)) )
  360. #define FORMAT_2321_32BIT(val) \
  361. ( (((val & 0x80) << 24) ) | \
  362. (((val & 0x60) << 17) ) | \
  363. (((val & 0x1C) << 3) << 8) | \
  364. (((val & 0x3) << 6) ) )
  365. #define FORMAT_2321_32BIT_BGR(val) \
  366. ( (((val & 0x80) << 24) ) | \
  367. (((val & 0x60) << 1) ) | \
  368. (((val & 0x1C) << 3) << 8) | \
  369. (((val & 0x3) << 22) ))
  370. #define FORMAT_2321_32BIT_ZEROEXTEND(val) \
  371. ( (((val & 0x80) << 17) ) | \
  372. (((val & 0x60) >> 5) ) | \
  373. (((val & 0x1C) << 3) << 3) | \
  374. (((val & 0x3) << 16) ) )
  375. #define FORMAT_8888_32BIT_BGR(val) \
  376. ( ((val & 0xFF00FF00) ) | \
  377. ((val & 0xFF0000) >> 16) | \
  378. ((val & 0xFF) << 16) )
  379. #define FORMAT_888_32BIT_BGR(val) \
  380. ( ((val & 0xFF00FF00) ) | \
  381. ((val & 0xFF0000) >> 16) | \
  382. ((val & 0xFF) << 16) )
  383. #define CHROMA_UPPER_ALPHA(val) \
  384. (val | 0xFF000000)
  385. #define CHROMA_LOWER_ALPHA(val) \
  386. (val & 0x00FFFFFF)
  387. #define CHROMA_332_UPPER(val) \
  388. (val | 0x001F1F3F)
  389. #define FORMAT_PALETTE_32BIT(val) \
  390. ( ((val & 0xFF) ) | \
  391. ((val & 0xFF) << 8) | \
  392. ((val & 0xFF) << 16))
  393. //------------------------------------------------------------------
  394. // Macros for handling Render IDs.
  395. //------------------------------------------------------------------
  396. #if 1
  397. // The real values
  398. #define RENDER_ID_KNACKERED_BITS 0x00000000
  399. #define RENDER_ID_VALID_BITS_UPPER 0x00000000
  400. #define RENDER_ID_VALID_BITS_LOWER 0xffffffff
  401. #define RENDER_ID_VALID_BITS_UPPER_SHIFT 0
  402. #define RENDER_ID_VALID_BITS_SIGN_SHIFT 0
  403. #define RENDER_ID_LOWER_LIMIT -100
  404. #define RENDER_ID_UPPER_LIMIT 65000
  405. #define RENDER_ID_REGISTER_NAME MemScratch
  406. #else
  407. // For soak-testing - should catch wrap errors much more quickly.
  408. // Also tests the mechanism that copes with dodgy bits in the
  409. // register (P2 MinRegion legacy stuff, but it's free to support).
  410. #define RENDER_ID_KNACKERED_BITS 0xfff0fff0
  411. #define RENDER_ID_VALID_BITS_UPPER 0x000f0000
  412. #define RENDER_ID_VALID_BITS_LOWER 0x0000000f
  413. #define RENDER_ID_VALID_BITS_UPPER_SHIFT 12
  414. #define RENDER_ID_VALID_BITS_SIGN_SHIFT 24
  415. #define RENDER_ID_LOWER_LIMIT -20
  416. #define RENDER_ID_UPPER_LIMIT 100
  417. #endif
  418. //------------------------------------------------------------------
  419. // Flipping compile time switches
  420. //------------------------------------------------------------------
  421. #if WNT_DDRAW
  422. // Can't use timeGetTime under WinNT
  423. // We should try to backoff using something else instead, but...
  424. #define USE_FLIP_BACKOFF 0
  425. #else
  426. // Set this to 1 to enable the back-off code for flips and locks.
  427. // On some things it's faster, on some things it's slower - tune as desired.
  428. #define USE_FLIP_BACKOFF 1
  429. #endif
  430. // Get a new render ID. Need to do the OR afterwards to make
  431. // sure the +1 gets the bits carried up properly next time.
  432. // No need to do the OR before, because we assume dwRenderID is
  433. // always a "valid" number, with those bits set.
  434. #define GET_NEW_HOST_RENDER_ID() ( pThisDisplay->dwRenderID = ( pThisDisplay->dwRenderID + 1 ) | RENDER_ID_KNACKERED_BITS, pThisDisplay->dwRenderID )
  435. // Get render ID of last operation.
  436. #define GET_HOST_RENDER_ID() ( pThisDisplay->dwRenderID )
  437. // Send this ID to the chip (do just after the render command).
  438. //#define SEND_HOST_RENDER_ID(my_id) SEND_P3_DATA(RENDER_ID_REGISTER_NAME,(my_id))
  439. #define SEND_HOST_RENDER_ID(my_id) \
  440. SEND_P3_DATA(VTGAddress, VTG_MEMORY_ADDRESS(MEM_MEMORYSCRATCH)); \
  441. SEND_P3_DATA(VTGData, my_id)
  442. // Read the current ID from the chip.
  443. #define GET_CURRENT_CHIP_RENDER_ID() ( READ_GLINT_CTRL_REG(RENDER_ID_REGISTER_NAME) | RENDER_ID_KNACKERED_BITS )
  444. // Is the RenderID value on the chip valid?
  445. #define CHIP_RENDER_ID_IS_VALID() ( (BOOL)pThisDisplay->bRenderIDValid )
  446. // Do a render ID comparison. RenderIDs wrap, so you have
  447. // to do the subtraction and _then_ test the top bit,
  448. // not do the comparison between the two directly.
  449. // think about a=0xfffffffe and b=0x1, and then
  450. // about a=0x7ffffffe and b=0x80000001.
  451. // If the two are more than 0x80000000 apart, then this
  452. // will give the wrong result, but that's a _lot_ of renders.
  453. // At a render every 1us (1MHz), that's still about 35 minutes.
  454. // Bear in mind, a render is a sequence of polygons, not just one.
  455. // If apps do as we suggest and send about 50 tris per render, and
  456. // if they manage to get 8million tris a second troughput
  457. // they get about 3.7 hours before wrapping.
  458. // If this really is a problem, just extend it to 64 bits using
  459. // MaxRegion as well.
  460. // On P2, we only have 24 useable bits, so the wrap will happen
  461. // sooner - every 52 seconds. However, this should at the very
  462. // worst cause a few more SYNCs than necessary, even if it does
  463. // go wrong. Use the above "debug" settings to do soak-testing -
  464. // they make only 8 bits valid.
  465. #define RENDER_ID_LESS_THAN(a,b) ( (signed)(a-b) < 0 )
  466. // Decide if a render has finished.
  467. #if !DBG
  468. #define RENDER_ID_HAS_COMPLETED(my_id) ( !RENDER_ID_LESS_THAN ( (GET_CURRENT_CHIP_RENDER_ID()), (my_id) ) )
  469. #else
  470. // A version that is rather more paranoid about correct values.
  471. // It's instantiated in gldd32.c
  472. BOOL HWC_bRenderIDHasCompleted ( DWORD dwID, P3_THUNKEDDATA* pThisDisplay );
  473. #define RENDER_ID_HAS_COMPLETED(my_id) ( HWC_bRenderIDHasCompleted ( (my_id), pThisDisplay ) )
  474. #endif // !DBG
  475. // This should be called once RENDER_ID_HAS_COMPLETED has failed,
  476. // just in case a wrap-round bug has occurred. If it's true, the
  477. // chip needs to be synced, and the surface RenderIDs updated with
  478. // GET_HOST_RENDER_ID(). This is fairly slow,
  479. // but that's OK, since most things that use RENDER_ID_HAS_COMPLETED
  480. // will start spinning when it fails anyway (locks, flips, etc).
  481. // Note that just re-syncing every time the wrap-around
  482. // happens is not enough - we need to bring the surface
  483. // up to date as well, so this is just as efficient
  484. // as always resyncing, and usually faster.
  485. // This should also never happen in real-life, but it's a
  486. // safety net in case it does. The soak-test settings should be
  487. // aggressive enough to force it to happen.
  488. #define NEED_TO_RESYNC_CHIP_AND_SURFACE(my_id) ( RENDER_ID_LESS_THAN ( GET_HOST_RENDER_ID(), (my_id) ) )
  489. // Set/get a surface's read-from/written-to render ID.
  490. #define SET_SIB_RENDER_ID_WRITE(lpSIB,my_id) (lpSIB)->dwRenderIDWrite = (my_id)
  491. #define SET_SIB_RENDER_ID_READ(lpSIB,my_id) (lpSIB)->dwRenderIDRead = (my_id)
  492. #define GET_SIB_RENDER_ID_WRITE(lpSIB) ((lpSIB)->dwRenderIDWrite)
  493. #define GET_SIB_RENDER_ID_READ(lpSIB) ((lpSIB)->dwRenderIDRead)
  494. #define SIB_WRITE_FINISHED(lpSIB) ( RENDER_ID_HAS_COMPLETED ( GET_SIB_RENDER_ID_WRITE ( lpSIB ) ) )
  495. #define SIB_READ_FINISHED(lpSIB) ( RENDER_ID_HAS_COMPLETED ( GET_SIB_RENDER_ID_READ ( lpSIB ) ) )
  496. //------------------------------------------------------------------
  497. // Macros for determining DDraw surface characteristics
  498. //------------------------------------------------------------------
  499. #define DDSurf_Width(lpLcl) ( (lpLcl)->lpGbl->wWidth )
  500. #define DDSurf_Height(lpLcl) ( (lpLcl)->lpGbl->wHeight )
  501. #define DDSurf_Pitch(lpLcl) ( (lpLcl)->lpGbl->lPitch)
  502. #define DDSurf_dwCaps(lpLcl) ( (lpLcl)->ddsCaps.dwCaps)
  503. #if WNT_DDRAW
  504. #define DDSurf_IsAGP(lpLcl) \
  505. ( ((lpLcl)->ddsCaps.dwCaps & DDSCAPS_NONLOCALVIDMEM) ? 1 : 0 )
  506. #define DDSurf_HasPixelFormat(dwFlags) (1)
  507. #define DDSurf_BitDepth(lpLcl) \
  508. ((lpLcl)->lpGbl->ddpfSurface.dwRGBBitCount)
  509. #define DDSurf_AlphaBitDepth(lpLcl) \
  510. ((lpLcl)->lpGbl->ddpfSurface.dwAlphaBitDepth)
  511. #define DDSurf_RGBAlphaBitMask(lpLcl) \
  512. ((lpLcl)->lpGbl->ddpfSurface.dwRGBAlphaBitMask)
  513. #define DDSurf_GetPixelFormat(lpLcl) \
  514. (&(lpLcl)->lpGbl->ddpfSurface)
  515. #else
  516. #define DDSurf_HasPixelFormat(dwFlags) \
  517. ((dwFlags & DDRAWISURF_HASPIXELFORMAT) ? 1 : 0)
  518. #define DDSurf_IsAGP(lpLcl) \
  519. ( ((lpLcl)->ddsCaps.dwCaps & DDSCAPS_NONLOCALVIDMEM) ? 1 : 0 )
  520. #define DDS_LCL(pdds) (((DDRAWI_DDRAWSURFACE_INT *)pdds)->lpLcl)
  521. #define DDP_LCL(pddp) (((DDRAWI_DDRAWPALETTE_INT *)pdds)->lpLcl)
  522. #define DDSurf_BitDepth(lpLcl) \
  523. ( ((lpLcl)->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? \
  524. ((lpLcl)->lpGbl->ddpfSurface.dwRGBBitCount) : \
  525. ((lpLcl)->lpGbl->lpDD->vmiData.ddpfDisplay.dwRGBBitCount) \
  526. )
  527. #define DDSurf_AlphaBitDepth(lpLcl) \
  528. ( ((lpLcl)->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? \
  529. ((lpLcl)->lpGbl->ddpfSurface.dwAlphaBitDepth) : \
  530. ((lpLcl)->lpGbl->lpDD->vmiData.ddpfDisplay.dwAlphaBitDepth) \
  531. )
  532. #define DDSurf_RGBAlphaBitMask(lpLcl) \
  533. ( ((lpLcl)->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? \
  534. ((lpLcl)->lpGbl->ddpfSurface.dwRGBAlphaBitMask) : \
  535. ((lpLcl)->lpGbl->lpDD->vmiData.ddpfDisplay.dwRGBAlphaBitMask) \
  536. )
  537. #define DDSurf_GetPixelFormat(lpLcl) \
  538. (((lpLcl)->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? \
  539. (&(lpLcl)->lpGbl->ddpfSurface) : \
  540. (&(lpLcl)->lpGbl->lpDD->vmiData.ddpfDisplay) \
  541. )
  542. #endif
  543. // Function to return the correct entry in the lookup table
  544. P3_SURF_FORMAT* _DD_SUR_GetSurfaceFormat(LPDDRAWI_DDRAWSURFACE_LCL pLcl);
  545. static DWORD ShiftLookup[5] = { 0, 0, 1, 0, 2};
  546. #define DDSurf_GetPixelShift(a) \
  547. (ShiftLookup[(DDSurf_BitDepth(a) >> 3)])
  548. #define DDSurf_GetPixelToDWORDShift(pSurfLcl) \
  549. (2 - DDSurf_GetPixelShift(pSurfLcl))
  550. #define DDSurf_GetPixelPitch(pSurfLcl) \
  551. ((DDSurf_BitDepth(pSurfLcl) == 24) ? \
  552. (DDSurf_Pitch(pSurfLcl) / 3) : \
  553. (DDSurf_BitDepth(pSurfLcl) == 4) ? \
  554. (DDSurf_Pitch(pSurfLcl) * 2) : \
  555. (DDSurf_Pitch(pSurfLcl) >> DDSurf_GetPixelShift(pSurfLcl)))
  556. #define DDSurf_GetByteWidth(pSurfLcl) \
  557. ((DDSurf_BitDepth(pSurfLcl) == 24) ? \
  558. (DDSurf_Width(pSurfLcl) * 3) : \
  559. (DDSurf_BitDepth(pSurfLcl) == 4) ? \
  560. (DDSurf_Width(pSurfLcl) / 2) : \
  561. (DDSurf_Width(pSurfLcl) << DDSurf_GetPixelShift(pSurfLcl)))
  562. #define DDSurf_FromInt(pSurfInt) \
  563. ((LPDDRAWI_DDRAWSURFACE_LCL)((LPDDRAWI_DDRAWSURFACE_INT)pSurfInt)->lpLcl)
  564. // 4bpp = 3, 8bpp = 0, 16bpp = 1, 24bpp = 4, 32bpp = 2
  565. static DWORD ChipPixelSize[9] = { 0, 3, 0, 0, 1, 0, 4, 0, 2 };
  566. #define DDSurf_GetChipPixelSize(pSurf) \
  567. (ChipPixelSize[(DDSurf_BitDepth(pSurf) >> 2)])
  568. #define DDSurf_GetBppMask(pSurfLcl) \
  569. (3 >> (DDSurf_GetChipPixelSize(pSurfLcl)))
  570. // Calculates the offset of this agp surface from the base of the agp region
  571. unsigned long __inline
  572. DDSurf_SurfaceOffsetFromAGPBase(
  573. P3_THUNKEDDATA* pThisDisplay,
  574. LPDDRAWI_DDRAWSURFACE_LCL pLcl)
  575. {
  576. unsigned long ulOffset;
  577. ASSERTDD(pLcl->ddsCaps.dwCaps & DDSCAPS_NONLOCALVIDMEM,
  578. "ERROR: DDSurf_SurfaceOffsetFromAGPBase passed non AGP surface");
  579. #if WNT_DDRAW
  580. // The offset into AGP memory can't be more than 4GB! //azn - check this
  581. ulOffset = (DWORD)(pLcl->lpGbl->fpHeapOffset -
  582. pLcl->lpGbl->lpVidMemHeap->fpStart);
  583. #else
  584. ulOffset = (SURFACE_PHYSICALVIDMEM(pLcl->lpGbl) -
  585. pThisDisplay->dwGARTDevBase);
  586. #endif
  587. return ulOffset;
  588. } // DDSurf_SurfaceOffsetFromAGPBase
  589. // Calculates the offset of this surface from the base of the memory as
  590. // the chip sees it. For AGP this is the currently scrolled window
  591. // position on P2, and on P3 it is the real physical memory address
  592. long __inline
  593. DDSurf_SurfaceOffsetFromMemoryBase(
  594. P3_THUNKEDDATA* pThisDisplay,
  595. LPDDRAWI_DDRAWSURFACE_LCL pLcl)
  596. {
  597. long lOffset;
  598. #if WNT_DDRAW
  599. if (pLcl->ddsCaps.dwCaps & DDSCAPS_NONLOCALVIDMEM) //azn
  600. {
  601. DISPDBG((DBGLVL,"HeapOffset: 0x%x, fpStart: 0x%x",
  602. pLcl->lpGbl->fpHeapOffset,
  603. pLcl->lpGbl->lpVidMemHeap->fpStart));
  604. if (pThisDisplay->pGLInfo->dwRenderFamily == P3R3_ID)
  605. {
  606. // Return the offset into the heap, accounting for the adjustment
  607. // we might have made to the base
  608. lOffset = ((long)pLcl->lpGbl->fpHeapOffset -
  609. (long)pLcl->lpGbl->lpVidMemHeap->fpStart) +
  610. ((long)pThisDisplay->dwGARTDevBase);
  611. }
  612. else
  613. {
  614. // Return the offset into the heap, accounting for the adjustment
  615. // we might have made to the base
  616. lOffset = ((long)pLcl->lpGbl->fpHeapOffset -
  617. (long)pLcl->lpGbl->lpVidMemHeap->fpStart) -
  618. ((long)pThisDisplay->dwGARTDev -
  619. (long)pThisDisplay->dwGARTDevBase );
  620. }
  621. }
  622. else
  623. {
  624. lOffset = ((long)pLcl->lpGbl->fpVidMem -
  625. (long)pThisDisplay->dwScreenFlatAddr);
  626. }
  627. #else
  628. if (pThisDisplay->pGLInfo->dwRenderFamily == P3R3_ID)
  629. {
  630. if (pLcl->ddsCaps.dwCaps & DDSCAPS_NONLOCALVIDMEM)
  631. {
  632. lOffset = (long)SURFACE_PHYSICALVIDMEM(pLcl->lpGbl);
  633. }
  634. else
  635. {
  636. lOffset = ((long)pLcl->lpGbl->fpVidMem -
  637. (long)pThisDisplay->dwScreenFlatAddr);
  638. }
  639. }
  640. else
  641. {
  642. if (pLcl->ddsCaps.dwCaps & DDSCAPS_NONLOCALVIDMEM)
  643. {
  644. lOffset = ((long)SURFACE_PHYSICALVIDMEM(pLcl->lpGbl) -
  645. (long)pThisDisplay->dwGARTDev);
  646. }
  647. else
  648. {
  649. lOffset = ((long)pLcl->lpGbl->fpVidMem -
  650. (long)pThisDisplay->dwScreenFlatAddr);
  651. }
  652. }
  653. #endif // WNT_DDRAW
  654. return lOffset;
  655. } // DDSurf_SurfaceOffsetFromMemoryBase
  656. //------------------------------------------------------------------
  657. // Function to send a command to the VXD.
  658. //------------------------------------------------------------------
  659. #if W95_DDRAW
  660. BOOL VXDCommand(DWORD dwCommand,
  661. void* pIn,
  662. DWORD dwInSize,
  663. void* pOut,
  664. DWORD dwOutSize);
  665. #endif
  666. //------------------------------------------------------------------
  667. // DirectDraw Callbacks
  668. //------------------------------------------------------------------
  669. DWORD CALLBACK DdCanCreateSurface( LPDDHAL_CANCREATESURFACEDATA pccsd );
  670. DWORD CALLBACK DdCreateSurface( LPDDHAL_CREATESURFACEDATA pcsd );
  671. DWORD CALLBACK DdDestroySurface( LPDDHAL_DESTROYSURFACEDATA psdd );
  672. DWORD CALLBACK DdBlt( LPDDHAL_BLTDATA lpBlt );
  673. DWORD CALLBACK UpdateOverlay32(LPDDHAL_UPDATEOVERLAYDATA puod);
  674. DWORD CALLBACK DdSetColorKey(LPDDHAL_SETCOLORKEYDATA psckd);
  675. DWORD CALLBACK DdUpdateOverlay(LPDDHAL_UPDATEOVERLAYDATA puod);
  676. void _D3D_SU_DirectDrawLocalDestroyCallback(HashTable* pTable,
  677. void* pData,
  678. void* pExtra);
  679. void _D3D_SU_SurfaceArrayDestroyCallback(PointerArray* pArray,
  680. void* pData,
  681. void* pExtra);
  682. void _D3D_SU_PaletteArrayDestroyCallback(PointerArray* pArray,
  683. void* pData,
  684. void* pExtra);
  685. #if DX7_STEREO
  686. BOOL _DD_bIsStereoMode(P3_THUNKEDDATA* pThisDisplay,
  687. DWORD dwWidth,
  688. DWORD dwHeight,
  689. DWORD dwBpp);
  690. #endif
  691. #if WNT_DDRAW
  692. DWORD CALLBACK DdMapMemory(PDD_MAPMEMORYDATA lpMapMemory);
  693. DWORD CALLBACK DdGetDriverInfo(LPDDHAL_GETDRIVERINFODATA lpData);
  694. // NT specific callbacks in gdi\heap.c
  695. DWORD CALLBACK DdFreeDriverMemory(PDD_FREEDRIVERMEMORYDATA lpFreeDriverMemory);
  696. DWORD CALLBACK DdSetExclusiveMode(PDD_SETEXCLUSIVEMODEDATA lpSetExclusiveMode);
  697. DWORD CALLBACK DdFlipToGDISurface(PDD_FLIPTOGDISURFACEDATA lpFlipToGDISurface);
  698. #else // WNT_DDRAW
  699. DWORD CALLBACK DdUpdateNonLocalHeap(LPDDHAL_UPDATENONLOCALHEAPDATA plhd);
  700. DWORD CALLBACK DdGetHeapAlignment(LPDDHAL_GETHEAPALIGNMENTDATA lpGhaData);
  701. DWORD CALLBACK DdGetDriverInfo(LPDDHAL_GETDRIVERINFODATA lpData);
  702. #endif // WNT_DDRAW
  703. DWORD CALLBACK DdGetAvailDriverMemory(LPDDHAL_GETAVAILDRIVERMEMORYDATA pgadmd);
  704. // Overlay source update
  705. void _DD_OV_UpdateSource(P3_THUNKEDDATA* pThisDisplay,
  706. LPDDRAWI_DDRAWSURFACE_LCL pSurf);
  707. DWORD CALLBACK SetOverlayPosition32(LPDDHAL_SETOVERLAYPOSITIONDATA psopd);
  708. DWORD CALLBACK DdSetOverlayPosition(LPDDHAL_SETOVERLAYPOSITIONDATA psopd);
  709. #if W95_DDRAW
  710. DWORD CALLBACK DDGetVideoPortConnectInfo(LPDDHAL_GETVPORTCONNECTDATA pInput);
  711. DWORD CALLBACK DdCanCreateVideoPort (LPDDHAL_CANCREATEVPORTDATA pInput);
  712. DWORD CALLBACK DdCreateVideoPort (LPDDHAL_CREATEVPORTDATA pInput);
  713. DWORD CALLBACK DdFlipVideoPort (LPDDHAL_FLIPVPORTDATA pInput);
  714. DWORD CALLBACK DdGetVideoPortBandwidth (LPDDHAL_GETVPORTBANDWIDTHDATA pInput);
  715. DWORD CALLBACK DdGetVideoPortInputFormats (LPDDHAL_GETVPORTINPUTFORMATDATA pInput);
  716. DWORD CALLBACK DdGetVideoPortOutputFormats (LPDDHAL_GETVPORTOUTPUTFORMATDATA pInput);
  717. DWORD CALLBACK DdGetVideoPortField (LPDDHAL_GETVPORTFIELDDATA pInput);
  718. DWORD CALLBACK DdGetVideoPortLine (LPDDHAL_GETVPORTLINEDATA pInput);
  719. DWORD CALLBACK DdDestroyVideoPort (LPDDHAL_DESTROYVPORTDATA pInput);
  720. DWORD CALLBACK DdGetVideoPortFlipStatus (LPDDHAL_GETVPORTFLIPSTATUSDATA pInput);
  721. DWORD CALLBACK DdUpdateVideoPort (LPDDHAL_UPDATEVPORTDATA pInput);
  722. DWORD CALLBACK DdWaitForVideoPortSync (LPDDHAL_WAITFORVPORTSYNCDATA pInput);
  723. DWORD CALLBACK DdGetVideoSignalStatus(LPDDHAL_GETVPORTSIGNALDATA pInput);
  724. DWORD CALLBACK DdSyncSurfaceData(LPDDHAL_SYNCSURFACEDATA pInput);
  725. DWORD CALLBACK DdSyncVideoPortData(LPDDHAL_SYNCVIDEOPORTDATA pInput);
  726. #endif // W95_DDRAW
  727. //------------------------------------------------------------------
  728. // Permedia3 Blit Functions
  729. //------------------------------------------------------------------
  730. typedef void (P3RXEFFECTSBLT)(struct tagThunkedData*,
  731. LPDDRAWI_DDRAWSURFACE_LCL pSource,
  732. LPDDRAWI_DDRAWSURFACE_LCL pDest,
  733. P3_SURF_FORMAT* pFormatSource,
  734. P3_SURF_FORMAT* pFormatDest,
  735. LPDDHAL_BLTDATA lpBlt,
  736. RECTL *rSrc,
  737. RECTL *rDest);
  738. VOID
  739. _DD_BLT_P3Clear( // Clearing
  740. P3_THUNKEDDATA* pThisDisplay,
  741. RECTL *rDest,
  742. DWORD ClearValue,
  743. BOOL bDisableFastFill,
  744. BOOL bIsZBuffer,
  745. FLATPTR pDestfpVidMem,
  746. DWORD dwDestPatchMode,
  747. DWORD dwDestPixelPitch,
  748. DWORD dwDestBitDepth
  749. );
  750. VOID _DD_BLT_P3Clear_AA(
  751. P3_THUNKEDDATA* pThisDisplay,
  752. RECTL *rDest,
  753. DWORD dwSurfaceOffset,
  754. DWORD ClearValue,
  755. BOOL bDisableFastFill,
  756. DWORD dwDestPatchMode,
  757. DWORD dwDestPixelPitch,
  758. DWORD dwDestBitDepth,
  759. DDSCAPS DestDdsCaps);
  760. void
  761. _DD_P3Download( // Downloads (sysmem -> video)
  762. P3_THUNKEDDATA* pThisDisplay,
  763. FLATPTR pSrcfpVidMem,
  764. FLATPTR pDestfpVidMem,
  765. DWORD dwSrcChipPatchMode,
  766. DWORD dwDestChipPatchMode,
  767. DWORD dwSrcPitch,
  768. DWORD dwDestPitch,
  769. DWORD dwDestPixelPitch,
  770. DWORD dwDestPixelSize,
  771. RECTL* rSrc,
  772. RECTL* rDest);
  773. void
  774. _DD_P3DownloadDD(
  775. P3_THUNKEDDATA* pThisDisplay,
  776. LPDDRAWI_DDRAWSURFACE_LCL pSource,
  777. LPDDRAWI_DDRAWSURFACE_LCL pDest,
  778. P3_SURF_FORMAT* pFormatSource,
  779. P3_SURF_FORMAT* pFormatDest,
  780. RECTL* rSrc,
  781. RECTL* rDest);
  782. void _DD_P3DownloadDstCh(
  783. struct tagThunkedData*,
  784. LPDDRAWI_DDRAWSURFACE_LCL pSource,
  785. LPDDRAWI_DDRAWSURFACE_LCL pDest,
  786. P3_SURF_FORMAT* pFormatSource,
  787. P3_SURF_FORMAT* pFormatDest,
  788. LPDDHAL_BLTDATA lpBlt,
  789. RECTL* rSrc,
  790. RECTL* rDest);
  791. VOID _DD_BLT_P3CopyBlt( // Blts
  792. P3_THUNKEDDATA* pThisDisplay,
  793. FLATPTR pSrcfpVidMem,
  794. FLATPTR pDestfpVidMem,
  795. DWORD dwSrcChipPatchMode,
  796. DWORD dwDestChipPatchMode,
  797. DWORD dwSrcPitch,
  798. DWORD dwDestPitch,
  799. DWORD dwSrcOffset,
  800. DWORD dwDestOffset,
  801. DWORD dwDestPixelSize,
  802. RECTL *rSrc,
  803. RECTL *rDest);
  804. VOID
  805. _DD_P3BltStretchSrcChDstCh(
  806. P3_THUNKEDDATA* pThisDisplay,
  807. FLATPTR fpSrcVidMem,
  808. P3_SURF_FORMAT* pFormatSource,
  809. DWORD dwSrcPixelSize,
  810. DWORD dwSrcWidth,
  811. DWORD dwSrcHeight,
  812. DWORD dwSrcPixelPitch,
  813. DWORD dwSrcPatchMode,
  814. ULONG ulSrcOffsetFromMemBase,
  815. DWORD dwSrcFlags,
  816. DDPIXELFORMAT* pSrcDDPF,
  817. BOOL bIsSourceAGP,
  818. FLATPTR fpDestVidMem,
  819. P3_SURF_FORMAT* pFormatDest,
  820. DWORD dwDestPixelSize,
  821. DWORD dwDestWidth,
  822. DWORD dwDestHeight,
  823. DWORD dwDestPixelPitch,
  824. DWORD dwDestPatchMode,
  825. ULONG ulDestOffsetFromMemBase,
  826. DWORD dwBltFlags,
  827. DWORD dwBltDDFX,
  828. DDCOLORKEY BltSrcColorKey,
  829. DDCOLORKEY BltDestColorKey,
  830. RECTL *rSrc,
  831. RECTL *rDest);
  832. VOID
  833. _DD_BLT_SysMemToSysMemCopy(
  834. FLATPTR fpSrcVidMem,
  835. LONG lSrcPitch,
  836. DWORD dwSrcBitCount,
  837. FLATPTR fpDstVidMem,
  838. LONG lDstPitch,
  839. DWORD dwDstBitCount,
  840. RECTL* rSource,
  841. RECTL* rDest);
  842. // FX Blits
  843. P3RXEFFECTSBLT _DD_P3BltStretchSrcChDstCh_DD;
  844. P3RXEFFECTSBLT _DD_P3BltStretchSrcChDstChOverlap;
  845. P3RXEFFECTSBLT _DD_P3BltSourceChroma;
  846. void P3RX_AA_Shrink(struct _p3_d3dcontext* pContext);
  847. BOOL _DD_BLT_FixRectlOrigin(char *pszPlace, RECTL *rSrc, RECTL *rDest);
  848. DWORD
  849. _DD_BLT_GetBltDirection(
  850. FLATPTR pSrcfpVidMem,
  851. FLATPTR pDestfpVidMem,
  852. RECTL *rSrc,
  853. RECTL *rDest,
  854. BOOL *pbBlocking);
  855. //------------------------------------------------------------------
  856. // DX Utility functions.
  857. //------------------------------------------------------------------
  858. // Initialise 32 Bit data
  859. BOOL _DD_InitDDHAL32Bit(struct tagThunkedData* pThisDisplay);
  860. // Query flip status
  861. HRESULT _DX_QueryFlipStatus( struct tagThunkedData* pThisDisplay,
  862. FLATPTR fpVidMem,
  863. BOOL bAllowDMAFlush );
  864. // Change the mode setup
  865. void ChangeDDHAL32Mode(struct tagThunkedData* pThisDisplay);
  866. // Checks that the current mode info is correct
  867. #define VALIDATE_MODE_AND_STATE(pThisDisplay) \
  868. if ((pThisDisplay->bResetMode != 0) || \
  869. (pThisDisplay->bStartOfDay)) \
  870. ChangeDDHAL32Mode(pThisDisplay);
  871. //-----------------------------------------------------------------------------
  872. //
  873. // ****************** Mathematical definitions and macros *********************
  874. //
  875. //-----------------------------------------------------------------------------
  876. #define math_e 2.718281828f
  877. // Usefull maths stuff
  878. extern float pow4( float x );
  879. extern float myPow( float x, float y );
  880. #if WNT_DDRAW
  881. // Might be running on non-Intel processors.
  882. static __inline void myDiv(float *result, float dividend, float divisor)
  883. {
  884. *result = dividend/divisor;
  885. } // myDiv()
  886. #else
  887. static __inline void myDiv(float *result, float dividend, float divisor)
  888. {
  889. __asm
  890. {
  891. fld dividend
  892. fdiv divisor
  893. mov eax,result
  894. fstp dword ptr [eax]
  895. }
  896. } // myDiv()
  897. #endif // WNT_DDRAW
  898. __inline void myFtoi(int *result, float f)
  899. {
  900. *result = (int)f;
  901. } //myFtoi
  902. static __inline float myFabs(float f)
  903. {
  904. float* pFloat = &f;
  905. DWORD dwReturn = *((DWORD*)pFloat);
  906. dwReturn &= ~0x80000000;
  907. return (*((float*)&dwReturn));
  908. } //
  909. // Utility functions, used by NT4, NT5 and Win9X
  910. static __inline int log2(int s)
  911. {
  912. int d = 1, iter = -1;
  913. do {
  914. d *= 2;
  915. iter++;
  916. } while (d <= s);
  917. iter += ((s << 1) != d);
  918. return iter;
  919. }
  920. #ifdef _X86_
  921. //-----------------------------------------------------------------------------
  922. //
  923. // myPow
  924. //
  925. // Compute x^y for arbitrary x and y
  926. //
  927. //-----------------------------------------------------------------------------
  928. __inline float
  929. myPow( float x, float y )
  930. {
  931. float res = 0.0f;
  932. int intres;
  933. __asm
  934. {
  935. fld y // y
  936. fld x // x y
  937. fyl2x // y*log2(x)
  938. fstp res
  939. }
  940. // Remove integer part of res as f2xm1 has limited input range
  941. myFtoi ( &intres, res );
  942. res -= intres;
  943. __asm
  944. {
  945. fild intres // Stash integer part for FSCALE
  946. fld res
  947. f2xm1 // ST = 2^^fracx - 1
  948. fld1
  949. fadd // ST = 2^^fracx
  950. fscale // ST = 2^^x
  951. fstp res
  952. fstp st(0) // Clean up stack
  953. }
  954. return res;
  955. } // myPow
  956. #elif defined(_AMD64_)
  957. double pow(double, double);
  958. __inline float
  959. myPow( float x, float y )
  960. {
  961. return (float)pow((double)x, (double)y);
  962. }
  963. #elif defined(_IA64_)
  964. __inline float
  965. myPow( float x, float y )
  966. {
  967. return powf(x,y);
  968. }
  969. #else
  970. #error "No Target Architecture"
  971. #endif //_X86_
  972. //-----------------------------------------------------------------------------
  973. //
  974. // pow4
  975. //
  976. // Compute 4^x for arbitrary x
  977. //
  978. //-----------------------------------------------------------------------------
  979. __inline float
  980. pow4(
  981. float x )
  982. {
  983. #if defined(_IA64_)
  984. return 0.0F;
  985. #else
  986. return myPow( 4.0F, x );
  987. #endif
  988. } // pow4
  989. #endif // __DIRECTX_H