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.

2587 lines
84 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: ddraw.c
  3. *
  4. * Client side stubs for the private DirectDraw system APIs.
  5. *
  6. * Created: 3-Dec-1995
  7. * Author: J. Andrew Goossen [andrewgo]
  8. *
  9. * Copyright (c) 1995-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #include <ddrawi.h>
  14. #include <ddrawgdi.h>
  15. #undef _NO_COM
  16. #define BUILD_DDDDK
  17. #include <d3dhal.h>
  18. #include <ddrawi.h>
  19. #include "ddstub.h"
  20. #include "d3dstub.h"
  21. // For the first incarnation of DirectDraw on Windows NT, we are
  22. // implementing a user-mode shared memory section between all instances
  23. // of DirectDraw to keep track of shared state -- mostly for off-screen
  24. // memory allocation and exclusive mode arbitration. Hopefully future
  25. // versions will move all this logic to kernel mode so that we can get
  26. // rid of the shared section, which is a robustness hole.
  27. //
  28. // One of the ramifications of this is that DirectDraw keeps its
  29. // global DirectDraw object in the shared memory section, where it is
  30. // used by all processes. Unfortunately, it is preferrable from a kernel
  31. // point of view to keep the DirectDraw objects unique between processes
  32. // so that proper cleanup can be done. As a compromise, so that
  33. // DirectDraw can keep using this global DirectDraw object, but that the
  34. // kernel still has unique DirectDraw objects per process, we simply stash
  35. // the unique per-process DirectDraw handle in a variable global to this
  36. // process, and use that instead of anything pulled out of DirectDraw's
  37. // own global DirectDraw object structure -- an advantage since the kernel
  38. // code is already written to the future model.
  39. //
  40. // One result of this, however, is that we are limiting ourselves to the
  41. // notion of only one DirectDraw device. However, since we will not
  42. // support multiple monitors for the NT 4.0 release, I don't consider this
  43. // to be a serious problem, and the non-shared-section model will fix this.
  44. HANDLE ghDirectDraw = 0; // Process-specific kernel-mode DirectDraw object
  45. // handle that we substitute for the 'global'
  46. // DirectDraw handle whenever we see it
  47. ULONG gcDirectDraw = 0; // Count of global DirectDraw instances
  48. /*****************************Private*Routine******************************\
  49. * CanCreateVideoPort
  50. *
  51. * History:
  52. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  53. * Wrote it.
  54. \**************************************************************************/
  55. DWORD
  56. WINAPI
  57. DvpCanCreateVideoPort(
  58. LPDDHAL_CANCREATEVPORTDATA pCanCreateVideoPort
  59. )
  60. {
  61. return(NtGdiDvpCanCreateVideoPort(DD_HANDLE(pCanCreateVideoPort->lpDD->lpGbl->hDD),
  62. (PDD_CANCREATEVPORTDATA)pCanCreateVideoPort));
  63. }
  64. /*****************************Private*Routine******************************\
  65. * CreateVideoPort
  66. *
  67. * History:
  68. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  69. * Wrote it.
  70. \**************************************************************************/
  71. DWORD
  72. WINAPI
  73. DvpCreateVideoPort(
  74. LPDDHAL_CREATEVPORTDATA pCreateVideoPort
  75. )
  76. {
  77. HANDLE h;
  78. h = NtGdiDvpCreateVideoPort(DD_HANDLE(pCreateVideoPort->lpDD->lpGbl->hDD),
  79. (PDD_CREATEVPORTDATA)pCreateVideoPort);
  80. pCreateVideoPort->lpVideoPort->hDDVideoPort = h;
  81. return(DDHAL_DRIVER_HANDLED);
  82. }
  83. /*****************************Private*Routine******************************\
  84. * DestroyVideoPort
  85. *
  86. * History:
  87. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  88. * Wrote it.
  89. \**************************************************************************/
  90. DWORD
  91. WINAPI
  92. DvpDestroyVideoPort(
  93. LPDDHAL_DESTROYVPORTDATA pDestroyVideoPort
  94. )
  95. {
  96. return(NtGdiDvpDestroyVideoPort((HANDLE) pDestroyVideoPort->lpVideoPort->hDDVideoPort,
  97. (PDD_DESTROYVPORTDATA)pDestroyVideoPort));
  98. }
  99. /*****************************Private*Routine******************************\
  100. * ColorControl
  101. *
  102. * History:
  103. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  104. * Wrote it.
  105. \**************************************************************************/
  106. DWORD
  107. WINAPI
  108. DvpColorControl(
  109. LPDDHAL_VPORTCOLORDATA pColorControl
  110. )
  111. {
  112. return(NtGdiDvpColorControl((HANDLE) pColorControl->lpVideoPort->hDDVideoPort,
  113. (PDD_VPORTCOLORDATA)pColorControl));
  114. }
  115. /*****************************Private*Routine******************************\
  116. * FlipVideoPort
  117. *
  118. * History:
  119. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  120. * Wrote it.
  121. \**************************************************************************/
  122. DWORD
  123. WINAPI
  124. DvpFlipVideoPort(
  125. LPDDHAL_FLIPVPORTDATA pFlipVideoPort
  126. )
  127. {
  128. return(NtGdiDvpFlipVideoPort((HANDLE) pFlipVideoPort->lpVideoPort->hDDVideoPort,
  129. (HANDLE) pFlipVideoPort->lpSurfCurr->hDDSurface,
  130. (HANDLE) pFlipVideoPort->lpSurfTarg->hDDSurface,
  131. (PDD_FLIPVPORTDATA) pFlipVideoPort));
  132. }
  133. /*****************************Private*Routine******************************\
  134. * GetVideoPortBandwidth
  135. *
  136. * History:
  137. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  138. * Wrote it.
  139. \**************************************************************************/
  140. DWORD
  141. WINAPI
  142. DvpGetVideoPortBandwidth(
  143. LPDDHAL_GETVPORTBANDWIDTHDATA pGetVPortBandwidth
  144. )
  145. {
  146. return(NtGdiDvpGetVideoPortBandwidth((HANDLE) pGetVPortBandwidth->lpVideoPort->hDDVideoPort,
  147. (PDD_GETVPORTBANDWIDTHDATA) pGetVPortBandwidth));
  148. }
  149. /*****************************Private*Routine******************************\
  150. * GetVideoPortField
  151. *
  152. * History:
  153. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  154. * Wrote it.
  155. \**************************************************************************/
  156. DWORD
  157. WINAPI
  158. DvpGetVideoPortField(
  159. LPDDHAL_GETVPORTFIELDDATA pGetVideoPortField
  160. )
  161. {
  162. return(NtGdiDvpGetVideoPortField((HANDLE) pGetVideoPortField->lpVideoPort->hDDVideoPort,
  163. (PDD_GETVPORTFIELDDATA)pGetVideoPortField));
  164. }
  165. /*****************************Private*Routine******************************\
  166. * GetVideoPortFlipStatus
  167. *
  168. * History:
  169. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  170. * Wrote it.
  171. \**************************************************************************/
  172. DWORD
  173. WINAPI
  174. DvpGetVideoPortFlipStatus(
  175. LPDDHAL_GETVPORTFLIPSTATUSDATA pGetVPortFlipStatus
  176. )
  177. {
  178. return(NtGdiDvpGetVideoPortFlipStatus(DD_HANDLE(pGetVPortFlipStatus->lpDD->lpGbl->hDD),
  179. (PDD_GETVPORTFLIPSTATUSDATA)pGetVPortFlipStatus));
  180. }
  181. /*****************************Private*Routine******************************\
  182. * GetVideoPortInputFormats
  183. *
  184. * History:
  185. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  186. * Wrote it.
  187. \**************************************************************************/
  188. DWORD
  189. WINAPI
  190. DvpGetVideoPortInputFormats(
  191. LPDDHAL_GETVPORTINPUTFORMATDATA pGetVPortInputFormat
  192. )
  193. {
  194. return(NtGdiDvpGetVideoPortInputFormats((HANDLE) pGetVPortInputFormat->lpVideoPort->hDDVideoPort,
  195. (PDD_GETVPORTINPUTFORMATDATA)pGetVPortInputFormat));
  196. }
  197. /*****************************Private*Routine******************************\
  198. * GetVideoPortLine
  199. *
  200. * History:
  201. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  202. * Wrote it.
  203. \**************************************************************************/
  204. DWORD
  205. WINAPI
  206. DvpGetVideoPortLine(
  207. LPDDHAL_GETVPORTLINEDATA pGetVideoPortLine
  208. )
  209. {
  210. return(NtGdiDvpGetVideoPortLine((HANDLE) pGetVideoPortLine->lpVideoPort->hDDVideoPort,
  211. (PDD_GETVPORTLINEDATA)pGetVideoPortLine));
  212. }
  213. /*****************************Private*Routine******************************\
  214. * GetVideoPortOutputFormats
  215. *
  216. * History:
  217. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  218. * Wrote it.
  219. \**************************************************************************/
  220. DWORD
  221. WINAPI
  222. DvpGetVideoPortOutputFormats(
  223. LPDDHAL_GETVPORTOUTPUTFORMATDATA pGetVPortOutputFormats
  224. )
  225. {
  226. return(NtGdiDvpGetVideoPortOutputFormats((HANDLE) pGetVPortOutputFormats->lpVideoPort->hDDVideoPort,
  227. (PDD_GETVPORTOUTPUTFORMATDATA)pGetVPortOutputFormats));
  228. }
  229. /*****************************Private*Routine******************************\
  230. * GetVideoPortConnectInfo
  231. *
  232. * History:
  233. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  234. * Wrote it.
  235. \**************************************************************************/
  236. DWORD
  237. WINAPI
  238. DvpGetVideoPortConnectInfo(
  239. LPDDHAL_GETVPORTCONNECTDATA pGetVPortConnectInfo
  240. )
  241. {
  242. return(NtGdiDvpGetVideoPortConnectInfo(DD_HANDLE(pGetVPortConnectInfo->lpDD->lpGbl->hDD),
  243. (PDD_GETVPORTCONNECTDATA)pGetVPortConnectInfo));
  244. }
  245. /*****************************Private*Routine******************************\
  246. * GetVideoSignalStatus
  247. *
  248. * History:
  249. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  250. * Wrote it.
  251. \**************************************************************************/
  252. DWORD
  253. WINAPI
  254. DvpGetVideoSignalStatus(
  255. LPDDHAL_GETVPORTSIGNALDATA pGetVideoSignalStatus
  256. )
  257. {
  258. return(NtGdiDvpGetVideoSignalStatus((HANDLE) pGetVideoSignalStatus->lpVideoPort->hDDVideoPort,
  259. (PDD_GETVPORTSIGNALDATA)pGetVideoSignalStatus));
  260. }
  261. /*****************************Private*Routine******************************\
  262. * UpdateVideoPort
  263. *
  264. * History:
  265. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  266. * Wrote it.
  267. \**************************************************************************/
  268. DWORD
  269. WINAPI
  270. DvpUpdateVideoPort(
  271. LPDDHAL_UPDATEVPORTDATA pUpdateVideoPort
  272. )
  273. {
  274. HANDLE ahSurfaceVideo[MAX_AUTOFLIP_BUFFERS];
  275. HANDLE ahSurfaceVbi[MAX_AUTOFLIP_BUFFERS];
  276. DWORD dwNumAutoflip;
  277. DWORD dwNumVBIAutoflip;
  278. ULONG i;
  279. if (pUpdateVideoPort->dwFlags != DDRAWI_VPORTSTOP)
  280. {
  281. dwNumAutoflip = pUpdateVideoPort->dwNumAutoflip;
  282. if ((dwNumAutoflip == 0) &&
  283. (pUpdateVideoPort->lplpDDSurface != NULL))
  284. {
  285. dwNumAutoflip = 1;
  286. }
  287. for (i = 0; i < dwNumAutoflip; i++)
  288. {
  289. ahSurfaceVideo[i] = (HANDLE)(pUpdateVideoPort->lplpDDSurface[i]->
  290. lpLcl->hDDSurface);
  291. }
  292. dwNumVBIAutoflip = pUpdateVideoPort->dwNumVBIAutoflip;
  293. if ((dwNumVBIAutoflip == 0) &&
  294. (pUpdateVideoPort->lplpDDVBISurface != NULL))
  295. {
  296. dwNumVBIAutoflip = 1;
  297. }
  298. for (i = 0; i < dwNumVBIAutoflip; i++)
  299. {
  300. ahSurfaceVbi[i] = (HANDLE)(pUpdateVideoPort->lplpDDVBISurface[i]->
  301. lpLcl->hDDSurface);
  302. }
  303. }
  304. return(NtGdiDvpUpdateVideoPort((HANDLE) pUpdateVideoPort->lpVideoPort->hDDVideoPort,
  305. ahSurfaceVideo,
  306. ahSurfaceVbi,
  307. (PDD_UPDATEVPORTDATA) pUpdateVideoPort));
  308. }
  309. /*****************************Private*Routine******************************\
  310. * WaitForVideoPortSync
  311. *
  312. * History:
  313. * 2-Oct-1996 -by- Lingyun Wang [lingyunw]
  314. * Wrote it.
  315. \**************************************************************************/
  316. DWORD
  317. WINAPI
  318. DvpWaitForVideoPortSync(
  319. LPDDHAL_WAITFORVPORTSYNCDATA pWaitForVideoPortSync
  320. )
  321. {
  322. return(NtGdiDvpWaitForVideoPortSync((HANDLE) pWaitForVideoPortSync->lpVideoPort->hDDVideoPort,
  323. (PDD_WAITFORVPORTSYNCDATA)pWaitForVideoPortSync));
  324. }
  325. /*****************************Private*Routine******************************\
  326. * AcquireNotification
  327. *
  328. * History:
  329. * 9-Oct-2000 -by- Scott MacDonald [smac]
  330. * Wrote it.
  331. \**************************************************************************/
  332. DWORD
  333. WINAPI
  334. DvpAcquireNotification(
  335. LPDDRAWI_DDVIDEOPORT_LCL pVideoPort,
  336. HANDLE * pHandle,
  337. LPDDVIDEOPORTNOTIFY pNotify)
  338. {
  339. return(NtGdiDvpAcquireNotification((HANDLE) pVideoPort->hDDVideoPort,
  340. pHandle,
  341. pNotify));
  342. }
  343. /*****************************Private*Routine******************************\
  344. * ReleaseNotification
  345. *
  346. * History:
  347. * 9-Oct-2000 -by- Scott MacDonald [smac]
  348. * Wrote it.
  349. \**************************************************************************/
  350. DWORD
  351. WINAPI
  352. DvpReleaseNotification(
  353. LPDDRAWI_DDVIDEOPORT_LCL pVideoPort,
  354. HANDLE Handle)
  355. {
  356. return(NtGdiDvpReleaseNotification((HANDLE) pVideoPort->hDDVideoPort,
  357. Handle));
  358. }
  359. /*****************************Private*Routine******************************\
  360. * GetMoCompGuids
  361. *
  362. * History:
  363. * 18-Nov-1997 -by- smac
  364. * Wrote it.
  365. \**************************************************************************/
  366. DWORD
  367. WINAPI
  368. DdGetMoCompGuids(
  369. LPDDHAL_GETMOCOMPGUIDSDATA pGetMoCompGuids
  370. )
  371. {
  372. return(NtGdiDdGetMoCompGuids(DD_HANDLE(pGetMoCompGuids->lpDD->lpGbl->hDD),
  373. (PDD_GETMOCOMPGUIDSDATA)pGetMoCompGuids));
  374. }
  375. /*****************************Private*Routine******************************\
  376. * GetMoCompFormats
  377. *
  378. * History:
  379. * 18-Nov-1997 -by- smac
  380. * Wrote it.
  381. \**************************************************************************/
  382. DWORD
  383. WINAPI
  384. DdGetMoCompFormats(
  385. LPDDHAL_GETMOCOMPFORMATSDATA pGetMoCompFormats
  386. )
  387. {
  388. return(NtGdiDdGetMoCompFormats(DD_HANDLE(pGetMoCompFormats->lpDD->lpGbl->hDD),
  389. (PDD_GETMOCOMPFORMATSDATA)pGetMoCompFormats));
  390. }
  391. /*****************************Private*Routine******************************\
  392. * GetMoCompBuffInfo
  393. *
  394. * History:
  395. * 18-Nov-1997 -by- smac
  396. * Wrote it.
  397. \**************************************************************************/
  398. DWORD
  399. WINAPI
  400. DdGetMoCompBuffInfo(
  401. LPDDHAL_GETMOCOMPCOMPBUFFDATA pGetBuffData
  402. )
  403. {
  404. return(NtGdiDdGetMoCompBuffInfo(DD_HANDLE(pGetBuffData->lpDD->lpGbl->hDD),
  405. (PDD_GETMOCOMPCOMPBUFFDATA)pGetBuffData));
  406. }
  407. /*****************************Private*Routine******************************\
  408. * GetInternalMoCompInfo
  409. *
  410. * History:
  411. * 18-Nov-1997 -by- smac
  412. * Wrote it.
  413. \**************************************************************************/
  414. DWORD
  415. WINAPI
  416. DdGetInternalMoCompInfo(
  417. LPDDHAL_GETINTERNALMOCOMPDATA pGetInternalData
  418. )
  419. {
  420. return(NtGdiDdGetInternalMoCompInfo(DD_HANDLE(pGetInternalData->lpDD->lpGbl->hDD),
  421. (PDD_GETINTERNALMOCOMPDATA)pGetInternalData));
  422. }
  423. /*****************************Private*Routine******************************\
  424. * CreateMoComp
  425. *
  426. * History:
  427. * 18-Nov-1997 -by- smac
  428. * Wrote it.
  429. \**************************************************************************/
  430. DWORD
  431. WINAPI
  432. DdCreateMoComp(
  433. LPDDHAL_CREATEMOCOMPDATA pCreateMoComp
  434. )
  435. {
  436. HANDLE h;
  437. h = NtGdiDdCreateMoComp(DD_HANDLE(pCreateMoComp->lpDD->lpGbl->hDD),
  438. (PDD_CREATEMOCOMPDATA)pCreateMoComp);
  439. pCreateMoComp->lpMoComp->hMoComp = h;
  440. return(DDHAL_DRIVER_HANDLED);
  441. }
  442. /*****************************Private*Routine******************************\
  443. * DestroyMoComp
  444. *
  445. * History:
  446. * 18-Nov-1997 -by- smac
  447. * Wrote it.
  448. \**************************************************************************/
  449. DWORD
  450. WINAPI
  451. DdDestroyMoComp(
  452. LPDDHAL_DESTROYMOCOMPDATA pDestroyMoComp
  453. )
  454. {
  455. return(NtGdiDdDestroyMoComp((HANDLE)pDestroyMoComp->lpMoComp->hMoComp,
  456. (PDD_DESTROYMOCOMPDATA)pDestroyMoComp));
  457. }
  458. /*****************************Private*Routine******************************\
  459. * BeginMoCompFrame
  460. *
  461. * History:
  462. * 18-Nov-1997 -by- smac
  463. * Wrote it.
  464. \**************************************************************************/
  465. DWORD
  466. WINAPI
  467. DdBeginMoCompFrame(
  468. LPDDHAL_BEGINMOCOMPFRAMEDATA pBeginFrame
  469. )
  470. {
  471. LPDDRAWI_DDRAWSURFACE_LCL *lpOriginal=NULL;
  472. LPDDRAWI_DDRAWSURFACE_LCL lpOrigDest=NULL;
  473. DWORD i;
  474. DWORD dwRet;
  475. if( pBeginFrame->lpDestSurface != NULL )
  476. {
  477. lpOrigDest = pBeginFrame->lpDestSurface;
  478. pBeginFrame->lpDestSurface = (LPDDRAWI_DDRAWSURFACE_LCL)
  479. pBeginFrame->lpDestSurface->hDDSurface;
  480. }
  481. dwRet = NtGdiDdBeginMoCompFrame((HANDLE)pBeginFrame->lpMoComp->hMoComp,
  482. (PDD_BEGINMOCOMPFRAMEDATA)pBeginFrame);
  483. if( lpOrigDest )
  484. {
  485. pBeginFrame->lpDestSurface = lpOrigDest;
  486. }
  487. return dwRet;
  488. }
  489. /*****************************Private*Routine******************************\
  490. * EndMoCompFrame
  491. *
  492. * History:
  493. * 18-Nov-1997 -by- smac
  494. * Wrote it.
  495. \**************************************************************************/
  496. DWORD
  497. WINAPI
  498. DdEndMoCompFrame(
  499. LPDDHAL_ENDMOCOMPFRAMEDATA pEndFrame
  500. )
  501. {
  502. return(NtGdiDdEndMoCompFrame((HANDLE)pEndFrame->lpMoComp->hMoComp,
  503. (PDD_ENDMOCOMPFRAMEDATA)pEndFrame));
  504. }
  505. /*****************************Private*Routine******************************\
  506. * RenderMoComp
  507. *
  508. * History:
  509. * 18-Nov-1997 -by- smac
  510. * Wrote it.
  511. \**************************************************************************/
  512. DWORD
  513. WINAPI
  514. DdRenderMoComp(
  515. LPDDHAL_RENDERMOCOMPDATA pRender
  516. )
  517. {
  518. DWORD i;
  519. DWORD dwRet;
  520. for( i = 0; i < pRender->dwNumBuffers; i++ )
  521. {
  522. pRender->lpBufferInfo[i].lpPrivate =
  523. pRender->lpBufferInfo[i].lpCompSurface;
  524. pRender->lpBufferInfo[i].lpCompSurface = (LPDDRAWI_DDRAWSURFACE_LCL)
  525. pRender->lpBufferInfo[i].lpCompSurface->hDDSurface;
  526. }
  527. dwRet = NtGdiDdRenderMoComp((HANDLE)pRender->lpMoComp->hMoComp,
  528. (PDD_RENDERMOCOMPDATA)pRender);
  529. for( i = 0; i < pRender->dwNumBuffers; i++ )
  530. {
  531. pRender->lpBufferInfo[i].lpCompSurface = (LPDDRAWI_DDRAWSURFACE_LCL)
  532. pRender->lpBufferInfo[i].lpPrivate;
  533. }
  534. return dwRet;
  535. }
  536. /*****************************Private*Routine******************************\
  537. * QueryMoCompStatus
  538. *
  539. * History:
  540. * 18-Nov-1997 -by- smac
  541. * Wrote it.
  542. \**************************************************************************/
  543. DWORD
  544. WINAPI
  545. DdQueryMoCompStatus(
  546. LPDDHAL_QUERYMOCOMPSTATUSDATA pQueryStatus
  547. )
  548. {
  549. DWORD dwRet;
  550. LPDDRAWI_DDRAWSURFACE_LCL surf_lcl;
  551. surf_lcl = pQueryStatus->lpSurface;
  552. pQueryStatus->lpSurface = (LPDDRAWI_DDRAWSURFACE_LCL) surf_lcl->hDDSurface;
  553. dwRet = NtGdiDdQueryMoCompStatus((HANDLE)pQueryStatus->lpMoComp->hMoComp,
  554. (PDD_QUERYMOCOMPSTATUSDATA)pQueryStatus);
  555. pQueryStatus->lpSurface = surf_lcl;
  556. return dwRet;
  557. }
  558. /*****************************Private*Routine******************************\
  559. * DdAlphaBlt
  560. *
  561. * History:
  562. * 24-Nov-1997 -by- Scott MacDonald [smac]
  563. * Wrote it.
  564. \**************************************************************************/
  565. DWORD
  566. WINAPI
  567. DdAlphaBlt(
  568. LPDDHAL_BLTDATA pBlt
  569. )
  570. {
  571. HANDLE hSurfaceSrc = (pBlt->lpDDSrcSurface != NULL)
  572. ? (HANDLE) pBlt->lpDDSrcSurface->hDDSurface : 0;
  573. return(NtGdiDdAlphaBlt((HANDLE) pBlt->lpDDDestSurface->hDDSurface,
  574. hSurfaceSrc,
  575. (PDD_BLTDATA) pBlt));
  576. }
  577. /*****************************Private*Routine******************************\
  578. * DdBlt
  579. *
  580. * History:
  581. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  582. * Wrote it.
  583. \**************************************************************************/
  584. DWORD
  585. WINAPI
  586. DdBlt(
  587. LPDDHAL_BLTDATA pBlt
  588. )
  589. {
  590. HANDLE hSurfaceSrc = (pBlt->lpDDSrcSurface != NULL)
  591. ? (HANDLE) pBlt->lpDDSrcSurface->hDDSurface : 0;
  592. return(NtGdiDdBlt((HANDLE) pBlt->lpDDDestSurface->hDDSurface,
  593. hSurfaceSrc,
  594. (PDD_BLTDATA) pBlt));
  595. }
  596. /*****************************Private*Routine******************************\
  597. * DdFlip
  598. *
  599. * History:
  600. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  601. * Wrote it.
  602. \**************************************************************************/
  603. DWORD
  604. APIENTRY
  605. DdFlip(
  606. LPDDHAL_FLIPDATA pFlip
  607. )
  608. {
  609. HANDLE hSurfTargLeft=NULL;
  610. HANDLE hSurfCurrLeft=NULL;
  611. if (pFlip->dwFlags & DDFLIP_STEREO)
  612. { if (pFlip->lpSurfTargLeft!=NULL && pFlip->lpSurfCurrLeft!=NULL)
  613. {
  614. hSurfTargLeft=(HANDLE)pFlip->lpSurfTargLeft->hDDSurface;
  615. hSurfCurrLeft=(HANDLE)pFlip->lpSurfCurrLeft->hDDSurface;
  616. }
  617. }
  618. return(NtGdiDdFlip((HANDLE) pFlip->lpSurfCurr->hDDSurface,
  619. (HANDLE) pFlip->lpSurfTarg->hDDSurface,
  620. hSurfCurrLeft,
  621. hSurfTargLeft,
  622. (PDD_FLIPDATA) pFlip));
  623. }
  624. /*****************************Private*Routine******************************\
  625. * DdLock
  626. *
  627. * History:
  628. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  629. * Wrote it.
  630. \**************************************************************************/
  631. DWORD
  632. APIENTRY
  633. DdLock(
  634. LPDDHAL_LOCKDATA pLock
  635. )
  636. {
  637. return(NtGdiDdLock((HANDLE) pLock->lpDDSurface->hDDSurface,
  638. (PDD_LOCKDATA) pLock,
  639. NULL));
  640. }
  641. /*****************************Private*Routine******************************\
  642. * DdUnlock
  643. *
  644. * History:
  645. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  646. * Wrote it.
  647. \**************************************************************************/
  648. DWORD
  649. APIENTRY
  650. DdUnlock(
  651. LPDDHAL_UNLOCKDATA pUnlock
  652. )
  653. {
  654. return(NtGdiDdUnlock((HANDLE) pUnlock->lpDDSurface->hDDSurface,
  655. (PDD_UNLOCKDATA) pUnlock));
  656. }
  657. /*****************************Private*Routine******************************\
  658. * DdLockD3D
  659. *
  660. * History:
  661. * 20-Jan-1998 -by- Anantha Kancherla [anankan]
  662. * Wrote it.
  663. \**************************************************************************/
  664. DWORD
  665. APIENTRY
  666. DdLockD3D(
  667. LPDDHAL_LOCKDATA pLock
  668. )
  669. {
  670. return(NtGdiDdLockD3D((HANDLE) pLock->lpDDSurface->hDDSurface,
  671. (PDD_LOCKDATA) pLock));
  672. }
  673. /*****************************Private*Routine******************************\
  674. * DdUnlockD3D
  675. *
  676. * History:
  677. * 20-Jan-1998 -by- Anantha Kancherla [anankan]
  678. * Wrote it.
  679. \**************************************************************************/
  680. DWORD
  681. APIENTRY
  682. DdUnlockD3D(
  683. LPDDHAL_UNLOCKDATA pUnlock
  684. )
  685. {
  686. return(NtGdiDdUnlockD3D((HANDLE) pUnlock->lpDDSurface->hDDSurface,
  687. (PDD_UNLOCKDATA) pUnlock));
  688. }
  689. /*****************************Private*Routine******************************\
  690. * DdGetBltStatus
  691. *
  692. * History:
  693. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  694. * Wrote it.
  695. \**************************************************************************/
  696. DWORD
  697. APIENTRY
  698. DdGetBltStatus(
  699. LPDDHAL_GETBLTSTATUSDATA pGetBltStatus
  700. )
  701. {
  702. return(NtGdiDdGetBltStatus((HANDLE) pGetBltStatus->lpDDSurface->hDDSurface,
  703. (PDD_GETBLTSTATUSDATA) pGetBltStatus));
  704. }
  705. /*****************************Private*Routine******************************\
  706. * DdGetFlipStatus
  707. *
  708. * History:
  709. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  710. * Wrote it.
  711. \**************************************************************************/
  712. DWORD
  713. APIENTRY
  714. DdGetFlipStatus(
  715. LPDDHAL_GETFLIPSTATUSDATA pGetFlipStatus
  716. )
  717. {
  718. return(NtGdiDdGetFlipStatus((HANDLE) pGetFlipStatus->lpDDSurface->hDDSurface,
  719. (PDD_GETFLIPSTATUSDATA) pGetFlipStatus));
  720. }
  721. /*****************************Private*Routine******************************\
  722. * DdWaitForVerticalBlank
  723. *
  724. * History:
  725. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  726. * Wrote it.
  727. \**************************************************************************/
  728. DWORD
  729. APIENTRY
  730. DdWaitForVerticalBlank(
  731. LPDDHAL_WAITFORVERTICALBLANKDATA pWaitForVerticalBlank
  732. )
  733. {
  734. return(NtGdiDdWaitForVerticalBlank(DD_HANDLE(pWaitForVerticalBlank->lpDD->hDD),
  735. (PDD_WAITFORVERTICALBLANKDATA) pWaitForVerticalBlank));
  736. }
  737. /*****************************Private*Routine******************************\
  738. * DdCanCreateSurface
  739. *
  740. * History:
  741. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  742. * Wrote it.
  743. \**************************************************************************/
  744. DWORD
  745. APIENTRY
  746. DdCanCreateSurface(
  747. LPDDHAL_CANCREATESURFACEDATA pCanCreateSurface
  748. )
  749. {
  750. return(NtGdiDdCanCreateSurface(DD_HANDLE(pCanCreateSurface->lpDD->hDD),
  751. (PDD_CANCREATESURFACEDATA) pCanCreateSurface));
  752. }
  753. /*****************************Private*Routine******************************\
  754. * DdCreateSurface
  755. *
  756. * History:
  757. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  758. * Wrote it.
  759. \**************************************************************************/
  760. DWORD
  761. APIENTRY
  762. DdCreateSurface(
  763. LPDDHAL_CREATESURFACEDATA pCreateSurface
  764. )
  765. {
  766. ULONG i;
  767. LPDDSURFACEDESC pSurfaceDesc;
  768. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal;
  769. LPDDRAWI_DDRAWSURFACE_GBL pSurfaceGlobal;
  770. DD_SURFACE_GLOBAL SurfaceGlobal;
  771. DD_SURFACE_LOCAL SurfaceLocal;
  772. DD_SURFACE_MORE SurfaceMore;
  773. HANDLE hInSurface;
  774. HANDLE hOutSurface;
  775. DD_SURFACE_LOCAL* pDDSurfaceLocal = NULL;
  776. DD_SURFACE_GLOBAL* pDDSurfaceGlobal = NULL;
  777. DD_SURFACE_MORE* pDDSurfaceMore = NULL;
  778. HANDLE* phInSurface = NULL;
  779. HANDLE* phOutSurface = NULL;
  780. DWORD dwRet;
  781. DWORD dwNumToCreate;
  782. // For every surface, convert to the kernel's surface data structure,
  783. // call the kernel, then convert back:
  784. // All video memory heaps are handled in the kernel so if
  785. // the kernel call cannot create a surface then user-mode can't
  786. // either. Always returns DRIVER_HANDLED to enforce this.
  787. dwRet = DDHAL_DRIVER_HANDLED;
  788. // If we are only creating one, no need to allocate gobs of memory; otherwise, do it
  789. dwNumToCreate = pCreateSurface->dwSCnt;
  790. if (pCreateSurface->dwSCnt == 1)
  791. {
  792. pDDSurfaceLocal = &SurfaceLocal;
  793. pDDSurfaceGlobal = &SurfaceGlobal;
  794. pDDSurfaceMore = &SurfaceMore;
  795. phInSurface = &hInSurface;
  796. phOutSurface = &hOutSurface;
  797. //
  798. // Wow64 genthnk will automatically thunk these structures, however,
  799. // since these structures are pointer dependent, we need to make sure
  800. // to NULL out these pointers so that Wow64 won't thunk them
  801. //
  802. RtlZeroMemory(pDDSurfaceLocal, sizeof(*pDDSurfaceLocal));
  803. RtlZeroMemory(pDDSurfaceGlobal, sizeof(*pDDSurfaceGlobal));
  804. RtlZeroMemory(pDDSurfaceMore, sizeof(*pDDSurfaceMore));
  805. }
  806. else
  807. {
  808. pDDSurfaceLocal = (DD_SURFACE_LOCAL*) LocalAlloc(LMEM_ZEROINIT,
  809. sizeof(DD_SURFACE_LOCAL) * dwNumToCreate);
  810. pDDSurfaceGlobal = (DD_SURFACE_GLOBAL*) LocalAlloc(LMEM_ZEROINIT,
  811. sizeof(DD_SURFACE_GLOBAL) * dwNumToCreate);
  812. pDDSurfaceMore = (DD_SURFACE_MORE*) LocalAlloc(LMEM_ZEROINIT,
  813. sizeof(DD_SURFACE_MORE) * dwNumToCreate);
  814. phInSurface = (HANDLE*) LocalAlloc(LMEM_ZEROINIT,
  815. sizeof(HANDLE) * dwNumToCreate);
  816. phOutSurface = (HANDLE*) LocalAlloc(LMEM_ZEROINIT,
  817. sizeof(HANDLE) * dwNumToCreate);
  818. if ((pDDSurfaceLocal == NULL) ||
  819. (pDDSurfaceGlobal == NULL) ||
  820. (pDDSurfaceMore == NULL) ||
  821. (phInSurface == NULL) ||
  822. (phOutSurface == NULL))
  823. {
  824. pCreateSurface->ddRVal = DDERR_OUTOFMEMORY;
  825. goto CleanupCreate;
  826. }
  827. }
  828. for (i = 0; i < dwNumToCreate; i++)
  829. {
  830. pSurfaceLocal = pCreateSurface->lplpSList[i];
  831. pSurfaceGlobal = pSurfaceLocal->lpGbl;
  832. pSurfaceDesc = pCreateSurface->lpDDSurfaceDesc;
  833. // Make sure there's always a valid pixel format for the surface:
  834. if (pSurfaceLocal->dwFlags & DDRAWISURF_HASPIXELFORMAT)
  835. {
  836. pDDSurfaceGlobal[i].ddpfSurface = pSurfaceGlobal->ddpfSurface;
  837. pDDSurfaceGlobal[i].ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
  838. }
  839. else
  840. {
  841. pDDSurfaceGlobal[i].ddpfSurface = pSurfaceGlobal->lpDD->vmiData.ddpfDisplay;
  842. }
  843. pDDSurfaceGlobal[i].wWidth = pSurfaceGlobal->wWidth;
  844. pDDSurfaceGlobal[i].wHeight = pSurfaceGlobal->wHeight;
  845. pDDSurfaceGlobal[i].lPitch = pSurfaceGlobal->lPitch;
  846. pDDSurfaceGlobal[i].fpVidMem = pSurfaceGlobal->fpVidMem;
  847. pDDSurfaceGlobal[i].dwBlockSizeX = pSurfaceGlobal->dwBlockSizeX;
  848. pDDSurfaceGlobal[i].dwBlockSizeY = pSurfaceGlobal->dwBlockSizeY;
  849. pDDSurfaceLocal[i].ddsCaps = pSurfaceLocal->ddsCaps;
  850. // Copy the driver managed flag
  851. pDDSurfaceLocal[i].dwFlags &= ~DDRAWISURF_DRIVERMANAGED;
  852. pDDSurfaceLocal[i].dwFlags |= (pSurfaceLocal->dwFlags & DDRAWISURF_DRIVERMANAGED);
  853. // lpSurfMore will be NULL if called from dciman
  854. if (pSurfaceLocal->lpSurfMore)
  855. {
  856. pDDSurfaceMore[i].ddsCapsEx = pSurfaceLocal->lpSurfMore->ddsCapsEx;
  857. pDDSurfaceMore[i].dwSurfaceHandle = pSurfaceLocal->lpSurfMore->dwSurfaceHandle;
  858. }
  859. else
  860. {
  861. pDDSurfaceMore[i].ddsCapsEx.dwCaps2 = 0;
  862. pDDSurfaceMore[i].ddsCapsEx.dwCaps3 = 0;
  863. pDDSurfaceMore[i].ddsCapsEx.dwCaps4 = 0;
  864. pDDSurfaceMore[i].dwSurfaceHandle = 0;
  865. }
  866. phInSurface[i] = (HANDLE) pSurfaceLocal->hDDSurface;
  867. }
  868. // Preset an error in case the kernel can't write status
  869. // back for some reason.
  870. pCreateSurface->ddRVal = DDERR_GENERIC;
  871. dwRet = NtGdiDdCreateSurface(DD_HANDLE(pCreateSurface->lpDD->hDD),
  872. phInSurface,
  873. pSurfaceDesc,
  874. pDDSurfaceGlobal,
  875. pDDSurfaceLocal,
  876. pDDSurfaceMore,
  877. (PDD_CREATESURFACEDATA) pCreateSurface,
  878. phOutSurface);
  879. ASSERTGDI(dwRet == DDHAL_DRIVER_HANDLED,
  880. "NtGdiDdCreateSurface returned NOTHANDLED");
  881. for (i = 0; i < dwNumToCreate; i++)
  882. {
  883. pSurfaceLocal = pCreateSurface->lplpSList[i];
  884. pSurfaceGlobal = pSurfaceLocal->lpGbl;
  885. if (pCreateSurface->ddRVal != DD_OK)
  886. {
  887. // Surface creation failed. Nothing in user-mode can
  888. // create video memory surfaces so this whole call
  889. // fails.
  890. // Ensure the current surface and all following surfaces
  891. // have a zero fpVidMem to indicate they weren't
  892. // allocated.
  893. pCreateSurface->lplpSList[i]->lpGbl->fpVidMem = 0;
  894. // Handle may have been allocated by DdAttachSurface
  895. if (pSurfaceLocal->hDDSurface != 0)
  896. NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
  897. pSurfaceLocal->hDDSurface = 0;
  898. }
  899. else
  900. {
  901. pSurfaceLocal->hDDSurface = (ULONG_PTR) phOutSurface[i];
  902. }
  903. pSurfaceGlobal->lPitch = pDDSurfaceGlobal[i].lPitch;
  904. pSurfaceGlobal->fpVidMem = pDDSurfaceGlobal[i].fpVidMem;
  905. pSurfaceGlobal->dwBlockSizeX = pDDSurfaceGlobal[i].dwBlockSizeX;
  906. pSurfaceGlobal->dwBlockSizeY = pDDSurfaceGlobal[i].dwBlockSizeY;
  907. if (pSurfaceLocal->dwFlags & DDRAWISURF_HASPIXELFORMAT)
  908. {
  909. pSurfaceGlobal->ddpfSurface = pDDSurfaceGlobal[i].ddpfSurface;
  910. }
  911. pSurfaceLocal->ddsCaps = pDDSurfaceLocal[i].ddsCaps;
  912. if (pSurfaceLocal->lpSurfMore)
  913. {
  914. pSurfaceLocal->lpSurfMore->ddsCapsEx = pDDSurfaceMore[i].ddsCapsEx;
  915. }
  916. }
  917. CleanupCreate:
  918. if (dwNumToCreate > 1)
  919. {
  920. if (pDDSurfaceLocal != NULL)
  921. {
  922. LocalFree(pDDSurfaceLocal);
  923. }
  924. if (pDDSurfaceGlobal != NULL)
  925. {
  926. LocalFree(pDDSurfaceGlobal);
  927. }
  928. if (pDDSurfaceMore != NULL)
  929. {
  930. LocalFree(pDDSurfaceMore);
  931. }
  932. if (phInSurface != NULL)
  933. {
  934. LocalFree(phInSurface);
  935. }
  936. if (phOutSurface != NULL)
  937. {
  938. LocalFree(phOutSurface);
  939. }
  940. }
  941. // fpVidMem is the real per-surface return value, so for the function
  942. // return value we'll simply return that of the last call:
  943. return(dwRet);
  944. }
  945. /*****************************Private*Routine******************************\
  946. * DdDestroySurface
  947. *
  948. * History:
  949. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  950. * Wrote it.
  951. \**************************************************************************/
  952. DWORD
  953. APIENTRY
  954. DdDestroySurface(
  955. LPDDHAL_DESTROYSURFACEDATA pDestroySurface
  956. )
  957. {
  958. DWORD dwRet;
  959. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal;
  960. dwRet = DDHAL_DRIVER_NOTHANDLED;
  961. pSurfaceLocal = pDestroySurface->lpDDSurface;
  962. if (pSurfaceLocal->hDDSurface != 0)
  963. {
  964. if((pSurfaceLocal->dwFlags & DDRAWISURF_DRIVERMANAGED) &&
  965. (pSurfaceLocal->dwFlags & DDRAWISURF_INVALID))
  966. dwRet = NtGdiDdDestroySurface((HANDLE) pSurfaceLocal->hDDSurface, FALSE);
  967. else
  968. dwRet = NtGdiDdDestroySurface((HANDLE) pSurfaceLocal->hDDSurface, TRUE);
  969. }
  970. return(dwRet);
  971. }
  972. /*****************************Private*Routine******************************\
  973. * DdCanCreateD3DBuffer
  974. *
  975. * History:
  976. * 20-Jan-1998 -by- Anantha Kancherla [anankan]
  977. * Wrote it.
  978. \**************************************************************************/
  979. DWORD
  980. APIENTRY
  981. DdCanCreateD3DBuffer(
  982. LPDDHAL_CANCREATESURFACEDATA pCanCreateSurface
  983. )
  984. {
  985. return(NtGdiDdCanCreateD3DBuffer(DD_HANDLE(pCanCreateSurface->lpDD->hDD),
  986. (PDD_CANCREATESURFACEDATA) pCanCreateSurface));
  987. }
  988. /*****************************Private*Routine******************************\
  989. * DdCreateD3DBuffer
  990. *
  991. * History:
  992. * 20-Jan-1998 -by- Anantha Kancherla [anankan]
  993. * Wrote it.
  994. \**************************************************************************/
  995. DWORD
  996. APIENTRY
  997. DdCreateD3DBuffer(
  998. LPDDHAL_CREATESURFACEDATA pCreateSurface
  999. )
  1000. {
  1001. ULONG i;
  1002. LPDDSURFACEDESC pSurfaceDesc;
  1003. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal;
  1004. LPDDRAWI_DDRAWSURFACE_GBL pSurfaceGlobal;
  1005. DD_SURFACE_GLOBAL SurfaceGlobal;
  1006. DD_SURFACE_LOCAL SurfaceLocal;
  1007. DD_SURFACE_MORE SurfaceMore;
  1008. HANDLE hSurface;
  1009. DWORD dwRet;
  1010. // For every surface, convert to the kernel's surface data structure,
  1011. // call the kernel, then convert back:
  1012. dwRet = DDHAL_DRIVER_NOTHANDLED;
  1013. //
  1014. // Wow64 genthnk will automatically thunk these structures, however,
  1015. // since these structures are pointer dependent, we need to make sure
  1016. // to NULL out these pointers so that Wow64 won't thunk them
  1017. //
  1018. RtlZeroMemory(&SurfaceLocal, sizeof(SurfaceLocal));
  1019. RtlZeroMemory(&SurfaceGlobal, sizeof(SurfaceGlobal));
  1020. RtlZeroMemory(&SurfaceMore, sizeof(SurfaceMore));
  1021. pSurfaceLocal = pCreateSurface->lplpSList[0];
  1022. pSurfaceGlobal = pSurfaceLocal->lpGbl;
  1023. pSurfaceDesc = pCreateSurface->lpDDSurfaceDesc;
  1024. pCreateSurface->dwSCnt = 1;
  1025. SurfaceGlobal.wWidth = pSurfaceGlobal->wWidth;
  1026. SurfaceGlobal.wHeight = pSurfaceGlobal->wHeight;
  1027. SurfaceGlobal.lPitch = pSurfaceGlobal->lPitch;
  1028. SurfaceGlobal.fpVidMem = pSurfaceGlobal->fpVidMem;
  1029. SurfaceGlobal.dwBlockSizeX = pSurfaceGlobal->dwBlockSizeX;
  1030. SurfaceGlobal.dwBlockSizeY = pSurfaceGlobal->dwBlockSizeY;
  1031. SurfaceLocal.dwFlags = pSurfaceLocal->dwFlags;
  1032. SurfaceLocal.ddsCaps = pSurfaceLocal->ddsCaps;
  1033. SurfaceMore.ddsCapsEx = pSurfaceLocal->lpSurfMore->ddsCapsEx;
  1034. SurfaceMore.dwSurfaceHandle = pSurfaceLocal->lpSurfMore->dwSurfaceHandle;
  1035. dwRet = NtGdiDdCreateD3DBuffer(DD_HANDLE(pCreateSurface->lpDD->hDD),
  1036. (HANDLE*) &pSurfaceLocal->hDDSurface,
  1037. pSurfaceDesc,
  1038. &SurfaceGlobal,
  1039. &SurfaceLocal,
  1040. &SurfaceMore,
  1041. (PDD_CREATESURFACEDATA) pCreateSurface,
  1042. &hSurface);
  1043. pSurfaceGlobal->lPitch = SurfaceGlobal.lPitch;
  1044. pSurfaceGlobal->fpVidMem = SurfaceGlobal.fpVidMem;
  1045. pSurfaceGlobal->dwBlockSizeX = SurfaceGlobal.dwBlockSizeX;
  1046. pSurfaceGlobal->dwBlockSizeY = SurfaceGlobal.dwBlockSizeY;
  1047. if (hSurface)
  1048. {
  1049. pCreateSurface->lplpSList[0]->hDDSurface = (ULONG_PTR) hSurface;
  1050. }
  1051. // fpVidMem is the real per-surface return value, so for the function
  1052. // return value we'll simply return that of the last call:
  1053. return(dwRet);
  1054. }
  1055. /*****************************Private*Routine******************************\
  1056. * DdDestroyD3DBuffer
  1057. *
  1058. * History:
  1059. * 20-Jan-1998 -by- Anantha Kancherla [anankan]
  1060. * Wrote it.
  1061. \**************************************************************************/
  1062. DWORD
  1063. APIENTRY
  1064. DdDestroyD3DBuffer(
  1065. LPDDHAL_DESTROYSURFACEDATA pDestroySurface
  1066. )
  1067. {
  1068. DWORD dwRet;
  1069. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal;
  1070. dwRet = DDHAL_DRIVER_NOTHANDLED;
  1071. pSurfaceLocal = pDestroySurface->lpDDSurface;
  1072. if (pSurfaceLocal->hDDSurface != 0)
  1073. {
  1074. dwRet = NtGdiDdDestroyD3DBuffer((HANDLE) pSurfaceLocal->hDDSurface);
  1075. }
  1076. return(dwRet);
  1077. }
  1078. /*****************************Private*Routine******************************\
  1079. * DdSetColorKey
  1080. *
  1081. * History:
  1082. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1083. * Wrote it.
  1084. \**************************************************************************/
  1085. DWORD
  1086. APIENTRY
  1087. DdSetColorKey(
  1088. LPDDHAL_SETCOLORKEYDATA pSetColorKey
  1089. )
  1090. {
  1091. return(NtGdiDdSetColorKey((HANDLE) pSetColorKey->lpDDSurface->hDDSurface,
  1092. (PDD_SETCOLORKEYDATA) pSetColorKey));
  1093. }
  1094. /*****************************Private*Routine******************************\
  1095. * DdAddAttachedSurface
  1096. *
  1097. * History:
  1098. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1099. * Wrote it.
  1100. \**************************************************************************/
  1101. DWORD
  1102. APIENTRY
  1103. DdAddAttachedSurface(
  1104. LPDDHAL_ADDATTACHEDSURFACEDATA pAddAttachedSurface
  1105. )
  1106. {
  1107. return(NtGdiDdAddAttachedSurface((HANDLE) pAddAttachedSurface->lpDDSurface->hDDSurface,
  1108. (HANDLE) pAddAttachedSurface->lpSurfAttached->hDDSurface,
  1109. (PDD_ADDATTACHEDSURFACEDATA) pAddAttachedSurface));
  1110. }
  1111. /*****************************Private*Routine******************************\
  1112. * DdUpdateOverlay
  1113. *
  1114. * History:
  1115. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1116. * Wrote it.
  1117. \**************************************************************************/
  1118. DWORD
  1119. APIENTRY
  1120. DdUpdateOverlay(
  1121. LPDDHAL_UPDATEOVERLAYDATA pUpdateOverlay
  1122. )
  1123. {
  1124. // Kernel doesn't track the color keys in the surface, so we'll always
  1125. // convert any calls that reference them to ones where we explicitly
  1126. // pass the key as a parameter, and pull the key out of the user-mode
  1127. // surface:
  1128. if (pUpdateOverlay->dwFlags & DDOVER_KEYDEST)
  1129. {
  1130. pUpdateOverlay->dwFlags &= ~DDOVER_KEYDEST;
  1131. pUpdateOverlay->dwFlags |= DDOVER_KEYDESTOVERRIDE;
  1132. pUpdateOverlay->overlayFX.dckDestColorkey
  1133. = pUpdateOverlay->lpDDDestSurface->ddckCKDestOverlay;
  1134. }
  1135. if (pUpdateOverlay->dwFlags & DDOVER_KEYSRC)
  1136. {
  1137. pUpdateOverlay->dwFlags &= ~DDOVER_KEYSRC;
  1138. pUpdateOverlay->dwFlags |= DDOVER_KEYSRCOVERRIDE;
  1139. pUpdateOverlay->overlayFX.dckSrcColorkey
  1140. = pUpdateOverlay->lpDDSrcSurface->ddckCKSrcOverlay;
  1141. }
  1142. return(NtGdiDdUpdateOverlay((HANDLE) pUpdateOverlay->lpDDDestSurface->hDDSurface,
  1143. (HANDLE) pUpdateOverlay->lpDDSrcSurface->hDDSurface,
  1144. (PDD_UPDATEOVERLAYDATA) pUpdateOverlay));
  1145. }
  1146. /*****************************Private*Routine******************************\
  1147. * DdSetOverlayPosition
  1148. *
  1149. * History:
  1150. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1151. * Wrote it.
  1152. \**************************************************************************/
  1153. DWORD
  1154. APIENTRY
  1155. DdSetOverlayPosition(
  1156. LPDDHAL_SETOVERLAYPOSITIONDATA pSetOverlayPosition
  1157. )
  1158. {
  1159. return(NtGdiDdSetOverlayPosition((HANDLE) pSetOverlayPosition->lpDDSrcSurface->hDDSurface,
  1160. (HANDLE) pSetOverlayPosition->lpDDDestSurface->hDDSurface,
  1161. (PDD_SETOVERLAYPOSITIONDATA) pSetOverlayPosition));
  1162. }
  1163. /*****************************Private*Routine******************************\
  1164. * DdGetScanLine
  1165. *
  1166. * History:
  1167. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1168. * Wrote it.
  1169. \**************************************************************************/
  1170. DWORD
  1171. APIENTRY
  1172. DdGetScanLine(
  1173. LPDDHAL_GETSCANLINEDATA pGetScanLine
  1174. )
  1175. {
  1176. return(NtGdiDdGetScanLine(DD_HANDLE(pGetScanLine->lpDD->hDD),
  1177. (PDD_GETSCANLINEDATA) pGetScanLine));
  1178. }
  1179. /*****************************Private*Routine******************************\
  1180. * DdSetExclusiveMode
  1181. *
  1182. * History:
  1183. * 22-Apr-1998 -by- John Stephens [johnstep]
  1184. * Wrote it.
  1185. \**************************************************************************/
  1186. DWORD
  1187. APIENTRY
  1188. DdSetExclusiveMode(
  1189. LPDDHAL_SETEXCLUSIVEMODEDATA pSetExclusiveMode
  1190. )
  1191. {
  1192. return(NtGdiDdSetExclusiveMode(
  1193. DD_HANDLE(pSetExclusiveMode->lpDD->hDD),
  1194. (PDD_SETEXCLUSIVEMODEDATA) pSetExclusiveMode));
  1195. }
  1196. /*****************************Private*Routine******************************\
  1197. * DdFlipToGDISurface
  1198. *
  1199. * History:
  1200. * 22-Apr-1998 -by- John Stephens [johnstep]
  1201. * Wrote it.
  1202. \**************************************************************************/
  1203. DWORD
  1204. APIENTRY
  1205. DdFlipToGDISurface(
  1206. LPDDHAL_FLIPTOGDISURFACEDATA pFlipToGDISurface
  1207. )
  1208. {
  1209. return(NtGdiDdFlipToGDISurface(
  1210. DD_HANDLE(pFlipToGDISurface->lpDD->hDD),
  1211. (PDD_FLIPTOGDISURFACEDATA) pFlipToGDISurface));
  1212. }
  1213. /*****************************Private*Routine******************************\
  1214. * DdGetAvailDriverMemory
  1215. *
  1216. * History:
  1217. * 16-Feb-1997 -by- J. Andrew Goossen [andrewgo]
  1218. * Wrote it.
  1219. \**************************************************************************/
  1220. DWORD
  1221. APIENTRY
  1222. DdGetAvailDriverMemory(
  1223. LPDDHAL_GETAVAILDRIVERMEMORYDATA pGetAvailDriverMemory
  1224. )
  1225. {
  1226. return(NtGdiDdGetAvailDriverMemory(
  1227. DD_HANDLE(pGetAvailDriverMemory->lpDD->hDD),
  1228. (PDD_GETAVAILDRIVERMEMORYDATA) pGetAvailDriverMemory));
  1229. }
  1230. /*****************************Private*Routine******************************\
  1231. * DdColorControl
  1232. *
  1233. * History:
  1234. * 16-Feb-1997 -by- J. Andrew Goossen [andrewgo]
  1235. * Wrote it.
  1236. \**************************************************************************/
  1237. DWORD
  1238. APIENTRY
  1239. DdColorControl(
  1240. LPDDHAL_COLORCONTROLDATA pColorControl
  1241. )
  1242. {
  1243. return(NtGdiDdColorControl((HANDLE) pColorControl->lpDDSurface->hDDSurface,
  1244. (PDD_COLORCONTROLDATA) pColorControl));
  1245. }
  1246. /*****************************Private*Routine******************************\
  1247. * DdCreateSurfaceEx
  1248. *
  1249. * History:
  1250. * 19-Feb-1999 -by- Kan Qiu [kanqiu]
  1251. * Wrote it.
  1252. \**************************************************************************/
  1253. DWORD
  1254. APIENTRY
  1255. DdCreateSurfaceEx(
  1256. LPDDHAL_CREATESURFACEEXDATA pCreateSurfaceExData
  1257. )
  1258. {
  1259. pCreateSurfaceExData->ddRVal=NtGdiDdCreateSurfaceEx(
  1260. DD_HANDLE(pCreateSurfaceExData->lpDDLcl->lpGbl->hDD),
  1261. (HANDLE)(pCreateSurfaceExData->lpDDSLcl->hDDSurface),
  1262. pCreateSurfaceExData->lpDDSLcl->lpSurfMore->dwSurfaceHandle);
  1263. return DDHAL_DRIVER_HANDLED;
  1264. }
  1265. /*****************************Private*Routine******************************\
  1266. * DdGetDriverInfo
  1267. *
  1268. * History:
  1269. * 16-Feb-1997 -by- J. Andrew Goossen [andrewgo]
  1270. * Wrote it.
  1271. \**************************************************************************/
  1272. DWORD
  1273. APIENTRY
  1274. DdGetDriverInfo(
  1275. LPDDHAL_GETDRIVERINFODATA lpGetDriverInfoData
  1276. )
  1277. {
  1278. DD_GETDRIVERINFODATA GetDriverInfoData;
  1279. DWORD dwRet;
  1280. HANDLE hDirectDraw;
  1281. GetDriverInfoData.guidInfo = lpGetDriverInfoData->guidInfo;
  1282. hDirectDraw = DD_HANDLE( (HANDLE) lpGetDriverInfoData->dwContext );
  1283. if (IsEqualIID(&lpGetDriverInfoData->guidInfo, &GUID_VideoPortCallbacks))
  1284. {
  1285. DD_VIDEOPORTCALLBACKS VideoPortCallBacks;
  1286. LPDDHAL_DDVIDEOPORTCALLBACKS lpVideoPortCallBacks;
  1287. // Translate VideoPort call-backs to user-mode:
  1288. lpVideoPortCallBacks = lpGetDriverInfoData->lpvData;
  1289. GetDriverInfoData.lpvData = &VideoPortCallBacks;
  1290. GetDriverInfoData.dwExpectedSize = sizeof(VideoPortCallBacks);
  1291. dwRet = NtGdiDdGetDriverInfo(hDirectDraw, &GetDriverInfoData);
  1292. RtlZeroMemory(lpVideoPortCallBacks, sizeof(*lpVideoPortCallBacks));
  1293. lpGetDriverInfoData->dwActualSize = sizeof(*lpVideoPortCallBacks);
  1294. lpVideoPortCallBacks->dwSize = sizeof(*lpVideoPortCallBacks);
  1295. lpVideoPortCallBacks->dwFlags = VideoPortCallBacks.dwFlags
  1296. | DDHAL_VPORT32_CREATEVIDEOPORT
  1297. | DDHAL_VPORT32_DESTROY
  1298. | DDHAL_VPORT32_UPDATE
  1299. | DDHAL_VPORT32_FLIP;
  1300. lpVideoPortCallBacks->dwFlags &= ~(DDHAL_VPORT32_GETAUTOFLIPSURF);
  1301. lpVideoPortCallBacks->CreateVideoPort = DvpCreateVideoPort;
  1302. lpVideoPortCallBacks->DestroyVideoPort = DvpDestroyVideoPort;
  1303. lpVideoPortCallBacks->UpdateVideoPort = DvpUpdateVideoPort;
  1304. lpVideoPortCallBacks->FlipVideoPort = DvpFlipVideoPort;
  1305. if (VideoPortCallBacks.CanCreateVideoPort)
  1306. {
  1307. lpVideoPortCallBacks->CanCreateVideoPort = DvpCanCreateVideoPort;
  1308. }
  1309. if (VideoPortCallBacks.GetVideoPortBandwidth)
  1310. {
  1311. lpVideoPortCallBacks->GetVideoPortBandwidth = DvpGetVideoPortBandwidth;
  1312. }
  1313. if (VideoPortCallBacks.GetVideoPortInputFormats)
  1314. {
  1315. lpVideoPortCallBacks->GetVideoPortInputFormats = DvpGetVideoPortInputFormats;
  1316. }
  1317. if (VideoPortCallBacks.GetVideoPortOutputFormats)
  1318. {
  1319. lpVideoPortCallBacks->GetVideoPortOutputFormats = DvpGetVideoPortOutputFormats;
  1320. }
  1321. if (VideoPortCallBacks.GetVideoPortField)
  1322. {
  1323. lpVideoPortCallBacks->GetVideoPortField = DvpGetVideoPortField;
  1324. }
  1325. if (VideoPortCallBacks.GetVideoPortLine)
  1326. {
  1327. lpVideoPortCallBacks->GetVideoPortLine = DvpGetVideoPortLine;
  1328. }
  1329. if (VideoPortCallBacks.GetVideoPortConnectInfo)
  1330. {
  1331. lpVideoPortCallBacks->GetVideoPortConnectInfo = DvpGetVideoPortConnectInfo;
  1332. }
  1333. if (VideoPortCallBacks.GetVideoPortFlipStatus)
  1334. {
  1335. lpVideoPortCallBacks->GetVideoPortFlipStatus = DvpGetVideoPortFlipStatus;
  1336. }
  1337. if (VideoPortCallBacks.WaitForVideoPortSync)
  1338. {
  1339. lpVideoPortCallBacks->WaitForVideoPortSync = DvpWaitForVideoPortSync;
  1340. }
  1341. if (VideoPortCallBacks.GetVideoSignalStatus)
  1342. {
  1343. lpVideoPortCallBacks->GetVideoSignalStatus = DvpGetVideoSignalStatus;
  1344. }
  1345. if (VideoPortCallBacks.ColorControl)
  1346. {
  1347. lpVideoPortCallBacks->ColorControl = DvpColorControl;
  1348. }
  1349. }
  1350. else if (IsEqualIID(&lpGetDriverInfoData->guidInfo, &GUID_ColorControlCallbacks))
  1351. {
  1352. DD_COLORCONTROLCALLBACKS ColorControlCallBacks;
  1353. LPDDHAL_DDCOLORCONTROLCALLBACKS lpColorControlCallBacks;
  1354. // Translate ColorControl call-backs to user-mode:
  1355. lpColorControlCallBacks = lpGetDriverInfoData->lpvData;
  1356. GetDriverInfoData.lpvData = &ColorControlCallBacks;
  1357. GetDriverInfoData.dwExpectedSize = sizeof(ColorControlCallBacks);
  1358. dwRet = NtGdiDdGetDriverInfo(hDirectDraw, &GetDriverInfoData);
  1359. RtlZeroMemory(lpColorControlCallBacks, sizeof(*lpColorControlCallBacks));
  1360. lpGetDriverInfoData->dwActualSize = sizeof(*lpColorControlCallBacks);
  1361. lpColorControlCallBacks->dwSize = sizeof(*lpColorControlCallBacks);
  1362. lpColorControlCallBacks->dwFlags = ColorControlCallBacks.dwFlags;
  1363. if (ColorControlCallBacks.ColorControl)
  1364. {
  1365. lpColorControlCallBacks->ColorControl = DdColorControl;
  1366. }
  1367. }
  1368. else if (IsEqualIID(&lpGetDriverInfoData->guidInfo, &GUID_MiscellaneousCallbacks))
  1369. {
  1370. DD_MISCELLANEOUSCALLBACKS MiscellaneousCallBacks;
  1371. LPDDHAL_DDMISCELLANEOUSCALLBACKS lpMiscellaneousCallBacks;
  1372. // Translate miscellaneous call-backs to user-mode:
  1373. lpMiscellaneousCallBacks = lpGetDriverInfoData->lpvData;
  1374. GetDriverInfoData.lpvData = &MiscellaneousCallBacks;
  1375. GetDriverInfoData.dwExpectedSize = sizeof(MiscellaneousCallBacks);
  1376. lpMiscellaneousCallBacks->dwFlags = 0;
  1377. // Don't return what the driver returns because we always want this
  1378. // to suceed
  1379. NtGdiDdGetDriverInfo(hDirectDraw, &GetDriverInfoData);
  1380. GetDriverInfoData.dwActualSize = sizeof(MiscellaneousCallBacks);
  1381. GetDriverInfoData.ddRVal = DD_OK;
  1382. dwRet = DDHAL_DRIVER_HANDLED;
  1383. RtlZeroMemory(lpMiscellaneousCallBacks, sizeof(*lpMiscellaneousCallBacks));
  1384. lpGetDriverInfoData->dwActualSize = sizeof(*lpMiscellaneousCallBacks);
  1385. lpMiscellaneousCallBacks->dwSize = sizeof(*lpMiscellaneousCallBacks);
  1386. lpMiscellaneousCallBacks->dwFlags = MiscellaneousCallBacks.dwFlags;
  1387. //We always implement this callback now that kernel owns vidmem management
  1388. lpMiscellaneousCallBacks->GetAvailDriverMemory = DdGetAvailDriverMemory;
  1389. lpMiscellaneousCallBacks->dwFlags |= DDHAL_MISCCB32_GETAVAILDRIVERMEMORY;
  1390. }
  1391. else if (IsEqualIID(&lpGetDriverInfoData->guidInfo, &GUID_Miscellaneous2Callbacks))
  1392. {
  1393. DD_MISCELLANEOUS2CALLBACKS Miscellaneous2CallBacks;
  1394. LPDDHAL_DDMISCELLANEOUS2CALLBACKS lpMiscellaneous2CallBacks;
  1395. // Translate miscellaneous call-backs to user-mode:
  1396. lpMiscellaneous2CallBacks = lpGetDriverInfoData->lpvData;
  1397. GetDriverInfoData.lpvData = &Miscellaneous2CallBacks;
  1398. GetDriverInfoData.dwExpectedSize = sizeof(Miscellaneous2CallBacks);
  1399. dwRet = NtGdiDdGetDriverInfo(hDirectDraw, &GetDriverInfoData);
  1400. RtlZeroMemory(lpMiscellaneous2CallBacks, sizeof(*lpMiscellaneous2CallBacks));
  1401. lpGetDriverInfoData->dwActualSize = sizeof(*lpMiscellaneous2CallBacks);
  1402. lpMiscellaneous2CallBacks->dwSize = sizeof(*lpMiscellaneous2CallBacks);
  1403. lpMiscellaneous2CallBacks->dwFlags = Miscellaneous2CallBacks.dwFlags;
  1404. if (Miscellaneous2CallBacks.AlphaBlt)
  1405. {
  1406. lpMiscellaneous2CallBacks->AlphaBlt = DdAlphaBlt;
  1407. }
  1408. if (Miscellaneous2CallBacks.GetDriverState)
  1409. {
  1410. lpMiscellaneous2CallBacks->GetDriverState =
  1411. (LPDDHAL_GETDRIVERSTATE)NtGdiDdGetDriverState;
  1412. }
  1413. if (Miscellaneous2CallBacks.CreateSurfaceEx)
  1414. {
  1415. lpMiscellaneous2CallBacks->CreateSurfaceEx =
  1416. (LPDDHAL_CREATESURFACEEX)DdCreateSurfaceEx;
  1417. }
  1418. // Dont pass back DestroyDDLocal
  1419. }
  1420. else if (IsEqualIID(&lpGetDriverInfoData->guidInfo, &GUID_NTCallbacks))
  1421. {
  1422. DD_NTCALLBACKS NTCallBacks;
  1423. LPDDHAL_DDNTCALLBACKS lpNTCallBacks;
  1424. // Translate NT call-backs to user-mode:
  1425. lpNTCallBacks = lpGetDriverInfoData->lpvData;
  1426. GetDriverInfoData.lpvData = &NTCallBacks;
  1427. GetDriverInfoData.dwExpectedSize = sizeof(NTCallBacks);
  1428. dwRet = NtGdiDdGetDriverInfo(hDirectDraw, &GetDriverInfoData);
  1429. RtlZeroMemory(lpNTCallBacks, sizeof(*lpNTCallBacks));
  1430. lpGetDriverInfoData->dwActualSize = sizeof(*lpNTCallBacks);
  1431. lpNTCallBacks->dwSize = sizeof(*lpNTCallBacks);
  1432. lpNTCallBacks->dwFlags = NTCallBacks.dwFlags;
  1433. // FreeDriverMemory is also an NTCallback but it will only be called
  1434. // from kernel-mode, so we don't have a user-mode thunk function.
  1435. if (NTCallBacks.SetExclusiveMode)
  1436. {
  1437. lpNTCallBacks->SetExclusiveMode = DdSetExclusiveMode;
  1438. }
  1439. if (NTCallBacks.FlipToGDISurface)
  1440. {
  1441. lpNTCallBacks->FlipToGDISurface = DdFlipToGDISurface;
  1442. }
  1443. }
  1444. else if (IsEqualIID(&lpGetDriverInfoData->guidInfo, &GUID_D3DCallbacks2))
  1445. {
  1446. // Fill NULL for D3DCALLBACKS2.
  1447. LPD3DHAL_CALLBACKS2 lpD3dCallbacks2;
  1448. lpD3dCallbacks2 = lpGetDriverInfoData->lpvData;
  1449. RtlZeroMemory(lpD3dCallbacks2, sizeof(*lpD3dCallbacks2));
  1450. lpGetDriverInfoData->dwActualSize = sizeof(*lpD3dCallbacks2);
  1451. lpD3dCallbacks2->dwSize = sizeof(*lpD3dCallbacks2);
  1452. GetDriverInfoData.ddRVal = DDERR_GENERIC;
  1453. dwRet = DDHAL_DRIVER_HANDLED;
  1454. }
  1455. else if (IsEqualIID(&lpGetDriverInfoData->guidInfo, &GUID_D3DCallbacks3))
  1456. {
  1457. D3DNTHAL_CALLBACKS3 D3dCallbacks3;
  1458. LPD3DHAL_CALLBACKS3 lpD3dCallbacks3;
  1459. // Translate D3DNTHAL_CALLBACKS3 to user-mode.
  1460. lpD3dCallbacks3 = lpGetDriverInfoData->lpvData;
  1461. GetDriverInfoData.lpvData = &D3dCallbacks3;
  1462. GetDriverInfoData.dwExpectedSize = sizeof(D3dCallbacks3);
  1463. dwRet = NtGdiDdGetDriverInfo(hDirectDraw, &GetDriverInfoData);
  1464. RtlZeroMemory((PVOID)lpD3dCallbacks3, sizeof(*lpD3dCallbacks3));
  1465. lpGetDriverInfoData->dwActualSize = sizeof(*lpD3dCallbacks3);
  1466. lpD3dCallbacks3->dwSize = sizeof(*lpD3dCallbacks3);
  1467. lpD3dCallbacks3->dwFlags = D3dCallbacks3.dwFlags;
  1468. lpD3dCallbacks3->Clear2 = NULL;
  1469. lpD3dCallbacks3->lpvReserved = NULL;
  1470. if (D3dCallbacks3.ValidateTextureStageState != NULL)
  1471. {
  1472. lpD3dCallbacks3->ValidateTextureStageState =
  1473. (LPD3DHAL_VALIDATETEXTURESTAGESTATECB)NtGdiD3dValidateTextureStageState;
  1474. }
  1475. if (D3dCallbacks3.DrawPrimitives2 != NULL)
  1476. {
  1477. lpD3dCallbacks3->DrawPrimitives2 =
  1478. (LPD3DHAL_DRAWPRIMITIVES2CB)D3dDrawPrimitives2;
  1479. }
  1480. }
  1481. else if (IsEqualIID(&lpGetDriverInfoData->guidInfo,
  1482. &GUID_D3DParseUnknownCommandCallback))
  1483. {
  1484. // On NT we ignore this callback
  1485. lpGetDriverInfoData->ddRVal = DD_OK;
  1486. return DDHAL_DRIVER_HANDLED;
  1487. }
  1488. else if (IsEqualIID(&lpGetDriverInfoData->guidInfo, &GUID_MotionCompCallbacks))
  1489. {
  1490. DD_MOTIONCOMPCALLBACKS MotionCompCallbacks;
  1491. LPDDHAL_DDMOTIONCOMPCALLBACKS lpMotionCompCallbacks;
  1492. // Translate Video call-backs to user-mode:
  1493. lpMotionCompCallbacks = lpGetDriverInfoData->lpvData;
  1494. GetDriverInfoData.lpvData = &MotionCompCallbacks;
  1495. GetDriverInfoData.dwExpectedSize = sizeof(MotionCompCallbacks);
  1496. dwRet = NtGdiDdGetDriverInfo(hDirectDraw, &GetDriverInfoData);
  1497. RtlZeroMemory(lpMotionCompCallbacks, sizeof(*lpMotionCompCallbacks));
  1498. lpGetDriverInfoData->dwActualSize = sizeof(*lpMotionCompCallbacks);
  1499. lpMotionCompCallbacks->dwSize = sizeof(*lpMotionCompCallbacks);
  1500. lpMotionCompCallbacks->dwFlags = MotionCompCallbacks.dwFlags
  1501. | DDHAL_MOCOMP32_CREATE
  1502. | DDHAL_MOCOMP32_DESTROY;
  1503. lpMotionCompCallbacks->CreateMoComp = DdCreateMoComp;
  1504. lpMotionCompCallbacks->DestroyMoComp = DdDestroyMoComp;
  1505. if (MotionCompCallbacks.GetMoCompGuids)
  1506. {
  1507. lpMotionCompCallbacks->GetMoCompGuids = DdGetMoCompGuids;
  1508. }
  1509. if (MotionCompCallbacks.GetMoCompFormats)
  1510. {
  1511. lpMotionCompCallbacks->GetMoCompFormats = DdGetMoCompFormats;
  1512. }
  1513. if (MotionCompCallbacks.GetMoCompBuffInfo)
  1514. {
  1515. lpMotionCompCallbacks->GetMoCompBuffInfo = DdGetMoCompBuffInfo;
  1516. }
  1517. if (MotionCompCallbacks.GetInternalMoCompInfo)
  1518. {
  1519. lpMotionCompCallbacks->GetInternalMoCompInfo = DdGetInternalMoCompInfo;
  1520. }
  1521. if (MotionCompCallbacks.BeginMoCompFrame)
  1522. {
  1523. lpMotionCompCallbacks->BeginMoCompFrame = DdBeginMoCompFrame;
  1524. }
  1525. if (MotionCompCallbacks.EndMoCompFrame)
  1526. {
  1527. lpMotionCompCallbacks->EndMoCompFrame = DdEndMoCompFrame;
  1528. }
  1529. if (MotionCompCallbacks.RenderMoComp)
  1530. {
  1531. lpMotionCompCallbacks->RenderMoComp = DdRenderMoComp;
  1532. }
  1533. if (MotionCompCallbacks.QueryMoCompStatus)
  1534. {
  1535. lpMotionCompCallbacks->QueryMoCompStatus = DdQueryMoCompStatus;
  1536. }
  1537. }
  1538. else if (IsEqualIID(&lpGetDriverInfoData->guidInfo, &GUID_VPE2Callbacks))
  1539. {
  1540. LPDDHAL_DDVPE2CALLBACKS lpVPE2CallBacks;
  1541. // Translate NT call-backs to user-mode:
  1542. lpVPE2CallBacks = lpGetDriverInfoData->lpvData;
  1543. RtlZeroMemory(lpVPE2CallBacks, sizeof(*lpVPE2CallBacks));
  1544. lpGetDriverInfoData->dwActualSize = sizeof(*lpVPE2CallBacks);
  1545. lpVPE2CallBacks->dwSize = sizeof(*lpVPE2CallBacks);
  1546. lpVPE2CallBacks->dwFlags = DDHAL_VPE2CB32_ACQUIRENOTIFICATION |
  1547. DDHAL_VPE2CB32_RELEASENOTIFICATION;
  1548. lpVPE2CallBacks->AcquireNotification = DvpAcquireNotification;
  1549. lpVPE2CallBacks->ReleaseNotification = DvpReleaseNotification;
  1550. GetDriverInfoData.ddRVal = DD_OK;
  1551. dwRet = DDHAL_DRIVER_HANDLED;
  1552. }
  1553. else
  1554. {
  1555. // Do data call:
  1556. GetDriverInfoData.dwExpectedSize = lpGetDriverInfoData->dwExpectedSize;
  1557. GetDriverInfoData.lpvData = lpGetDriverInfoData->lpvData;
  1558. dwRet = NtGdiDdGetDriverInfo(hDirectDraw, &GetDriverInfoData);
  1559. lpGetDriverInfoData->dwActualSize = GetDriverInfoData.dwActualSize;
  1560. }
  1561. lpGetDriverInfoData->ddRVal = GetDriverInfoData.ddRVal;
  1562. return(dwRet);
  1563. }
  1564. /******************************Public*Routine******************************\
  1565. * DdCreateDirectDrawObject
  1566. *
  1567. * When 'hdc' is 0, this function creates a 'global' DirectDraw object that
  1568. * may be used by any process, as a work-around for the DirectDraw folks.
  1569. * In reality, we still create a local DirectDraw object that is specific
  1570. * to this process, and whenever we're called with this 'special' global
  1571. * handle, we substitute the process-specific handle. See the declaration
  1572. * of 'ghDirectDraw' for a commonet on why we do this.
  1573. *
  1574. * History:
  1575. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1576. * Wrote it.
  1577. \**************************************************************************/
  1578. BOOL
  1579. APIENTRY
  1580. DdCreateDirectDrawObject( // AKA 'GdiEntry1'
  1581. LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
  1582. HDC hdc
  1583. )
  1584. {
  1585. BOOL b;
  1586. b = FALSE;
  1587. if (hdc == 0)
  1588. {
  1589. // Only one 'global' DirectDraw object may be active at a time.
  1590. //
  1591. // Note that this 'ghDirectDraw' assignment isn't thread safe;
  1592. // DirectDraw must have its own critical section held when making
  1593. // this call. (Naturally, the kernel always properly synchronizes
  1594. // itself in the NtGdi call.)
  1595. if (ghDirectDraw == 0)
  1596. {
  1597. hdc = CreateDCW(L"Display", NULL, NULL, NULL);
  1598. if (hdc != 0)
  1599. {
  1600. ghDirectDraw = NtGdiDdCreateDirectDrawObject(hdc);
  1601. DeleteDC(hdc);
  1602. }
  1603. }
  1604. if (ghDirectDraw)
  1605. {
  1606. gcDirectDraw++;
  1607. b = TRUE;
  1608. }
  1609. // Mark the DirectDraw object handle stored in the DirectDraw
  1610. // object as 'special' by making it zero:
  1611. pDirectDrawGlobal->hDD = 0;
  1612. }
  1613. else
  1614. {
  1615. pDirectDrawGlobal->hDD = (ULONG_PTR) NtGdiDdCreateDirectDrawObject(hdc);
  1616. b = (pDirectDrawGlobal->hDD != 0);
  1617. }
  1618. return(b);
  1619. }
  1620. /*****************************Private*Routine******************************\
  1621. * DdQueryDirectDrawObject
  1622. *
  1623. * History:
  1624. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1625. * Wrote it.
  1626. \**************************************************************************/
  1627. BOOL
  1628. APIENTRY
  1629. DdQueryDirectDrawObject( // AKA 'GdiEntry2'
  1630. LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
  1631. LPDDHALINFO pHalInfo,
  1632. LPDDHAL_DDCALLBACKS pDDCallBacks,
  1633. LPDDHAL_DDSURFACECALLBACKS pDDSurfaceCallBacks,
  1634. LPDDHAL_DDPALETTECALLBACKS pDDPaletteCallBacks,
  1635. LPD3DHAL_CALLBACKS pD3dCallbacks,
  1636. LPD3DHAL_GLOBALDRIVERDATA pD3dDriverData,
  1637. LPDDHAL_DDEXEBUFCALLBACKS pD3dBufferCallbacks,
  1638. LPDDSURFACEDESC pD3dTextureFormats,
  1639. LPDWORD pdwFourCC, // May be NULL
  1640. LPVIDMEM pvmList // May be NULL
  1641. )
  1642. {
  1643. DD_HALINFO HalInfo;
  1644. DWORD adwCallBackFlags[3];
  1645. DWORD dwFlags;
  1646. VIDEOMEMORY* pVideoMemoryList;
  1647. VIDEOMEMORY* pVideoMemory;
  1648. DWORD dwNumHeaps;
  1649. DWORD dwNumFourCC;
  1650. D3DNTHAL_CALLBACKS D3dCallbacks;
  1651. D3DNTHAL_GLOBALDRIVERDATA D3dDriverData;
  1652. DD_D3DBUFCALLBACKS D3dBufferCallbacks;
  1653. pVideoMemoryList = NULL;
  1654. if( (pvmList != NULL) && (pHalInfo->vmiData.dwNumHeaps != 0) )
  1655. {
  1656. pVideoMemoryList = (VIDEOMEMORY*) LocalAlloc(LMEM_ZEROINIT,
  1657. sizeof(VIDEOMEMORY) * pHalInfo->vmiData.dwNumHeaps);
  1658. if (pVideoMemoryList == NULL)
  1659. return(FALSE);
  1660. }
  1661. //
  1662. // Initialize to zero, so that Wow64's genthnk won't
  1663. // thunk bogus pointers.
  1664. //
  1665. RtlZeroMemory(&HalInfo, sizeof(HalInfo));
  1666. RtlZeroMemory(&D3dCallbacks, sizeof(D3dCallbacks));
  1667. RtlZeroMemory(&D3dDriverData, sizeof(D3dDriverData));
  1668. RtlZeroMemory(&D3dBufferCallbacks, sizeof(D3dBufferCallbacks));
  1669. //
  1670. // set dwNumTextureFormats in the global driver data so that WoW64
  1671. // can thunk the texture formats
  1672. //
  1673. if( (NULL != pD3dTextureFormats) &&
  1674. (NULL != pD3dDriverData) )
  1675. {
  1676. D3dDriverData.dwNumTextureFormats = pD3dDriverData->dwNumTextureFormats;
  1677. }
  1678. if (!NtGdiDdQueryDirectDrawObject(DD_HANDLE(pDirectDrawGlobal->hDD),
  1679. &HalInfo,
  1680. &adwCallBackFlags[0],
  1681. &D3dCallbacks,
  1682. &D3dDriverData,
  1683. &D3dBufferCallbacks,
  1684. pD3dTextureFormats,
  1685. &dwNumHeaps,
  1686. pVideoMemoryList,
  1687. &dwNumFourCC,
  1688. pdwFourCC))
  1689. {
  1690. if (pVideoMemoryList != NULL)
  1691. LocalFree(pVideoMemoryList);
  1692. return(FALSE);
  1693. }
  1694. // Convert from the kernel-mode data structures to the user-mode
  1695. // ones:
  1696. memset(pHalInfo, 0, sizeof(DDHALINFO));
  1697. pHalInfo->dwSize = sizeof(DDHALINFO);
  1698. pHalInfo->lpDDCallbacks = pDDCallBacks;
  1699. pHalInfo->lpDDSurfaceCallbacks = pDDSurfaceCallBacks;
  1700. pHalInfo->lpDDPaletteCallbacks = pDDPaletteCallBacks;
  1701. if (D3dCallbacks.dwSize != 0 && D3dDriverData.dwSize != 0)
  1702. {
  1703. pHalInfo->lpD3DGlobalDriverData = (LPVOID)pD3dDriverData;
  1704. pHalInfo->lpD3DHALCallbacks = (LPVOID)pD3dCallbacks;
  1705. if( D3dBufferCallbacks.dwSize != 0 )
  1706. pHalInfo->lpDDExeBufCallbacks = (LPDDHAL_DDEXEBUFCALLBACKS)pD3dBufferCallbacks;
  1707. }
  1708. pHalInfo->vmiData.fpPrimary = 0;
  1709. pHalInfo->vmiData.dwFlags = HalInfo.vmiData.dwFlags;
  1710. pHalInfo->vmiData.dwDisplayWidth = HalInfo.vmiData.dwDisplayWidth;
  1711. pHalInfo->vmiData.dwDisplayHeight = HalInfo.vmiData.dwDisplayHeight;
  1712. pHalInfo->vmiData.lDisplayPitch = HalInfo.vmiData.lDisplayPitch;
  1713. pHalInfo->vmiData.ddpfDisplay = HalInfo.vmiData.ddpfDisplay;
  1714. pHalInfo->vmiData.dwOffscreenAlign = HalInfo.vmiData.dwOffscreenAlign;
  1715. pHalInfo->vmiData.dwOverlayAlign = HalInfo.vmiData.dwOverlayAlign;
  1716. pHalInfo->vmiData.dwTextureAlign = HalInfo.vmiData.dwTextureAlign;
  1717. pHalInfo->vmiData.dwZBufferAlign = HalInfo.vmiData.dwZBufferAlign;
  1718. pHalInfo->vmiData.dwAlphaAlign = HalInfo.vmiData.dwAlphaAlign;
  1719. pHalInfo->vmiData.dwNumHeaps = dwNumHeaps;
  1720. pHalInfo->vmiData.pvmList = pvmList;
  1721. ASSERTGDI(sizeof(pHalInfo->ddCaps) == sizeof(HalInfo.ddCaps),
  1722. "DdQueryDirectDrawObject():DDCORECAPS structure size is not equal to DDNTCORECAPS\n");
  1723. RtlCopyMemory(&(pHalInfo->ddCaps),&(HalInfo.ddCaps),sizeof(HalInfo.ddCaps));
  1724. pHalInfo->ddCaps.dwNumFourCCCodes = dwNumFourCC;
  1725. pHalInfo->ddCaps.dwRops[0xCC / 32] = 1 << (0xCC % 32); // Only SRCCOPY
  1726. pHalInfo->lpdwFourCC = pdwFourCC;
  1727. pHalInfo->dwFlags = HalInfo.dwFlags | DDHALINFO_GETDRIVERINFOSET;
  1728. pHalInfo->GetDriverInfo = DdGetDriverInfo;
  1729. if (pDDCallBacks != NULL)
  1730. {
  1731. memset(pDDCallBacks, 0, sizeof(DDHAL_DDCALLBACKS));
  1732. dwFlags = adwCallBackFlags[0];
  1733. pDDCallBacks->dwSize = sizeof(DDHAL_DDCALLBACKS);
  1734. pDDCallBacks->dwFlags = dwFlags;
  1735. // Always set CreateSurface so that the kernel mode
  1736. // heap manager has a chance to allocate the surface if
  1737. // necessary. It will take care of calling the driver
  1738. // if necessary.
  1739. pDDCallBacks->CreateSurface = DdCreateSurface;
  1740. pDDCallBacks->dwFlags |= DDHAL_CB32_CREATESURFACE;
  1741. if (dwFlags & DDHAL_CB32_WAITFORVERTICALBLANK)
  1742. pDDCallBacks->WaitForVerticalBlank = DdWaitForVerticalBlank;
  1743. if (dwFlags & DDHAL_CB32_CANCREATESURFACE)
  1744. pDDCallBacks->CanCreateSurface = DdCanCreateSurface;
  1745. if (dwFlags & DDHAL_CB32_GETSCANLINE)
  1746. pDDCallBacks->GetScanLine = DdGetScanLine;
  1747. }
  1748. if (pDDSurfaceCallBacks != NULL)
  1749. {
  1750. memset(pDDSurfaceCallBacks, 0, sizeof(DDHAL_DDSURFACECALLBACKS));
  1751. dwFlags = adwCallBackFlags[1];
  1752. pDDSurfaceCallBacks->dwSize = sizeof(DDHAL_DDSURFACECALLBACKS);
  1753. pDDSurfaceCallBacks->dwFlags = (DDHAL_SURFCB32_LOCK
  1754. | DDHAL_SURFCB32_UNLOCK
  1755. | DDHAL_SURFCB32_SETCOLORKEY
  1756. | DDHAL_SURFCB32_DESTROYSURFACE)
  1757. | dwFlags;
  1758. pDDSurfaceCallBacks->Lock = DdLock;
  1759. pDDSurfaceCallBacks->Unlock = DdUnlock;
  1760. pDDSurfaceCallBacks->SetColorKey = DdSetColorKey;
  1761. pDDSurfaceCallBacks->DestroySurface = DdDestroySurface;
  1762. if (dwFlags & DDHAL_SURFCB32_FLIP)
  1763. pDDSurfaceCallBacks->Flip = DdFlip;
  1764. if (dwFlags & DDHAL_SURFCB32_BLT)
  1765. pDDSurfaceCallBacks->Blt = DdBlt;
  1766. if (dwFlags & DDHAL_SURFCB32_GETBLTSTATUS)
  1767. pDDSurfaceCallBacks->GetBltStatus = DdGetBltStatus;
  1768. if (dwFlags & DDHAL_SURFCB32_GETFLIPSTATUS)
  1769. pDDSurfaceCallBacks->GetFlipStatus = DdGetFlipStatus;
  1770. if (dwFlags & DDHAL_SURFCB32_UPDATEOVERLAY)
  1771. pDDSurfaceCallBacks->UpdateOverlay = DdUpdateOverlay;
  1772. if (dwFlags & DDHAL_SURFCB32_SETOVERLAYPOSITION)
  1773. pDDSurfaceCallBacks->SetOverlayPosition = DdSetOverlayPosition;
  1774. if (dwFlags & DDHAL_SURFCB32_ADDATTACHEDSURFACE)
  1775. pDDSurfaceCallBacks->AddAttachedSurface = DdAddAttachedSurface;
  1776. }
  1777. if (pDDPaletteCallBacks != NULL)
  1778. {
  1779. memset(pDDPaletteCallBacks, 0, sizeof(DDHAL_DDPALETTECALLBACKS));
  1780. dwFlags = adwCallBackFlags[2];
  1781. pDDPaletteCallBacks->dwSize = sizeof(DDHAL_DDPALETTECALLBACKS);
  1782. pDDPaletteCallBacks->dwFlags = dwFlags;
  1783. }
  1784. if (pD3dCallbacks != NULL)
  1785. {
  1786. memset(pD3dCallbacks, 0, sizeof(D3DHAL_CALLBACKS));
  1787. if (D3dCallbacks.dwSize > 0)
  1788. {
  1789. pD3dCallbacks->dwSize = sizeof(D3DHAL_CALLBACKS);
  1790. if (D3dCallbacks.ContextCreate != NULL)
  1791. {
  1792. pD3dCallbacks->ContextCreate = D3dContextCreate;
  1793. }
  1794. if (D3dCallbacks.ContextDestroy != NULL)
  1795. {
  1796. pD3dCallbacks->ContextDestroy =
  1797. (LPD3DHAL_CONTEXTDESTROYCB)NtGdiD3dContextDestroy;
  1798. }
  1799. if (D3dCallbacks.ContextDestroyAll != NULL)
  1800. {
  1801. pD3dCallbacks->ContextDestroyAll =
  1802. (LPD3DHAL_CONTEXTDESTROYALLCB)NtGdiD3dContextDestroyAll;
  1803. }
  1804. pD3dCallbacks->SceneCapture = NULL;
  1805. pD3dCallbacks->TextureCreate = NULL;
  1806. pD3dCallbacks->TextureDestroy = NULL;
  1807. pD3dCallbacks->TextureSwap = NULL;
  1808. pD3dCallbacks->TextureGetSurf = NULL;
  1809. }
  1810. }
  1811. if (pD3dDriverData != NULL)
  1812. {
  1813. *pD3dDriverData = *(D3DHAL_GLOBALDRIVERDATA *)&D3dDriverData;
  1814. pD3dDriverData->lpTextureFormats = pD3dTextureFormats;
  1815. }
  1816. if (pD3dBufferCallbacks != NULL)
  1817. {
  1818. memset( pD3dBufferCallbacks, 0, sizeof(DDHAL_DDEXEBUFCALLBACKS));
  1819. if (D3dBufferCallbacks.dwSize > 0)
  1820. {
  1821. pD3dBufferCallbacks->dwSize = sizeof(DDHAL_DDEXEBUFCALLBACKS);
  1822. pD3dBufferCallbacks->dwFlags = D3dBufferCallbacks.dwFlags;
  1823. if (D3dBufferCallbacks.CanCreateD3DBuffer != NULL)
  1824. {
  1825. pD3dBufferCallbacks->CanCreateExecuteBuffer =
  1826. (LPDDHALEXEBUFCB_CANCREATEEXEBUF)DdCanCreateD3DBuffer;
  1827. }
  1828. if (D3dBufferCallbacks.CreateD3DBuffer != NULL)
  1829. {
  1830. pD3dBufferCallbacks->CreateExecuteBuffer =
  1831. (LPDDHALEXEBUFCB_CREATEEXEBUF)DdCreateD3DBuffer;
  1832. }
  1833. if (D3dBufferCallbacks.DestroyD3DBuffer != NULL)
  1834. {
  1835. pD3dBufferCallbacks->DestroyExecuteBuffer =
  1836. (LPDDHALEXEBUFCB_DESTROYEXEBUF)DdDestroyD3DBuffer;
  1837. }
  1838. if (D3dBufferCallbacks.LockD3DBuffer != NULL)
  1839. {
  1840. pD3dBufferCallbacks->LockExecuteBuffer =
  1841. (LPDDHALEXEBUFCB_LOCKEXEBUF)DdLockD3D;
  1842. }
  1843. if (D3dBufferCallbacks.UnlockD3DBuffer != NULL)
  1844. {
  1845. pD3dBufferCallbacks->UnlockExecuteBuffer =
  1846. (LPDDHALEXEBUFCB_UNLOCKEXEBUF)DdUnlockD3D;
  1847. }
  1848. }
  1849. }
  1850. if (pVideoMemoryList != NULL)
  1851. {
  1852. pVideoMemory = pVideoMemoryList;
  1853. while (dwNumHeaps-- != 0)
  1854. {
  1855. pvmList->dwFlags = pVideoMemory->dwFlags;
  1856. pvmList->fpStart = pVideoMemory->fpStart;
  1857. pvmList->fpEnd = pVideoMemory->fpEnd;
  1858. pvmList->ddsCaps = pVideoMemory->ddsCaps;
  1859. pvmList->ddsCapsAlt = pVideoMemory->ddsCapsAlt;
  1860. pvmList->dwHeight = pVideoMemory->dwHeight;
  1861. pvmList++;
  1862. pVideoMemory++;
  1863. }
  1864. LocalFree(pVideoMemoryList);
  1865. }
  1866. return(TRUE);
  1867. }
  1868. /*****************************Private*Routine******************************\
  1869. * DdDeleteDirectDrawObject
  1870. *
  1871. * Note that all associated surface objects must be deleted before the
  1872. * DirectDrawObject can be deleted.
  1873. *
  1874. * History:
  1875. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1876. * Wrote it.
  1877. \**************************************************************************/
  1878. BOOL
  1879. APIENTRY
  1880. DdDeleteDirectDrawObject( // AKA 'GdiEntry3'
  1881. LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal
  1882. )
  1883. {
  1884. BOOL b = FALSE;
  1885. if (pDirectDrawGlobal->hDD != 0)
  1886. {
  1887. b = NtGdiDdDeleteDirectDrawObject((HANDLE) pDirectDrawGlobal->hDD);
  1888. }
  1889. else if (ghDirectDraw != 0)
  1890. {
  1891. b = TRUE;
  1892. if (--gcDirectDraw == 0)
  1893. {
  1894. b = NtGdiDdDeleteDirectDrawObject(ghDirectDraw);
  1895. ghDirectDraw = 0;
  1896. }
  1897. }
  1898. return(b);
  1899. }
  1900. /*****************************Private*Routine******************************\
  1901. * bDdCreateSurfaceObject
  1902. *
  1903. * History:
  1904. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1905. * Wrote it.
  1906. \**************************************************************************/
  1907. BOOL
  1908. bDdCreateSurfaceObject(
  1909. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
  1910. BOOL bComplete
  1911. )
  1912. {
  1913. LPDDRAWI_DDRAWSURFACE_GBL pSurfaceGlobal;
  1914. DD_SURFACE_GLOBAL SurfaceGlobal;
  1915. DD_SURFACE_LOCAL SurfaceLocal;
  1916. DD_SURFACE_MORE SurfaceMore;
  1917. LPATTACHLIST pAttach;
  1918. BOOL bAttached;
  1919. //
  1920. // Wow64 genthnk will automatically thunk these structures, however,
  1921. // since these structures are pointer dependent, we need to make sure
  1922. // to NULL out these pointers so that Wow64 won't thunk them
  1923. //
  1924. RtlZeroMemory(&SurfaceLocal, sizeof(SurfaceLocal));
  1925. RtlZeroMemory(&SurfaceGlobal, sizeof(SurfaceGlobal));
  1926. RtlZeroMemory(&SurfaceMore, sizeof(SurfaceMore));
  1927. SurfaceLocal.dwFlags = pSurfaceLocal->dwFlags;
  1928. SurfaceLocal.ddsCaps = pSurfaceLocal->ddsCaps;
  1929. SurfaceMore.ddsCapsEx = pSurfaceLocal->lpSurfMore->ddsCapsEx;
  1930. SurfaceMore.dwSurfaceHandle = pSurfaceLocal->lpSurfMore->dwSurfaceHandle;
  1931. pSurfaceGlobal = pSurfaceLocal->lpGbl;
  1932. SurfaceGlobal.fpVidMem = pSurfaceGlobal->fpVidMem;
  1933. SurfaceGlobal.lPitch = pSurfaceGlobal->lPitch;
  1934. SurfaceGlobal.wHeight = pSurfaceGlobal->wHeight;
  1935. SurfaceGlobal.wWidth = pSurfaceGlobal->wWidth;
  1936. // If HASPIXELFORMAT is not set, we have to get the pixel format out
  1937. // of the global DirectDraw object:
  1938. if (pSurfaceLocal->dwFlags & DDRAWISURF_HASPIXELFORMAT)
  1939. {
  1940. SurfaceGlobal.ddpfSurface = pSurfaceGlobal->ddpfSurface;
  1941. }
  1942. else
  1943. {
  1944. SurfaceGlobal.ddpfSurface = pSurfaceGlobal->lpDD->vmiData.ddpfDisplay;
  1945. }
  1946. pSurfaceLocal->hDDSurface = (ULONG_PTR)
  1947. NtGdiDdCreateSurfaceObject(DD_HANDLE(pSurfaceGlobal->lpDD->hDD),
  1948. (HANDLE) pSurfaceLocal->hDDSurface,
  1949. &SurfaceLocal,
  1950. &SurfaceMore,
  1951. &SurfaceGlobal,
  1952. bComplete);
  1953. return(pSurfaceLocal->hDDSurface != 0);
  1954. }
  1955. /*****************************Private*Routine******************************\
  1956. * DdCreateSurfaceObject
  1957. *
  1958. * History:
  1959. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1960. * Wrote it.
  1961. \**************************************************************************/
  1962. BOOL
  1963. APIENTRY
  1964. DdCreateSurfaceObject( // AKA 'GdiEntry4'
  1965. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
  1966. BOOL bUnused
  1967. )
  1968. {
  1969. // TRUE means surface is now complete:
  1970. return(bDdCreateSurfaceObject(pSurfaceLocal, TRUE));
  1971. }
  1972. /*****************************Private*Routine******************************\
  1973. * DdDeleteSurfaceObject
  1974. *
  1975. * History:
  1976. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1977. * Wrote it.
  1978. \**************************************************************************/
  1979. BOOL
  1980. APIENTRY
  1981. DdDeleteSurfaceObject( // AKA 'GdiEntry5'
  1982. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal
  1983. )
  1984. {
  1985. BOOL b;
  1986. b = TRUE;
  1987. if (pSurfaceLocal->hDDSurface != 0)
  1988. {
  1989. b = NtGdiDdDeleteSurfaceObject((HANDLE) pSurfaceLocal->hDDSurface);
  1990. pSurfaceLocal->hDDSurface = 0; // Needed so CreateSurfaceObject works
  1991. }
  1992. return(b);
  1993. }
  1994. /*****************************Private*Routine******************************\
  1995. * DdResetVisrgn
  1996. *
  1997. * History:
  1998. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  1999. * Wrote it.
  2000. \**************************************************************************/
  2001. BOOL
  2002. APIENTRY
  2003. DdResetVisrgn( // AKA 'GdiEntry6'
  2004. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
  2005. HWND hWnd
  2006. )
  2007. {
  2008. return(NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd));
  2009. }
  2010. /*****************************Private*Routine******************************\
  2011. * DdGetDC
  2012. *
  2013. * History:
  2014. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  2015. * Wrote it.
  2016. \**************************************************************************/
  2017. HDC
  2018. APIENTRY
  2019. DdGetDC( // AKA 'GdiEntry7'
  2020. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
  2021. LPPALETTEENTRY pPalette
  2022. )
  2023. {
  2024. return(NtGdiDdGetDC((HANDLE) pSurfaceLocal->hDDSurface, pPalette));
  2025. }
  2026. /*****************************Private*Routine******************************\
  2027. * DdReleaseDC
  2028. *
  2029. * History:
  2030. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  2031. * Wrote it.
  2032. \**************************************************************************/
  2033. BOOL
  2034. APIENTRY
  2035. DdReleaseDC(
  2036. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal // AKA 'GdiEntry8'
  2037. )
  2038. {
  2039. return(NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface));
  2040. }
  2041. /******************************Public*Routine******************************\
  2042. * DdCreateDIBSection
  2043. *
  2044. * Cloned from CreateDIBSection.
  2045. *
  2046. * The only difference from CreateDIBSection is that at 8bpp, we create the
  2047. * DIBSection to act like a device-dependent bitmap and don't create a palette.
  2048. * This way, the application is always ensured an identity translate on a blt,
  2049. * and doesn't have to worry about GDI's goofy colour matching.
  2050. *
  2051. * History:
  2052. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  2053. * Wrote it.
  2054. \**************************************************************************/
  2055. HBITMAP
  2056. APIENTRY
  2057. DdCreateDIBSection( // AKA 'GdiEntry9'
  2058. HDC hdc,
  2059. CONST BITMAPINFO* pbmi,
  2060. UINT iUsage,
  2061. VOID** ppvBits,
  2062. HANDLE hSectionApp,
  2063. DWORD dwOffset
  2064. )
  2065. {
  2066. HBITMAP hbm = NULL;
  2067. PVOID pjBits = NULL;
  2068. BITMAPINFO * pbmiNew = NULL;
  2069. INT cjHdr;
  2070. pbmiNew = pbmiConvertInfo(pbmi, iUsage, &cjHdr, FALSE);
  2071. // dwOffset has to be a multiple of 4 (sizeof(DWORD))
  2072. // if there is a section. If the section is NULL we do
  2073. // not care
  2074. if ( (hSectionApp == NULL) ||
  2075. ((dwOffset & 3) == 0) )
  2076. {
  2077. hbm = NtGdiCreateDIBSection(
  2078. hdc,
  2079. hSectionApp,
  2080. dwOffset,
  2081. (LPBITMAPINFO) pbmiNew,
  2082. iUsage,
  2083. cjHdr,
  2084. CDBI_NOPALETTE,
  2085. 0,
  2086. (PVOID *)&pjBits);
  2087. if ((hbm == NULL) || (pjBits == NULL))
  2088. {
  2089. hbm = 0;
  2090. pjBits = NULL;
  2091. }
  2092. #if TRACE_SURFACE_ALLOCS
  2093. else
  2094. {
  2095. PULONG pUserAlloc;
  2096. PSHARED_GET_VALIDATE(pUserAlloc, hbm, SURF_TYPE);
  2097. if (pUserAlloc != NULL)
  2098. {
  2099. pUserAlloc[1] = RtlWalkFrameChain((PVOID *)&pUserAlloc[2], pUserAlloc[0], 0);
  2100. }
  2101. }
  2102. #endif
  2103. }
  2104. // Assign the appropriate value to the caller's pointer
  2105. if (ppvBits != NULL)
  2106. {
  2107. *ppvBits = pjBits;
  2108. }
  2109. if (pbmiNew && (pbmiNew != pbmi))
  2110. LocalFree(pbmiNew);
  2111. return(hbm);
  2112. }
  2113. /*****************************Private*Routine******************************\
  2114. * DdReenableDirectDrawObject
  2115. *
  2116. * History:
  2117. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  2118. * Wrote it.
  2119. \**************************************************************************/
  2120. BOOL
  2121. APIENTRY
  2122. DdReenableDirectDrawObject( // AKA 'GdiEntry10'
  2123. LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
  2124. BOOL* pbNewMode
  2125. )
  2126. {
  2127. return(NtGdiDdReenableDirectDrawObject(DD_HANDLE(pDirectDrawGlobal->hDD),
  2128. pbNewMode));
  2129. }
  2130. /*****************************Private*Routine******************************\
  2131. * DdAttachSurface
  2132. *
  2133. * History:
  2134. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  2135. * Wrote it.
  2136. \**************************************************************************/
  2137. BOOL
  2138. APIENTRY
  2139. DdAttachSurface( // AKA 'GdiEntry11'
  2140. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
  2141. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo
  2142. )
  2143. {
  2144. BOOL bRet = TRUE;
  2145. // We may be called to attach the surfaces before the kernel objects
  2146. // have been created; if so, create a kernel surface on the fly but
  2147. // mark it as incomplete:
  2148. // must test failure case for leak
  2149. if (pSurfaceFrom->hDDSurface == 0)
  2150. {
  2151. bRet &= bDdCreateSurfaceObject(pSurfaceFrom, FALSE);
  2152. }
  2153. if (pSurfaceTo->hDDSurface == 0)
  2154. {
  2155. bRet &= bDdCreateSurfaceObject(pSurfaceTo, FALSE);
  2156. }
  2157. if (bRet)
  2158. {
  2159. bRet = NtGdiDdAttachSurface((HANDLE) pSurfaceFrom->hDDSurface,
  2160. (HANDLE) pSurfaceTo->hDDSurface);
  2161. }
  2162. return(bRet);
  2163. }
  2164. /*****************************Private*Routine******************************\
  2165. * DdUnattachSurface
  2166. *
  2167. * History:
  2168. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  2169. * Wrote it.
  2170. \**************************************************************************/
  2171. VOID
  2172. APIENTRY
  2173. DdUnattachSurface( // AKA 'GdiEntry12'
  2174. LPDDRAWI_DDRAWSURFACE_LCL pSurface,
  2175. LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached
  2176. )
  2177. {
  2178. NtGdiDdUnattachSurface((HANDLE) pSurface->hDDSurface,
  2179. (HANDLE) pSurfaceAttached->hDDSurface);
  2180. }
  2181. /*****************************Private*Routine******************************\
  2182. * DdQueryDisplaySettingsUniqueness
  2183. *
  2184. * History:
  2185. * 3-Dec-1995 -by- J. Andrew Goossen [andrewgo]
  2186. * Wrote it.
  2187. \**************************************************************************/
  2188. ULONG
  2189. APIENTRY
  2190. DdQueryDisplaySettingsUniqueness( // AKA 'GdiEntry13'
  2191. VOID
  2192. )
  2193. {
  2194. return(pGdiSharedMemory->iDisplaySettingsUniqueness);
  2195. }
  2196. /*****************************Private*Routine******************************\
  2197. * DdGetDxHandle
  2198. *
  2199. * History:
  2200. * 18-Oct-1997 -by- smac
  2201. * Wrote it.
  2202. \**************************************************************************/
  2203. HANDLE
  2204. APIENTRY
  2205. DdGetDxHandle( // AKA 'GdiEntry14'
  2206. LPDDRAWI_DIRECTDRAW_LCL pDDraw,
  2207. LPDDRAWI_DDRAWSURFACE_LCL pSurface,
  2208. BOOL bRelease
  2209. )
  2210. {
  2211. if( pSurface != NULL )
  2212. {
  2213. return( NtGdiDdGetDxHandle( NULL, (HANDLE)(pSurface->hDDSurface),
  2214. bRelease ) );
  2215. }
  2216. return( NtGdiDdGetDxHandle( DD_HANDLE(pDDraw->lpGbl->hDD), NULL,
  2217. bRelease ) );
  2218. }
  2219. /*****************************Private*Routine******************************\
  2220. * DdSetGammaRamp
  2221. *
  2222. * History:
  2223. * 18-Oct-1997 -by- smac
  2224. * Wrote it.
  2225. \**************************************************************************/
  2226. BOOL
  2227. APIENTRY
  2228. DdSetGammaRamp( // AKA 'GdiEntry15'
  2229. LPDDRAWI_DIRECTDRAW_LCL pDDraw,
  2230. HDC hdc,
  2231. LPVOID lpGammaRamp
  2232. )
  2233. {
  2234. return( NtGdiDdSetGammaRamp( DD_HANDLE(pDDraw->lpGbl->hDD), hdc,
  2235. lpGammaRamp ) );
  2236. }
  2237. /*****************************Private*Routine******************************\
  2238. * DdSwapTextureHandles
  2239. *
  2240. * History:
  2241. * 17-Nov-1998 -by- anankan
  2242. * Wrote it.
  2243. \**************************************************************************/
  2244. ULONG
  2245. APIENTRY
  2246. DdSwapTextureHandles( // AKA 'GdiEntry16'
  2247. LPDDRAWI_DIRECTDRAW_LCL pDDLcl,
  2248. LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl1,
  2249. LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl2
  2250. )
  2251. {
  2252. //this entry is going away now that CreateSurfaceEx is added
  2253. return DDHAL_DRIVER_HANDLED;
  2254. }