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.

1375 lines
42 KiB

  1. /***************************************************************************
  2. *
  3. * ******************************************
  4. * * Copyright (c) 1996, Cirrus Logic, Inc. *
  5. * * All Rights Reserved *
  6. * ******************************************
  7. *
  8. * PROJECT: Laguna I (CL-GD546x) -
  9. *
  10. * FILE: ddsurf.c
  11. *
  12. * AUTHOR: Benny Ng
  13. *
  14. * DESCRIPTION:
  15. * This module implements the DirectDraw SURFACE
  16. * components for the Laguna NT driver.
  17. *
  18. * MODULES:
  19. * DdLock()
  20. * DdUnlock()
  21. * CanCreateSurface()
  22. * CreateSurface()
  23. * DestroySurface()
  24. *
  25. * REVISION HISTORY:
  26. * 7/12/96 Benny Ng Initial version
  27. *
  28. * $Log: X:/log/laguna/nt35/displays/cl546x/ddsurf.c $
  29. *
  30. * Rev 1.25 May 01 1998 11:33:02 frido
  31. * Added one more check for PC98.
  32. *
  33. * Rev 1.24 May 01 1998 11:07:24 frido
  34. * Finally the programmable blitter stride works.
  35. *
  36. * Rev 1.23 Mar 30 1998 13:04:38 frido
  37. * Added one more call to Set256ByteFetch if an overlay failed to be created.
  38. *
  39. * Rev 1.22 Mar 25 1998 18:09:44 frido
  40. * PDR#11184. Finally. When overlays are turned on, 256-byte fetch
  41. * should be turned off. And when overlays are turned off again, 256-byte
  42. * fetch should be restored.
  43. *
  44. * Rev 1.21 17 Oct 1997 11:29:48 bennyn
  45. * Clear dwReserved1 after DestroySurface.
  46. *
  47. * Rev 1.20 16 Oct 1997 09:52:56 bennyn
  48. *
  49. * Fixed the FlipCube FPS exceed refresh rate problem
  50. *
  51. * Rev 1.19 08 Oct 1997 11:29:38 RUSSL
  52. * Fix so this file can be compiled without OVERLAY defined
  53. *
  54. * Rev 1.18 26 Sep 1997 11:01:14 bennyn
  55. * Fixed PDR 10563
  56. *
  57. * Rev 1.17 16 Sep 1997 15:13:46 bennyn
  58. * Added DD overlay support.
  59. *
  60. * Rev 1.16 03 Sep 1997 17:00:48 bennyn
  61. * In CreateSurface() punts the request if at 320x240x8 or 320x200x8
  62. *
  63. ****************************************************************************
  64. ****************************************************************************/
  65. /*----------------------------- INCLUDES ----------------------------------*/
  66. #include "precomp.h"
  67. #include <clioctl.h>
  68. //
  69. // This file isn't used in NT 3.51
  70. //
  71. #ifndef WINNT_VER35
  72. /*----------------------------- DEFINES -----------------------------------*/
  73. //#define DBGBRK
  74. #define DBGLVL 1
  75. /*--------------------- STATIC FUNCTION PROTOTYPES ------------------------*/
  76. #if DRIVER_5465 && defined(OVERLAY)
  77. VOID GetFormatInfo (LPDDPIXELFORMAT lpFormat, LPDWORD lpFourcc, LPDWORD lpBitCount);
  78. #endif
  79. /*--------------------------- ENUMERATIONS --------------------------------*/
  80. /*----------------------------- TYPEDEFS ----------------------------------*/
  81. /*-------------------------- STATIC VARIABLES -----------------------------*/
  82. /*-------------------------- GLOBAL FUNCTIONS -----------------------------*/
  83. #if DRIVER_5465 // PDR#11184
  84. VOID Set256ByteFetch(PPDEV ppdev, BOOL fEnable)
  85. {
  86. ULONG ulStall = 50 * 1000;
  87. ULONG ulReturn;
  88. while (LLDR_SZ(grSTATUS) != 0) ; // Wait for idle chip.
  89. while (LLDR_SZ(grQFREE) != 25) ; // Wait for empty FIFO queue.
  90. if (!DEVICE_IO_CTRL(ppdev->hDriver, // Wait for 50 ms.
  91. IOCTL_STALL,
  92. &ulStall, sizeof(ulStall),
  93. NULL, 0,
  94. &ulReturn,
  95. NULL))
  96. {
  97. RIP(_DISP_ "Set256ByteFetch - IOCTL_STALL failed!\n");
  98. }
  99. if (fEnable)
  100. {
  101. // Restore the CONTROL2 register value.
  102. LL16(grCONTROL2, ppdev->DriverData.dwCONTROL2Save);
  103. }
  104. else
  105. {
  106. // Disable 256-byte fetch after storing the current value.
  107. ppdev->DriverData.dwCONTROL2Save = LLDR_SZ(grCONTROL2);
  108. LL16(grCONTROL2, ppdev->DriverData.dwCONTROL2Save & ~0x0010);
  109. }
  110. }
  111. #endif
  112. /****************************************************************************
  113. * FUNCTION NAME: DdLock
  114. *
  115. * DESCRIPTION: This callback is invoked whenever a surface is about
  116. * to be directly accessed by the user. This is where you
  117. * need to make sure that a surface can be safely accessed
  118. * by the user.
  119. * If your memory cannot be accessed while in accelerator
  120. * mode, you should take either take the card out of
  121. * accelerator mode or else return DDERR_SURFACEBUSY
  122. * If someone is accessing a surface that was just flipped
  123. * away from, make sure that the old surface (what was the
  124. * primary) has finished being displayed.
  125. * (Based on Laguna Win95 DirectDraw code)
  126. ****************************************************************************/
  127. DWORD DdLock(PDD_LOCKDATA lpLock)
  128. {
  129. #ifdef RDRAM_8BIT
  130. RECTL SrcRectl;
  131. #endif
  132. DRIVERDATA* pDriverData;
  133. PDEV* ppdev;
  134. HRESULT ddrval;
  135. DWORD tmp;
  136. DISPDBG((DBGLVL, "DDraw - DdLock\n"));
  137. #ifdef DBGBRK
  138. DBGBREAKPOINT();
  139. #endif
  140. ppdev = (PDEV*) lpLock->lpDD->dhpdev;
  141. pDriverData = (DRIVERDATA*) &ppdev->DriverData;
  142. SYNC_W_3D(ppdev);
  143. #if DRIVER_5465 && defined(OVERLAY)
  144. if (DDSCAPS_OVERLAY & lpLock->lpDDSurface->ddsCaps.dwCaps)
  145. {
  146. ppdev->dwDDLinearCnt++;
  147. return pDriverData->OverlayTable.pfnLock(ppdev, lpLock);
  148. }
  149. #endif
  150. #ifdef RDRAM_8BIT
  151. if (lpLock->lpDDSurface->lpGbl->ddpfSurface.dwFlags & DDPF_FOURCC)
  152. {
  153. if (lpLock->bHasRect)
  154. SrcRectl = lpLock->rArea;
  155. else
  156. {
  157. tmp = lpLock->lpDDSurface->lpGbl->fpVidMem;
  158. SrcRectl.top = cvlxy(ppdev->lDeltaScreen, tmp, BYTESPERPIXEL);
  159. SrcRectl.left = SrcRectl.top & 0xFFFF;
  160. SrcRectl.top = (SrcRectl.top >> 16) & 0xFFFF;
  161. SrcRectl.bottom = SrcRectl.top + lpLock->lpDDSurface->lpGbl->wHeight;
  162. SrcRectl.right = SrcRectl.left + lpLock->lpDDSurface->lpGbl->wWidth;
  163. };
  164. ppdev->offscr_YUV.nInUse = TRUE;
  165. ppdev->offscr_YUV.SrcRect = SrcRectl;
  166. ppdev->offscr_YUV.ratio = 0;
  167. lpLock->lpDDSurface->lpGbl->dwReserved1 = 0;
  168. };
  169. #endif
  170. // get the monitor frequency after a mode reset
  171. if (pDriverData->fReset)
  172. {
  173. vGetDisplayDuration(&ppdev->flipRecord);
  174. pDriverData->fReset = FALSE;
  175. };
  176. // Check to see if any pending physical flip has occurred.
  177. // Don't allow a lock if a blt is in progress:
  178. ddrval = vUpdateFlipStatus(&ppdev->flipRecord,
  179. lpLock->lpDDSurface->lpGbl->fpVidMem);
  180. if (ddrval != DD_OK)
  181. {
  182. lpLock->ddRVal = DDERR_WASSTILLDRAWING;
  183. return(DDHAL_DRIVER_HANDLED);
  184. };
  185. // don't allow a lock if a blt is in progress
  186. // (only do this if your hardware requires it)
  187. // Note: GD5462 requires it. Blitter and screen
  188. // access are not otherwise synchronized.
  189. if ((ppdev->dwDDLinearCnt == 0) && (DrawEngineBusy(pDriverData)))
  190. {
  191. lpLock->ddRVal = DDERR_WASSTILLDRAWING;
  192. return DDHAL_DRIVER_HANDLED;
  193. };
  194. // Reference count it, just for the heck of it:
  195. ppdev->dwDDLinearCnt++;
  196. return(DDHAL_DRIVER_NOTHANDLED);
  197. } // Lock
  198. /****************************************************************************
  199. * FUNCTION NAME: DdUnlock
  200. *
  201. * DESCRIPTION:
  202. ****************************************************************************/
  203. DWORD DdUnlock(PDD_UNLOCKDATA lpUnlock)
  204. {
  205. PDEV* ppdev = (PDEV*) lpUnlock->lpDD->dhpdev;
  206. DISPDBG((DBGLVL, "DDraw - DdUnlock\n"));
  207. #if DRIVER_5465 && defined(OVERLAY)
  208. if (DDSCAPS_OVERLAY & lpUnlock->lpDDSurface->ddsCaps.dwCaps)
  209. ppdev->DriverData.OverlayTable.pfnUnlock(ppdev,lpUnlock);
  210. #endif
  211. #ifdef DBGBRK
  212. DBGBREAKPOINT();
  213. #endif
  214. ppdev->dwDDLinearCnt--;
  215. return DDHAL_DRIVER_NOTHANDLED;
  216. } // Unlock
  217. /****************************************************************************
  218. * FUNCTION NAME: CanCreateSurface
  219. *
  220. * DESCRIPTION:
  221. * (Based on Laguna Win95 DirectDraw code)
  222. ****************************************************************************/
  223. DWORD CanCreateSurface (PDD_CANCREATESURFACEDATA lpInput)
  224. {
  225. DRIVERDATA* pDriverData;
  226. PDEV* ppdev;
  227. DISPDBG((DBGLVL, "DDraw - CanCreateSurface\n"));
  228. #ifdef DBGBRK
  229. DBGBREAKPOINT();
  230. #endif
  231. ppdev = (PDEV*) lpInput->lpDD->dhpdev;
  232. pDriverData = (DRIVERDATA*) &ppdev->DriverData;
  233. // First check for overlay surfaces
  234. if (lpInput->lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_OVERLAY)
  235. {
  236. #if DRIVER_5465 && defined(OVERLAY)
  237. if (DDSCAPS_OVERLAY & lpInput->lpDDSurfaceDesc->ddsCaps.dwCaps)
  238. {
  239. DWORD dwFourCC;
  240. DWORD dwBitCount;
  241. HRESULT hr;
  242. if (lpInput->bIsDifferentPixelFormat)
  243. {
  244. GetFormatInfo(&(lpInput->lpDDSurfaceDesc->ddpfPixelFormat),
  245. &dwFourCC, &dwBitCount);
  246. }
  247. else
  248. {
  249. dwBitCount = BITSPERPIXEL;
  250. if (16 == dwBitCount)
  251. dwFourCC = BI_BITFIELDS;
  252. else
  253. dwFourCC = BI_RGB;
  254. }
  255. hr = pDriverData->OverlayTable.pfnCanCreateSurface(ppdev,dwFourCC,dwBitCount);
  256. if (DD_OK != hr)
  257. {
  258. lpInput->ddRVal = hr;
  259. return DDHAL_DRIVER_HANDLED;
  260. }
  261. }
  262. #else
  263. lpInput->ddRVal = DDERR_NOOVERLAYHW;;
  264. return (DDHAL_DRIVER_HANDLED);
  265. #endif
  266. }
  267. else if (lpInput->bIsDifferentPixelFormat)
  268. {
  269. // Next check for formats that don't match the primary surface.
  270. LPDDPIXELFORMAT lpFormat = &lpInput->lpDDSurfaceDesc->ddpfPixelFormat;
  271. if (lpFormat->dwFlags & DDPF_FOURCC)
  272. {
  273. // YUV422 surface
  274. if (lpFormat->dwFourCC == FOURCC_UYVY)
  275. {
  276. #if DRIVER_5465
  277. if (ppdev->iBitmapFormat == BMF_8BPP)
  278. lpInput->ddRVal = DDERR_INVALIDPIXELFORMAT;
  279. else
  280. lpInput->ddRVal = DD_OK;
  281. return (DDHAL_DRIVER_HANDLED);
  282. #else // 5462 and 5464 driver
  283. #if _WIN32_WINNT >= 0x0500
  284. // For NT5 do not allow any YUV surfaces that are not
  285. // overlays.
  286. ;
  287. #else // NT4
  288. // if we have nine bit RDRAMs then surface creation is okay
  289. if (TRUE == pDriverData->fNineBitRDRAMS)
  290. {
  291. lpInput->ddRVal = DD_OK;
  292. return (DDHAL_DRIVER_HANDLED);
  293. }
  294. // if we have eight bit RDRAMs then see if already
  295. // have a YUV422 surface
  296. else if (FALSE == ppdev->offscr_YUV.nInUse)
  297. {
  298. lpInput->ddRVal = DD_OK;
  299. return (DDHAL_DRIVER_HANDLED);
  300. };
  301. #endif
  302. #endif // DRIVER_5465
  303. }; // endif (lpFormat->dwFourCC == FOURCC_UYVY)
  304. }
  305. else
  306. {
  307. // support RGB565 with RGB8 primary surface !!!
  308. }; // endif (lpFormat->dwFlags & DDPF_FOURCC)
  309. lpInput->ddRVal = DDERR_INVALIDPIXELFORMAT;
  310. return (DDHAL_DRIVER_HANDLED);
  311. }; // endif (lpInput->lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_OVERLAY)
  312. lpInput->ddRVal = DD_OK;
  313. return (DDHAL_DRIVER_HANDLED);
  314. } // CanCreateSurface
  315. /****************************************************************************
  316. * FUNCTION NAME: InsertInDDOFSQ()
  317. *
  318. * DESCRIPTION: Insert the handle into the DD Offscreen memory queue.
  319. ****************************************************************************/
  320. void InsertInDDOFSQ(PPDEV ppdev, DDOFM *hdl)
  321. {
  322. hdl->prevhdl = NULL;
  323. if (ppdev->DDOffScnMemQ == NULL)
  324. {
  325. hdl->nexthdl = NULL;
  326. ppdev->DDOffScnMemQ = hdl;
  327. }
  328. else
  329. {
  330. ppdev->DDOffScnMemQ->prevhdl = hdl;
  331. hdl->nexthdl = ppdev->DDOffScnMemQ;
  332. ppdev->DDOffScnMemQ = hdl;
  333. };
  334. } // InsertInDDOFSQ()
  335. /****************************************************************************
  336. * FUNCTION NAME: RemoveFrmDDOFSQ()
  337. *
  338. * DESCRIPTION: Remove the handle from the DD Offscreen memory queue.
  339. ****************************************************************************/
  340. BOOL RemoveFrmDDOFSQ(PPDEV ppdev, DDOFM *hdl)
  341. {
  342. DDOFM *prvpds, *nxtpds;
  343. DDOFM *pds;
  344. BOOL fndflg;
  345. // Validate the release block
  346. fndflg = FALSE;
  347. pds = ppdev->DDOffScnMemQ;
  348. while (pds != 0)
  349. {
  350. if (hdl == pds)
  351. {
  352. fndflg = TRUE;
  353. break;
  354. };
  355. // Next free block
  356. pds = pds->nexthdl;
  357. }; // end while
  358. // Return if it is an invalid handle
  359. if (!fndflg)
  360. return (FALSE);
  361. prvpds = hdl->prevhdl;
  362. nxtpds = hdl->nexthdl;
  363. if (hdl == ppdev->DDOffScnMemQ)
  364. {
  365. ppdev->DDOffScnMemQ = nxtpds;
  366. if (nxtpds != 0)
  367. nxtpds->prevhdl = NULL;
  368. }
  369. else
  370. {
  371. if (nxtpds != NULL)
  372. nxtpds->prevhdl = prvpds;
  373. if (prvpds != NULL)
  374. prvpds->nexthdl = nxtpds;
  375. };
  376. // Free allocated DDOFM structure from host memory
  377. MEMORY_FREE(hdl);
  378. return (TRUE);
  379. } // RemoveFrmDDOFSQ()
  380. /****************************************************************************
  381. * FUNCTION NAME: CreateSurface
  382. *
  383. * DESCRIPTION:
  384. * (Based on Laguna Win95 DirectDraw code)
  385. ****************************************************************************/
  386. DWORD CreateSurface (PDD_CREATESURFACEDATA lpInput)
  387. {
  388. BOOL puntflag = FALSE;
  389. BOOL bYUVsurf;
  390. #if DRIVER_5465 && defined(OVERLAY)
  391. BOOL bOverlaySurf;
  392. #endif // #if DRIVER_5465 && defined(OVERLAY)
  393. DRIVERDATA* pDriverData;
  394. PDEV* ppdev;
  395. LPDDSURFACEDESC lpDDSurfaceDesc = lpInput->lpDDSurfaceDesc;
  396. LPDDPIXELFORMAT lpFormat = &lpInput->lpDDSurfaceDesc->ddpfPixelFormat;
  397. DWORD dwPitch = 0;
  398. DISPDBG((DBGLVL, "DDraw - CreateSurface\n"));
  399. #ifdef DBGBRK
  400. DBGBREAKPOINT();
  401. #endif
  402. ppdev = (PDEV*) lpInput->lpDD->dhpdev;
  403. pDriverData = (DRIVERDATA*) &ppdev->DriverData;
  404. bYUVsurf = FALSE;
  405. #if DRIVER_5465 && defined(OVERLAY)
  406. bOverlaySurf = FALSE;
  407. #endif // #if DRIVER_5465 && defined(OVERLAY)
  408. #if DRIVER_5465
  409. #ifdef ALLOC_IN_CREATESURFACE
  410. { // Support for 5465
  411. PDD_SURFACE_LOCAL *lplpSurface;
  412. SIZEL sizl;
  413. OFMHDL *hdl;
  414. DDOFM *pds;
  415. DWORD i;
  416. #if DRIVER_5465 && defined(OVERLAY)
  417. DWORD dwBitCount;
  418. DWORD dwFourCC;
  419. // check for overlay surface
  420. if (lpDDSurfaceDesc->ddsCaps.dwCaps & ( DDSCAPS_OVERLAY
  421. #if DDRAW_COMPAT >= 50
  422. | DDSCAPS_VIDEOPORT
  423. #endif
  424. ))
  425. {
  426. if (lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)
  427. {
  428. GetFormatInfo(&(lpInput->lpDDSurfaceDesc->ddpfPixelFormat),
  429. &dwFourCC, &dwBitCount);
  430. }
  431. else
  432. {
  433. dwFourCC = 0;
  434. dwBitCount = BITSPERPIXEL;
  435. }
  436. #if DDRAW_COMPAT >= 50
  437. if((CL_GD5465 == pDriverData->dwLgVenDevID)
  438. && (DDSCAPS_VIDEOPORT & lpDDSurfaceDesc->ddsCaps.dwCaps))
  439. {
  440. if((lpDDSurfaceDesc->dwWidth * dwBitCount >> 3) >= 2048 )
  441. {
  442. //Surface is too wide for video port
  443. lpInput->ddRVal = DDERR_TOOBIGWIDTH;
  444. return DDHAL_DRIVER_HANDLED;
  445. }
  446. }
  447. #endif
  448. bOverlaySurf = TRUE;
  449. } // end overlay surface handler
  450. else
  451. #endif // #if DRIVER_5465 && defined(OVERLAY)
  452. if (lpInput->lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)
  453. {
  454. // Specify the block size for non-RGB surfaces
  455. if (lpFormat->dwFlags & DDPF_FOURCC)
  456. {
  457. // YUV422 surface
  458. if (lpFormat->dwFourCC == FOURCC_UYVY)
  459. {
  460. bYUVsurf = TRUE;
  461. }; // endif (lpFormat->dwFourCC == FOURCC_UYVY)
  462. }; // endif (lpFormat->dwFlags & DDPF_FOURCC)
  463. } // endif (lpInput->lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)
  464. // Not support 8BPP YUV surface
  465. if (
  466. #if DRIVER_5465 && defined(OVERLAY)
  467. (!bOverlaySurf) &&
  468. #endif // #if DRIVER_5465 && defined(OVERLAY)
  469. ((bYUVsurf) && (8 == BITSPERPIXEL)))
  470. {
  471. lpInput->ddRVal = DDERR_INVALIDPIXELFORMAT;
  472. return DDHAL_DRIVER_HANDLED;
  473. }; // endif (8 == BITSPERPIXEL)
  474. lplpSurface = lpInput->lplpSList;
  475. for (i = 0; i < lpInput->dwSCnt; i++)
  476. {
  477. PDD_SURFACE_LOCAL lpSurface = *lplpSurface;
  478. sizl.cx = lpSurface->lpGbl->wWidth;
  479. sizl.cy = lpSurface->lpGbl->wHeight;
  480. #if 1 // PC98
  481. if ( (lpDDSurfaceDesc->dwFlags == (DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH))
  482. && (lpDDSurfaceDesc->ddsCaps.dwCaps == DDSCAPS_VIDEOMEMORY)
  483. && (lpDDSurfaceDesc->dwHeight == 32 && lpDDSurfaceDesc->dwWidth == 32)
  484. && (sizl.cx == 32 && sizl.cy == 32)
  485. && (lpInput->dwSCnt == 1)
  486. )
  487. {
  488. sizl.cx = min(32 * 32, ppdev->lDeltaScreen / ppdev->iBytesPerPixel);
  489. sizl.cy = (32 * 32) / sizl.cx;
  490. if ( (sizl.cx * sizl.cy) < (32 * 32) )
  491. {
  492. sizl.cy++;
  493. }
  494. dwPitch = 32 * ppdev->iBytesPerPixel;
  495. }
  496. #endif
  497. #if DRIVER_5465 && defined(OVERLAY)
  498. // Adjust the overlay surface request size with pixel format
  499. if (bOverlaySurf)
  500. {
  501. unsigned long OvlyBPP;
  502. if (bYUVsurf)
  503. OvlyBPP = lpSurface->lpGbl->ddpfSurface.dwYUVBitCount/8;
  504. else
  505. OvlyBPP = lpSurface->lpGbl->ddpfSurface.dwRGBBitCount/8;
  506. if (OvlyBPP > BYTESPERPIXEL)
  507. sizl.cx = (sizl.cx * OvlyBPP) / BYTESPERPIXEL;
  508. };
  509. #endif // #if DRIVER_5465 && defined(OVERLAY)
  510. // At certain modes (eg 1280x1024x24), When you runs MOV or AVI from
  511. // desktop, the DD CreateSurface has to punt the request back to DD
  512. // due to no offscreen memmory available. When you hit ALT-ENTER to
  513. // go full screen, the appl swithces to mode (320x240x8 or 320x200x8),
  514. // create DD surfaces and then directly write to the DD surfaces.
  515. // Unfortunely, in those modes the pitch is 640 but the appl assumes
  516. // the pitch is 320 and we got half screen of the imagine.
  517. //
  518. // To fix the problem, just fails the create surface for those
  519. // particule request.
  520. //
  521. puntflag = FALSE;
  522. if (ppdev->iBytesPerPixel == 1)
  523. {
  524. if ((ppdev->cxScreen == 320) && (sizl.cx == 320))
  525. {
  526. if (((ppdev->cyScreen == 240) && (sizl.cy == 240)) ||
  527. ((ppdev->cyScreen == 200) && (sizl.cy == 200)))
  528. {
  529. // Punt the create surface cause FlipCube FPS exceeds the
  530. // refresh rate.
  531. // So in order to bypass the above problem, it is looking for
  532. // bPrevModeDDOutOfVideoMem to be set when create surface fails
  533. // due to out of video memory in the previous mode before
  534. // punting the request.
  535. if (ppdev->bPrevModeDDOutOfVideoMem)
  536. puntflag = TRUE;
  537. };
  538. };
  539. };
  540. if (!puntflag)
  541. {
  542. #if DRIVER_5465 && defined(OVERLAY)
  543. if (bOverlaySurf)
  544. {
  545. hdl = AllocOffScnMem(ppdev, &sizl, EIGHT_BYTES_ALIGN, NULL);
  546. }
  547. else
  548. #endif // #if DRIVER_5465 && defined(OVERLAY)
  549. hdl = AllocOffScnMem(ppdev, &sizl, PIXEL_AlIGN, NULL);
  550. #if 1 // PC98
  551. if (!bOverlaySurf)
  552. #endif
  553. // Somehow when allocate the bottom of the offscreen memory to
  554. // DirectDraw, it hangs the DirectDraw.
  555. // The following is temporary patch fix for the problem
  556. {
  557. BOOL gotit;
  558. ULONG val;
  559. ULONG fpvidmem;
  560. val = ppdev->lTotalMem - 0x20000;
  561. gotit = FALSE;
  562. while ((!gotit) && (hdl != NULL))
  563. {
  564. fpvidmem = (hdl->aligned_y * ppdev->lDeltaScreen) + hdl->aligned_x;
  565. if (fpvidmem > val)
  566. {
  567. pds = (DDOFM *) MEM_ALLOC (FL_ZERO_MEMORY, sizeof(DDOFM), ALLOC_TAG);
  568. if (pds==NULL)
  569. {
  570. FreeOffScnMem(ppdev, hdl);
  571. lpInput->ddRVal = DDERR_OUTOFMEMORY;
  572. return DDHAL_DRIVER_NOTHANDLED;
  573. }
  574. pds->prevhdl = 0;
  575. pds->nexthdl = 0;
  576. pds->phdl = hdl;
  577. InsertInDDOFSQ(ppdev, pds);
  578. hdl = AllocOffScnMem(ppdev, &sizl, PIXEL_AlIGN, NULL);
  579. }
  580. else
  581. {
  582. gotit = TRUE;
  583. };
  584. }; // endwhile
  585. }
  586. lpSurface->dwReserved1 = 0;
  587. if (hdl != NULL)
  588. {
  589. #ifdef WINNT_VER40
  590. if ((pds = (DDOFM *) MEM_ALLOC (FL_ZERO_MEMORY, sizeof(DDOFM), ALLOC_TAG)) != NULL)
  591. #else
  592. if ((pds = (DDOFM *) MEM_ALLOC (LPTR, sizeof(DDOFM))) != NULL)
  593. #endif
  594. {
  595. ppdev->bPrevModeDDOutOfVideoMem = FALSE;
  596. // If pixel format is difference from FB, set the flag
  597. if (lpInput->lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)
  598. {
  599. lpSurface->dwFlags |= DDRAWISURF_HASPIXELFORMAT;
  600. };
  601. // lpSurface->lpGbl->fpVidMem = DDHAL_PLEASEALLOC_BLOCKSIZE;
  602. if (bYUVsurf)
  603. {
  604. lpSurface->lpGbl->ddpfSurface.dwYUVBitCount = 16;
  605. lpSurface->lpGbl->ddpfSurface.dwYBitMask = (DWORD) -1;
  606. lpSurface->lpGbl->ddpfSurface.dwUBitMask = (DWORD) -1;
  607. lpSurface->lpGbl->ddpfSurface.dwVBitMask = (DWORD) -1;
  608. lpSurface->lpGbl->dwBlockSizeX = lpSurface->lpGbl->wWidth;
  609. lpSurface->lpGbl->dwBlockSizeY = lpSurface->lpGbl->wHeight;
  610. lpSurface->dwFlags |= DDRAWISURF_HASPIXELFORMAT;
  611. }; // endif (bYUVsurf)
  612. #if DRIVER_5465 && defined(OVERLAY)
  613. if (bOverlaySurf)
  614. {
  615. #if DDRAW_COMPAT >= 50
  616. if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_OVERLAY)
  617. #endif
  618. {
  619. HRESULT hResult;
  620. #if 1 // PDR#11184
  621. // Finally... When overlays are turned on, 256-byte fetch should be turned off.
  622. if (pDriverData->dwOverlayCount++ == 0)
  623. {
  624. Set256ByteFetch(ppdev, FALSE);
  625. }
  626. #endif
  627. lpSurface->dwReserved1 = (DWORD) pds;
  628. hResult = pDriverData->OverlayTable.pfnCreateSurface(ppdev,
  629. lpSurface,
  630. dwFourCC);
  631. if (DD_OK != hResult)
  632. {
  633. #if 1 // PDR#11184
  634. // Decrement overlay counter and maybe turn 256-byte fetch
  635. // back on.
  636. if (--pDriverData->dwOverlayCount == 0)
  637. {
  638. Set256ByteFetch(ppdev, TRUE);
  639. }
  640. #endif
  641. // Free the allocated offscreen memory
  642. FreeOffScnMem(ppdev, hdl);
  643. // Free allocated DDOFM structure from host memory
  644. MEMORY_FREE(pds);
  645. lpSurface->dwReserved1 = 0;
  646. lpInput->ddRVal = hResult;
  647. return DDHAL_DRIVER_HANDLED;
  648. }
  649. }
  650. // don't need this for NT yet
  651. #if 0
  652. // if the surface width is larger than the display pitch, or
  653. // its a 5465, and a videoport surface wider than 2048 bytes or
  654. // its a CLPL surface
  655. // then convert to a linear allocation
  656. //
  657. // prior to DX5 we never even get called for surfaces wider than
  658. // the display pitch
  659. if ( (FOURCC_YUVPLANAR == dwFourCC)
  660. #if DDRAW_COMPAT >= 50
  661. || (lpSurface->lpGbl->dwBlockSizeX > pDriverData->ScreenPitch)
  662. || ( (CL_GD5465 == pDriverData->dwLgVenDevID)
  663. && (DDSCAPS_VIDEOPORT & lpDDSurfaceDesc->ddsCaps.dwCaps)
  664. && (2048 <= pDriverData->ScreenPitch)
  665. )
  666. #endif
  667. )
  668. {
  669. // fake a linear space in rectangular memory
  670. LP_SURFACE_DATA lpSurfaceData = (LP_SURFACE_DATA)(lpSurface->dwReserved1);
  671. DWORD dwTotalBytes;
  672. DWORD dwNumScanLines;
  673. lpSurfaceData->dwOverlayFlags |= FLG_LINEAR;
  674. // CLPL surfaces need 3/4 of the space an equivalent size
  675. // YUV422 surface would need, the space allocated for the
  676. // Y values is the width * height and the space for the UV
  677. // interleaved values is half again as much. Pad the Y
  678. // region so the UV interleaved data is on a qword boundary
  679. // in aperture 0
  680. if (FOURCC_YUVPLANAR == dwFourCC)
  681. {
  682. // compute space needed for Y values
  683. dwTotalBytes = ((lpSurface->lpGbl->wHeight * lpSurface->lpGbl->wWidth) + 7) & ~7;
  684. // add on space for UV interleaved values
  685. dwTotalBytes += dwTotalBytes / 2;
  686. // CLPL surfaces have pitch same as width
  687. lpSurface->lpGbl->lPitch = lpSurface->lpGbl->wWidth;
  688. }
  689. // the normal case
  690. else
  691. {
  692. dwTotalBytes = lpSurface->lpGbl->dwBlockSizeY *
  693. lpSurface->lpGbl->dwBlockSizeX;
  694. lpSurface->lpGbl->lPitch = lpSurface->lpGbl->dwBlockSizeX;
  695. }
  696. dwNumScanLines = (dwTotalBytes + pDriverData->ScreenPitch - 1) /
  697. pDriverData->ScreenPitch;
  698. lpSurface->lpGbl->dwBlockSizeY = dwNumScanLines;
  699. lpSurface->lpGbl->dwBlockSizeX = pDriverData->ScreenPitch;
  700. if (! pDriverData->fWeAllocDDSurfaces)
  701. {
  702. LOAD_THE_STILL(lpSurface->lpGbl->dwBlockSizeX,
  703. lpSurface->lpGbl->dwBlockSizeY);
  704. }
  705. lpSurface->lpGbl->fpVidMem = DDHAL_PLEASEALLOC_BLOCKSIZE;
  706. }
  707. #endif // if 0
  708. }; // endif (bOverlaySurf)
  709. #endif // #if DRIVER_5465 && defined(OVERLAY)
  710. pds->prevhdl = 0;
  711. pds->nexthdl = 0;
  712. pds->phdl = hdl;
  713. InsertInDDOFSQ(ppdev, pds);
  714. lpSurface->lpGbl->fpVidMem = (hdl->aligned_y * ppdev->lDeltaScreen) +
  715. hdl->aligned_x;
  716. lpSurface->dwReserved1 = (DWORD) pds ;
  717. lpSurface->lpGbl->xHint = hdl->aligned_x/ppdev->iBytesPerPixel;
  718. lpSurface->lpGbl->yHint = hdl->aligned_y;
  719. #if 1 // PC98
  720. if (dwPitch)
  721. {
  722. lpSurface->lpGbl->lPitch = dwPitch;
  723. }
  724. else
  725. #endif
  726. lpSurface->lpGbl->lPitch = ppdev->lDeltaScreen;
  727. #if 1 // PC98
  728. if (dwPitch)
  729. {
  730. lpDDSurfaceDesc->lPitch = dwPitch;
  731. }
  732. else
  733. #endif
  734. lpDDSurfaceDesc->lPitch = ppdev->lDeltaScreen;
  735. lpDDSurfaceDesc->dwFlags |= DDSD_PITCH;
  736. // We handled the creation entirely ourselves, so we have to
  737. // set the return code and return DDHAL_DRIVER_HANDLED:
  738. lpInput->ddRVal = DD_OK;
  739. }
  740. else
  741. {
  742. FreeOffScnMem(ppdev, hdl);
  743. lpInput->ddRVal = DDERR_OUTOFMEMORY;
  744. return DDHAL_DRIVER_NOTHANDLED;
  745. };
  746. }
  747. else
  748. {
  749. ppdev->bPrevModeDDOutOfVideoMem = TRUE;
  750. lpInput->ddRVal = DDERR_OUTOFVIDEOMEMORY;
  751. return DDHAL_DRIVER_NOTHANDLED;
  752. // lpSurface->lpGbl->lPitch = (ppdev->iBytesPerPixel * sizl.cx + 3) & ~3;
  753. // lpSurface->lpGbl->dwUserMemSize = lpSurface->lpGbl->lPitch * sizl.cy;
  754. // if (bYUVsurf)
  755. // lpSurface->lpGbl->fpVidMem |= DDHAL_PLEASEALLOC_USERMEM;
  756. }; // if (hdl != NULL)
  757. } // endif (puntflag)
  758. lplpSurface++;
  759. }; // endfor
  760. if (puntflag)
  761. {
  762. lpInput->ddRVal = DDERR_GENERIC;
  763. return DDHAL_DRIVER_HANDLED;
  764. };
  765. if (hdl != NULL)
  766. {
  767. lpInput->ddRVal = DD_OK;
  768. return DDHAL_DRIVER_HANDLED;
  769. }
  770. else
  771. {
  772. return DDHAL_DRIVER_NOTHANDLED;
  773. };
  774. }; // // Support for 5465
  775. #endif // ALLOC_IN_CREATESURFACE
  776. #else
  777. { // Support for 5462 or 5464
  778. // Do nothing except fill in the block size for YUV surfaces.
  779. // We tag and count the video surfaces in Blt32.
  780. if (lpInput->lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)
  781. {
  782. // only support alternate pixel format in 8 & 16 bpp frame buffers
  783. if ((8 != BITSPERPIXEL) && (16 != BITSPERPIXEL))
  784. {
  785. lpInput->ddRVal = DDERR_INVALIDPIXELFORMAT;
  786. return DDHAL_DRIVER_HANDLED;
  787. };
  788. // Specify the block size for non-RGB surfaces
  789. if (lpFormat->dwFlags & DDPF_FOURCC)
  790. {
  791. #if _WIN32_WINNT >= 0x0500
  792. // For NT5, do not allow any YUV surfaces for 5462 and 5464
  793. lpInput->ddRVal = DDERR_INVALIDPIXELFORMAT;
  794. return DDHAL_DRIVER_HANDLED;
  795. #endif
  796. // YUV422 surface
  797. if (lpFormat->dwFourCC == FOURCC_UYVY)
  798. {
  799. PDD_SURFACE_LOCAL *lplpSurface;
  800. unsigned int i;
  801. GRAB_VIDEO_FORMAT_SEMAPHORE(&(pDriverData->VideoSemaphore));
  802. if (0 == pDriverData->NumVideoSurfaces)
  803. {
  804. // no video surfaces so we can create anu format we want
  805. pDriverData->NumVideoSurfaces += (WORD)lpInput->dwSCnt;
  806. pDriverData->CurrentVideoFormat &= 0xFF00;
  807. pDriverData->CurrentVideoFormat |= FMT_VID_16BPP | FMT_VID_YUV422;
  808. if (2 == BYTESPERPIXEL)
  809. {
  810. pDriverData->CurrentVideoFormat |= FMT_VID_GAMMA;
  811. SetGamma(ppdev, pDriverData);
  812. };
  813. ppdev->grFORMAT = (ppdev->grFORMAT & 0xFF00) |
  814. (pDriverData->CurrentVideoFormat & 0x00FF);
  815. LL16(grFormat, ppdev->grFORMAT);
  816. if (TRUE == pDriverData->fNineBitRDRAMS)
  817. {
  818. LL8(grStop_BLT_2, ENABLE_VIDEO_FORMAT);
  819. LL8(grExternal_Overlay, ENABLE_RAMBUS_9TH_BIT);
  820. }
  821. else // 8 bit RDRAMs
  822. {
  823. LL8(grStart_BLT_2, ENABLE_VIDEO_FORMAT | ENABLE_VIDEO_WINDOW);
  824. LL8(grStop_BLT_2, ENABLE_VIDEO_FORMAT | ENABLE_VIDEO_WINDOW);
  825. };
  826. }
  827. else
  828. {
  829. if ((FMT_VID_16BPP | FMT_VID_YUV422) == pDriverData->CurrentVideoFormat)
  830. {
  831. pDriverData->NumVideoSurfaces += (WORD)lpInput->dwSCnt;
  832. }
  833. else
  834. {
  835. UNGRAB_VIDEO_FORMAT_SEMAPHORE(&(pDriverData->VideoSemaphore));
  836. lpInput->ddRVal = DDERR_CURRENTLYNOTAVAIL;
  837. return DDHAL_DRIVER_HANDLED;
  838. };
  839. }; // endif (0 == pDriverData->NumVideoSurfaces)
  840. UNGRAB_VIDEO_FORMAT_SEMAPHORE(&(pDriverData->VideoSemaphore));
  841. SET_DRVSEM_YUV();
  842. ppdev->bYUVSurfaceOn = TRUE;
  843. bYUVsurf = TRUE;
  844. // They may have specified multiple surfaces
  845. lplpSurface = lpInput->lplpSList;
  846. for (i = 0; i < lpInput->dwSCnt; i++)
  847. {
  848. PDD_SURFACE_LOCAL lpSurface = *lplpSurface;
  849. lpSurface->lpGbl->ddpfSurface.dwYUVBitCount = 16;
  850. lpSurface->lpGbl->ddpfSurface.dwYBitMask = (DWORD) -1;
  851. lpSurface->lpGbl->ddpfSurface.dwUBitMask = (DWORD) -1;
  852. lpSurface->lpGbl->ddpfSurface.dwVBitMask = (DWORD) -1;
  853. lpSurface->lpGbl->lPitch = ppdev->lDeltaScreen;
  854. if (CL_GD5462 == ppdev->dwLgDevID)
  855. lpSurface->lpGbl->dwBlockSizeX = lpSurface->lpGbl->wWidth << 1;
  856. else
  857. lpSurface->lpGbl->dwBlockSizeX = lpSurface->lpGbl->wWidth * 3;
  858. lpSurface->lpGbl->dwBlockSizeY = lpSurface->lpGbl->wHeight;
  859. lpSurface->lpGbl->fpVidMem = DDHAL_PLEASEALLOC_BLOCKSIZE;
  860. lplpSurface++;
  861. }; // endfor
  862. }; // endif (lpFormat->dwFourCC == FOURCC_UYVY)
  863. }; // endif (lpFormat->dwFlags & DDPF_FOURCC)
  864. } // endif (lpInput->lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)
  865. #ifdef ALLOC_IN_CREATESURFACE
  866. {
  867. PDD_SURFACE_LOCAL *lplpSurface;
  868. SIZEL sizl;
  869. OFMHDL *hdl;
  870. DDOFM *pds;
  871. DWORD i;
  872. hdl = NULL;
  873. lplpSurface = lpInput->lplpSList;
  874. for (i = 0; i < lpInput->dwSCnt; i++)
  875. {
  876. PDD_SURFACE_LOCAL lpSurface = *lplpSurface;
  877. if (bYUVsurf)
  878. {
  879. sizl.cx = lpSurface->lpGbl->dwBlockSizeX/ppdev->iBytesPerPixel;
  880. sizl.cy = lpSurface->lpGbl->dwBlockSizeY;
  881. lpSurface->dwFlags |= DDRAWISURF_HASPIXELFORMAT;
  882. }
  883. else
  884. {
  885. sizl.cx = lpSurface->lpGbl->wWidth;
  886. sizl.cy = lpSurface->lpGbl->wHeight;
  887. };
  888. hdl = AllocOffScnMem(ppdev, &sizl, PIXEL_AlIGN, NULL);
  889. // Somehow when allocate the bottom of the offscreen memory to
  890. // DirectDraw, it hangs the DirectDraw.
  891. // The following is temporary patch fix for the problem
  892. {
  893. BOOL gotit;
  894. ULONG val;
  895. ULONG fpvidmem;
  896. val = ppdev->lTotalMem - 0x20000;
  897. gotit = FALSE;
  898. while ((!gotit) && (hdl != NULL))
  899. {
  900. fpvidmem = (hdl->aligned_y * ppdev->lDeltaScreen) + hdl->aligned_x;
  901. if (fpvidmem > val)
  902. {
  903. pds = (DDOFM *) MEM_ALLOC (FL_ZERO_MEMORY, sizeof(DDOFM), ALLOC_TAG);
  904. if (pds==NULL)
  905. {
  906. FreeOffScnMem(ppdev, hdl);
  907. lpInput->ddRVal = DDERR_OUTOFMEMORY;
  908. return DDHAL_DRIVER_NOTHANDLED;
  909. }
  910. pds->prevhdl = 0;
  911. pds->nexthdl = 0;
  912. pds->phdl = hdl;
  913. InsertInDDOFSQ(ppdev, pds);
  914. hdl = AllocOffScnMem(ppdev, &sizl, PIXEL_AlIGN, NULL);
  915. }
  916. else
  917. {
  918. gotit = TRUE;
  919. };
  920. }; // endwhile
  921. }
  922. lpSurface->dwReserved1 = 0;
  923. if (hdl != NULL)
  924. {
  925. #ifdef WINNT_VER40
  926. if ((pds = (DDOFM *) MEM_ALLOC (FL_ZERO_MEMORY, sizeof(DDOFM), ALLOC_TAG)) != NULL)
  927. #else
  928. if ((pds = (DDOFM *) MEM_ALLOC (LPTR, sizeof(DDOFM))) != NULL)
  929. #endif
  930. {
  931. pds->prevhdl = 0;
  932. pds->nexthdl = 0;
  933. pds->phdl = hdl;
  934. InsertInDDOFSQ(ppdev, pds);
  935. lpSurface->lpGbl->fpVidMem = (hdl->aligned_y * ppdev->lDeltaScreen) +
  936. hdl->aligned_x;
  937. lpSurface->dwReserved1 = (DWORD) pds ;
  938. lpSurface->lpGbl->xHint = hdl->aligned_x/ppdev->iBytesPerPixel;
  939. lpSurface->lpGbl->yHint = hdl->aligned_y;
  940. lpSurface->lpGbl->lPitch = ppdev->lDeltaScreen;
  941. lpDDSurfaceDesc->lPitch = ppdev->lDeltaScreen;
  942. lpDDSurfaceDesc->dwFlags |= DDSD_PITCH;
  943. // We handled the creation entirely ourselves, so we have to
  944. // set the return code and return DDHAL_DRIVER_HANDLED:
  945. lpInput->ddRVal = DD_OK;
  946. }
  947. else
  948. {
  949. FreeOffScnMem(ppdev, hdl);
  950. };
  951. }; // if (hdl != NULL)
  952. lplpSurface++;
  953. }; // endfor
  954. if (hdl != NULL)
  955. return DDHAL_DRIVER_HANDLED;
  956. else
  957. return DDHAL_DRIVER_NOTHANDLED;
  958. };
  959. #endif // ALLOC_IN_CREATESURFACE
  960. } // Support for 5462 or 5464
  961. #endif // DRIVER_5465
  962. return DDHAL_DRIVER_NOTHANDLED;
  963. } // CreateSurface
  964. /****************************************************************************
  965. * FUNCTION NAME: DestroySurface
  966. *
  967. * DESCRIPTION:
  968. * (Based on Laguna Win95 DirectDraw code)
  969. ****************************************************************************/
  970. DWORD DestroySurface (PDD_DESTROYSURFACEDATA lpInput)
  971. {
  972. PDD_SURFACE_LOCAL lpLocalSurface;
  973. DRIVERDATA* pDriverData;
  974. PDEV* ppdev;
  975. DDOFM *hdl;
  976. DISPDBG((DBGLVL, "DDraw - DestroySurface\n"));
  977. #ifdef DBGBRK
  978. DBGBREAKPOINT();
  979. #endif
  980. ppdev = (PDEV*) lpInput->lpDD->dhpdev;
  981. pDriverData = (DRIVERDATA*) &ppdev->DriverData;
  982. lpLocalSurface = lpInput->lpDDSurface;
  983. #if DRIVER_5465
  984. { // Support for 5465
  985. #if DRIVER_5465 && defined(OVERLAY)
  986. // check for overlay surface
  987. if (lpInput->lpDDSurface->ddsCaps.dwCaps & DDSCAPS_OVERLAY)
  988. {
  989. pDriverData->OverlayTable.pfnDestroySurface(ppdev,lpInput);
  990. #if 1 // PDR#11184
  991. // Enable 256-byte fetch if the last overlay surface has been destroyed.
  992. if (--pDriverData->dwOverlayCount == 0)
  993. {
  994. Set256ByteFetch(ppdev, TRUE);
  995. }
  996. #endif
  997. }
  998. #endif
  999. } // Support for 5465
  1000. #else
  1001. { // Support for 5462 or 5464
  1002. if (DDRAWISURF_HASPIXELFORMAT & lpInput->lpDDSurface->dwFlags)
  1003. {
  1004. LPDDPIXELFORMAT lpFormat = &lpInput->lpDDSurface->lpGbl->ddpfSurface;
  1005. if (DDPF_FOURCC & lpFormat->dwFlags)
  1006. {
  1007. if (FOURCC_UYVY == lpFormat->dwFourCC)
  1008. {
  1009. GRAB_VIDEO_FORMAT_SEMAPHORE(&(pDriverData->VideoSemaphore));
  1010. if (0 == --pDriverData->NumVideoSurfaces)
  1011. {
  1012. CLR_DRVSEM_YUV();
  1013. // disable stuff if there's no more video windows
  1014. pDriverData->CurrentVideoFormat = pDriverData->CurrentVideoFormat & 0xFF00;
  1015. // These trash the video window left on screen
  1016. //pDriverData->grFormat = pREG->grFormat & 0xFF00;
  1017. //pDriverData->grStop_BLT_2 &= ~ENABLE_VIDEO_FORMAT;
  1018. //pDriverData->grExternal_Overlay &= ~ENABLE_RAMBUS_9TH_BIT;
  1019. }; // endif (0 == --pDriverData->NumVideoSurfaces)
  1020. UNGRAB_VIDEO_FORMAT_SEMAPHORE(&(pDriverData->VideoSemaphore));
  1021. #ifdef RDRAM_8BIT
  1022. if (FALSE == pDriverData->fNineBitRDRAMS)
  1023. {
  1024. // Need to Delete Rectangle and Clear Window
  1025. ppdev->offscr_YUV.nInUse = FALSE;
  1026. LL16(grX_Start_2, 0);
  1027. LL16(grY_Start_2, 0);
  1028. LL16(grX_End_2, 0);
  1029. LL16(grY_End_2, 0);
  1030. };
  1031. #endif
  1032. }; // endif (FOURCC_UYVY == lpFormat->dwFourCC)
  1033. }; // endif (DDPF_FOURCC & lpFormat->dwFlags)
  1034. }; // endif (DDRAWISURF_HASPIXELFORMAT & lpInput->lpDDSurface->dwFlags)
  1035. } // Support for 5462 or 5464
  1036. #endif // #endif DRIVER_5465
  1037. #ifdef ALLOC_IN_CREATESURFACE
  1038. if (lpLocalSurface->dwReserved1 != 0)
  1039. {
  1040. hdl = (DDOFM *) lpLocalSurface->dwReserved1;
  1041. FreeOffScnMem(ppdev, hdl->phdl);
  1042. RemoveFrmDDOFSQ(ppdev, hdl);
  1043. lpLocalSurface->dwReserved1 = 0;
  1044. };
  1045. lpInput->ddRVal = DD_OK;
  1046. return DDHAL_DRIVER_HANDLED;
  1047. #endif // ALLOC_IN_CREATESURFACE
  1048. return DDHAL_DRIVER_NOTHANDLED;
  1049. } // DestroySurface
  1050. #if DRIVER_5465 && defined(OVERLAY)
  1051. /***************************************************************************
  1052. *
  1053. * FUNCTION: GetFormatInfo()
  1054. *
  1055. * DESCRIPTION: This returns the FOURCC and the bit depth of the specified
  1056. * format. This is useful since DirectDraw has so many
  1057. * different ways to determine the format.
  1058. *
  1059. ****************************************************************************/
  1060. VOID
  1061. GetFormatInfo (LPDDPIXELFORMAT lpFormat, LPDWORD lpFourcc, LPDWORD lpBitCount)
  1062. {
  1063. if (lpFormat->dwFlags & DDPF_FOURCC)
  1064. {
  1065. *lpFourcc = lpFormat->dwFourCC;
  1066. if (lpFormat->dwFourCC == BI_RGB)
  1067. {
  1068. *lpBitCount = lpFormat->dwRGBBitCount;
  1069. #ifdef DEBUG
  1070. if (lpFormat->dwRGBBitCount == 8)
  1071. {
  1072. DBG_MESSAGE(("Format: RGB 8"));
  1073. }
  1074. else if (lpFormat->dwRGBBitCount == 16)
  1075. {
  1076. DBG_MESSAGE(("Format: RGB 5:5:5"));
  1077. }
  1078. #endif
  1079. }
  1080. else if (lpFormat->dwFourCC == BI_BITFIELDS)
  1081. {
  1082. if ((lpFormat->dwRGBBitCount != 16) ||
  1083. (lpFormat->dwRBitMask != 0xf800) ||
  1084. (lpFormat->dwGBitMask != 0x07e0) ||
  1085. (lpFormat->dwBBitMask != 0x001f))
  1086. {
  1087. *lpFourcc = (DWORD) -1;
  1088. }
  1089. else
  1090. {
  1091. *lpBitCount = 16;
  1092. DBG_MESSAGE(("Format: RGB 5:6:5"));
  1093. }
  1094. }
  1095. else
  1096. {
  1097. lpFormat->dwRBitMask = (DWORD) -1;
  1098. lpFormat->dwGBitMask = (DWORD) -1;
  1099. lpFormat->dwBBitMask = (DWORD) -1;
  1100. if (FOURCC_YUVPLANAR == lpFormat->dwFourCC)
  1101. {
  1102. *lpBitCount = 8;
  1103. DBG_MESSAGE(("Format: CLPL"));
  1104. }
  1105. else
  1106. {
  1107. *lpBitCount = 16;
  1108. DBG_MESSAGE(("Format: UYVY"));
  1109. }
  1110. }
  1111. }
  1112. else if (lpFormat->dwFlags & DDPF_RGB)
  1113. {
  1114. if (lpFormat->dwRGBBitCount == 8)
  1115. {
  1116. *lpFourcc = BI_RGB;
  1117. DBG_MESSAGE(("Format: RGB 8"));
  1118. }
  1119. else if ((lpFormat->dwRGBBitCount == 16) &&
  1120. (lpFormat->dwRBitMask == 0xf800) &&
  1121. (lpFormat->dwGBitMask == 0x07e0) &&
  1122. (lpFormat->dwBBitMask == 0x001f))
  1123. {
  1124. *lpFourcc = BI_BITFIELDS;
  1125. DBG_MESSAGE(("Format: RGB 5:6:5"));
  1126. }
  1127. else if ((lpFormat->dwRGBBitCount == 16) &&
  1128. (lpFormat->dwRBitMask == 0x7C00) &&
  1129. (lpFormat->dwGBitMask == 0x03e0) &&
  1130. (lpFormat->dwBBitMask == 0x001f))
  1131. {
  1132. *lpFourcc = BI_RGB;
  1133. DBG_MESSAGE(("Format: RGB 5:5:5"));
  1134. }
  1135. else if (((lpFormat->dwRGBBitCount == 24) ||
  1136. (lpFormat->dwRGBBitCount == 32)) &&
  1137. (lpFormat->dwRBitMask == 0xff0000) &&
  1138. (lpFormat->dwGBitMask == 0x00ff00) &&
  1139. (lpFormat->dwBBitMask == 0x0000ff))
  1140. {
  1141. *lpFourcc = BI_RGB;
  1142. DBG_MESSAGE(("Format: RGB 8:8:8"));
  1143. }
  1144. else
  1145. {
  1146. *lpFourcc = (DWORD) -1;
  1147. }
  1148. *lpBitCount = lpFormat->dwRGBBitCount;
  1149. }
  1150. else if (DDPF_PALETTEINDEXED4 & lpFormat->dwFlags)
  1151. {
  1152. *lpFourcc = (DWORD)-1;
  1153. *lpBitCount = 4;
  1154. }
  1155. else if (DDPF_PALETTEINDEXED8 & lpFormat->dwFlags)
  1156. {
  1157. *lpFourcc = (DWORD)-1;
  1158. *lpBitCount = 8;
  1159. }
  1160. else if (lpFormat->dwRGBBitCount == 16)
  1161. {
  1162. *lpFourcc = BI_RGB;
  1163. *lpBitCount = lpFormat->dwRGBBitCount; // always 16 for now.
  1164. }
  1165. else
  1166. {
  1167. *lpFourcc = (DWORD) -1;
  1168. *lpBitCount = 0;
  1169. }
  1170. }
  1171. #endif // DRIVER_5465 && OVERLAY
  1172. #endif // ! ver 3.51
  1173. 
  1174. 
  1175.