Source code of Windows XP (NT5)
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.

1120 lines
38 KiB

  1. #include "precomp.h"
  2. // this will be compiled only for NT40 and greater
  3. #if TARGET_BUILD > 351
  4. void ModifyOverlayPosition (PDEV* , LPRECTL , LPDWORD );
  5. /* This procedure writes the Overlay pitch*/
  6. __inline void WriteVTOverlayPitch (PDEV* ppdev, DWORD Pitch)
  7. {
  8. DD_WriteVTReg ( DD_BUF0_PITCH, Pitch );
  9. DD_WriteVTReg ( DD_BUF1_PITCH, Pitch );
  10. }
  11. void DeskScanCallback (PDEV* ppdev )
  12. {
  13. RECTL rPhysOverlay;
  14. DWORD dwBuf0Offset, dwBuf1Offset;
  15. DWORD dwVInc = ppdev->OverlayInfo16.dwVInc;
  16. DWORD dwHInc = ppdev->OverlayInfo16.dwHInc;
  17. static DWORD dwOldVInc = 0, dwOldHInc = 0;
  18. static WORD wOldX = 0xFFFF, wOldY = 0xFFFF;
  19. static RECTL rOldPhysOverlay = { 0, 0, 0, 0 };
  20. /*
  21. * If we have not allocated the overlay then we better not do
  22. * anything or we might collide with the video capture stuff
  23. */
  24. if ( ! ( ppdev->OverlayInfo16.dwFlags & OVERLAY_ALLOCATED ) )
  25. {
  26. return;
  27. }
  28. dwBuf0Offset = ppdev->OverlayInfo16.dwBuf0Start;
  29. dwBuf1Offset = ppdev->OverlayInfo16.dwBuf1Start;
  30. rPhysOverlay.top = ppdev->OverlayInfo16.rDst.top;
  31. rPhysOverlay.bottom = ppdev->OverlayInfo16.rDst.bottom ;
  32. rPhysOverlay.left = ppdev->OverlayInfo16.rDst.left ;
  33. rPhysOverlay.right = ppdev->OverlayInfo16.rDst.right ;
  34. /*
  35. * Turn off keyer if overlay has moved off the screen.
  36. */
  37. if ( rPhysOverlay.right < 0 ||
  38. rPhysOverlay.bottom < 0 ||
  39. rPhysOverlay.left > ppdev->cxScreen - 1 ||
  40. rPhysOverlay.top > ppdev->cyScreen - 1 )
  41. {
  42. DD_WriteVTReg ( DD_OVERLAY_KEY_CNTL, 0x00000110L );
  43. return;
  44. }
  45. /*
  46. * Adjust Offsets if overlay source rectangle is clipped
  47. */
  48. if ( ppdev->OverlayInfo16.dwFlags & UPDATEOVERLAY )
  49. {
  50. if ( ppdev->OverlayInfo16.rSrc.left > 0 )
  51. {
  52. dwBuf0Offset += ppdev->OverlayInfo16.rSrc.left * 2;
  53. dwBuf1Offset += ppdev->OverlayInfo16.rSrc.left * 2;
  54. }
  55. if ( ppdev->OverlayInfo16.rSrc.top > 0 )
  56. {
  57. if ( ppdev->OverlayInfo16.dwFlags & DOUBLE_PITCH )
  58. {
  59. dwBuf0Offset +=
  60. ppdev->OverlayInfo16.rSrc.top * ppdev->OverlayInfo16.lBuf0Pitch * 2;
  61. dwBuf1Offset +=
  62. ppdev->OverlayInfo16.rSrc.top * ppdev->OverlayInfo16.lBuf1Pitch * 2;
  63. }
  64. else
  65. {
  66. dwBuf0Offset +=
  67. ppdev->OverlayInfo16.rSrc.top * ppdev->OverlayInfo16.lBuf0Pitch;
  68. dwBuf1Offset +=
  69. ppdev->OverlayInfo16.rSrc.top * ppdev->OverlayInfo16.lBuf1Pitch;
  70. }
  71. }
  72. }
  73. if ( M64_ID_DIRECT(ppdev->pjMmBase, CRTC_GEN_CNTL ) & CRTC_INTERLACE_EN )
  74. ModifyOverlayPosition (ppdev, &rPhysOverlay, &dwVInc );
  75. if ( dwVInc != dwOldVInc || dwHInc != dwOldHInc )
  76. DD_WriteVTReg ( DD_OVERLAY_SCALE_INC, ( dwHInc << 16 ) | dwVInc );
  77. /*
  78. * Try not to write new position at a bad time!
  79. */
  80. // if ((ppdev->iAsic ==CI_M64_VTA)||(ppdev->iAsic ==CI_M64_GTA))
  81. // {
  82. if ( rPhysOverlay.top != rOldPhysOverlay.top ||
  83. rPhysOverlay.bottom != rOldPhysOverlay.bottom ||
  84. rPhysOverlay.left != rOldPhysOverlay.left ||
  85. rPhysOverlay.right != rOldPhysOverlay.right )
  86. //((M64_ID(ppdev->pjMmBase, CRTC_VLINE_CRNT_VLINE)&0x07FF0000L)>>16L)
  87. if ( (LONG)((M64_ID_DIRECT(ppdev->pjMmBase, CRTC_VLINE_CRNT_VLINE)&0x07FF0000L)>>16L)>= rOldPhysOverlay.top )
  88. while ( (LONG)((M64_ID_DIRECT(ppdev->pjMmBase, CRTC_VLINE_CRNT_VLINE)&0x07FF0000L)>>16L) <= rOldPhysOverlay.bottom );
  89. // }
  90. /*
  91. * Hit the registers with the new overlay information.
  92. */
  93. DD_WriteVTReg ( DD_BUF0_OFFSET, dwBuf0Offset );
  94. DD_WriteVTReg ( DD_BUF1_OFFSET, dwBuf1Offset );
  95. DD_WriteVTReg ( DD_OVERLAY_Y_X, (DWORD)(
  96. ( (DWORD)rPhysOverlay.left << 16L ) |
  97. ( (DWORD)rPhysOverlay.top ) | (0x80000000) ) );
  98. DD_WriteVTReg ( DD_OVERLAY_Y_X_END, (DWORD)(
  99. ( (DWORD)rPhysOverlay.right << 16L ) |
  100. ( (DWORD)rPhysOverlay.bottom ) ) );
  101. if ( ppdev->OverlayInfo16.dwFlags & UPDATEOVERLAY )
  102. {
  103. DD_WriteVTReg ( DD_OVERLAY_KEY_CNTL, ppdev->OverlayInfo16.dwOverlayKeyCntl );
  104. }
  105. dwOldVInc = dwVInc;
  106. dwOldHInc = dwHInc;
  107. rOldPhysOverlay.top = max ( rPhysOverlay.top, 0 );
  108. rOldPhysOverlay.bottom = min ( rPhysOverlay.bottom, (LONG)ppdev->cyScreen - 1 );
  109. rOldPhysOverlay.left = rPhysOverlay.left;
  110. rOldPhysOverlay.right = rPhysOverlay.right;
  111. }
  112. void ModifyOverlayPosition (PDEV* ppdev, LPRECTL lprOverlay, LPDWORD lpdwVInc )
  113. {
  114. DWORD dwVInc;
  115. DWORD dwScaleChange;
  116. DWORD dwHeight;
  117. DWORD dwTop, dwBottom;
  118. lprOverlay->top -= 3;
  119. if ( lprOverlay->top < 0 )
  120. {
  121. lprOverlay->top += M64_ID(ppdev->pjMmBase, CRTC_V_TOTAL_DISP )& 0x07FFL;
  122. }
  123. if ( lprOverlay->top != 0 )
  124. {
  125. if ( lprOverlay->top % 2 == 0 )
  126. lprOverlay->top++;
  127. if ( lprOverlay->top == 1 )
  128. lprOverlay->top = 0;
  129. }
  130. if ( lprOverlay->bottom%2 == 1 )
  131. lprOverlay->bottom++;
  132. lprOverlay->bottom = min ( lprOverlay->bottom,
  133. (LONG) ppdev->cyScreen - 2 );
  134. /*
  135. * Adjust scaling factor so we don't get the "green line" at the
  136. * bottom of the overlay if we are moving the overlay off the top
  137. * of the screen
  138. */
  139. dwVInc = ppdev->OverlayInfo16.dwVInc;
  140. dwBottom = lprOverlay->bottom;
  141. dwTop = lprOverlay->top;
  142. if ( (LONG)dwTop > ppdev->cyScreen - 1 )
  143. dwTop = 0L;
  144. dwHeight = dwBottom - dwTop;
  145. if ( dwHeight != 0 )
  146. dwScaleChange = ( ( dwHeight - 1 ) << 12 ) / ( dwHeight );
  147. if ( dwScaleChange != 0 )
  148. dwVInc = ( dwVInc * dwScaleChange ) >> 12;
  149. *lpdwVInc = dwVInc;
  150. }
  151. void TurnOnVTRegisters ( PDEV* ppdev )
  152. {
  153. DWORD dwBusCntl;
  154. dwBusCntl = M64_ID_DIRECT(ppdev->pjMmBase, BUS_CNTL );
  155. dwBusCntl |= 0x08000000U;
  156. M64_OD_DIRECT(ppdev->pjMmBase, BUS_CNTL, dwBusCntl );
  157. }
  158. void TurnOffVTRegisters ( PDEV* ppdev )
  159. {
  160. DWORD dwBusCntl;
  161. dwBusCntl = M64_ID(ppdev->pjMmBase, BUS_CNTL );
  162. dwBusCntl &= ~0x08000000U;
  163. M64_CHECK_FIFO_SPACE(ppdev,ppdev-> pjMmBase, 2);
  164. M64_OD(ppdev->pjMmBase, BUS_CNTL, dwBusCntl );
  165. }
  166. DWORD DdSetColorKey(PDD_SETCOLORKEYDATA lpSetColorKey)
  167. {
  168. PDEV* ppdev;
  169. BYTE* pjIoBase;
  170. BYTE* pjMmBase;
  171. DD_SURFACE_GLOBAL* lpSurface;
  172. DWORD dwKeyLow;
  173. DWORD dwKeyHigh;
  174. ppdev = (PDEV*) lpSetColorKey->lpDD->dhpdev;
  175. pjMmBase = ppdev->pjMmBase;
  176. lpSurface = lpSetColorKey->lpDDSurface->lpGbl;
  177. // We don't have to do anything for normal blt source colour keys:
  178. if (lpSetColorKey->dwFlags & DDCKEY_SRCBLT)
  179. {
  180. lpSetColorKey->ddRVal = DD_OK;
  181. return(DDHAL_DRIVER_HANDLED);
  182. }
  183. else if (lpSetColorKey->dwFlags & DDCKEY_DESTOVERLAY)
  184. {
  185. dwKeyLow = lpSetColorKey->ckNew.dwColorSpaceLowValue;
  186. /*
  187. if (lpSurface->ddpfSurface.dwFlags & DDPF_PALETTEINDEXED8)
  188. {
  189. dwKeyLow = dwGetPaletteEntry(ppdev, dwKeyLow);
  190. }
  191. else
  192. {
  193. ASSERTDD(lpSurface->ddpfSurface.dwFlags & DDPF_RGB,
  194. "Expected only RGB cases here");
  195. // We have to transform the colour key from its native format
  196. // to 8-8-8:
  197. if (lpSurface->ddpfSurface.dwRGBBitCount == 16)
  198. {
  199. if (IS_RGB15_R(lpSurface->ddpfSurface.dwRBitMask))
  200. dwKeyLow = RGB15to32(dwKeyLow);
  201. else
  202. dwKeyLow = RGB16to32(dwKeyLow);
  203. }
  204. else
  205. {
  206. ASSERTDD((lpSurface->ddpfSurface.dwRGBBitCount == 32),
  207. "Expected the primary surface to be either 8, 16, or 32bpp");
  208. }
  209. }
  210. */
  211. DD_WriteVTReg ( DD_OVERLAY_GRAPHICS_KEY_CLR, dwKeyLow );
  212. ppdev->OverlayInfo16.dwOverlayKeyCntl &= 0xFFFFFF8FL;
  213. ppdev->OverlayInfo16.dwOverlayKeyCntl |= 0x00000050L;
  214. DD_WriteVTReg ( DD_OVERLAY_KEY_CNTL, ppdev->OverlayInfo16.dwOverlayKeyCntl );
  215. lpSetColorKey->ddRVal = DD_OK;
  216. return(DDHAL_DRIVER_HANDLED);
  217. }
  218. DISPDBG((0, "DdSetColorKey: Invalid command"));
  219. return(DDHAL_DRIVER_NOTHANDLED);
  220. }
  221. /******************************Public*Routine******************************\
  222. * DWORD DdCanCreateSurface
  223. *
  224. \**************************************************************************/
  225. DWORD DdCanCreateSurface( PDD_CANCREATESURFACEDATA lpCanCreateSurface)
  226. {
  227. PDEV* ppdev;
  228. DWORD dwRet;
  229. LPDDSURFACEDESC lpSurfaceDesc;
  230. ppdev = (PDEV*) lpCanCreateSurface->lpDD->dhpdev;
  231. lpSurfaceDesc = lpCanCreateSurface->lpDDSurfaceDesc;
  232. dwRet = DDHAL_DRIVER_NOTHANDLED;
  233. if (!lpCanCreateSurface->bIsDifferentPixelFormat)
  234. {
  235. // It's trivially easy to create plain surfaces that are the same
  236. // type as the primary surface:
  237. dwRet = DDHAL_DRIVER_HANDLED;
  238. }
  239. else if (ppdev->iAsic >=CI_M64_VTA)
  240. {
  241. // When using the Streams processor, we handle only overlays of
  242. // different pixel formats -- not any off-screen memory:
  243. if (lpSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_OVERLAY)
  244. {
  245. // We handle two types of YUV overlay surfaces:
  246. if (lpSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_FOURCC)
  247. {
  248. // Check first for a supported YUV type:
  249. if ( (lpSurfaceDesc->ddpfPixelFormat.dwFourCC == FOURCC_UYVY) || (lpSurfaceDesc->ddpfPixelFormat.dwFourCC == FOURCC_YUY2) )
  250. {
  251. lpSurfaceDesc->ddpfPixelFormat.dwYUVBitCount = 16;
  252. dwRet = DDHAL_DRIVER_HANDLED;
  253. }
  254. }
  255. // We handle 16bpp and 32bpp RGB overlay surfaces:
  256. else if ((lpSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_RGB) &&
  257. !(lpSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8))
  258. {
  259. if (lpSurfaceDesc->ddpfPixelFormat.dwRGBBitCount == 16)
  260. {
  261. if (IS_RGB15(&lpSurfaceDesc->ddpfPixelFormat) ||
  262. IS_RGB16(&lpSurfaceDesc->ddpfPixelFormat))
  263. {
  264. dwRet = DDHAL_DRIVER_HANDLED;
  265. }
  266. }
  267. else if (lpSurfaceDesc->ddpfPixelFormat.dwRGBBitCount == 32)
  268. {
  269. if (IS_RGB32(&lpSurfaceDesc->ddpfPixelFormat))
  270. {
  271. dwRet = DDHAL_DRIVER_HANDLED;
  272. }
  273. }
  274. }
  275. }
  276. }
  277. // Print some spew if this was a surface we refused to create:
  278. if (dwRet == DDHAL_DRIVER_NOTHANDLED)
  279. {
  280. if (lpSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_RGB)
  281. {
  282. DISPDBG((10, "Failed creation of %libpp RGB surface %lx %lx %lx",
  283. lpSurfaceDesc->ddpfPixelFormat.dwRGBBitCount,
  284. lpSurfaceDesc->ddpfPixelFormat.dwRBitMask,
  285. lpSurfaceDesc->ddpfPixelFormat.dwGBitMask,
  286. lpSurfaceDesc->ddpfPixelFormat.dwBBitMask));
  287. }
  288. else
  289. {
  290. DISPDBG((10, "Failed creation of type 0x%lx YUV 0x%lx surface",
  291. lpSurfaceDesc->ddpfPixelFormat.dwFlags,
  292. lpSurfaceDesc->ddpfPixelFormat.dwFourCC));
  293. }
  294. }
  295. lpCanCreateSurface->ddRVal = DD_OK;
  296. return(dwRet);
  297. }
  298. /******************************Public*Routine******************************\
  299. * DWORD DdCreateSurface
  300. *
  301. \**************************************************************************/
  302. DWORD DdCreateSurface(
  303. PDD_CREATESURFACEDATA lpCreateSurface)
  304. {
  305. PDEV* ppdev;
  306. DD_SURFACE_LOCAL* lpSurfaceLocal;
  307. DD_SURFACE_GLOBAL* lpSurfaceGlobal;
  308. LPDDSURFACEDESC lpSurfaceDesc;
  309. DWORD dwByteCount;
  310. LONG lLinearPitch;
  311. DWORD dwHeight;
  312. OH* poh;
  313. FLATPTR fpVidMem;
  314. DISPDBG((10, " Enter Create Surface"));
  315. ppdev = (PDEV*) lpCreateSurface->lpDD->dhpdev;
  316. // On Windows NT, dwSCnt will always be 1, so there will only ever
  317. // be one entry in the 'lplpSList' array:
  318. lpSurfaceLocal = lpCreateSurface->lplpSList[0];
  319. lpSurfaceGlobal = lpSurfaceLocal->lpGbl;
  320. lpSurfaceDesc = lpCreateSurface->lpDDSurfaceDesc;
  321. // We repeat the same checks we did in 'DdCanCreateSurface' because
  322. // it's possible that an application doesn't call 'DdCanCreateSurface'
  323. // before calling 'DdCreateSurface'.
  324. ASSERTDD(lpSurfaceGlobal->ddpfSurface.dwSize == sizeof(DDPIXELFORMAT), "NT is supposed to guarantee that ddpfSurface.dwSize is valid");
  325. // DdCanCreateSurface already validated whether the hardware supports
  326. // the surface, so we don't need to do any validation here. We'll
  327. // just go ahead and allocate it.
  328. //
  329. //
  330. // Note that on NT, an overlay can be created only if the driver
  331. // okay's it here in this routine. Under Win95, the overlay will be
  332. // created automatically if it's the same pixel format as the primary
  333. // display.
  334. if ((lpSurfaceLocal->ddsCaps.dwCaps & DDSCAPS_OVERLAY) ||
  335. (lpSurfaceGlobal->ddpfSurface.dwFlags & DDPF_FOURCC) ||
  336. (lpSurfaceGlobal->ddpfSurface.dwYUVBitCount != (DWORD) 8 * ppdev->cjPelSize) ||
  337. (lpSurfaceGlobal->ddpfSurface.dwRBitMask != ppdev->flRed))
  338. {
  339. if (lpSurfaceGlobal->wWidth <= (DWORD) ppdev->cxMemory)
  340. {
  341. if (lpSurfaceGlobal->ddpfSurface.dwFlags & DDPF_FOURCC)
  342. {
  343. //dwByteCount = (lpSurfaceGlobal->ddpfSurface.dwFourCC == FOURCC_UYVY)? 2 : 1;
  344. dwByteCount =2;
  345. // We have to fill in the bit-count for FourCC surfaces:
  346. lpSurfaceGlobal->ddpfSurface.dwYUVBitCount = 8 * dwByteCount;
  347. DISPDBG((10, "Created YUV: %li x %li",
  348. lpSurfaceGlobal->wWidth, lpSurfaceGlobal->wHeight));
  349. }
  350. else
  351. {
  352. dwByteCount = lpSurfaceGlobal->ddpfSurface.dwRGBBitCount >> 3;
  353. DISPDBG((10, "Created RGB %libpp: %li x %li Red: %lx",
  354. 8 * dwByteCount, lpSurfaceGlobal->wWidth, lpSurfaceGlobal->wHeight,
  355. lpSurfaceGlobal->ddpfSurface.dwRBitMask));
  356. // we support 15,16 and 32 bits
  357. if (((dwByteCount < 2)||(dwByteCount ==3)) &&
  358. (lpSurfaceLocal->ddsCaps.dwCaps & DDSCAPS_OVERLAY))
  359. {
  360. lpCreateSurface->ddRVal = DDERR_INVALIDPIXELFORMAT;
  361. return(DDHAL_DRIVER_HANDLED);
  362. }
  363. }
  364. // We want to allocate a linear surface to store the FourCC
  365. // surface, but our driver is using a 2-D heap-manager because
  366. // the rest of our surfaces have to be 2-D. So here we have to
  367. // convert the linear size to a 2-D size.
  368. //
  369. lLinearPitch = (lpSurfaceGlobal->wWidth * dwByteCount ) ; // + 7) & ~7; // The stride has to be a qword multiple.
  370. dwHeight = ( (lpSurfaceGlobal->wHeight * lLinearPitch + ppdev->lDelta - 1) / ppdev->lDelta) ; /// ppdev->cjPelSize; // in pixels
  371. // Free up as much off-screen memory as possible:
  372. bMoveAllDfbsFromOffscreenToDibs(ppdev);
  373. poh = pohAllocate(ppdev, NULL, ppdev->cxMemory, dwHeight, FLOH_MAKE_PERMANENT);
  374. if (poh != NULL)
  375. {
  376. fpVidMem = (poh->y * ppdev->lDelta) + (poh->x ) * ppdev->cjPelSize; // poh->x must be 0 in this case
  377. lpSurfaceGlobal->dwReserved1 = (ULONG_PTR)poh;
  378. lpSurfaceGlobal->xHint = poh->x;
  379. lpSurfaceGlobal->yHint = poh->y;
  380. lpSurfaceGlobal->fpVidMem = fpVidMem;
  381. lpSurfaceGlobal->lPitch = lLinearPitch;
  382. lpSurfaceDesc->lPitch = lLinearPitch;
  383. lpSurfaceDesc->dwFlags |= DDSD_PITCH;
  384. // We handled the creation entirely ourselves, so we have to
  385. // set the return code and return DDHAL_DRIVER_HANDLED:
  386. lpCreateSurface->ddRVal = DD_OK;
  387. DISPDBG((10, " Exit Create Surface 1: Created YUV surface at poh X=%d, Y=%d", poh->x, poh->y));
  388. return(DDHAL_DRIVER_HANDLED);
  389. }
  390. /*
  391. // Now fill in enough stuff to have the DirectDraw heap-manager
  392. // do the allocation for us:
  393. lpSurfaceGlobal->fpVidMem = DDHAL_PLEASEALLOC_BLOCKSIZE;
  394. lpSurfaceGlobal->dwBlockSizeX = ppdev->lDelta; // Specified in bytes
  395. lpSurfaceGlobal->dwBlockSizeY = dwHeight;
  396. lpSurfaceGlobal->lPitch = lLinearPitch;
  397. lpSurfaceGlobal->dwReserved1 = DD_RESERVED_DIFFERENTPIXELFORMAT;
  398. lpSurfaceDesc->lPitch = lLinearPitch;
  399. lpSurfaceDesc->dwFlags |= DDSD_PITCH;
  400. */
  401. }
  402. else
  403. {
  404. DISPDBG((10, "Refused to create surface with large width"));
  405. }
  406. }
  407. else
  408. {
  409. if (lpSurfaceGlobal->wWidth <= (DWORD) ppdev->cxMemory)
  410. {
  411. if(lpSurfaceGlobal->ddpfSurface.dwRBitMask == ppdev->flRed)
  412. {
  413. DISPDBG((10, "Surface with the same pixel format as primary"));
  414. dwByteCount = lpSurfaceGlobal->ddpfSurface.dwRGBBitCount >> 3;
  415. lLinearPitch = ppdev->lDelta ;
  416. dwHeight = lpSurfaceGlobal->wHeight ;
  417. // Free up as much off-screen memory as possible:
  418. bMoveAllDfbsFromOffscreenToDibs(ppdev);
  419. DISPDBG((10, "Try to allocate Cx=%d, Cy=%d", ppdev->cxMemory, dwHeight));
  420. if((ULONG)lpSurfaceGlobal->wWidth*dwByteCount < (ULONG)ppdev->lDelta)
  421. poh = pohAllocate(ppdev, NULL, ( (lpSurfaceGlobal->wWidth*dwByteCount + 8) / (ppdev->cjPelSize) ) +1, dwHeight, FLOH_MAKE_PERMANENT);
  422. else
  423. poh = pohAllocate(ppdev, NULL, (lpSurfaceGlobal->wWidth*dwByteCount )/ppdev->cjPelSize , dwHeight, FLOH_MAKE_PERMANENT);
  424. if (poh != NULL)
  425. {
  426. if((ULONG)lpSurfaceGlobal->wWidth*dwByteCount < (ULONG)ppdev->lDelta)
  427. fpVidMem =( ( (poh->y * ppdev->lDelta) + ((poh->x ) * ppdev->cjPelSize) + 7 )&~7 ); // poh->x must be 0 in this case
  428. else
  429. fpVidMem = (poh->y * ppdev->lDelta) + ((poh->x ) * ppdev->cjPelSize) ;
  430. // no allocation for flip surfaces beyond 4MB
  431. if (( (LONG)lpSurfaceGlobal->wWidth < ppdev->cxScreen) ||
  432. ( (LONG)lpSurfaceGlobal->wHeight < ppdev->cyScreen) ||
  433. (fpVidMem < 0x400000))
  434. {
  435. lpSurfaceGlobal->dwReserved1=(ULONG_PTR)poh;
  436. lpSurfaceGlobal->xHint = poh->x;
  437. lpSurfaceGlobal->yHint = poh->y;
  438. lpSurfaceGlobal->fpVidMem = fpVidMem;
  439. lpSurfaceGlobal->lPitch = ppdev->lDelta;
  440. lpSurfaceDesc->lPitch = ppdev->lDelta;
  441. lpSurfaceDesc->dwFlags |= DDSD_PITCH;
  442. // We handled the creation entirely ourselves, so we have to
  443. // set the return code and return DDHAL_DRIVER_HANDLED:
  444. DISPDBG((10, " Exit Create Surface 2: Created RGB surface at poh X=%d, Y=%d", poh->x, poh->y));
  445. lpCreateSurface->ddRVal = DD_OK;
  446. return(DDHAL_DRIVER_HANDLED);
  447. }
  448. // dealocate the poh because The allocation is beyond 4MB for a flip surface: cx = cxScreen ; cy = cyScreen
  449. // bMoveAllDfbsFromOffscreenToDibs(ppdev); // avoid fragmentation
  450. pohFree(ppdev, poh);
  451. DISPDBG((10, " The allocation is beyond 4MB, so we deallocate; for a flip surface: cx = cxScreen ; cy = cyScreen"));
  452. }
  453. DISPDBG((10, " Cannot allocate poh"));
  454. }
  455. }
  456. }
  457. DISPDBG((10, " Exit Create Surface NOTOK"));
  458. return(DDHAL_DRIVER_NOTHANDLED);
  459. }
  460. /******************************Public*Routine******************************\
  461. * DWORD DdUpdateOverlay
  462. *
  463. \**************************************************************************/
  464. DWORD DdUpdateOverlay(PDD_UPDATEOVERLAYDATA lpUpdateOverlay)
  465. {
  466. PDEV* ppdev;
  467. BYTE* pjIoBase;
  468. BYTE* pjMmBase;
  469. DD_SURFACE_GLOBAL* lpSource;
  470. DD_SURFACE_GLOBAL* lpDestination;
  471. DWORD dwStride;
  472. LONG srcWidth;
  473. LONG srcHeight;
  474. LONG dstWidth;
  475. LONG dstHeight;
  476. DWORD dwBitCount;
  477. DWORD dwStart;
  478. DWORD dwTmp;
  479. BOOL bColorKey;
  480. DWORD dwKeyLow;
  481. DWORD dwKeyHigh;
  482. DWORD dwBytesPerPixel;
  483. DWORD dwSecCtrl;
  484. DWORD dwBlendCtrl;
  485. LONG dwVInc;
  486. LONG dwHInc;
  487. DWORD SrcBufOffset,Temp;
  488. BYTE bPLLAddr,bFatPixel;
  489. RECTL rSrc,rDst,rOverlay;
  490. DWORD myval;
  491. DWORD g_dwGamma=0; // Used to set the gamma correction for the overlay.
  492. DWORD value;
  493. ppdev = (PDEV*) lpUpdateOverlay->lpDD->dhpdev;
  494. pjMmBase = ppdev->pjMmBase;
  495. // 'Source' is the overlay surface, 'destination' is the surface to
  496. // be overlayed:
  497. lpSource = lpUpdateOverlay->lpDDSrcSurface->lpGbl;
  498. if (lpUpdateOverlay->dwFlags & DDOVER_HIDE)
  499. {
  500. if (lpSource->fpVidMem == ppdev->fpVisibleOverlay)
  501. {
  502. ppdev->semph_overlay=0; // = 0 ; resource free
  503. //WAIT_FOR_VBLANK(pjIoBase);
  504. ppdev->OverlayInfo16.dwFlags |= UPDATEOVERLAY;
  505. ppdev->OverlayInfo16.dwFlags &= ~OVERLAY_VISIBLE;
  506. ppdev->OverlayInfo16.dwOverlayKeyCntl = 0x00000110L;
  507. DeskScanCallback (ppdev );
  508. ppdev->OverlayInfo16.dwFlags &= ~UPDATEOVERLAY;
  509. ppdev->fpVisibleOverlay = 0;
  510. }
  511. lpUpdateOverlay->ddRVal = DD_OK;
  512. return(DDHAL_DRIVER_HANDLED);
  513. }
  514. // Dereference 'lpDDDestSurface' only after checking for the DDOVER_HIDE
  515. // case:
  516. lpDestination = lpUpdateOverlay->lpDDDestSurface->lpGbl;
  517. if (lpSource->fpVidMem != ppdev->fpVisibleOverlay)
  518. {
  519. if (lpUpdateOverlay->dwFlags & DDOVER_SHOW)
  520. {
  521. if (ppdev->fpVisibleOverlay != 0)
  522. {
  523. // Some other overlay is already visible:
  524. DISPDBG((10, "DdUpdateOverlay: An overlay is already visible"));
  525. lpUpdateOverlay->ddRVal = DDERR_OUTOFCAPS;
  526. return(DDHAL_DRIVER_HANDLED);
  527. }
  528. else
  529. {
  530. // first we have to verify if the overlay resource is in use
  531. if(ppdev->semph_overlay==0) // = 0 ; resource free
  532. // = 1 ; in use by DDraw
  533. // = 2 ; in use by Palindrome
  534. {
  535. // We're going to make the overlay visible, so mark it as
  536. // such:
  537. ppdev->semph_overlay = 1;
  538. ppdev->fpVisibleOverlay = lpSource->fpVidMem;
  539. }
  540. else
  541. {
  542. // Palindrome is using the overlay :
  543. DISPDBG((10, "DdUpdateOverlay: An overlay is already visible (used byPalindrome) "));
  544. lpUpdateOverlay->ddRVal = DDERR_OUTOFCAPS;
  545. return(DDHAL_DRIVER_HANDLED);
  546. }
  547. }
  548. }
  549. else
  550. {
  551. // The overlay isn't visible, and we haven't been asked to make
  552. // it visible, so this call is trivially easy:
  553. lpUpdateOverlay->ddRVal = DD_OK;
  554. return(DDHAL_DRIVER_HANDLED);
  555. }
  556. }
  557. dwStride = lpSource->lPitch;
  558. srcWidth = lpUpdateOverlay->rSrc.right - lpUpdateOverlay->rSrc.left;
  559. srcHeight = lpUpdateOverlay->rSrc.bottom - lpUpdateOverlay->rSrc.top;
  560. dstWidth = lpUpdateOverlay->rDest.right - lpUpdateOverlay->rDest.left;
  561. dstHeight = lpUpdateOverlay->rDest.bottom - lpUpdateOverlay->rDest.top;
  562. if ( dstHeight < srcHeight || lpUpdateOverlay->rSrc.top > 0 )
  563. ppdev->OverlayScalingDown = 1;
  564. else
  565. ppdev->OverlayScalingDown = 0;
  566. /*
  567. * Determine scaling factors for the hardware. These factors will
  568. * be modified based on either "fat pixel" mode or interlace mode.
  569. */
  570. dwHInc = ( srcWidth << 12L ) / ( dstWidth );
  571. /*
  572. * Determine if VT/GT is in FAT PIXEL MODE
  573. */
  574. /* Get current PLL reg so we can restore. */
  575. value=M64_ID_DIRECT(ppdev->pjMmBase, CLOCK_CNTL );
  576. /* Set PLL reg 5 for reading. This is where the "fat pixel" bit is */
  577. M64_OD_DIRECT(ppdev->pjMmBase, CLOCK_CNTL, (value&0xFFFF00FF)|0x1400);
  578. /* Get the "fat pixel" bit from PLL reg */
  579. bFatPixel =(BYTE)( (M64_ID_DIRECT(ppdev->pjMmBase, CLOCK_CNTL )&0x00FF0000)>>16 ) & 0x30;
  580. /* Restore original register pointer in PLL reg */
  581. M64_OD_DIRECT( ppdev->pjMmBase, CLOCK_CNTL, value);
  582. /* adjust horizontal scaling if necessary */
  583. if ( bFatPixel )
  584. dwHInc *= 2;
  585. /*
  586. * We can't clip overlays, so we must make sure the co-ord, are within
  587. * the bounds of the screen.
  588. */
  589. rOverlay.top = max ( 0,lpUpdateOverlay->rDest.top );
  590. rOverlay.left = max ( 0, lpUpdateOverlay->rDest.left );
  591. rOverlay.bottom = min ( (DWORD)ppdev->cyScreen - 1,
  592. (DWORD)lpUpdateOverlay->rDest.bottom );
  593. rOverlay.right = min ( (DWORD)ppdev->cxScreen - 1,
  594. (DWORD)lpUpdateOverlay->rDest.right );
  595. /*
  596. * Modify overlay destination based on wether we are in inerlace mode.
  597. * If we are in interlace dwVInc must be multiplied by 2.
  598. */
  599. dwVInc = ( srcHeight << 12L ) / ( dstHeight );
  600. if ( M64_ID_DIRECT(ppdev->pjMmBase, CRTC_GEN_CNTL ) & CRTC_INTERLACE_EN )
  601. {
  602. ppdev->OverlayScalingDown = 1; /* Always replicate UVs in this case */
  603. dwVInc *= 2;
  604. }
  605. /*
  606. * Overlay destination must be primary, so we will check current
  607. * pixel depth of the screen.
  608. */
  609. // here we have to turn on the second block of regs
  610. switch ( ppdev->cBitsPerPel) //Screen BPP
  611. {
  612. case 8:
  613. DD_WriteVTReg ( DD_OVERLAY_GRAPHICS_KEY_MSK, 0x000000FFL );
  614. break;
  615. case 16:
  616. DD_WriteVTReg ( DD_OVERLAY_GRAPHICS_KEY_MSK, 0x0000FFFFL );
  617. break;
  618. case 24:
  619. case 32:
  620. DD_WriteVTReg ( DD_OVERLAY_GRAPHICS_KEY_MSK, 0x00FFFFFFL );
  621. break;
  622. default:
  623. DD_WriteVTReg ( DD_OVERLAY_GRAPHICS_KEY_MSK, 0x0000FFFFL );
  624. break;
  625. }
  626. /* Scaler */
  627. DD_WriteVTReg ( DD_SCALER_HEIGHT_WIDTH, ( srcWidth << 16L ) |
  628. ( srcHeight ) );
  629. // Overlay input data format:
  630. if (lpSource->ddpfSurface.dwFlags & DDPF_FOURCC)
  631. {
  632. dwBitCount = lpSource->ddpfSurface.dwYUVBitCount;
  633. switch (lpSource->ddpfSurface.dwFourCC)
  634. {
  635. case FOURCC_UYVY: /* YVYU in VT Specs */
  636. WriteVTOverlayPitch (ppdev, lpUpdateOverlay->lpDDSrcSurface->lpGbl->lPitch /2); //Check's to see if it's VTB or not.
  637. DD_WriteVTReg ( DD_VIDEO_FORMAT, 0x000C000CL );
  638. DD_WriteVTReg ( DD_OVERLAY_VIDEO_KEY_MSK, 0x0000FFFF );
  639. ppdev->OverlayInfo16.dwFlags &= ~DOUBLE_PITCH;
  640. break;
  641. case FOURCC_YUY2: /* VYUY in VT Specs */
  642. WriteVTOverlayPitch (ppdev, lpUpdateOverlay->lpDDSrcSurface->lpGbl->lPitch /2 ); //Check's to see if it's VTB or not.
  643. DD_WriteVTReg ( DD_VIDEO_FORMAT, 0x000B000BL );
  644. DD_WriteVTReg ( DD_OVERLAY_VIDEO_KEY_MSK, 0x0000FFFF );
  645. ppdev->OverlayInfo16.dwFlags &= ~DOUBLE_PITCH;
  646. break;
  647. default:
  648. WriteVTOverlayPitch (ppdev, lpUpdateOverlay->lpDDSrcSurface->lpGbl->lPitch); //Check's to see if it's VTB or not.
  649. DD_WriteVTReg ( DD_VIDEO_FORMAT, 0x000B000BL );
  650. DD_WriteVTReg ( DD_OVERLAY_VIDEO_KEY_MSK, 0x0000FFFF );
  651. ppdev->OverlayInfo16.dwFlags &= ~DOUBLE_PITCH;
  652. break;
  653. }
  654. }
  655. else
  656. {
  657. ASSERTDD(lpSource->ddpfSurface.dwFlags & DDPF_RGB,
  658. "Expected us to have created only RGB or YUV overlays");
  659. // The overlay surface is in RGB format:
  660. dwBitCount = lpSource->ddpfSurface.dwRGBBitCount;
  661. switch ( lpSource->ddpfSurface.dwRGBBitCount )
  662. {
  663. case 16:
  664. /***********
  665. *
  666. * Are we 5:5:5 or 5:6:5?
  667. *
  668. ************/
  669. if ( lpUpdateOverlay->lpDDSrcSurface->lpGbl->ddpfSurface.dwRBitMask & 0x00008000L )
  670. {
  671. DD_WriteVTReg ( DD_VIDEO_FORMAT, 0x00040004L );
  672. }
  673. else
  674. {
  675. DD_WriteVTReg ( DD_VIDEO_FORMAT, 0x00030003L );
  676. }
  677. WriteVTOverlayPitch (ppdev, lpUpdateOverlay->lpDDSrcSurface->lpGbl->lPitch /2);
  678. DD_WriteVTReg ( DD_OVERLAY_VIDEO_KEY_MSK, 0x0000FFFF );
  679. ppdev->OverlayInfo16.dwFlags &= ~DOUBLE_PITCH;
  680. break;
  681. case 32:
  682. WriteVTOverlayPitch (ppdev, lpUpdateOverlay->lpDDSrcSurface->lpGbl->lPitch /4);
  683. DD_WriteVTReg ( DD_VIDEO_FORMAT, 0x00060006L );
  684. DD_WriteVTReg ( DD_OVERLAY_VIDEO_KEY_MSK, 0xFFFFFFFF );
  685. ppdev->OverlayInfo16.dwFlags &= ~DOUBLE_PITCH;
  686. break;
  687. default:
  688. WriteVTOverlayPitch (ppdev, lpUpdateOverlay->lpDDSrcSurface->lpGbl->lPitch /2); //Check's to see if it's VTB or not.
  689. DD_WriteVTReg ( DD_VIDEO_FORMAT, 0x00030003L );
  690. DD_WriteVTReg ( DD_OVERLAY_VIDEO_KEY_MSK, 0x0000FFFF );
  691. ppdev->OverlayInfo16.dwFlags &= ~DOUBLE_PITCH;
  692. break;
  693. }
  694. }
  695. // Calculate start of video memory in QWORD boundary
  696. dwBytesPerPixel = dwBitCount >> 3;
  697. dwStart = (lpUpdateOverlay->rSrc.top * dwStride)
  698. + (lpUpdateOverlay->rSrc.left * dwBytesPerPixel);
  699. dwStart = dwStart - (dwStart & 0x7);
  700. ppdev->dwOverlayFlipOffset = dwStart; // Save for flip
  701. dwStart += (DWORD)lpSource->fpVidMem;
  702. // Set overlay filter characteristics:
  703. /*
  704. * This register write enables the overlay and scaler registers
  705. */
  706. //gwRedTemp =0 ; //gamma control
  707. if(0) //if ( gwRedTemp )
  708. {
  709. DD_WriteVTReg ( DD_OVERLAY_SCALE_CNTL, 0xC0000001L | g_dwGamma );
  710. }
  711. else
  712. {
  713. DD_WriteVTReg ( DD_OVERLAY_SCALE_CNTL, 0xC0000003L | g_dwGamma );
  714. }
  715. /*
  716. * Get offset of buffer, if we are using a YUV Planar Overlay we
  717. * must extract the address from another field (dwReserved1).
  718. */
  719. SrcBufOffset = (DWORD)(lpUpdateOverlay->lpDDSrcSurface->lpGbl->fpVidMem); //- (FLATPTR)ppdev->pjScreen;
  720. ppdev->OverlayInfo16.dwBuf0Start = SrcBufOffset;
  721. ppdev->OverlayInfo16.dwBuf1Start = SrcBufOffset;
  722. /*
  723. * Set up the colour keying, if any?
  724. */
  725. if ( lpUpdateOverlay->dwFlags & DDOVER_KEYSRC ||
  726. lpUpdateOverlay->dwFlags & DDOVER_KEYSRCOVERRIDE ||
  727. lpUpdateOverlay->dwFlags & DDOVER_KEYDEST ||
  728. lpUpdateOverlay->dwFlags & DDOVER_KEYDESTOVERRIDE )
  729. {
  730. ppdev->OverlayInfo16.dwOverlayKeyCntl = 0;
  731. if ( lpUpdateOverlay->dwFlags & DDOVER_KEYSRC ||
  732. lpUpdateOverlay->dwFlags & DDOVER_KEYSRCOVERRIDE )
  733. {
  734. //Set source colour key
  735. if ( lpUpdateOverlay->dwFlags & DDOVER_KEYSRC )
  736. {
  737. Temp=lpUpdateOverlay->lpDDDestSurface->ddckCKSrcOverlay.dwColorSpaceLowValue;
  738. }
  739. else
  740. {
  741. Temp=lpUpdateOverlay->overlayFX.dckSrcColorkey.dwColorSpaceLowValue;
  742. }
  743. DD_WriteVTReg ( DD_OVERLAY_VIDEO_KEY_CLR, Temp );
  744. //ppdev->OverlayInfo16.dwOverlayKeyCntl &= 0xFFFFFEE8;
  745. if(ppdev->iAsic ==CI_M64_VTA)
  746. {
  747. ppdev->OverlayInfo16.dwOverlayKeyCntl &= 0xFFFFF0E8;
  748. ppdev->OverlayInfo16.dwOverlayKeyCntl |= 0x00000c14;
  749. }
  750. else
  751. {
  752. ppdev->OverlayInfo16.dwOverlayKeyCntl &= 0xFFFFFEE8;
  753. ppdev->OverlayInfo16.dwOverlayKeyCntl |= 0x00000114;
  754. }
  755. }
  756. if ( lpUpdateOverlay->dwFlags & DDOVER_KEYDEST ||
  757. lpUpdateOverlay->dwFlags & DDOVER_KEYDESTOVERRIDE )
  758. {
  759. //Set destination colour key
  760. if ( lpUpdateOverlay->dwFlags & DDOVER_KEYDEST )
  761. {
  762. Temp=lpUpdateOverlay->lpDDDestSurface->ddckCKDestOverlay.dwColorSpaceLowValue;
  763. }
  764. else
  765. {
  766. Temp=lpUpdateOverlay->overlayFX.dckDestColorkey.dwColorSpaceLowValue;
  767. if ( Temp == 0 && ppdev->cBitsPerPel == 32 )
  768. Temp = 0x00FF00FF;
  769. }
  770. DD_WriteVTReg ( DD_OVERLAY_GRAPHICS_KEY_CLR, Temp );
  771. ppdev->OverlayInfo16.dwOverlayKeyCntl &= 0xFFFFFF8FL;
  772. ppdev->OverlayInfo16.dwOverlayKeyCntl |= 0x00000050L;
  773. }
  774. }
  775. else
  776. {
  777. //No source or destination colour keying
  778. DD_WriteVTReg ( DD_OVERLAY_GRAPHICS_KEY_CLR, 0x00000000 );
  779. ppdev->OverlayInfo16.dwOverlayKeyCntl = 0x8000211L;
  780. }
  781. /*
  782. * Now set the stretch factor and overlay position.
  783. */
  784. ppdev->OverlayWidth = rOverlay.right - rOverlay.left;
  785. ppdev->OverlayHeight = rOverlay.bottom - rOverlay.top;
  786. //LastOverlayPos=OverlayRect;
  787. ppdev->OverlayInfo16.dwFlags |= OVERLAY_ALLOCATED;
  788. ppdev->OverlayInfo16.dwFlags |= UPDATEOVERLAY;
  789. ppdev->OverlayInfo16.dwFlags |= OVERLAY_VISIBLE;
  790. ppdev->OverlayInfo16.rOverlay = rOverlay;
  791. ppdev->OverlayInfo16.dwVInc = dwVInc;
  792. ppdev->OverlayInfo16.dwHInc = dwHInc;
  793. // new for DeskScanCallback
  794. ppdev->OverlayInfo16.rDst = rOverlay;
  795. ppdev->OverlayInfo16.rSrc = lpUpdateOverlay->rSrc;
  796. DeskScanCallback (ppdev );
  797. ppdev->OverlayInfo16.dwFlags &= ~UPDATEOVERLAY;
  798. /*
  799. * return to DirectDraw.
  800. */
  801. lpUpdateOverlay->ddRVal = DD_OK;
  802. return(DDHAL_DRIVER_HANDLED);
  803. }
  804. /*
  805. * structure for passing information to DDHAL SetOverlayPosition
  806. */
  807. DWORD DdSetOverlayPosition (PDD_SETOVERLAYPOSITIONDATA lpSetOverlayPosition )
  808. {
  809. RECTL rOverlay;
  810. PDEV* ppdev;
  811. ppdev = (PDEV*) lpSetOverlayPosition->lpDD->dhpdev;
  812. rOverlay.left = lpSetOverlayPosition->lXPos;
  813. rOverlay.top = lpSetOverlayPosition->lYPos;
  814. rOverlay.right = ppdev->OverlayWidth + lpSetOverlayPosition->lXPos;
  815. rOverlay.bottom = ppdev->OverlayHeight + lpSetOverlayPosition->lYPos;
  816. /*
  817. * We can't clip overlays, so we must make sure the co-ord, are within the
  818. * boundaries of the screen.
  819. */
  820. rOverlay.top = max ( 0, rOverlay.top );
  821. rOverlay.left = max ( 0, rOverlay.left );
  822. rOverlay.bottom = min ( (DWORD)ppdev->cyScreen -1 ,
  823. (DWORD) rOverlay.bottom );
  824. rOverlay.right = min ( (DWORD)ppdev->cxScreen -1 ,
  825. (DWORD) rOverlay.right );
  826. /*
  827. *Set overlay position
  828. */
  829. M64_CHECK_FIFO_SPACE(ppdev,ppdev-> pjMmBase, 1);
  830. ppdev->OverlayWidth =rOverlay.right - rOverlay.left;
  831. ppdev->OverlayHeight = rOverlay.bottom - rOverlay.top;
  832. ppdev->OverlayInfo16.dwFlags |= SETOVERLAYPOSITION;
  833. ppdev->OverlayInfo16.rOverlay = rOverlay;
  834. ppdev->OverlayInfo16.rDst = rOverlay;
  835. DeskScanCallback (ppdev );
  836. ppdev->OverlayInfo16.dwFlags &= ~SETOVERLAYPOSITION;
  837. /*
  838. * return to DirectDraw
  839. */
  840. lpSetOverlayPosition->ddRVal = DD_OK;
  841. return DDHAL_DRIVER_HANDLED;
  842. }
  843. /******************************Public*Routine******************************\
  844. * DWORD DdDestroySurface
  845. *
  846. * Note that if DirectDraw did the allocation, DDHAL_DRIVER_NOTHANDLED
  847. * should be returned.
  848. *
  849. \**************************************************************************/
  850. DWORD DdDestroySurface(
  851. PDD_DESTROYSURFACEDATA lpDestroySurface)
  852. {
  853. PDEV* ppdev;
  854. DD_SURFACE_GLOBAL* lpSurface;
  855. LONG lPitch;
  856. OH* poh;
  857. DISPDBG((10, " Enter Destroy Surface"));
  858. ppdev = (PDEV*) lpDestroySurface->lpDD->dhpdev;
  859. lpSurface = lpDestroySurface->lpDDSurface->lpGbl;
  860. poh= (OH*)( lpSurface->dwReserved1);
  861. if( (ULONG)lpSurface->dwReserved1 != (ULONG_PTR) NULL )
  862. {
  863. // let's see first if the value in reserved field is indeed an poh and not a cookie
  864. // because I don't know if ddraw is using also this value for system memory surfaces
  865. if(poh->ohState==OH_PERMANENT)
  866. {
  867. // bMoveAllDfbsFromOffscreenToDibs(ppdev); // avoid fragmentation
  868. pohFree(ppdev, poh);
  869. // Since we did the original allocation ourselves, we have to
  870. // return DDHAL_DRIVER_HANDLED here:
  871. lpDestroySurface->ddRVal = DD_OK;
  872. DISPDBG((10, " Exit Destroy Surface OK; deallocate poh X=%d, Y=%d ", poh->x, poh->y));
  873. return(DDHAL_DRIVER_HANDLED);
  874. }
  875. DISPDBG((10, " Exit Destroy Surface Not OK : The Reserved1 is not a poh"));
  876. }
  877. DISPDBG((10, " Exit Destroy Surface Not OK : The Reserved1 is NULL"));
  878. return(DDHAL_DRIVER_NOTHANDLED);
  879. }
  880. #endif