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.

1533 lines
40 KiB

  1. /*==========================================================================
  2. * Copyright (C) 1997 Microsoft Corporation. All Rights Reserved.
  3. *
  4. * File: ddmc.c
  5. * Content: DirectDrawMotionComp
  6. * History:
  7. * Date By Reason
  8. * ==== == ======
  9. * 22-sep-97 smac created
  10. *
  11. ***************************************************************************/
  12. #include "ddrawpr.h"
  13. #ifdef WINNT
  14. #include "ddrawgdi.h"
  15. #endif
  16. #define DPF_MODNAME "DirectDrawMotionComp"
  17. /*
  18. * IsMotionCompSupported
  19. */
  20. BOOL IsMotionCompSupported( LPDDRAWI_DIRECTDRAW_LCL this_lcl )
  21. {
  22. if( this_lcl->lpDDCB->HALDDMotionComp.GetMoCompGuids == NULL )
  23. {
  24. return FALSE;
  25. }
  26. return TRUE;
  27. }
  28. /*
  29. * DD_MC_AddRef
  30. */
  31. DWORD DDAPI DD_MC_AddRef( LPDIRECTDRAWVIDEOACCELERATOR lpDDMC )
  32. {
  33. LPDDRAWI_DDMOTIONCOMP_INT this_int;
  34. LPDDRAWI_DDMOTIONCOMP_LCL this_lcl;
  35. ENTER_DDRAW();
  36. DPF(2,A,"ENTERAPI: DD_MC_AddRef");
  37. /* DPF( 2, "DD_MC_AddRef, pid=%08lx, obj=%08lx", GETCURRPID(), lpDDMC ); */
  38. TRY
  39. {
  40. this_int = (LPDDRAWI_DDMOTIONCOMP_INT) lpDDMC;
  41. if( !VALID_DDMOTIONCOMP_PTR( this_int ) )
  42. {
  43. LEAVE_DDRAW();
  44. return 0;
  45. }
  46. this_lcl = this_int->lpLcl;
  47. }
  48. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  49. {
  50. DPF_ERR( "Exception encountered validating parameters" );
  51. LEAVE_DDRAW();
  52. return 0;
  53. }
  54. /*
  55. * bump refcnt
  56. */
  57. this_lcl->dwRefCnt++;
  58. this_int->dwIntRefCnt++;
  59. LEAVE_DDRAW();
  60. return this_int->dwIntRefCnt;
  61. } /* DD_MC_AddRef */
  62. /*
  63. * DD_MC_QueryInterface
  64. */
  65. HRESULT DDAPI DD_MC_QueryInterface(LPDIRECTDRAWVIDEOACCELERATOR lpDDMC, REFIID riid, LPVOID FAR * ppvObj )
  66. {
  67. LPDDRAWI_DDMOTIONCOMP_INT this_int;
  68. LPDDRAWI_DDMOTIONCOMP_LCL this_lcl;
  69. ENTER_DDRAW();
  70. DPF(2,A,"ENTERAPI: DD_MC_QueryInterface");
  71. /*
  72. * validate parms
  73. */
  74. TRY
  75. {
  76. this_int = (LPDDRAWI_DDMOTIONCOMP_INT) lpDDMC;
  77. if( !VALID_DDMOTIONCOMP_PTR( this_int ) )
  78. {
  79. DPF_ERR( "Invalid motion comp pointer" );
  80. LEAVE_DDRAW();
  81. return DDERR_INVALIDOBJECT;
  82. }
  83. this_lcl = this_int->lpLcl;
  84. if( !VALID_PTR_PTR( ppvObj ) )
  85. {
  86. DPF_ERR( "Invalid motion comp interface pointer" );
  87. LEAVE_DDRAW();
  88. return DDERR_INVALIDPARAMS;
  89. }
  90. *ppvObj = NULL;
  91. if( !VALIDEX_IID_PTR( riid ) )
  92. {
  93. DPF_ERR( "Invalid IID pointer" );
  94. LEAVE_DDRAW();
  95. return DDERR_INVALIDPARAMS;
  96. }
  97. }
  98. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  99. {
  100. DPF_ERR( "Exception encountered validating parameters" );
  101. LEAVE_DDRAW();
  102. return DDERR_INVALIDPARAMS;
  103. }
  104. /*
  105. * asking for IUnknown?
  106. */
  107. if( IsEqualIID(riid, &IID_IUnknown) ||
  108. IsEqualIID(riid, &IID_IDirectDrawVideoAccelerator) )
  109. {
  110. /*
  111. * Our IUnknown interface is the same as our V1
  112. * interface. We must always return the V1 interface
  113. * if IUnknown is requested.
  114. */
  115. *ppvObj = (LPVOID) this_int;
  116. DD_MC_AddRef( *ppvObj );
  117. LEAVE_DDRAW();
  118. return DD_OK;
  119. }
  120. DPF_ERR( "IID not understood by DirectDraw" );
  121. LEAVE_DDRAW();
  122. return E_NOINTERFACE;
  123. } /* DD_MC_QueryInterface */
  124. /*
  125. * DD_MC_Release
  126. */
  127. DWORD DDAPI DD_MC_Release(LPDIRECTDRAWVIDEOACCELERATOR lpDDMC )
  128. {
  129. LPDDRAWI_DDMOTIONCOMP_INT this_int;
  130. LPDDRAWI_DDMOTIONCOMP_LCL this_lcl;
  131. LPDDRAWI_DIRECTDRAW_GBL pdrv;
  132. LPDDHALMOCOMPCB_DESTROY pfn;
  133. DWORD dwIntRefCnt;
  134. DWORD rc;
  135. LPDDRAWI_DDMOTIONCOMP_INT curr_int;
  136. LPDDRAWI_DDMOTIONCOMP_INT last_int;
  137. ENTER_DDRAW();
  138. DPF(2,A,"ENTERAPI: DD_MC_Release");
  139. TRY
  140. {
  141. this_int = (LPDDRAWI_DDMOTIONCOMP_INT) lpDDMC;
  142. if( !VALID_DDMOTIONCOMP_PTR( this_int ) )
  143. {
  144. DPF_ERR( "Invalid motion comp pointer" );
  145. LEAVE_DDRAW();
  146. return 0;
  147. }
  148. this_lcl = this_int->lpLcl;
  149. pdrv = this_lcl->lpDD->lpGbl;
  150. }
  151. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  152. {
  153. DPF_ERR( "Exception encountered validating parameters" );
  154. LEAVE_DDRAW();
  155. return 0;
  156. }
  157. /*
  158. * decrement the reference count. if it hits zero, free the surface
  159. */
  160. this_lcl->dwRefCnt--;
  161. this_int->dwIntRefCnt--;
  162. DPF( 5, "DD_MC_Release, Reference Count: Local = %ld Int = %ld",
  163. this_lcl->dwRefCnt, this_int->dwIntRefCnt );
  164. /*
  165. * interface at zero?
  166. */
  167. dwIntRefCnt = this_int->dwIntRefCnt;
  168. if( dwIntRefCnt == 0 )
  169. {
  170. /*
  171. * Notify the HAL
  172. */
  173. pfn = this_lcl->lpDD->lpDDCB->HALDDMotionComp.DestroyMoComp;
  174. if( NULL != pfn )
  175. {
  176. DDHAL_DESTROYMOCOMPDATA DestroyData;
  177. DestroyData.lpDD = this_lcl->lpDD;
  178. DestroyData.lpMoComp = this_lcl;
  179. DOHALCALL( DestroyMoComp, pfn, DestroyData, rc, 0 );
  180. if( ( DDHAL_DRIVER_HANDLED == rc ) && ( DD_OK != DestroyData.ddRVal ) )
  181. {
  182. LEAVE_DDRAW();
  183. return DestroyData.ddRVal;
  184. }
  185. }
  186. /*
  187. * Remove it from our internal list
  188. */
  189. curr_int = pdrv->mcList;
  190. last_int = NULL;
  191. while( curr_int != this_int )
  192. {
  193. last_int = curr_int;
  194. curr_int = curr_int->lpLink;
  195. if( curr_int == NULL )
  196. {
  197. DPF_ERR( "MotionComp object not in list!" );
  198. LEAVE_DDRAW();
  199. return 0;
  200. }
  201. }
  202. if( last_int == NULL )
  203. {
  204. pdrv->mcList = pdrv->mcList->lpLink;
  205. }
  206. else
  207. {
  208. last_int->lpLink = curr_int->lpLink;
  209. }
  210. /*
  211. * just in case someone comes back in with this pointer, set
  212. * an invalid vtbl & data ptr.
  213. */
  214. this_int->lpVtbl = NULL;
  215. this_int->lpLcl = NULL;
  216. MemFree( this_int );
  217. }
  218. LEAVE_DDRAW();
  219. return dwIntRefCnt;
  220. }
  221. /*
  222. * IsApprovedMCGuid
  223. *
  224. * The Motion Comp API can be used as a generic escape mechanism to
  225. * the driver, which we don't want to happen. One way to deter this is
  226. * to control which GUIDs are used. If somebody wants to use a new GUID,
  227. * we should approve their need and then assign them a GUID. Since we want
  228. * to reserve GUIDs that we can assign in the future, we will reserve
  229. * four ranges 20 GUID values and will only accept GUIDs within one of
  230. * these ranges.
  231. */
  232. BOOL IsApprovedMCGuid( LPGUID lpGuid )
  233. {
  234. return TRUE;
  235. }
  236. /*
  237. * DDMCC_CreateMotionComp
  238. */
  239. HRESULT DDAPI DDMCC_CreateMotionComp(
  240. LPDDVIDEOACCELERATORCONTAINER lpDDMCC,
  241. LPGUID lpGuid,
  242. LPDDVAUncompDataInfo lpUncompInfo,
  243. LPVOID lpData,
  244. DWORD dwDataSize,
  245. LPDIRECTDRAWVIDEOACCELERATOR FAR *lplpDDMotionComp,
  246. IUnknown FAR *pUnkOuter )
  247. {
  248. LPDDRAWI_DIRECTDRAW_INT this_int;
  249. LPDDRAWI_DIRECTDRAW_LCL this_lcl;
  250. LPDDRAWI_DIRECTDRAW_GBL this;
  251. LPDDHALMOCOMPCB_CREATE cvpfn;
  252. LPDDRAWI_DDMOTIONCOMP_INT new_int;
  253. LPDDRAWI_DDMOTIONCOMP_LCL new_lcl;
  254. DWORD dwNumGuids;
  255. LPGUID lpGuidList;
  256. LPGUID lpTemp;
  257. DWORD rc;
  258. DWORD i;
  259. if( pUnkOuter != NULL )
  260. {
  261. return CLASS_E_NOAGGREGATION;
  262. }
  263. ENTER_DDRAW();
  264. DPF(2,A,"ENTERAPI: DDMCC_CreateMotionComp");
  265. /*
  266. * Validate parameters
  267. */
  268. TRY
  269. {
  270. this_int = (LPDDRAWI_DIRECTDRAW_INT) lpDDMCC;
  271. if( !VALID_DIRECTDRAW_PTR( this_int ) )
  272. {
  273. LEAVE_DDRAW();
  274. return DDERR_INVALIDOBJECT;
  275. }
  276. this_lcl = this_int->lpLcl;
  277. this = this_lcl->lpGbl;
  278. #ifdef WINNT
  279. // Update DDraw handle in driver GBL object.
  280. this->hDD = this_lcl->hDD;
  281. #endif
  282. if( ( NULL == lplpDDMotionComp ) || !VALID_PTR_PTR( lplpDDMotionComp ) )
  283. {
  284. LEAVE_DDRAW();
  285. return DDERR_INVALIDPARAMS;
  286. }
  287. if( ( lpGuid == NULL ) || !VALID_BYTE_ARRAY( lpGuid, sizeof( GUID ) ) )
  288. {
  289. DPF_ERR ( "DDMCC_CreateMotionComp: invalid GUID passed in");
  290. LEAVE_DDRAW();
  291. return DDERR_INVALIDPARAMS;
  292. }
  293. if( ( lpUncompInfo == NULL ) ||
  294. !VALID_BYTE_ARRAY( lpUncompInfo, sizeof( DDVAUncompDataInfo ) ) )
  295. {
  296. DPF_ERR ( "DDMCC_CreateMotionComp: invalid GUID passed in");
  297. LEAVE_DDRAW();
  298. return DDERR_INVALIDPARAMS;
  299. }
  300. if( !IsApprovedMCGuid( lpGuid ) )
  301. {
  302. DPF_ERR ( "DDMCC_CreateMotionComp: invalid GUID passed in");
  303. LEAVE_DDRAW();
  304. return DDERR_INVALIDPARAMS;
  305. }
  306. if( dwDataSize > 0 )
  307. {
  308. if( ( lpData == NULL ) || !VALID_BYTE_ARRAY( lpData, dwDataSize ) )
  309. {
  310. DPF_ERR ( "DDMCC_CreateMotionComp: invalid lpData passed in");
  311. LEAVE_DDRAW();
  312. return DDERR_INVALIDPARAMS;
  313. }
  314. }
  315. else
  316. {
  317. lpData = NULL;
  318. }
  319. }
  320. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  321. {
  322. DPF_ERR( "Exception encountered validating parameters" );
  323. LEAVE_DDRAW();
  324. return DDERR_EXCEPTION;
  325. }
  326. if( this_lcl->dwProcessId != GetCurrentProcessId() )
  327. {
  328. DPF_ERR( "Process does not have access to object" );
  329. LEAVE_DDRAW();
  330. return DDERR_INVALIDPARAMS;
  331. }
  332. /*
  333. * Verify that the GUID can be supported.
  334. */
  335. rc = DDMCC_GetMotionCompGUIDs( lpDDMCC,
  336. &dwNumGuids, NULL );
  337. if( rc != DD_OK )
  338. {
  339. LEAVE_DDRAW();
  340. return DDERR_INVALIDPARAMS;
  341. }
  342. lpGuidList = (LPGUID) MemAlloc( sizeof( GUID ) * dwNumGuids );
  343. if( NULL == lpGuidList )
  344. {
  345. LEAVE_DDRAW();
  346. return DDERR_OUTOFMEMORY;
  347. }
  348. rc = DDMCC_GetMotionCompGUIDs( lpDDMCC, &dwNumGuids, lpGuidList );
  349. if( rc != DD_OK )
  350. {
  351. LEAVE_DDRAW();
  352. return DDERR_INVALIDPARAMS;
  353. }
  354. lpTemp = lpGuidList;
  355. for (i = 0; i < dwNumGuids; i++)
  356. {
  357. if( ( IsEqualIID( lpGuid, lpTemp++ ) ) )
  358. {
  359. break;
  360. }
  361. }
  362. MemFree( lpGuidList );
  363. if( i >= dwNumGuids )
  364. {
  365. DPF_ERR( "invalid GUID specified" );
  366. LEAVE_DDRAW();
  367. return DDERR_INVALIDPARAMS;
  368. }
  369. /*
  370. * Allocate it
  371. */
  372. new_int = MemAlloc( sizeof( DDRAWI_DDMOTIONCOMP_INT ) +
  373. sizeof( DDRAWI_DDMOTIONCOMP_LCL ) );
  374. if( NULL == new_int )
  375. {
  376. LEAVE_DDRAW();
  377. return DDERR_OUTOFMEMORY;
  378. }
  379. new_lcl = (LPDDRAWI_DDMOTIONCOMP_LCL) ((LPBYTE)new_int + sizeof( DDRAWI_DDMOTIONCOMP_INT ) );
  380. new_int->lpLcl = new_lcl;
  381. new_int->lpVtbl = (LPVOID)&ddMotionCompCallbacks;
  382. new_lcl->lpDD = this_lcl;
  383. new_lcl->dwProcessId = GetCurrentProcessId();
  384. memcpy( &(new_lcl->guid), lpGuid, sizeof( GUID ) );
  385. new_lcl->dwUncompWidth = lpUncompInfo->dwUncompWidth;
  386. new_lcl->dwUncompHeight = lpUncompInfo->dwUncompHeight;
  387. memcpy( &(new_lcl->ddUncompPixelFormat), &(lpUncompInfo->ddUncompPixelFormat), sizeof( DDPIXELFORMAT ) );
  388. /*
  389. * Notify the HAL that we created it
  390. */
  391. cvpfn = this_lcl->lpDDCB->HALDDMotionComp.CreateMoComp;
  392. if( NULL != cvpfn )
  393. {
  394. DDHAL_CREATEMOCOMPDATA CreateData;
  395. CreateData.lpDD = this_lcl;
  396. CreateData.lpMoComp = new_lcl;
  397. CreateData.lpGuid = lpGuid;
  398. CreateData.dwUncompWidth = lpUncompInfo->dwUncompWidth;
  399. CreateData.dwUncompHeight = lpUncompInfo->dwUncompHeight;
  400. memcpy( &(CreateData.ddUncompPixelFormat), &(lpUncompInfo->ddUncompPixelFormat), sizeof( DDPIXELFORMAT ) );
  401. CreateData.lpData = lpData;
  402. CreateData.dwDataSize = dwDataSize;
  403. DOHALCALL( CreateMoComp, cvpfn, CreateData, rc, 0 );
  404. if( ( DDHAL_DRIVER_HANDLED == rc ) && (DD_OK != CreateData.ddRVal ) )
  405. {
  406. LEAVE_DDRAW();
  407. return CreateData.ddRVal;
  408. }
  409. }
  410. DD_MC_AddRef( (LPDIRECTDRAWVIDEOACCELERATOR )new_int );
  411. *lplpDDMotionComp = (LPDIRECTDRAWVIDEOACCELERATOR) new_int;
  412. new_int->lpLink = this->mcList;
  413. this->mcList = new_int;
  414. LEAVE_DDRAW();
  415. return DD_OK;
  416. } /* DDMCC_CreateMotionComp */
  417. /*
  418. * DDMCC_GetMotionCompFormats
  419. */
  420. HRESULT DDAPI DDMCC_GetUncompressedFormats(
  421. LPDDVIDEOACCELERATORCONTAINER lpDDMCC,
  422. LPGUID lpGuid,
  423. LPDWORD lpdwNumFormats,
  424. LPDDPIXELFORMAT lpFormats )
  425. {
  426. LPDDHALMOCOMPCB_GETFORMATS pfn;
  427. LPDDRAWI_DIRECTDRAW_INT this_int;
  428. LPDDRAWI_DIRECTDRAW_LCL this_lcl;
  429. LPDDPIXELFORMAT lpTemp;
  430. DDHAL_GETMOCOMPFORMATSDATA GetFormatData;
  431. DWORD rc;
  432. ENTER_DDRAW();
  433. DPF(2,A,"ENTERAPI: DDMCC_GetMotionCompFormats");
  434. /*
  435. * Validate parameters
  436. */
  437. TRY
  438. {
  439. this_int = (LPDDRAWI_DIRECTDRAW_INT) lpDDMCC;
  440. if( !VALID_DIRECTDRAW_PTR( this_int ) )
  441. {
  442. DPF_ERR ( "DDMCC_GetMotionCompFormats: Invalid DirectDraw ptr");
  443. LEAVE_DDRAW();
  444. return DDERR_INVALIDOBJECT;
  445. }
  446. this_lcl = this_int->lpLcl;
  447. #ifdef WINNT
  448. // Update DDraw handle in driver GBL object.
  449. this_lcl->lpGbl->hDD = this_lcl->hDD;
  450. #endif
  451. if( (lpdwNumFormats == NULL) || !VALID_BYTE_ARRAY( lpdwNumFormats, sizeof( LPVOID ) ) )
  452. {
  453. DPF_ERR ( "DDMCC_GetMotionCompFormats: lpNumFormats not valid");
  454. LEAVE_DDRAW();
  455. return DDERR_INVALIDPARAMS;
  456. }
  457. if( NULL != lpFormats )
  458. {
  459. if( 0 == *lpdwNumFormats )
  460. {
  461. DPF_ERR ( "DDMCC_GetMotionCompFormats: lpNumFormats not valid");
  462. LEAVE_DDRAW();
  463. return DDERR_INVALIDPARAMS;
  464. }
  465. if( !VALID_BYTE_ARRAY( lpFormats, *lpdwNumFormats * sizeof( DDPIXELFORMAT ) ) )
  466. {
  467. DPF_ERR ( "DDMCC_GetMotionCompFormats: invalid array passed in");
  468. LEAVE_DDRAW();
  469. return DDERR_INVALIDPARAMS;
  470. }
  471. }
  472. if( ( lpGuid == NULL ) || !VALID_BYTE_ARRAY( lpGuid, sizeof( GUID ) ) )
  473. {
  474. DPF_ERR ( "DDMCC_GetMotionCompFormats: invalid GUID passed in");
  475. LEAVE_DDRAW();
  476. return DDERR_INVALIDPARAMS;
  477. }
  478. if( !IsApprovedMCGuid( lpGuid ) )
  479. {
  480. DPF_ERR ( "DDMCC_GetMotionCompFormats: invalid GUID passed in");
  481. LEAVE_DDRAW();
  482. return DDERR_INVALIDPARAMS;
  483. }
  484. }
  485. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  486. {
  487. DPF_ERR( "Exception encountered validating parameters" );
  488. LEAVE_DDRAW();
  489. return DDERR_EXCEPTION;
  490. }
  491. pfn = this_int->lpLcl->lpDDCB->HALDDMotionComp.GetMoCompFormats;
  492. if( pfn != NULL )
  493. {
  494. /*
  495. * Get the number of formats
  496. */
  497. GetFormatData.lpDD = this_int->lpLcl;
  498. GetFormatData.lpGuid = lpGuid;
  499. GetFormatData.lpFormats = NULL;
  500. DOHALCALL( GetMoCompFormats, pfn, GetFormatData, rc, 0 );
  501. if( DDHAL_DRIVER_HANDLED != rc )
  502. {
  503. LEAVE_DDRAW();
  504. return GetFormatData.ddRVal;
  505. }
  506. else if( DD_OK != GetFormatData.ddRVal )
  507. {
  508. LEAVE_DDRAW();
  509. return GetFormatData.ddRVal;
  510. }
  511. if( NULL == lpFormats )
  512. {
  513. *lpdwNumFormats = GetFormatData.dwNumFormats;
  514. }
  515. else
  516. {
  517. /*
  518. * Make sure we have enough room for formats
  519. */
  520. if( GetFormatData.dwNumFormats > *lpdwNumFormats )
  521. {
  522. lpTemp = (LPDDPIXELFORMAT) MemAlloc(
  523. sizeof( DDPIXELFORMAT ) * GetFormatData.dwNumFormats );
  524. GetFormatData.lpFormats = lpTemp;
  525. }
  526. else
  527. {
  528. GetFormatData.lpFormats = lpFormats;
  529. }
  530. DOHALCALL( GetMoCompFormats, pfn, GetFormatData, rc, 0 );
  531. if( DDHAL_DRIVER_HANDLED != rc )
  532. {
  533. LEAVE_DDRAW();
  534. return DDERR_UNSUPPORTED;
  535. }
  536. else if( DD_OK != GetFormatData.ddRVal )
  537. {
  538. LEAVE_DDRAW();
  539. return GetFormatData.ddRVal;
  540. }
  541. if( GetFormatData.lpFormats != lpFormats )
  542. {
  543. memcpy( lpFormats, lpTemp,
  544. sizeof( DDPIXELFORMAT ) * *lpdwNumFormats );
  545. MemFree( lpTemp );
  546. LEAVE_DDRAW();
  547. return DDERR_MOREDATA;
  548. }
  549. else
  550. {
  551. *lpdwNumFormats = GetFormatData.dwNumFormats;
  552. }
  553. }
  554. }
  555. else
  556. {
  557. LEAVE_DDRAW();
  558. return DDERR_UNSUPPORTED;
  559. }
  560. LEAVE_DDRAW();
  561. return DD_OK;
  562. } /* DDMCC_GetMotionCompFormats */
  563. /*
  564. * DDMCC_GetMotionCompGUIDs
  565. */
  566. HRESULT DDAPI DDMCC_GetMotionCompGUIDs(
  567. LPDDVIDEOACCELERATORCONTAINER lpDDMCC,
  568. LPDWORD lpdwNumGuids,
  569. LPGUID lpGuids )
  570. {
  571. LPDDHALMOCOMPCB_GETGUIDS pfn;
  572. LPDDRAWI_DIRECTDRAW_INT this_int;
  573. LPDDRAWI_DIRECTDRAW_LCL this_lcl;
  574. LPGUID lpTemp = NULL;
  575. LPGUID lpTempGuid;
  576. DDHAL_GETMOCOMPGUIDSDATA GetGuidData;
  577. DWORD rc;
  578. DWORD i;
  579. ENTER_DDRAW();
  580. DPF(2,A,"ENTERAPI: GetMotionCompGUIDs");
  581. /*
  582. * Validate parameters
  583. */
  584. TRY
  585. {
  586. this_int = (LPDDRAWI_DIRECTDRAW_INT) lpDDMCC;
  587. if( !VALID_DIRECTDRAW_PTR( this_int ) )
  588. {
  589. DPF_ERR ( "DDMCC_GetMotionCompGUIDs: Invalid DirectDraw ptr");
  590. LEAVE_DDRAW();
  591. return DDERR_INVALIDOBJECT;
  592. }
  593. this_lcl = this_int->lpLcl;
  594. #ifdef WINNT
  595. // Update DDraw handle in driver GBL object.
  596. this_lcl->lpGbl->hDD = this_lcl->hDD;
  597. #endif
  598. if( (lpdwNumGuids == NULL) || !VALID_BYTE_ARRAY( lpdwNumGuids, sizeof( LPVOID ) ) )
  599. {
  600. DPF_ERR ( "DDMCC_GetMotionCompGuids: lpNumGuids not valid");
  601. LEAVE_DDRAW();
  602. return DDERR_INVALIDPARAMS;
  603. }
  604. if( NULL != lpGuids )
  605. {
  606. if( 0 == *lpdwNumGuids )
  607. {
  608. DPF_ERR ( "DDMCC_GetMotionCompGUIDs: lpNumGuids not valid");
  609. LEAVE_DDRAW();
  610. return DDERR_INVALIDPARAMS;
  611. }
  612. if( !VALID_BYTE_ARRAY( lpGuids, *lpdwNumGuids * sizeof( GUID ) ) )
  613. {
  614. DPF_ERR ( "DDMCC_GetMotionCompGUIDs: invalid array passed in");
  615. LEAVE_DDRAW();
  616. return DDERR_INVALIDPARAMS;
  617. }
  618. }
  619. }
  620. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  621. {
  622. DPF_ERR( "Exception encountered validating parameters" );
  623. LEAVE_DDRAW();
  624. return DDERR_EXCEPTION;
  625. }
  626. pfn = this_int->lpLcl->lpDDCB->HALDDMotionComp.GetMoCompGuids;
  627. if( pfn != NULL )
  628. {
  629. /*
  630. * Get the number of GUIDs
  631. */
  632. GetGuidData.lpDD = this_int->lpLcl;
  633. GetGuidData.lpGuids = NULL;
  634. DOHALCALL( GetMoCompGuids, pfn, GetGuidData, rc, 0 );
  635. if( DDHAL_DRIVER_HANDLED != rc )
  636. {
  637. LEAVE_DDRAW();
  638. return GetGuidData.ddRVal;
  639. }
  640. else if( DD_OK != GetGuidData.ddRVal )
  641. {
  642. LEAVE_DDRAW();
  643. return GetGuidData.ddRVal;
  644. }
  645. if( NULL == lpGuids )
  646. {
  647. *lpdwNumGuids = GetGuidData.dwNumGuids;
  648. }
  649. else
  650. {
  651. /*
  652. * Make sure we have enough room for GUIDs
  653. */
  654. if( GetGuidData.dwNumGuids > *lpdwNumGuids )
  655. {
  656. lpTemp = (LPGUID) MemAlloc(
  657. sizeof( GUID ) * GetGuidData.dwNumGuids );
  658. GetGuidData.lpGuids = lpTemp;
  659. }
  660. else
  661. {
  662. GetGuidData.lpGuids = lpGuids;
  663. }
  664. DOHALCALL( GetMoCompGuids, pfn, GetGuidData, rc, 0 );
  665. if( DDHAL_DRIVER_HANDLED != rc )
  666. {
  667. LEAVE_DDRAW();
  668. return DDERR_UNSUPPORTED;
  669. }
  670. else if( DD_OK != GetGuidData.ddRVal )
  671. {
  672. LEAVE_DDRAW();
  673. return GetGuidData.ddRVal;
  674. }
  675. /*
  676. * If the driver returned a GUID that is not from our valid
  677. * range, fail the call
  678. */
  679. lpTempGuid = GetGuidData.lpGuids;
  680. for( i = 0; i < GetGuidData.dwNumGuids; i++ )
  681. {
  682. if( !IsApprovedMCGuid( lpTempGuid ) )
  683. {
  684. if( lpTemp != NULL )
  685. {
  686. MemFree( lpTemp );
  687. }
  688. DPF_ERR("The driver returned a GUID that DDraw didn't assign");
  689. LEAVE_DDRAW();
  690. return DDERR_GENERIC;
  691. }
  692. lpTempGuid++;
  693. }
  694. if( GetGuidData.lpGuids != lpGuids )
  695. {
  696. memcpy( lpGuids, lpTemp,
  697. sizeof( GUID ) * *lpdwNumGuids );
  698. MemFree( lpTemp );
  699. LEAVE_DDRAW();
  700. return DDERR_MOREDATA;
  701. }
  702. else
  703. {
  704. *lpdwNumGuids = GetGuidData.dwNumGuids;
  705. }
  706. }
  707. }
  708. else
  709. {
  710. LEAVE_DDRAW();
  711. return DDERR_UNSUPPORTED;
  712. }
  713. LEAVE_DDRAW();
  714. return DD_OK;
  715. } /* DDMCC_GetMotionCompGUIDs */
  716. /*
  717. * DDMCC_GetCompBuffInfo
  718. */
  719. HRESULT DDAPI DDMCC_GetCompBuffInfo(
  720. LPDDVIDEOACCELERATORCONTAINER lpDDMCC,
  721. LPGUID lpGuid,
  722. LPDDVAUncompDataInfo lpUncompInfo,
  723. LPDWORD lpdwNumBuffInfo,
  724. LPDDVACompBufferInfo lpCompBuffInfo )
  725. {
  726. LPDDHALMOCOMPCB_GETCOMPBUFFINFO pfn;
  727. LPDDRAWI_DIRECTDRAW_INT this_int;
  728. LPDDRAWI_DIRECTDRAW_LCL this_lcl;
  729. LPDDMCCOMPBUFFERINFO lpTemp = NULL;
  730. DDHAL_GETMOCOMPCOMPBUFFDATA GetCompBuffData;
  731. DWORD rc;
  732. ENTER_DDRAW();
  733. /*
  734. * Validate parameters
  735. */
  736. TRY
  737. {
  738. this_int = (LPDDRAWI_DIRECTDRAW_INT) lpDDMCC;
  739. if( !VALID_DIRECTDRAW_PTR( this_int ) )
  740. {
  741. DPF_ERR ( "DDMCC_GetCompBuffInfo: Invalid DirectDraw ptr");
  742. LEAVE_DDRAW();
  743. return DDERR_INVALIDOBJECT;
  744. }
  745. this_lcl = this_int->lpLcl;
  746. if( (lpdwNumBuffInfo == NULL) || !VALID_BYTE_ARRAY( lpdwNumBuffInfo, sizeof( LPVOID ) ) )
  747. {
  748. DPF_ERR ( "DDMCC_GetCompBuffInfo: lpNumBuffInfo not valid");
  749. LEAVE_DDRAW();
  750. return DDERR_INVALIDPARAMS;
  751. }
  752. if( NULL != lpCompBuffInfo )
  753. {
  754. if( 0 == *lpdwNumBuffInfo )
  755. {
  756. DPF_ERR ( "DDMCC_GetCompBuffInfo lpCompBuffInfo not valid");
  757. LEAVE_DDRAW();
  758. return DDERR_INVALIDPARAMS;
  759. }
  760. if( !VALID_BYTE_ARRAY( lpCompBuffInfo, *lpdwNumBuffInfo * sizeof( DDVACompBufferInfo ) ) )
  761. {
  762. DPF_ERR ( "DDMCC_GetCompBuffInfo: invalid array passed in");
  763. LEAVE_DDRAW();
  764. return DDERR_INVALIDPARAMS;
  765. }
  766. }
  767. if( ( lpUncompInfo == NULL ) ||
  768. !VALID_BYTE_ARRAY( lpUncompInfo, sizeof( DDVAUncompDataInfo ) ) )
  769. {
  770. DPF_ERR ( "DDMCC_GetCompBuffInfo: invalid lpUncompInfo passed in");
  771. LEAVE_DDRAW();
  772. return DDERR_INVALIDPARAMS;
  773. }
  774. if( ( lpGuid == NULL ) || !VALID_BYTE_ARRAY( lpGuid, sizeof( GUID ) ) )
  775. {
  776. DPF_ERR ( "DDMCC_GetCompBuffInfo: invalid GUID passed in");
  777. LEAVE_DDRAW();
  778. return DDERR_INVALIDPARAMS;
  779. }
  780. if( !IsApprovedMCGuid( lpGuid ) )
  781. {
  782. DPF_ERR ( "DDMCC_GetCompBuffInfo: invalid GUID passed in");
  783. LEAVE_DDRAW();
  784. return DDERR_INVALIDPARAMS;
  785. }
  786. }
  787. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  788. {
  789. DPF_ERR( "Exception encountered validating parameters" );
  790. LEAVE_DDRAW();
  791. return DDERR_EXCEPTION;
  792. }
  793. pfn = this_int->lpLcl->lpDDCB->HALDDMotionComp.GetMoCompBuffInfo;
  794. if( pfn != NULL )
  795. {
  796. /*
  797. * Get the number of buffer types
  798. */
  799. GetCompBuffData.lpDD = this_int->lpLcl;
  800. GetCompBuffData.lpGuid = lpGuid;
  801. GetCompBuffData.dwWidth= lpUncompInfo->dwUncompWidth;
  802. GetCompBuffData.dwHeight= lpUncompInfo->dwUncompHeight;
  803. memcpy( &GetCompBuffData.ddPixelFormat,
  804. &(lpUncompInfo->ddUncompPixelFormat), sizeof( DDPIXELFORMAT ) );
  805. GetCompBuffData.lpCompBuffInfo = NULL;
  806. GetCompBuffData.dwNumTypesCompBuffs = 0;
  807. DOHALCALL( GetMoCompBuffInfo, pfn, GetCompBuffData, rc, 0 );
  808. if( DDHAL_DRIVER_HANDLED != rc )
  809. {
  810. LEAVE_DDRAW();
  811. return GetCompBuffData.ddRVal;
  812. }
  813. else if( DD_OK != GetCompBuffData.ddRVal )
  814. {
  815. LEAVE_DDRAW();
  816. return GetCompBuffData.ddRVal;
  817. }
  818. if( NULL == lpCompBuffInfo )
  819. {
  820. *lpdwNumBuffInfo = GetCompBuffData.dwNumTypesCompBuffs;
  821. }
  822. else
  823. {
  824. /*
  825. * Make sure we have enough room for formats
  826. */
  827. if( GetCompBuffData.dwNumTypesCompBuffs > *lpdwNumBuffInfo )
  828. {
  829. lpTemp = (LPDDMCCOMPBUFFERINFO) MemAlloc(
  830. sizeof( DDMCCOMPBUFFERINFO ) * GetCompBuffData.dwNumTypesCompBuffs );
  831. GetCompBuffData.lpCompBuffInfo = lpTemp;
  832. }
  833. else
  834. {
  835. GetCompBuffData.lpCompBuffInfo = (LPDDMCCOMPBUFFERINFO)lpCompBuffInfo;
  836. }
  837. DOHALCALL( GetMoCompBuffInfo, pfn, GetCompBuffData, rc, 0 );
  838. if( DDHAL_DRIVER_HANDLED != rc )
  839. {
  840. LEAVE_DDRAW();
  841. return DDERR_UNSUPPORTED;
  842. }
  843. else if( DD_OK != GetCompBuffData.ddRVal )
  844. {
  845. LEAVE_DDRAW();
  846. return GetCompBuffData.ddRVal;
  847. }
  848. if( GetCompBuffData.lpCompBuffInfo != (LPDDMCCOMPBUFFERINFO)lpCompBuffInfo )
  849. {
  850. memcpy( lpCompBuffInfo, lpTemp,
  851. sizeof( DDVACompBufferInfo ) * *lpdwNumBuffInfo );
  852. MemFree( lpTemp );
  853. LEAVE_DDRAW();
  854. return DDERR_MOREDATA;
  855. }
  856. else
  857. {
  858. *lpdwNumBuffInfo = GetCompBuffData.dwNumTypesCompBuffs;
  859. }
  860. }
  861. }
  862. else
  863. {
  864. LEAVE_DDRAW();
  865. return DDERR_UNSUPPORTED;
  866. }
  867. LEAVE_DDRAW();
  868. return DD_OK;
  869. } /* DDMCC_GetCompBuffInfo */
  870. /*
  871. * DDMCC_GetInternalMemInfo
  872. */
  873. HRESULT DDAPI DDMCC_GetInternalMoCompInfo(
  874. LPDDVIDEOACCELERATORCONTAINER lpDDMCC,
  875. LPGUID lpGuid,
  876. LPDDVAUncompDataInfo lpUncompInfo,
  877. LPDDVAInternalMemInfo lpMemInfo )
  878. {
  879. LPDDHALMOCOMPCB_GETINTERNALINFO pfn;
  880. LPDDRAWI_DIRECTDRAW_INT this_int;
  881. LPDDRAWI_DIRECTDRAW_LCL this_lcl;
  882. DDHAL_GETINTERNALMOCOMPDATA GetInternalData;
  883. DWORD rc;
  884. ENTER_DDRAW();
  885. /*
  886. * Validate parameters
  887. */
  888. TRY
  889. {
  890. this_int = (LPDDRAWI_DIRECTDRAW_INT) lpDDMCC;
  891. if( !VALID_DIRECTDRAW_PTR( this_int ) )
  892. {
  893. DPF_ERR ( "DDMCC_GetInternalMemInfo: Invalid DirectDraw ptr");
  894. LEAVE_DDRAW();
  895. return DDERR_INVALIDOBJECT;
  896. }
  897. this_lcl = this_int->lpLcl;
  898. if( ( lpUncompInfo == NULL ) ||
  899. !VALID_BYTE_ARRAY( lpUncompInfo, sizeof( DDVAUncompDataInfo ) ) )
  900. {
  901. DPF_ERR ( "DDMCC_GetInternalMemInfo: invalid lpUncompInfo passed in");
  902. LEAVE_DDRAW();
  903. return DDERR_INVALIDPARAMS;
  904. }
  905. if( ( lpMemInfo == NULL ) ||
  906. !VALID_BYTE_ARRAY( lpMemInfo, sizeof( DDVAInternalMemInfo ) ) )
  907. {
  908. DPF_ERR ( "DDMCC_GetInternalMemInfo: invalid lpUncompInfo passed in");
  909. LEAVE_DDRAW();
  910. return DDERR_INVALIDPARAMS;
  911. }
  912. if( ( lpGuid == NULL ) || !VALID_BYTE_ARRAY( lpGuid, sizeof( GUID ) ) )
  913. {
  914. DPF_ERR ( "DDMCC_GetInternalMemInfo: invalid GUID passed in");
  915. LEAVE_DDRAW();
  916. return DDERR_INVALIDPARAMS;
  917. }
  918. if( !IsApprovedMCGuid( lpGuid ) )
  919. {
  920. DPF_ERR ( "DDMCC_GetInternalMemInfo: invalid GUID passed in");
  921. LEAVE_DDRAW();
  922. return DDERR_INVALIDPARAMS;
  923. }
  924. }
  925. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  926. {
  927. DPF_ERR( "Exception encountered validating parameters" );
  928. LEAVE_DDRAW();
  929. return DDERR_EXCEPTION;
  930. }
  931. lpMemInfo->dwScratchMemAlloc = 0;
  932. pfn = this_int->lpLcl->lpDDCB->HALDDMotionComp.GetInternalMoCompInfo;
  933. if( pfn != NULL )
  934. {
  935. /*
  936. * Get the number of buffer types
  937. */
  938. GetInternalData.lpDD = this_int->lpLcl;
  939. GetInternalData.lpGuid = lpGuid;
  940. GetInternalData.dwWidth= lpUncompInfo->dwUncompWidth;
  941. GetInternalData.dwHeight= lpUncompInfo->dwUncompHeight;
  942. memcpy( &GetInternalData.ddPixelFormat,
  943. &(lpUncompInfo->ddUncompPixelFormat), sizeof( DDPIXELFORMAT ) );
  944. DOHALCALL( GetInternalMoCompInfo, pfn, GetInternalData, rc, 0 );
  945. if( DDHAL_DRIVER_HANDLED != rc )
  946. {
  947. LEAVE_DDRAW();
  948. return GetInternalData.ddRVal;
  949. }
  950. else if( DD_OK != GetInternalData.ddRVal )
  951. {
  952. LEAVE_DDRAW();
  953. return GetInternalData.ddRVal;
  954. }
  955. lpMemInfo->dwScratchMemAlloc = GetInternalData.dwScratchMemAlloc;
  956. }
  957. LEAVE_DDRAW();
  958. return DD_OK;
  959. } /* DDMCC_GetInternalMemInfo */
  960. /*
  961. * DD_MC_BeginFrame
  962. */
  963. HRESULT DDAPI DD_MC_BeginFrame(LPDIRECTDRAWVIDEOACCELERATOR lpDDMC,
  964. LPDDVABeginFrameInfo lpInfo )
  965. {
  966. LPDDRAWI_DDMOTIONCOMP_INT this_int;
  967. LPDDRAWI_DDMOTIONCOMP_LCL this_lcl;
  968. DDHAL_BEGINMOCOMPFRAMEDATA BeginFrameData;
  969. LPDDHALMOCOMPCB_BEGINFRAME pfn;
  970. DWORD i;
  971. DWORD rc;
  972. ENTER_DDRAW();
  973. DPF(2,A,"ENTERAPI: DD_MC_BeginFrame");
  974. /*
  975. * Validate parameters
  976. */
  977. TRY
  978. {
  979. this_int = (LPDDRAWI_DDMOTIONCOMP_INT) lpDDMC;
  980. if( !VALID_DDMOTIONCOMP_PTR( this_int ) )
  981. {
  982. LEAVE_DDRAW();
  983. return DDERR_INVALIDOBJECT;
  984. }
  985. this_lcl = this_int->lpLcl;
  986. if( ( lpInfo == NULL ) || !VALID_BYTE_ARRAY( lpInfo, sizeof( DDVABeginFrameInfo ) ) )
  987. {
  988. DPF_ERR ( "DD_MC_BeginFrame: invalid structure passed in");
  989. LEAVE_DDRAW();
  990. return DDERR_INVALIDPARAMS;
  991. }
  992. if( ( lpInfo->pddDestSurface == NULL ) ||
  993. !VALID_DIRECTDRAWSURFACE_PTR( ((LPDDRAWI_DDRAWSURFACE_INT)lpInfo->pddDestSurface) ) )
  994. {
  995. DPF_ERR ( "DD_MC_BeginFrame: invalid dest surface specified");
  996. LEAVE_DDRAW();
  997. return DDERR_INVALIDPARAMS;
  998. }
  999. if( lpInfo->dwSizeInputData > 0 )
  1000. {
  1001. if( ( lpInfo->pInputData == NULL ) ||
  1002. !VALID_BYTE_ARRAY( lpInfo->pInputData, lpInfo->dwSizeInputData ) )
  1003. {
  1004. DPF_ERR ( "DD_MC_BeginFrame: invalid lpInputData passed in");
  1005. LEAVE_DDRAW();
  1006. return DDERR_INVALIDPARAMS;
  1007. }
  1008. }
  1009. if( lpInfo->dwSizeOutputData > 0 )
  1010. {
  1011. if( ( lpInfo->pOutputData == NULL ) ||
  1012. !VALID_BYTE_ARRAY( lpInfo->pOutputData, lpInfo->dwSizeOutputData ) )
  1013. {
  1014. DPF_ERR ( "DD_MC_BeginFrame: invalid lpOutputData passed in");
  1015. LEAVE_DDRAW();
  1016. return DDERR_INVALIDPARAMS;
  1017. }
  1018. }
  1019. }
  1020. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  1021. {
  1022. DPF_ERR( "Exception encountered validating parameters" );
  1023. LEAVE_DDRAW();
  1024. return DDERR_EXCEPTION;
  1025. }
  1026. /*
  1027. * Call the HAL
  1028. */
  1029. pfn = this_lcl->lpDD->lpDDCB->HALDDMotionComp.BeginMoCompFrame;
  1030. if( pfn != NULL )
  1031. {
  1032. BeginFrameData.lpDD = this_lcl->lpDD;
  1033. BeginFrameData.lpMoComp = this_lcl;
  1034. BeginFrameData.lpDestSurface = ((LPDDRAWI_DDRAWSURFACE_INT)lpInfo->pddDestSurface)->lpLcl;
  1035. BeginFrameData.dwInputDataSize = lpInfo->dwSizeInputData;
  1036. BeginFrameData.lpInputData = BeginFrameData.dwInputDataSize == 0 ? NULL : lpInfo->pInputData;
  1037. BeginFrameData.dwOutputDataSize = lpInfo->dwSizeOutputData;
  1038. BeginFrameData.lpOutputData = BeginFrameData.dwOutputDataSize == 0 ? NULL : lpInfo->pOutputData;
  1039. DOHALCALL( BeginMoCompFrame, pfn, BeginFrameData, rc, 0 );
  1040. if( DDHAL_DRIVER_HANDLED != rc )
  1041. {
  1042. LEAVE_DDRAW();
  1043. return DDERR_UNSUPPORTED;
  1044. }
  1045. if( BeginFrameData.ddRVal == DD_OK )
  1046. {
  1047. if( BeginFrameData.dwOutputDataSize > 0 )
  1048. {
  1049. lpInfo->dwSizeOutputData = BeginFrameData.dwOutputDataSize;
  1050. }
  1051. }
  1052. }
  1053. else
  1054. {
  1055. LEAVE_DDRAW();
  1056. return DDERR_UNSUPPORTED;
  1057. }
  1058. LEAVE_DDRAW();
  1059. return BeginFrameData.ddRVal;
  1060. }
  1061. /*
  1062. * DD_MC_EndFrame
  1063. */
  1064. HRESULT DDAPI DD_MC_EndFrame(LPDIRECTDRAWVIDEOACCELERATOR lpDDMC,
  1065. LPDDVAEndFrameInfo lpInfo )
  1066. {
  1067. LPDDRAWI_DDMOTIONCOMP_INT this_int;
  1068. LPDDRAWI_DDMOTIONCOMP_LCL this_lcl;
  1069. DDHAL_ENDMOCOMPFRAMEDATA EndFrameData;
  1070. LPDDHALMOCOMPCB_ENDFRAME pfn;
  1071. DWORD rc;
  1072. ENTER_DDRAW();
  1073. DPF(2,A,"ENTERAPI: DD_MC_EndFrame");
  1074. /*
  1075. * Validate parameters
  1076. */
  1077. TRY
  1078. {
  1079. this_int = (LPDDRAWI_DDMOTIONCOMP_INT) lpDDMC;
  1080. if( !VALID_DDMOTIONCOMP_PTR( this_int ) )
  1081. {
  1082. LEAVE_DDRAW();
  1083. return DDERR_INVALIDOBJECT;
  1084. }
  1085. this_lcl = this_int->lpLcl;
  1086. if( ( lpInfo == NULL ) || !VALID_BYTE_ARRAY( lpInfo, sizeof( DDVAEndFrameInfo ) ) )
  1087. {
  1088. DPF_ERR ( "DD_MC_EndFrame: invalid structure passed in");
  1089. LEAVE_DDRAW();
  1090. return DDERR_INVALIDPARAMS;
  1091. }
  1092. if( lpInfo->dwSizeMiscData > 0 )
  1093. {
  1094. if( ( lpInfo->pMiscData == NULL ) ||
  1095. !VALID_BYTE_ARRAY( lpInfo->pMiscData, lpInfo->dwSizeMiscData ) )
  1096. {
  1097. DPF_ERR ( "DD_MC_BeginFrame: invalid lpData passed in");
  1098. LEAVE_DDRAW();
  1099. return DDERR_INVALIDPARAMS;
  1100. }
  1101. }
  1102. }
  1103. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  1104. {
  1105. DPF_ERR( "Exception encountered validating parameters" );
  1106. LEAVE_DDRAW();
  1107. return DDERR_EXCEPTION;
  1108. }
  1109. /*
  1110. * Call the HAL
  1111. */
  1112. pfn = this_lcl->lpDD->lpDDCB->HALDDMotionComp.EndMoCompFrame;
  1113. if( pfn != NULL )
  1114. {
  1115. EndFrameData.lpDD = this_lcl->lpDD;
  1116. EndFrameData.lpMoComp = this_lcl;
  1117. EndFrameData.dwInputDataSize = lpInfo->dwSizeMiscData;
  1118. EndFrameData.lpInputData = EndFrameData.dwInputDataSize > 0 ? lpInfo->pMiscData : NULL;
  1119. DOHALCALL( EndMoCompFrame, pfn, EndFrameData, rc, 0 );
  1120. if( DDHAL_DRIVER_HANDLED != rc )
  1121. {
  1122. LEAVE_DDRAW();
  1123. return DDERR_UNSUPPORTED;
  1124. }
  1125. }
  1126. else
  1127. {
  1128. LEAVE_DDRAW();
  1129. return DDERR_UNSUPPORTED;
  1130. }
  1131. LEAVE_DDRAW();
  1132. return EndFrameData.ddRVal;
  1133. }
  1134. /*
  1135. * DD_MC_RenderMacroBlocks
  1136. */
  1137. HRESULT DDAPI DD_MC_RenderMacroBlocks(LPDIRECTDRAWVIDEOACCELERATOR lpDDMC,
  1138. DWORD dwFunction, LPVOID lpInData, DWORD dwInSize, LPVOID lpOutData,
  1139. DWORD dwOutSize, DWORD dwNumBuffers, LPDDVABUFFERINFO lpBuffInfo )
  1140. {
  1141. LPDDRAWI_DDMOTIONCOMP_INT this_int;
  1142. LPDDRAWI_DDMOTIONCOMP_LCL this_lcl;
  1143. DDHAL_RENDERMOCOMPDATA RenderData;
  1144. LPDDHALMOCOMPCB_RENDER pfn;
  1145. LPDDMCBUFFERINFO lpTempArray = NULL;
  1146. LPDDMCBUFFERINFO lpTempDest;
  1147. LPDDVABUFFERINFO lpTempSrc;
  1148. DWORD rc;
  1149. DWORD i;
  1150. ENTER_DDRAW();
  1151. DPF(2,A,"ENTERAPI: DD_MC_RenderMacroBlocks");
  1152. /*
  1153. * Validate parameters
  1154. */
  1155. TRY
  1156. {
  1157. this_int = (LPDDRAWI_DDMOTIONCOMP_INT) lpDDMC;
  1158. if( !VALID_DDMOTIONCOMP_PTR( this_int ) )
  1159. {
  1160. LEAVE_DDRAW();
  1161. return DDERR_INVALIDOBJECT;
  1162. }
  1163. this_lcl = this_int->lpLcl;
  1164. if( dwNumBuffers > 0 )
  1165. {
  1166. if( ( lpBuffInfo== NULL ) ||
  1167. !VALID_BYTE_ARRAY( lpBuffInfo, sizeof( DDVABUFFERINFO) * dwNumBuffers ) )
  1168. {
  1169. DPF_ERR ( "DD_MC_RenderMacroBlocks: invalid buffer pointer passed in");
  1170. LEAVE_DDRAW();
  1171. return DDERR_INVALIDPARAMS;
  1172. }
  1173. if( lpInData == NULL )
  1174. {
  1175. dwInSize = 0;
  1176. }
  1177. else if( !VALID_BYTE_ARRAY( lpInData, dwInSize) )
  1178. {
  1179. DPF_ERR ( "DD_MC_RenderMacroBlocks: invalid input data pointer passed in");
  1180. LEAVE_DDRAW();
  1181. return DDERR_INVALIDPARAMS;
  1182. }
  1183. if( lpOutData == NULL )
  1184. {
  1185. dwOutSize = 0;
  1186. }
  1187. else if( !VALID_BYTE_ARRAY( lpOutData, dwOutSize) )
  1188. {
  1189. DPF_ERR ( "DD_MC_RenderMacroBlocks: invalid output data pointer passed in");
  1190. LEAVE_DDRAW();
  1191. return DDERR_INVALIDPARAMS;
  1192. }
  1193. lpTempArray = LocalAlloc( LPTR, sizeof( DDMCBUFFERINFO ) * dwNumBuffers );
  1194. if( lpTempArray == NULL )
  1195. {
  1196. LEAVE_DDRAW();
  1197. return DDERR_OUTOFMEMORY;
  1198. }
  1199. lpTempSrc = lpBuffInfo;
  1200. lpTempDest = lpTempArray;
  1201. for( i = 0; i < dwNumBuffers; i++)
  1202. {
  1203. if( ( lpTempSrc->pddCompSurface == NULL ) ||
  1204. !VALID_DIRECTDRAWSURFACE_PTR( ((LPDDRAWI_DDRAWSURFACE_INT)lpTempSrc->pddCompSurface) ) )
  1205. {
  1206. if( lpTempArray != NULL )
  1207. {
  1208. LocalFree( lpTempArray );
  1209. }
  1210. DPF_ERR ( "DD_MC_RendermacroBlockse: invalid surface specified");
  1211. LEAVE_DDRAW();
  1212. return DDERR_INVALIDPARAMS;
  1213. }
  1214. lpTempDest->dwSize = lpTempSrc->dwSize;
  1215. lpTempDest->lpCompSurface = ((LPDDRAWI_DDRAWSURFACE_INT)(lpTempSrc->pddCompSurface))->lpLcl;
  1216. lpTempDest->dwDataOffset = lpTempSrc->dwDataOffset;
  1217. lpTempDest++->dwDataSize = lpTempSrc++->dwDataSize;
  1218. }
  1219. }
  1220. }
  1221. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  1222. {
  1223. if( lpTempArray != NULL )
  1224. {
  1225. LocalFree( lpTempArray );
  1226. }
  1227. DPF_ERR( "Exception encountered validating parameters" );
  1228. LEAVE_DDRAW();
  1229. return DDERR_EXCEPTION;
  1230. }
  1231. /*
  1232. * Call the HAL
  1233. */
  1234. pfn = this_lcl->lpDD->lpDDCB->HALDDMotionComp.RenderMoComp;
  1235. if( pfn != NULL )
  1236. {
  1237. RenderData.lpDD = this_lcl->lpDD;
  1238. RenderData.lpMoComp = this_lcl;
  1239. RenderData.dwNumBuffers = dwNumBuffers;
  1240. RenderData.lpBufferInfo = lpTempArray;
  1241. RenderData.lpInputData = lpInData;
  1242. RenderData.dwInputDataSize = dwInSize;
  1243. RenderData.lpOutputData = lpOutData;
  1244. RenderData.dwOutputDataSize = dwOutSize;
  1245. RenderData.dwFunction = dwFunction;
  1246. DOHALCALL( RenderMoComp, pfn, RenderData, rc, 0 );
  1247. if( lpTempArray != NULL )
  1248. {
  1249. LocalFree( lpTempArray );
  1250. }
  1251. if( DDHAL_DRIVER_HANDLED != rc )
  1252. {
  1253. LEAVE_DDRAW();
  1254. return DDERR_UNSUPPORTED;
  1255. }
  1256. }
  1257. else
  1258. {
  1259. if( lpTempArray != NULL )
  1260. {
  1261. LocalFree( lpTempArray );
  1262. }
  1263. LEAVE_DDRAW();
  1264. return DDERR_UNSUPPORTED;
  1265. }
  1266. LEAVE_DDRAW();
  1267. return RenderData.ddRVal;
  1268. }
  1269. /*
  1270. * DD_MC_QueryRenderStatus
  1271. */
  1272. HRESULT DDAPI DD_MC_QueryRenderStatus(LPDIRECTDRAWVIDEOACCELERATOR lpDDMC,
  1273. LPDIRECTDRAWSURFACE7 lpSurface, DWORD dwFlags )
  1274. {
  1275. LPDDRAWI_DDMOTIONCOMP_INT this_int;
  1276. LPDDRAWI_DDMOTIONCOMP_LCL this_lcl;
  1277. LPDDRAWI_DDRAWSURFACE_INT surf_int;
  1278. DDHAL_QUERYMOCOMPSTATUSDATA QueryData;
  1279. LPDDHALMOCOMPCB_QUERYSTATUS pfn;
  1280. DWORD rc;
  1281. DWORD i;
  1282. ENTER_DDRAW();
  1283. DPF(2,A,"ENTERAPI: DD_MC_QueryRenderStatus");
  1284. /*
  1285. * Validate parameters
  1286. */
  1287. TRY
  1288. {
  1289. this_int = (LPDDRAWI_DDMOTIONCOMP_INT) lpDDMC;
  1290. if( !VALID_DDMOTIONCOMP_PTR( this_int ) )
  1291. {
  1292. LEAVE_DDRAW();
  1293. return DDERR_INVALIDOBJECT;
  1294. }
  1295. this_lcl = this_int->lpLcl;
  1296. surf_int = (LPDDRAWI_DDRAWSURFACE_INT) lpSurface;
  1297. if( ( surf_int == NULL ) ||
  1298. !VALID_DIRECTDRAWSURFACE_PTR( surf_int ) )
  1299. {
  1300. DPF_ERR("DD_MD_QueryRenderStatus: Invalid surface passed in");
  1301. LEAVE_DDRAW();
  1302. return DDERR_INVALIDPARAMS;
  1303. }
  1304. if( dwFlags & ~(DDMCQUERY_VALID) )
  1305. {
  1306. DPF_ERR("DD_MD_QueryRenderStatus: Invalid flag specified");
  1307. LEAVE_DDRAW();
  1308. return DDERR_INVALIDPARAMS;
  1309. }
  1310. }
  1311. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  1312. {
  1313. DPF_ERR( "Exception encountered validating parameters" );
  1314. LEAVE_DDRAW();
  1315. return DDERR_EXCEPTION;
  1316. }
  1317. /*
  1318. * Call the HAL
  1319. */
  1320. pfn = this_lcl->lpDD->lpDDCB->HALDDMotionComp.QueryMoCompStatus;
  1321. if( pfn != NULL )
  1322. {
  1323. QueryData.lpDD = this_lcl->lpDD;
  1324. QueryData.lpMoComp = this_lcl;
  1325. QueryData.lpSurface = surf_int->lpLcl;
  1326. QueryData.dwFlags = dwFlags;
  1327. DOHALCALL( QueryMoCompStatus, pfn, QueryData, rc, 0 );
  1328. if( DDHAL_DRIVER_HANDLED != rc )
  1329. {
  1330. LEAVE_DDRAW();
  1331. return DDERR_UNSUPPORTED;
  1332. }
  1333. }
  1334. else
  1335. {
  1336. LEAVE_DDRAW();
  1337. return DDERR_UNSUPPORTED;
  1338. }
  1339. LEAVE_DDRAW();
  1340. return QueryData.ddRVal;
  1341. }
  1342. /*
  1343. * ProcessMotionCompCleanup
  1344. *
  1345. * A process is done, clean up any motion comp objects that it may
  1346. * still exist.
  1347. *
  1348. * NOTE: we enter with a lock taken on the DIRECTDRAW object.
  1349. */
  1350. void ProcessMotionCompCleanup( LPDDRAWI_DIRECTDRAW_GBL pdrv, DWORD pid, LPDDRAWI_DIRECTDRAW_LCL pdrv_lcl )
  1351. {
  1352. LPDDRAWI_DDMOTIONCOMP_INT pmc_int;
  1353. LPDDRAWI_DDMOTIONCOMP_LCL pmc_lcl;
  1354. LPDDRAWI_DDMOTIONCOMP_INT pmcnext_int;
  1355. DWORD rcnt;
  1356. ULONG rc;
  1357. /*
  1358. * run through all motion comp objects owned by the driver object, and find ones
  1359. * that have been accessed by this process. If the pdrv_lcl parameter
  1360. * is non-null, only delete motion comp objects created by that local driver object.
  1361. */
  1362. pmc_int = pdrv->mcList;
  1363. DPF( 4, "ProcessMotionCompCleanup" );
  1364. while( pmc_int != NULL )
  1365. {
  1366. pmc_lcl = pmc_int->lpLcl;
  1367. pmcnext_int = pmc_int->lpLink;
  1368. rc = 1;
  1369. if( ( pmc_lcl->dwProcessId == pid ) &&
  1370. ( (NULL == pdrv_lcl) || (pmc_lcl->lpDD == pdrv_lcl) ) )
  1371. {
  1372. /*
  1373. * release the references by this process
  1374. */
  1375. rcnt = pmc_int->dwIntRefCnt;
  1376. DPF( 5, "Process %08lx had %ld accesses to motion comp %08lx", pid, rcnt, pmc_int );
  1377. while( rcnt > 0 )
  1378. {
  1379. rc = DD_MC_Release( (LPDIRECTDRAWVIDEOACCELERATOR) pmc_int );
  1380. pmcnext_int = pdrv->mcList;
  1381. if( rc == 0 )
  1382. {
  1383. break;
  1384. }
  1385. rcnt--;
  1386. }
  1387. }
  1388. else
  1389. {
  1390. DPF( 5, "Process %08lx had no accesses to motion comp object %08lx", pid, pmc_int );
  1391. }
  1392. pmc_int = pmcnext_int;
  1393. }
  1394. DPF( 4, "Leaving ProcessMotionCompCleanup");
  1395. } /* ProcessMotionCompCleanup */