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.

817 lines
28 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *********************
  4. * * DDraw SAMPLE CODE *
  5. * *********************
  6. *
  7. * Module Name: ddstrblt.c
  8. *
  9. * Content:
  10. *
  11. * Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #include "precomp.h"
  15. #include "directx.h"
  16. #include "dd.h"
  17. //--------------------------------------------------------------------------
  18. //
  19. // ConvertColorKeys
  20. //
  21. // converts a color key to the Permedia internal format according to
  22. // the given Permedia surface format
  23. //
  24. //--------------------------------------------------------------------------
  25. VOID
  26. ConvertColorKeys(PermediaSurfaceData *pSurface,
  27. DWORD &dwLowerBound,
  28. DWORD &dwUpperBound)
  29. {
  30. switch (pSurface->SurfaceFormat.Format)
  31. {
  32. case PERMEDIA_444_RGB:
  33. dwLowerBound = CHROMA_LOWER_ALPHA(
  34. FORMAT_4444_32BIT_BGR(dwLowerBound));
  35. dwUpperBound = CHROMA_UPPER_ALPHA(
  36. FORMAT_4444_32BIT_BGR(dwUpperBound));
  37. break;
  38. case PERMEDIA_332_RGB:
  39. dwLowerBound = CHROMA_LOWER_ALPHA(
  40. FORMAT_332_32BIT_BGR(dwLowerBound));
  41. dwUpperBound = CHROMA_UPPER_ALPHA(
  42. FORMAT_332_32BIT_BGR(dwUpperBound));
  43. break;
  44. case PERMEDIA_2321_RGB:
  45. dwLowerBound = CHROMA_LOWER_ALPHA(
  46. FORMAT_2321_32BIT_BGR(dwLowerBound));
  47. dwUpperBound = CHROMA_UPPER_ALPHA(
  48. FORMAT_2321_32BIT_BGR(dwUpperBound));
  49. break;
  50. case PERMEDIA_4BIT_PALETTEINDEX:
  51. case PERMEDIA_8BIT_PALETTEINDEX:
  52. dwLowerBound = CHROMA_LOWER_ALPHA(
  53. FORMAT_PALETTE_32BIT(dwLowerBound));
  54. dwUpperBound = CHROMA_UPPER_ALPHA(
  55. FORMAT_PALETTE_32BIT(dwUpperBound));
  56. break;
  57. case PERMEDIA_5551_RGB:
  58. dwLowerBound = CHROMA_LOWER_ALPHA(
  59. FORMAT_5551_32BIT_BGR(dwLowerBound));
  60. dwUpperBound = CHROMA_UPPER_ALPHA(
  61. FORMAT_5551_32BIT_BGR(dwUpperBound));
  62. dwLowerBound = dwLowerBound & 0xF8F8F8F8;
  63. dwUpperBound = dwUpperBound | 0x07070707;
  64. break;
  65. case PERMEDIA_8888_RGB:
  66. // The permedia 565 mode is an extension, so don't confuse it with
  67. // the 8888 mode which has the same number
  68. if (pSurface->SurfaceFormat.FormatExtension ==
  69. PERMEDIA_565_RGB_EXTENSION)
  70. {
  71. dwLowerBound = CHROMA_LOWER_ALPHA(
  72. FORMAT_565_32BIT_BGR(dwLowerBound));
  73. dwUpperBound = CHROMA_UPPER_ALPHA(
  74. FORMAT_565_32BIT_BGR(dwUpperBound));
  75. dwLowerBound = dwLowerBound & 0xF8F8FcF8;
  76. dwUpperBound = dwUpperBound | 0x07070307;
  77. }
  78. else
  79. {
  80. dwLowerBound = CHROMA_LOWER_ALPHA(
  81. FORMAT_8888_32BIT_BGR(dwLowerBound));
  82. dwUpperBound = CHROMA_UPPER_ALPHA(
  83. FORMAT_8888_32BIT_BGR(dwUpperBound));
  84. }
  85. break;
  86. case PERMEDIA_888_RGB:
  87. dwLowerBound = CHROMA_LOWER_ALPHA(
  88. FORMAT_8888_32BIT_BGR(dwLowerBound));
  89. dwUpperBound = CHROMA_UPPER_ALPHA(
  90. FORMAT_8888_32BIT_BGR(dwUpperBound));
  91. break;
  92. }
  93. // swap blue and red if we have a RGB surface
  94. if (!pSurface->SurfaceFormat.ColorOrder)
  95. {
  96. dwLowerBound = SWAP_BR(dwLowerBound);
  97. dwUpperBound = SWAP_BR(dwUpperBound);
  98. }
  99. }
  100. //--------------------------------------------------------------------------
  101. //
  102. // PermediaStretchCopyBlt
  103. //
  104. // stretched blt through texture unit. no keying.
  105. // handle mirroring if the stretched image requires it.
  106. //
  107. //--------------------------------------------------------------------------
  108. VOID
  109. PermediaStretchCopyBlt( PPDev ppdev,
  110. LPDDHAL_BLTDATA lpBlt,
  111. PermediaSurfaceData* pDest,
  112. PermediaSurfaceData* pSource,
  113. RECTL *rDest,
  114. RECTL *rSrc,
  115. DWORD dwWindowBase,
  116. DWORD dwSourceOffset
  117. )
  118. {
  119. LONG lXScale;
  120. LONG lYScale;
  121. BOOL bYMirror=FALSE;
  122. BOOL bXMirror=FALSE;
  123. LONG lPixelSize=pDest->SurfaceFormat.PixelSize;
  124. DWORD dwDestWidth = rDest->right - rDest->left;
  125. DWORD dwDestHeight = rDest->bottom - rDest->top;
  126. DWORD dwSourceWidth = rSrc->right - rSrc->left;
  127. DWORD dwSourceHeight = rSrc->bottom - rSrc->top;
  128. DWORD dwTexSStart, dwTexTStart;
  129. DWORD dwRenderDirection;
  130. PERMEDIA_DEFS(ppdev);
  131. DBG_DD(( 5, "DDraw:PermediaStretchCopyBlt dwWindowBase=%08lx "
  132. "dwSourceOffset=%08lx", dwWindowBase, dwSourceOffset));
  133. ASSERTDD(pDest, "Not valid private surface in destination");
  134. ASSERTDD(pSource, "Not valid private surface in source");
  135. lXScale = (dwSourceWidth << 20) / dwDestWidth;
  136. lYScale = (dwSourceHeight << 20) / dwDestHeight;
  137. // Changes pixel depth to Dest buffer pixel depth if neccessary.
  138. RESERVEDMAPTR(28);
  139. SEND_PERMEDIA_DATA( FBPixelOffset, 0x0);
  140. SEND_PERMEDIA_DATA( FBReadPixel, pDest->SurfaceFormat.FBReadPixel);
  141. if (lPixelSize != 0)
  142. {
  143. // set writeback to dest surface...
  144. SEND_PERMEDIA_DATA( DitherMode,
  145. (pDest->SurfaceFormat.ColorOrder <<
  146. PM_DITHERMODE_COLORORDER) |
  147. (pDest->SurfaceFormat.Format <<
  148. PM_DITHERMODE_COLORFORMAT) |
  149. (pDest->SurfaceFormat.FormatExtension <<
  150. PM_DITHERMODE_COLORFORMATEXTENSION) |
  151. (__PERMEDIA_ENABLE << PM_DITHERMODE_ENABLE));
  152. }
  153. SEND_PERMEDIA_DATA(FBWindowBase, dwWindowBase);
  154. // set no read of dest.
  155. SEND_PERMEDIA_DATA(FBReadMode, pDest->ulPackedPP);
  156. SEND_PERMEDIA_DATA(LogicalOpMode, __PERMEDIA_DISABLE);
  157. // set base of source
  158. SEND_PERMEDIA_DATA(TextureBaseAddress, dwSourceOffset);
  159. SEND_PERMEDIA_DATA(TextureAddressMode,(1 << PM_TEXADDRESSMODE_ENABLE));
  160. SEND_PERMEDIA_DATA(TextureColorMode, (1 << PM_TEXCOLORMODE_ENABLE) |
  161. (_P2_TEXTURE_COPY <<
  162. PM_TEXCOLORMODE_APPLICATION));
  163. SEND_PERMEDIA_DATA(TextureReadMode,
  164. PM_TEXREADMODE_ENABLE(__PERMEDIA_ENABLE)|
  165. PM_TEXREADMODE_FILTER(__PERMEDIA_DISABLE)|
  166. PM_TEXREADMODE_WIDTH(11) |
  167. PM_TEXREADMODE_HEIGHT(11) );
  168. // set source bitmap format
  169. SEND_PERMEDIA_DATA(TextureDataFormat,
  170. (pSource->SurfaceFormat.Format <<
  171. PM_TEXDATAFORMAT_FORMAT) |
  172. (pSource->SurfaceFormat.FormatExtension <<
  173. PM_TEXDATAFORMAT_FORMATEXTENSION) |
  174. (pSource->SurfaceFormat.ColorOrder <<
  175. PM_TEXDATAFORMAT_COLORORDER));
  176. SEND_PERMEDIA_DATA(TextureMapFormat, (pSource->ulPackedPP) |
  177. (pSource->SurfaceFormat.PixelSize <<
  178. PM_TEXMAPFORMAT_TEXELSIZE) );
  179. // If we are doing special effects, and we are mirroring,
  180. // we need to fix up the rectangles and change the sense of
  181. // the render operation - we need to be carefull with overlapping
  182. // rectangles
  183. if (dwWindowBase != dwSourceOffset)
  184. {
  185. dwRenderDirection = 1;
  186. }
  187. else
  188. {
  189. if(rSrc->top < rDest->top)
  190. {
  191. dwRenderDirection = 0;
  192. }
  193. else if(rSrc->top > rDest->top)
  194. {
  195. dwRenderDirection = 1;
  196. }
  197. else if(rSrc->left < rDest->left)
  198. {
  199. dwRenderDirection = 0;
  200. }
  201. else dwRenderDirection = 1;
  202. }
  203. if(NULL != lpBlt && lpBlt->dwFlags & DDBLT_DDFX)
  204. {
  205. bYMirror = lpBlt->bltFX.dwDDFX & DDBLTFX_MIRRORUPDOWN;
  206. bXMirror = lpBlt->bltFX.dwDDFX & DDBLTFX_MIRRORLEFTRIGHT;
  207. } else
  208. {
  209. if (dwRenderDirection==0)
  210. {
  211. bXMirror = TRUE;
  212. bYMirror = TRUE;
  213. }
  214. }
  215. if (bXMirror)
  216. {
  217. dwTexSStart = rSrc->right - 1;
  218. lXScale = -lXScale;
  219. }
  220. else
  221. {
  222. dwTexSStart = rSrc->left;
  223. }
  224. if (bYMirror)
  225. {
  226. dwTexTStart = rSrc->bottom - 1;
  227. lYScale = -lYScale;
  228. }
  229. else
  230. {
  231. dwTexTStart = rSrc->top;
  232. }
  233. SEND_PERMEDIA_DATA(SStart, dwTexSStart << 20);
  234. SEND_PERMEDIA_DATA(TStart, dwTexTStart << 20);
  235. SEND_PERMEDIA_DATA(dSdx, lXScale);
  236. SEND_PERMEDIA_DATA(dSdyDom, 0);
  237. SEND_PERMEDIA_DATA(dTdx, 0);
  238. SEND_PERMEDIA_DATA(dTdyDom, lYScale);
  239. // Render the rectangle
  240. if (dwRenderDirection)
  241. {
  242. SEND_PERMEDIA_DATA(StartXDom, INTtoFIXED(rDest->left));
  243. SEND_PERMEDIA_DATA(StartXSub, INTtoFIXED(rDest->right));
  244. SEND_PERMEDIA_DATA(StartY, INTtoFIXED(rDest->top));
  245. SEND_PERMEDIA_DATA(dY, INTtoFIXED(1));
  246. SEND_PERMEDIA_DATA(Count, rDest->bottom - rDest->top);
  247. SEND_PERMEDIA_DATA(Render, __RENDER_TRAPEZOID_PRIMITIVE |
  248. __RENDER_TEXTURED_PRIMITIVE);
  249. }
  250. else
  251. {
  252. // Render right to left, bottom to top
  253. SEND_PERMEDIA_DATA(StartXDom, INTtoFIXED(rDest->right));
  254. SEND_PERMEDIA_DATA(StartXSub, INTtoFIXED(rDest->left));
  255. SEND_PERMEDIA_DATA(StartY, INTtoFIXED(rDest->bottom - 1));
  256. SEND_PERMEDIA_DATA(dY, (DWORD)INTtoFIXED(-1));
  257. SEND_PERMEDIA_DATA(Count, rDest->bottom - rDest->top);
  258. SEND_PERMEDIA_DATA(Render, __RENDER_TRAPEZOID_PRIMITIVE |
  259. __RENDER_TEXTURED_PRIMITIVE);
  260. }
  261. SEND_PERMEDIA_DATA(DitherMode, __PERMEDIA_DISABLE);
  262. SEND_PERMEDIA_DATA(TextureAddressMode, __PERMEDIA_DISABLE);
  263. SEND_PERMEDIA_DATA(TextureColorMode, __PERMEDIA_DISABLE);
  264. SEND_PERMEDIA_DATA(TextureReadMode, __PERMEDIA_DISABLE);
  265. COMMITDMAPTR();
  266. FLUSHDMA();
  267. } // PermediaStretchCopyBlt
  268. //--------------------------------------------------------------------------
  269. //
  270. // PermediaSourceChromaBlt
  271. //
  272. // Does a blit through the texture unit to allow chroma keying.
  273. // Note the unpacking of the colour key to fit into the Permedia format.
  274. //
  275. //--------------------------------------------------------------------------
  276. VOID
  277. PermediaSourceChromaBlt( PPDev ppdev,
  278. LPDDHAL_BLTDATA lpBlt,
  279. PermediaSurfaceData* pDest,
  280. PermediaSurfaceData* pSource,
  281. RECTL *rDest,
  282. RECTL *rSrc,
  283. DWORD dwWindowBase,
  284. DWORD dwSourceOffset
  285. )
  286. {
  287. DWORD dwLowerBound = lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceLowValue;
  288. DWORD dwUpperBound = lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceHighValue;
  289. DWORD dwRenderDirection;
  290. LONG lPixelSize=pDest->SurfaceFormat.PixelSize;
  291. PERMEDIA_DEFS(ppdev);
  292. DBG_DD(( 5, "DDraw:PermediaSourceChromaBlt"));
  293. ASSERTDD(pDest, "Not valid private surface in destination");
  294. ASSERTDD(pSource, "Not valid private surface in source");
  295. // Changes pixel depth to Frame buffer pixel depth if neccessary.
  296. ConvertColorKeys( pSource, dwLowerBound, dwUpperBound);
  297. RESERVEDMAPTR(31);
  298. SEND_PERMEDIA_DATA(FBReadPixel, pDest->SurfaceFormat.FBReadPixel);
  299. if (lPixelSize != 0)
  300. {
  301. // set writeback to dest surface...
  302. SEND_PERMEDIA_DATA( DitherMode,
  303. (pDest->SurfaceFormat.ColorOrder <<
  304. PM_DITHERMODE_COLORORDER) |
  305. (pDest->SurfaceFormat.Format <<
  306. PM_DITHERMODE_COLORFORMAT) |
  307. (pDest->SurfaceFormat.FormatExtension <<
  308. PM_DITHERMODE_COLORFORMATEXTENSION) |
  309. (1 << PM_DITHERMODE_ENABLE));
  310. }
  311. // Reject range
  312. SEND_PERMEDIA_DATA(YUVMode, PM_YUVMODE_CHROMATEST_FAILWITHIN << 1);
  313. SEND_PERMEDIA_DATA(FBWindowBase, dwWindowBase);
  314. // set no read of source.
  315. // add read src/dest enable
  316. SEND_PERMEDIA_DATA(FBReadMode,pDest->ulPackedPP);
  317. SEND_PERMEDIA_DATA(LogicalOpMode, __PERMEDIA_DISABLE);
  318. // set base of source
  319. SEND_PERMEDIA_DATA(TextureBaseAddress, dwSourceOffset);
  320. SEND_PERMEDIA_DATA(TextureAddressMode,(1 << PM_TEXADDRESSMODE_ENABLE));
  321. //
  322. // modulate & ramp??
  323. SEND_PERMEDIA_DATA(TextureColorMode, (1 << PM_TEXCOLORMODE_ENABLE) |
  324. (_P2_TEXTURE_COPY <<
  325. PM_TEXCOLORMODE_APPLICATION));
  326. SEND_PERMEDIA_DATA(TextureReadMode,
  327. PM_TEXREADMODE_ENABLE(__PERMEDIA_ENABLE) |
  328. PM_TEXREADMODE_FILTER(__PERMEDIA_DISABLE) |
  329. PM_TEXREADMODE_WIDTH(11) |
  330. PM_TEXREADMODE_HEIGHT(11) );
  331. SEND_PERMEDIA_DATA(TextureDataFormat,
  332. (pSource->SurfaceFormat.Format <<
  333. PM_TEXDATAFORMAT_FORMAT) |
  334. (pSource->SurfaceFormat.FormatExtension <<
  335. PM_TEXDATAFORMAT_FORMATEXTENSION) |
  336. (pSource->SurfaceFormat.ColorOrder <<
  337. PM_TEXDATAFORMAT_COLORORDER));
  338. SEND_PERMEDIA_DATA( TextureMapFormat,
  339. (pSource->ulPackedPP) |
  340. (pSource->SurfaceFormat.PixelSize <<
  341. PM_TEXMAPFORMAT_TEXELSIZE) );
  342. SEND_PERMEDIA_DATA(ChromaLowerBound, dwLowerBound);
  343. SEND_PERMEDIA_DATA(ChromaUpperBound, dwUpperBound);
  344. if ((lpBlt->lpDDDestSurface->lpGbl->fpVidMem) !=
  345. (lpBlt->lpDDSrcSurface->lpGbl->fpVidMem))
  346. {
  347. dwRenderDirection = 1;
  348. }
  349. else
  350. {
  351. if(rSrc->top < rDest->top)
  352. {
  353. dwRenderDirection = 0;
  354. }
  355. else if(rSrc->top > rDest->top)
  356. {
  357. dwRenderDirection = 1;
  358. }
  359. else if(rSrc->left < rDest->left)
  360. {
  361. dwRenderDirection = 0;
  362. }
  363. else dwRenderDirection = 1;
  364. }
  365. /*
  366. * Render the rectangle
  367. */
  368. // Left -> right, top->bottom
  369. if (dwRenderDirection)
  370. {
  371. // set offset of source
  372. SEND_PERMEDIA_DATA(SStart, rSrc->left<<20);
  373. SEND_PERMEDIA_DATA(TStart, rSrc->top<<20);
  374. SEND_PERMEDIA_DATA(dSdx, 1 << 20);
  375. SEND_PERMEDIA_DATA(dSdyDom, 0);
  376. SEND_PERMEDIA_DATA(dTdx, 0);
  377. SEND_PERMEDIA_DATA(dTdyDom, 1 << 20);
  378. SEND_PERMEDIA_DATA(StartXDom, INTtoFIXED(rDest->left));
  379. SEND_PERMEDIA_DATA(StartXSub, INTtoFIXED(rDest->right));
  380. SEND_PERMEDIA_DATA(StartY, INTtoFIXED(rDest->top));
  381. SEND_PERMEDIA_DATA(dY, INTtoFIXED(1));
  382. SEND_PERMEDIA_DATA(Count, rDest->bottom - rDest->top);
  383. SEND_PERMEDIA_DATA(Render, __RENDER_TRAPEZOID_PRIMITIVE |
  384. __RENDER_TEXTURED_PRIMITIVE);
  385. }
  386. else
  387. // right->left, bottom->top
  388. {
  389. // set offset of source
  390. SEND_PERMEDIA_DATA(SStart, rSrc->right << 20);
  391. SEND_PERMEDIA_DATA(TStart, (rSrc->bottom - 1) << 20);
  392. SEND_PERMEDIA_DATA(dSdx, (DWORD)(-1 << 20));
  393. SEND_PERMEDIA_DATA(dSdyDom, 0);
  394. SEND_PERMEDIA_DATA(dTdx, 0);
  395. SEND_PERMEDIA_DATA(dTdyDom, (DWORD)(-1 << 20));
  396. // Render right to left, bottom to top
  397. SEND_PERMEDIA_DATA(StartXDom, INTtoFIXED(rDest->right));
  398. SEND_PERMEDIA_DATA(StartXSub, INTtoFIXED(rDest->left));
  399. SEND_PERMEDIA_DATA(StartY, INTtoFIXED(rDest->bottom - 1));
  400. SEND_PERMEDIA_DATA(dY, (DWORD)INTtoFIXED(-1));
  401. SEND_PERMEDIA_DATA(Count, rDest->bottom - rDest->top);
  402. SEND_PERMEDIA_DATA(Render, __RENDER_TRAPEZOID_PRIMITIVE |
  403. __RENDER_TEXTURED_PRIMITIVE);
  404. }
  405. // Turn off chroma key
  406. SEND_PERMEDIA_DATA(YUVMode, 0x0);
  407. SEND_PERMEDIA_DATA(TextureAddressMode, __PERMEDIA_DISABLE);
  408. SEND_PERMEDIA_DATA(TextureColorMode, __PERMEDIA_DISABLE);
  409. SEND_PERMEDIA_DATA(TextureReadMode, __PERMEDIA_DISABLE);
  410. if (pSource->SurfaceFormat.PixelSize != 0)
  411. {
  412. SEND_PERMEDIA_DATA(DitherMode, 0);
  413. }
  414. COMMITDMAPTR();
  415. FLUSHDMA();
  416. } // PermediaSourceChromaBlt
  417. //--------------------------------------------------------------------------
  418. //
  419. // PermediaStretchCopyChromaBlt
  420. //
  421. // Does a blit through the texture unit to allow stretching. Also
  422. // handle mirroring and chroma keying if the stretched image requires it.
  423. //
  424. //--------------------------------------------------------------------------
  425. VOID
  426. PermediaStretchCopyChromaBlt( PPDev ppdev,
  427. LPDDHAL_BLTDATA lpBlt,
  428. PermediaSurfaceData* pDest,
  429. PermediaSurfaceData* pSource,
  430. RECTL *rDest,
  431. RECTL *rSrc,
  432. DWORD dwWindowBase,
  433. DWORD dwSourceOffset
  434. )
  435. {
  436. LONG lXScale;
  437. LONG lYScale;
  438. BOOL bYMirror;
  439. BOOL bXMirror;
  440. DWORD dwDestWidth = rDest->right - rDest->left;
  441. DWORD dwDestHeight = rDest->bottom - rDest->top;
  442. DWORD dwSourceWidth = rSrc->right - rSrc->left;
  443. DWORD dwSourceHeight = rSrc->bottom - rSrc->top;
  444. DWORD dwTexSStart, dwTexTStart;
  445. DWORD dwRenderDirection;
  446. LONG lPixelSize=pDest->SurfaceFormat.PixelSize;
  447. DWORD dwLowerBound = lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceLowValue;
  448. DWORD dwUpperBound = lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceHighValue;
  449. PERMEDIA_DEFS(ppdev);
  450. DBG_DD(( 5, "DDraw:PermediaStretchCopyChromaBlt"));
  451. ASSERTDD(pDest, "Not valid private surface in destination");
  452. ASSERTDD(pSource, "Not valid private surface in source");
  453. // Changes pixel depth to Frame buffer pixel depth if neccessary.
  454. ConvertColorKeys( pSource, dwLowerBound, dwUpperBound);
  455. RESERVEDMAPTR(31);
  456. SEND_PERMEDIA_DATA(FBReadPixel, pDest->SurfaceFormat.FBReadPixel);
  457. if (lPixelSize != 0)
  458. {
  459. // set writeback to dest surface...
  460. SEND_PERMEDIA_DATA( DitherMode,
  461. (pDest->SurfaceFormat.ColorOrder <<
  462. PM_DITHERMODE_COLORORDER) |
  463. (pDest->SurfaceFormat.Format <<
  464. PM_DITHERMODE_COLORFORMAT) |
  465. (pDest->SurfaceFormat.FormatExtension <<
  466. PM_DITHERMODE_COLORFORMATEXTENSION) |
  467. (1 << PM_DITHERMODE_ENABLE));
  468. }
  469. // Reject range
  470. SEND_PERMEDIA_DATA(YUVMode, PM_YUVMODE_CHROMATEST_FAILWITHIN <<1);
  471. SEND_PERMEDIA_DATA(FBWindowBase, dwWindowBase);
  472. // set no read of source.
  473. SEND_PERMEDIA_DATA(FBReadMode, pDest->ulPackedPP);
  474. SEND_PERMEDIA_DATA(LogicalOpMode, __PERMEDIA_DISABLE);
  475. // set base of source
  476. SEND_PERMEDIA_DATA(TextureBaseAddress, dwSourceOffset);
  477. SEND_PERMEDIA_DATA(TextureAddressMode,(1 << PM_TEXADDRESSMODE_ENABLE));
  478. SEND_PERMEDIA_DATA( TextureColorMode,
  479. (1 << PM_TEXCOLORMODE_ENABLE) |
  480. (_P2_TEXTURE_COPY << PM_TEXCOLORMODE_APPLICATION));
  481. SEND_PERMEDIA_DATA( TextureReadMode,
  482. PM_TEXREADMODE_ENABLE(__PERMEDIA_ENABLE) |
  483. PM_TEXREADMODE_FILTER(__PERMEDIA_DISABLE) |
  484. PM_TEXREADMODE_WIDTH(11) |
  485. PM_TEXREADMODE_HEIGHT(11));
  486. lXScale = (dwSourceWidth << 20) / (dwDestWidth);
  487. lYScale = (dwSourceHeight << 20) / (dwDestHeight);
  488. SEND_PERMEDIA_DATA( TextureDataFormat,
  489. (pSource->SurfaceFormat.Format <<
  490. PM_TEXDATAFORMAT_FORMAT) |
  491. (pSource->SurfaceFormat.FormatExtension <<
  492. PM_TEXDATAFORMAT_FORMATEXTENSION) |
  493. (pSource->SurfaceFormat.ColorOrder <<
  494. PM_TEXDATAFORMAT_COLORORDER));
  495. SEND_PERMEDIA_DATA( TextureMapFormat,
  496. (pSource->ulPackedPP) |
  497. (pSource->SurfaceFormat.PixelSize <<
  498. PM_TEXMAPFORMAT_TEXELSIZE) );
  499. bYMirror = FALSE;
  500. bXMirror = FALSE;
  501. if ((lpBlt->lpDDDestSurface->lpGbl->fpVidMem) !=
  502. (lpBlt->lpDDSrcSurface->lpGbl->fpVidMem))
  503. {
  504. dwRenderDirection = 1;
  505. }
  506. else
  507. {
  508. if(rSrc->top < rDest->top)
  509. {
  510. dwRenderDirection = 0;
  511. }
  512. else if(rSrc->top > rDest->top)
  513. {
  514. dwRenderDirection = 1;
  515. }
  516. else if(rSrc->left < rDest->left)
  517. {
  518. dwRenderDirection = 0;
  519. }
  520. else dwRenderDirection = 1;
  521. }
  522. if(lpBlt->dwFlags & DDBLT_DDFX)
  523. {
  524. bYMirror = lpBlt->bltFX.dwDDFX & DDBLTFX_MIRRORUPDOWN;
  525. bXMirror = lpBlt->bltFX.dwDDFX & DDBLTFX_MIRRORLEFTRIGHT;
  526. } else
  527. {
  528. if (dwRenderDirection==0)
  529. {
  530. bXMirror = TRUE;
  531. bYMirror = TRUE;
  532. }
  533. }
  534. if (bXMirror)
  535. {
  536. dwTexSStart = rSrc->right - 1;
  537. lXScale = -lXScale;
  538. }
  539. else
  540. {
  541. dwTexSStart = rSrc->left;
  542. }
  543. if (bYMirror)
  544. {
  545. dwTexTStart = rSrc->bottom - 1;
  546. lYScale = -lYScale;
  547. }
  548. else
  549. {
  550. dwTexTStart = rSrc->top;
  551. }
  552. SEND_PERMEDIA_DATA(dTdyDom, lYScale);
  553. SEND_PERMEDIA_DATA(ChromaLowerBound, dwLowerBound);
  554. SEND_PERMEDIA_DATA(ChromaUpperBound, dwUpperBound);
  555. // set texture coordinates
  556. SEND_PERMEDIA_DATA(SStart, dwTexSStart << 20);
  557. SEND_PERMEDIA_DATA(TStart, dwTexTStart << 20);
  558. SEND_PERMEDIA_DATA(dSdx, lXScale);
  559. SEND_PERMEDIA_DATA(dSdyDom, 0);
  560. SEND_PERMEDIA_DATA(dTdx, 0);
  561. //
  562. // Render the rectangle
  563. //
  564. if (dwRenderDirection)
  565. {
  566. SEND_PERMEDIA_DATA(StartXDom, INTtoFIXED(rDest->left));
  567. SEND_PERMEDIA_DATA(StartXSub, INTtoFIXED(rDest->right));
  568. SEND_PERMEDIA_DATA(StartY, INTtoFIXED(rDest->top));
  569. SEND_PERMEDIA_DATA(dY, INTtoFIXED(1));
  570. }
  571. else
  572. {
  573. SEND_PERMEDIA_DATA(StartXDom, INTtoFIXED(rDest->right));
  574. SEND_PERMEDIA_DATA(StartXSub, INTtoFIXED(rDest->left));
  575. SEND_PERMEDIA_DATA(StartY, INTtoFIXED(rDest->bottom - 1));
  576. SEND_PERMEDIA_DATA(dY, (DWORD)INTtoFIXED(-1));
  577. }
  578. SEND_PERMEDIA_DATA(Count, rDest->bottom - rDest->top);
  579. SEND_PERMEDIA_DATA(Render, __RENDER_TRAPEZOID_PRIMITIVE |
  580. __RENDER_TEXTURED_PRIMITIVE);
  581. // Turn off units
  582. SEND_PERMEDIA_DATA(YUVMode, __PERMEDIA_DISABLE);
  583. SEND_PERMEDIA_DATA(TextureAddressMode, __PERMEDIA_DISABLE);
  584. SEND_PERMEDIA_DATA(TextureColorMode, __PERMEDIA_DISABLE);
  585. SEND_PERMEDIA_DATA(TextureReadMode, __PERMEDIA_DISABLE);
  586. if (pSource->SurfaceFormat.PixelSize != 0)
  587. {
  588. SEND_PERMEDIA_DATA(DitherMode, 0);
  589. }
  590. COMMITDMAPTR();
  591. FLUSHDMA();
  592. } // PermediaStretchCopyChromaBlt
  593. //--------------------------------------------------------------------------
  594. //
  595. // PermediaYUVtoRGB
  596. //
  597. // Permedia2 YUV to RGB conversion blt
  598. //
  599. //--------------------------------------------------------------------------
  600. VOID
  601. PermediaYUVtoRGB( PPDev ppdev,
  602. DDBLTFX* lpBltFX,
  603. PermediaSurfaceData* pDest,
  604. PermediaSurfaceData* pSource,
  605. RECTL *rDest,
  606. RECTL *rSrc,
  607. DWORD dwWindowBase,
  608. DWORD dwSourceOffset)
  609. {
  610. DWORD lXScale;
  611. DWORD lYScale;
  612. DWORD dwDestWidth = rDest->right - rDest->left;
  613. DWORD dwDestHeight = rDest->bottom - rDest->top;
  614. DWORD dwSourceWidth = rSrc->right - rSrc->left;
  615. DWORD dwSourceHeight = rSrc->bottom - rSrc->top;
  616. PERMEDIA_DEFS(ppdev);
  617. ASSERTDD(pDest, "Not valid private surface in destination");
  618. ASSERTDD(pSource, "Not valid private surface in source");
  619. lXScale = (dwSourceWidth << 20) / dwDestWidth;
  620. lYScale = (dwSourceHeight << 20) / dwDestHeight;
  621. // Changes pixel depth to Frame buffer pixel depth if neccessary.
  622. RESERVEDMAPTR(29);
  623. SEND_PERMEDIA_DATA(FBReadPixel,ppdev->bPixShift);
  624. if (pDest->SurfaceFormat.PixelSize != __PERMEDIA_8BITPIXEL)
  625. {
  626. SEND_PERMEDIA_DATA(DitherMode,
  627. (COLOR_MODE << PM_DITHERMODE_COLORORDER) |
  628. (pDest->SurfaceFormat.Format << PM_DITHERMODE_COLORFORMAT) |
  629. (pDest->SurfaceFormat.FormatExtension <<
  630. PM_DITHERMODE_COLORFORMATEXTENSION) |
  631. (1 << PM_DITHERMODE_ENABLE) |
  632. (1 << PM_DITHERMODE_DITHERENABLE));
  633. }
  634. SEND_PERMEDIA_DATA(FBWindowBase, dwWindowBase);
  635. // set no read of source.
  636. SEND_PERMEDIA_DATA(FBReadMode, pDest->ulPackedPP);
  637. SEND_PERMEDIA_DATA(LogicalOpMode, __PERMEDIA_DISABLE);
  638. // set base of source
  639. SEND_PERMEDIA_DATA(TextureBaseAddress, dwSourceOffset);
  640. SEND_PERMEDIA_DATA(TextureAddressMode,(1 << PM_TEXADDRESSMODE_ENABLE));
  641. SEND_PERMEDIA_DATA( TextureColorMode,
  642. (1 << PM_TEXCOLORMODE_ENABLE) |
  643. (_P2_TEXTURE_COPY << PM_TEXCOLORMODE_APPLICATION));
  644. SEND_PERMEDIA_DATA( TextureReadMode,
  645. PM_TEXREADMODE_ENABLE(__PERMEDIA_ENABLE) |
  646. PM_TEXREADMODE_FILTER(__PERMEDIA_ENABLE) |
  647. PM_TEXREADMODE_WIDTH(11) |
  648. PM_TEXREADMODE_HEIGHT(11) );
  649. SEND_PERMEDIA_DATA( TextureDataFormat,
  650. (pSource->SurfaceFormat.Format <<
  651. PM_TEXDATAFORMAT_FORMAT) |
  652. (pSource->SurfaceFormat.FormatExtension <<
  653. PM_TEXDATAFORMAT_FORMATEXTENSION) |
  654. (INV_COLOR_MODE << PM_TEXDATAFORMAT_COLORORDER));
  655. SEND_PERMEDIA_DATA( TextureMapFormat,
  656. (pSource->ulPackedPP) |
  657. (pSource->SurfaceFormat.PixelSize <<
  658. PM_TEXMAPFORMAT_TEXELSIZE) );
  659. // Turn on the YUV unit
  660. SEND_PERMEDIA_DATA(YUVMode, 0x1);
  661. SEND_PERMEDIA_DATA(LogicalOpMode, 0);
  662. // set offset of source
  663. SEND_PERMEDIA_DATA(SStart, rSrc->left << 20);
  664. SEND_PERMEDIA_DATA(TStart, rSrc->top << 20);
  665. SEND_PERMEDIA_DATA(dSdx, lXScale);
  666. SEND_PERMEDIA_DATA(dSdyDom, 0);
  667. SEND_PERMEDIA_DATA(dTdx, 0);
  668. SEND_PERMEDIA_DATA(dTdyDom, lYScale);
  669. // Render the rectangle
  670. //
  671. SEND_PERMEDIA_DATA(StartXDom, INTtoFIXED(rDest->left));
  672. SEND_PERMEDIA_DATA(StartXSub, INTtoFIXED(rDest->right));
  673. SEND_PERMEDIA_DATA(StartY, INTtoFIXED(rDest->top));
  674. SEND_PERMEDIA_DATA(dY, INTtoFIXED(1));
  675. SEND_PERMEDIA_DATA(Count, rDest->bottom - rDest->top);
  676. SEND_PERMEDIA_DATA(Render, __RENDER_TRAPEZOID_PRIMITIVE |
  677. __RENDER_TEXTURED_PRIMITIVE);
  678. if (pSource->SurfaceFormat.PixelSize != __PERMEDIA_8BITPIXEL)
  679. {
  680. SEND_PERMEDIA_DATA(DitherMode, 0);
  681. }
  682. // Turn off units
  683. SEND_PERMEDIA_DATA(YUVMode, 0x0);
  684. SEND_PERMEDIA_DATA( TextureAddressMode,
  685. (0 << PM_TEXADDRESSMODE_ENABLE));
  686. SEND_PERMEDIA_DATA( TextureColorMode,
  687. (0 << PM_TEXCOLORMODE_ENABLE));
  688. COMMITDMAPTR();
  689. FLUSHDMA();
  690. }