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.

4213 lines
167 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: COPYBITS.c
  3. *
  4. * Author: Noel VanHook
  5. * Date: May. 31, 1995
  6. * Purpose: Handle calls to DrvCopyBits
  7. *
  8. * Copyright (c) 1997 Cirrus Logic, Inc.
  9. *
  10. * $Log: X:/log/laguna/nt35/displays/cl546x/COPYBITS.C $
  11. *
  12. * Rev 1.50 Mar 04 1998 15:22:54 frido
  13. * Added new shadow macros.
  14. *
  15. * Rev 1.49 Feb 25 1998 16:43:48 frido
  16. * Fixed a 16-bpp color translation problem for NT 5.0.
  17. *
  18. * Rev 1.48 Feb 24 1998 13:19:10 frido
  19. * Removed a few warning messages for NT 5.0.
  20. *
  21. * Rev 1.47 Dec 10 1997 13:29:54 frido
  22. * Merged from 1.62 branch.
  23. *
  24. * Rev 1.46.1.0 Nov 10 1997 14:58:46 frido
  25. * PDR#10893: With monochrome color translations in 8-bpp (palette) NT
  26. * decides that a 2-color translation table with values 0 and 1 is a TRIVIAL
  27. * translation table. But this breaks our assumption that the background is
  28. * always black (0) and the foreground if white (FF). Lucky for us NT sets
  29. * an extra bit in this case: the translation table is both TRIVIAL and has a
  30. * TABLE.
  31. *
  32. * Rev 1.46 Nov 04 1997 17:36:58 frido
  33. * Fixed 8-bpp path when no color translation is required.
  34. *
  35. * Rev 1.45 Nov 04 1997 09:41:10 frido
  36. * Added COLOR_TRANSLATE switches around hardware color translation code.
  37. * Removed unaccessed local variables.
  38. *
  39. * Rev 1.44 Nov 03 1997 15:09:24 frido
  40. * Added REQUIRE and WRITE_STRING macros.
  41. *
  42. * Rev 1.43 15 Oct 1997 12:02:26 noelv
  43. * Added host to screen color translation
  44. *
  45. * Rev 1.42 08 Aug 1997 17:23:34 FRIDO
  46. *
  47. * Updatded SWAT7 code for monochrome hardware bug.
  48. *
  49. * Rev 1.41 25 Jun 1997 16:01:36 noelv
  50. * Check for NULL translation table before using it.
  51. *
  52. * Rev 1.40 12 Jun 1997 14:46:12 noelv
  53. * Frido's optimized workaround for MONO HOSTDATA bug (SWAT7)
  54. * SWAT:
  55. * SWAT: Rev 1.3 06 Jun 1997 10:42:34 frido
  56. * SWAT: Changed 896 pixel width into 888.
  57. * SWAT:
  58. * SWAT: Rev 1.2 05 Jun 1997 14:48:14 frido
  59. * SWAT: Added SWAT7 code (monochrome bitblt cut-off).
  60. *
  61. * Rev 1.39 08 Apr 1997 12:14:16 einkauf
  62. *
  63. * add SYNC_W_3D to coordinate MCD/2D HW access
  64. *
  65. * Rev 1.38 21 Mar 1997 10:54:16 noelv
  66. *
  67. * Combined 'do_flag' and 'sw_test_flag' together into 'pointer_switch'
  68. *
  69. * Rev 1.37 19 Feb 1997 13:14:50 noelv
  70. * Moved default xlate table to xlate.c
  71. *
  72. * Rev 1.36 06 Feb 1997 10:37:38 noelv
  73. *
  74. * Put device to device stuff in it's own file.
  75. *
  76. * Rev 1.35 28 Jan 1997 11:13:42 noelv
  77. *
  78. * Removed extra dword requirements from 5465 driver.
  79. *
  80. * Rev 1.34 23 Jan 1997 17:26:36 bennyn
  81. * Modified to support 5465 DD
  82. *
  83. * Rev 1.33 23 Jan 1997 11:26:10 noelv
  84. *
  85. * Modified the '62 workaround to only happen on the '62
  86. *
  87. * Rev 1.32 17 Jan 1997 10:10:30 noelv
  88. * Workaround (punt) for HOSTDATA lockup on '62
  89. *
  90. * Rev 1.31 18 Dec 1996 11:35:30 noelv
  91. * Official workaround for mono hostdata bug.
  92. *
  93. * Rev 1.30 17 Dec 1996 17:05:48 SueS
  94. * Added test for writing to log file based on cursor at (0,0). Added more
  95. * information to the log file.
  96. *
  97. * Rev 1.29 11 Dec 1996 14:18:54 noelv
  98. *
  99. * Punt 24bpp mono host to screen with rop=66 (hw bug?)
  100. *
  101. * Rev 1.28 26 Nov 1996 10:47:34 SueS
  102. * Changed WriteLogFile parameters for buffering.
  103. *
  104. * Rev 1.27 13 Nov 1996 17:21:38 SueS
  105. * Changed WriteFile calls to WriteLogFile. Ifdef'ed out YUVBlt code
  106. * if USE_ASM is turned off.
  107. *
  108. * Rev 1.26 04 Oct 1996 16:52:00 bennyn
  109. *
  110. * Added DirectDraw YUV support
  111. *
  112. * Rev 1.25 06 Sep 1996 09:14:46 noelv
  113. *
  114. * Cleaned up NULL driver code.
  115. *
  116. * Rev 1.24 20 Aug 1996 11:03:20 noelv
  117. * Bugfix release from Frido 8-19-96
  118. *
  119. * Rev 1.3 18 Aug 1996 20:39:08 frido
  120. * Changed DrvCopyBits' detection of memory bitmaps. This fixes some GPF's.
  121. *
  122. * Rev 1.2 17 Aug 1996 13:18:14 frido
  123. * New release from Bellevue.
  124. *
  125. * Rev 1.1 15 Aug 1996 11:44:08 frido
  126. * Added precompiled header.
  127. *
  128. * Rev 1.0 14 Aug 1996 17:16:16 frido
  129. * Initial revision.
  130. *
  131. * Rev 1.22 28 May 1996 15:11:18 noelv
  132. * Updated data logging.
  133. *
  134. * Rev 1.21 24 Apr 1996 20:41:46 noelv
  135. * Fixed syntax error in C code (not used when using inline assembler)
  136. *
  137. * Rev 1.20 16 Apr 1996 22:48:42 noelv
  138. * accelerated color xlate for device to device.
  139. *
  140. * Rev 1.22 15 Apr 1996 17:26:46 frido
  141. * Added color translation in DeviceToDevice.
  142. *
  143. * Rev 1.21 12 Apr 1996 11:27:00 frido
  144. * Fixed a type in DeviceToHost24.
  145. *
  146. * Rev 1.20 08 Apr 1996 16:45:08 frido
  147. * Added call to PuntBitBlt.
  148. * Added check for translation in ScreenToHost.
  149. * Added SolidBrush cache.
  150. *
  151. * Rev 1.19 04 Apr 1996 09:57:10 frido
  152. * Added test for bitmap format in ScreenToHost.
  153. *
  154. * Rev 1.18 30 Mar 1996 22:12:16 frido
  155. * Refined checking for invalid translation flags.
  156. *
  157. * Rev 1.17 29 Mar 1996 14:53:52 frido
  158. * Fixed problem with grayed icons.
  159. *
  160. * Rev 1.16 27 Mar 1996 16:56:14 frido
  161. * Added return values to Do... routines.
  162. * Added check for undocumented translation flags.
  163. * Added check for translation tables.
  164. * Removed OP0 field in BLTDEF.
  165. *
  166. * Rev 1.15 25 Mar 1996 12:03:58 frido
  167. * Changed #ifdef frido into #if frido.
  168. *
  169. * Rev 1.14 25 Mar 1996 11:53:30 frido
  170. * Removed assembly for DoDeviceToDevice.
  171. *
  172. * Rev 1.13 25 Mar 1996 11:52:38 frido
  173. * Bellevue 102B03.
  174. *
  175. * Rev 1.9 20 Mar 1996 17:16:08 BENNYN
  176. * Fixed the BPR910 & BPR920 Phostone problems
  177. *
  178. * Rev 1.8 20 Mar 1996 14:17:42 bennyn
  179. *
  180. *
  181. * Rev 1.7 19 Mar 1996 11:37:32 noelv
  182. *
  183. * Added data logging.
  184. *
  185. * Rev 1.6 14 Mar 1996 09:38:46 andys
  186. *
  187. * Added if def on DoDeviceToDevice
  188. *
  189. * Rev 1.5 07 Mar 1996 18:20:58 bennyn
  190. * Removed read/modify/write on CONTROL reg
  191. *
  192. * Rev 1.4 06 Mar 1996 12:51:30 noelv
  193. * Frido ver 19b
  194. *
  195. * Rev 1.9 06 Mar 1996 14:59:06 frido
  196. * Added 'striping' wide bitmaps in 16-bpp and higher.
  197. *
  198. * Rev 1.8 04 Mar 1996 20:22:50 frido
  199. * Cached grCONTROL register.
  200. *
  201. * Rev 1.7 01 Mar 1996 17:48:12 frido
  202. * Added in-line assembly.
  203. *
  204. * Rev 1.6 29 Feb 1996 20:23:46 frido
  205. * Added 8-bpp source translation in 24- and 32-bpp HostToScreen.
  206. *
  207. * Rev 1.5 28 Feb 1996 22:35:20 frido
  208. * Added 8-bpp source translation in 16-bpp HostToScreen.
  209. *
  210. * Rev 1.4 27 Feb 1996 16:38:06 frido
  211. * Added device bitmap store/restore.
  212. *
  213. * Rev 1.3 26 Feb 1996 23:37:08 frido
  214. * Added comments.
  215. * Rewritten ScreenToHost and HostToScreen routines.
  216. * Removed several other bugs.
  217. *
  218. \**************************************************************************/
  219. #include "precomp.h"
  220. #include "SWAT.h"
  221. #define COPYBITS_DBG_LEVEL 1
  222. #if LOG_CALLS
  223. void LogCopyBits(
  224. int acc,
  225. SURFOBJ* psoSrc,
  226. SURFOBJ* psoDest,
  227. CLIPOBJ* pco,
  228. XLATEOBJ* pxlo);
  229. #else
  230. #define LogCopyBits(acc, psoSrc, psoDest, pco, pxlo)
  231. #endif
  232. //
  233. // Top level BLT functions.
  234. //
  235. #if (defined(i386) && USE_ASM)
  236. BOOL YUVBlt(SURFOBJ* psoTrg, SURFOBJ* psoSrc, CLIPOBJ* pco,
  237. XLATEOBJ* pxlo, RECTL* prclTrg, POINTL* pptlSrc);
  238. #endif
  239. BOOL CopyDeviceBitmap(SURFOBJ* psoTrg, SURFOBJ* psoSrc, CLIPOBJ* pco,
  240. XLATEOBJ* pxlo, RECTL* prclTrg, POINTL* pptlSrc,
  241. ULONG ulDRAWBLTDEF, COPYFN* pfn);
  242. BOOL DoDeviceToDevice(SURFOBJ* psoTrg, SURFOBJ* psoSrc, XLATEOBJ* pxlo,
  243. RECTL* prclTrg, POINTL* pptlSrc, ULONG ulDRAWBLTDEF);
  244. BOOL PuntBitBlt(SURFOBJ* psoDest, SURFOBJ* psoSrc, SURFOBJ* psoMask,
  245. CLIPOBJ* pco, XLATEOBJ* pxlo, RECTL* prclDest, POINTL* pptlSrc,
  246. POINTL* pptlMask, BRUSHOBJ* pbo, POINTL* pptlBrush, ROP4 rop4);
  247. BOOL DoDeviceToDeviceWithXlate(SURFOBJ* psoTrg, SURFOBJ* psoSrc, ULONG* pulXlate,
  248. RECTL* prclTrg, POINTL* pptlSrc, ULONG ulDRAWBLTDEF);
  249. #if SOLID_CACHE
  250. VOID CacheSolid(PDEV* ppdev);
  251. #endif
  252. /******************************************************************************\
  253. * *
  254. * DrvCopyBits *
  255. * *
  256. \******************************************************************************/
  257. BOOL DrvCopyBits(
  258. SURFOBJ* psoTrg,
  259. SURFOBJ* psoSrc,
  260. CLIPOBJ* pco,
  261. XLATEOBJ* pxlo,
  262. RECTL* prclTrg,
  263. POINTL* pptlSrc)
  264. {
  265. BOOL fSrc, fDest;
  266. PDEV* ppdev;
  267. #if NULL_COPYBITS
  268. {
  269. if (pointer_switch) return(TRUE);
  270. }
  271. #endif
  272. DISPDBG((COPYBITS_DBG_LEVEL, "DrvCopyBits\n"));
  273. // Determine if the source and target are the screen or a device bitmap. I
  274. // have seen several cases where memory bitmaps are created with the dhpdev
  275. // set to the screen, so we must check if the surface handles to the screen
  276. // match.
  277. fDest = (psoTrg->dhpdev != 0);
  278. if (fDest)
  279. {
  280. // The destination must be either the screen or a device bitmap.
  281. if ((psoTrg->hsurf != ((PDEV*)(psoTrg->dhpdev))->hsurfEng) &&
  282. (psoTrg->iType != STYPE_DEVBITMAP))
  283. {
  284. fDest = FALSE; // The destination is a memory bitmap.
  285. }
  286. }
  287. fSrc = (psoSrc->dhpdev != 0);
  288. if (fSrc)
  289. {
  290. // The source must be either the screen or a device bitmap.
  291. if ((psoSrc->hsurf != ((PDEV*)(psoSrc->dhpdev))->hsurfEng) &&
  292. (psoSrc->iType != STYPE_DEVBITMAP))
  293. {
  294. fSrc = FALSE; // The source is a memory bitmap.
  295. }
  296. }
  297. ppdev = (PDEV*) (fSrc ? psoSrc->dhpdev : (fDest ? psoTrg->dhpdev : NULL));
  298. SYNC_W_3D(ppdev);
  299. #if (defined(i386) && USE_ASM)
  300. if (ppdev->dwLgDevID < CL_GD5465)
  301. {
  302. if (YUVBlt(psoTrg, psoSrc, pco, pxlo, prclTrg, pptlSrc))
  303. return TRUE;
  304. };
  305. #endif
  306. // If the destination is a DIB device bitmap, try copying it into
  307. // off-screen memory.
  308. if ( fDest && // Is destination valid?
  309. (psoTrg->iType == STYPE_DEVBITMAP) && // Is it a device bitmap?
  310. ((DSURF*) psoTrg->dhsurf)->pso ) // Has it a surface?
  311. {
  312. if ( !bCreateScreenFromDib(ppdev, (DSURF*) psoTrg->dhsurf) )
  313. {
  314. psoTrg = ((DSURF*) psoTrg->dhsurf)->pso;
  315. fDest = FALSE; // Destination is memory.
  316. }
  317. }
  318. // If the source is a DIB device bitmap, try copying it into off-screen
  319. // memory.
  320. if ( fSrc && // Is source valid?
  321. (psoSrc->iType == STYPE_DEVBITMAP) && // Is it a device bitmap?
  322. ((DSURF*) psoSrc->dhsurf)->pso ) // Has it a surface?
  323. {
  324. if ( !bCreateScreenFromDib(ppdev, (DSURF*) psoSrc->dhsurf) )
  325. {
  326. psoSrc = ((DSURF*) psoSrc->dhsurf)->pso;
  327. fSrc = FALSE; // Source is memory.
  328. }
  329. }
  330. if (fDest)
  331. {
  332. // The target is the screen.
  333. if (fSrc)
  334. {
  335. // The source is the screen.
  336. if (CopyDeviceBitmap(psoTrg, psoSrc, pco, pxlo, prclTrg, pptlSrc,
  337. 0x000000CC, DoDeviceToDevice))
  338. {
  339. LogCopyBits(0, psoSrc, psoTrg, pco, pxlo);
  340. return(TRUE);
  341. }
  342. }
  343. else if ( (psoSrc->iBitmapFormat <= BMF_8BPP) ||
  344. (psoSrc->iBitmapFormat == psoTrg->iBitmapFormat) )
  345. {
  346. // Ths source is main memory. We only support 1-bpp, 4-bpp, 8-bpp,
  347. // or the device-bpp formats.
  348. if (CopyDeviceBitmap(psoTrg, psoSrc, pco, pxlo, prclTrg, pptlSrc,
  349. 0x000000CC, ppdev->pfnHostToScreen))
  350. {
  351. LogCopyBits(0, psoSrc, psoTrg, pco, pxlo);
  352. return(TRUE);
  353. }
  354. }
  355. }
  356. else if (fSrc)
  357. {
  358. // The source is the screen.
  359. if (CopyDeviceBitmap(psoTrg, psoSrc, pco, pxlo, prclTrg, pptlSrc,
  360. 0x000000CC, ppdev->pfnScreenToHost))
  361. {
  362. LogCopyBits(0, psoSrc, psoTrg, pco, pxlo);
  363. return(TRUE);
  364. }
  365. }
  366. // We have a memory to memory blit. Let NT handle it!
  367. LogCopyBits(1, psoSrc, psoTrg, pco, pxlo);
  368. return PuntBitBlt(psoTrg, psoSrc, NULL, pco, pxlo, prclTrg, pptlSrc, NULL,
  369. NULL, NULL, 0x0000CCCC);
  370. }
  371. #if LOG_CALLS
  372. // ****************************************************************************
  373. //
  374. // LogCopyBlt()
  375. // This routine is called only from DrvCopyBits()
  376. // Dump information to a file about what is going on in CopyBit land.
  377. //
  378. // ****************************************************************************
  379. void LogCopyBits(
  380. int acc,
  381. SURFOBJ* psoSrc,
  382. SURFOBJ* psoDest,
  383. CLIPOBJ* pco,
  384. XLATEOBJ* pxlo)
  385. {
  386. PPDEV dppdev,sppdev,ppdev;
  387. char buf[256];
  388. int i;
  389. BYTE fg_rop, bg_rop;
  390. ULONG iDComplexity;
  391. dppdev = (PPDEV) (psoDest ? psoDest->dhpdev : 0);
  392. sppdev = (PPDEV) (psoSrc ? psoSrc->dhpdev : 0);
  393. ppdev = dppdev ? dppdev : sppdev;
  394. #if ENABLE_LOG_SWITCH
  395. if (pointer_switch == 0) return;
  396. #endif
  397. i = sprintf(buf,"DCB: ");
  398. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  399. switch(acc)
  400. {
  401. case 0: // Accelerated
  402. i = sprintf(buf, "ACCL ");
  403. break;
  404. case 1: // Punted
  405. i = sprintf(buf, "PUNT BitBlt ");
  406. break;
  407. default:
  408. i = sprintf(buf, "PUNT unknown ");
  409. break;
  410. }
  411. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  412. //
  413. // Check the SRC
  414. //
  415. if (psoSrc)
  416. {
  417. if (psoSrc->iType == STYPE_DEVBITMAP)
  418. {
  419. i = sprintf(buf, "Src Id=%p ", psoSrc->dhsurf);
  420. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  421. if ( ((PDSURF)psoSrc->dhsurf)->pso )
  422. i = sprintf(buf,"S=DH ");
  423. else
  424. i = sprintf(buf,"S=DF ");
  425. }
  426. else if (psoSrc->hsurf == ppdev->hsurfEng)
  427. i = sprintf(buf,"S=S ");
  428. else
  429. i = sprintf(buf,"S=H ");
  430. }
  431. else
  432. i = sprintf(buf,"S=N ");
  433. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  434. //
  435. // Check the DEST
  436. //
  437. if (psoDest)
  438. {
  439. if (psoDest->iType == STYPE_DEVBITMAP)
  440. {
  441. i = sprintf(buf, "Dst Id=%p ", psoDest->dhsurf);
  442. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  443. if ( ((PDSURF)psoDest->dhsurf)->pso )
  444. i = sprintf(buf,"D=DH ");
  445. else
  446. i = sprintf(buf,"D=DF ");
  447. }
  448. else if (psoDest->hsurf == ppdev->hsurfEng)
  449. i = sprintf(buf,"D=S ");
  450. else
  451. i = sprintf(buf,"D=H ");
  452. }
  453. else
  454. i = sprintf(buf,"D=N ");
  455. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  456. //
  457. // Check the type of clipping.
  458. //
  459. iDComplexity = (pco ? pco->iDComplexity : DC_TRIVIAL);
  460. i = sprintf(buf,"C=%s ",
  461. (iDComplexity==DC_TRIVIAL ? "T":
  462. (iDComplexity == DC_RECT ? "R" : "C" )));
  463. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  464. //
  465. // Type of translation
  466. //
  467. if (!pxlo)
  468. {
  469. i = sprintf(buf,"T=N ");
  470. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  471. }
  472. else if (pxlo->flXlate & XO_TRIVIAL)
  473. {
  474. i = sprintf(buf,"T=T ");
  475. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  476. }
  477. else
  478. {
  479. i = sprintf(buf,"T=NT ");
  480. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  481. }
  482. i = sprintf(buf,"\r\n");
  483. WriteLogFile(ppdev->pmfile, buf, i, ppdev->TxtBuff, &ppdev->TxtBuffIndex);
  484. }
  485. #endif
  486. /*****************************************************************************\
  487. * CopyDeviceBitmap
  488. *
  489. * This is the main entry routine for all bitblt functions. It will dispatch
  490. * the blit to the correct handler and performs the clipping.
  491. *
  492. * On entry: psoTrg Pointer to target surface object.
  493. * psoSrc Pointer to source surface object.
  494. * pco Pointer to clip object.
  495. * pxlo Pointer to translation object.
  496. * prclTrg Destination rectangle.
  497. * pptlSrc Source offset.
  498. * ulDRAWBLTDEF Value for grDRAWBLTDEF register. This value has
  499. * the ROP and the brush flags. It will be filled
  500. * by the dispatch routine.
  501. * pfn Pointer to dispatch function.
  502. *
  503. * Returns: TRUE if successful, FALSE if we cannot handle this blit.
  504. \*****************************************************************************/
  505. BOOL CopyDeviceBitmap(
  506. SURFOBJ *psoTrg,
  507. SURFOBJ *psoSrc,
  508. CLIPOBJ *pco,
  509. XLATEOBJ *pxlo,
  510. RECTL *prclTrg,
  511. POINTL *pptlSrc,
  512. ULONG ulDRAWBLTDEF,
  513. COPYFN *pfn
  514. )
  515. {
  516. // Check for no clipping.
  517. if ( (pco == NULL) || (pco->iDComplexity == DC_TRIVIAL) )
  518. {
  519. return(pfn(psoTrg, psoSrc, pxlo, prclTrg, pptlSrc, ulDRAWBLTDEF));
  520. }
  521. // Check for single rectangle clipping.
  522. else if (pco->iDComplexity == DC_RECT)
  523. {
  524. RECTL rcl;
  525. POINTL ptl;
  526. // Intersect the destination rectangle with the clipping rectangle.
  527. rcl.left = max(prclTrg->left, pco->rclBounds.left);
  528. rcl.top = max(prclTrg->top, pco->rclBounds.top);
  529. rcl.right = min(prclTrg->right, pco->rclBounds.right);
  530. rcl.bottom = min(prclTrg->bottom, pco->rclBounds.bottom);
  531. // Do we have a valid rectangle?
  532. if ( (rcl.left < rcl.right) && (rcl.top < rcl.bottom) )
  533. {
  534. // Setup the source offset.
  535. ptl.x = pptlSrc->x + (rcl.left - prclTrg->left);
  536. ptl.y = pptlSrc->y + (rcl.top - prclTrg->top);
  537. // Dispatch the blit.
  538. return(pfn(psoTrg, psoSrc, pxlo, &rcl, &ptl, ulDRAWBLTDEF));
  539. }
  540. }
  541. // Complex clipping.
  542. else
  543. {
  544. BOOL bMore;
  545. ENUMRECTS8 ce;
  546. RECTL* prcl;
  547. ULONG ulDirClip = CD_ANY;
  548. // If we have a screen to screen blit, we must specify the sorting of
  549. // the rectangles since we must take care not to draw on a destination
  550. // before that destination itself may be used as the source for a blit.
  551. // This only accounts for the same physical surface, not between
  552. // different device bitmaps.
  553. if ( (pfn == DoDeviceToDevice) && (psoSrc->dhsurf == psoTrg->dhsurf) )
  554. {
  555. if (prclTrg->left > pptlSrc->x)
  556. {
  557. ulDirClip =
  558. (prclTrg->top > pptlSrc->y) ? CD_LEFTUP : CD_LEFTDOWN;
  559. }
  560. else
  561. {
  562. ulDirClip =
  563. (prclTrg->top > pptlSrc->y) ? CD_RIGHTUP : CD_RIGHTDOWN;
  564. }
  565. }
  566. // Start the enumeration process.
  567. CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES, ulDirClip, 0);
  568. do
  569. {
  570. // Get a bunch of clipping rectangles.
  571. bMore = CLIPOBJ_bEnum(pco, sizeof(ce), (ULONG *) &ce);
  572. // Loop through all clipping rectangles.
  573. for (prcl = ce.arcl; ce.c--; prcl++)
  574. {
  575. RECTL rcl;
  576. POINTL ptl;
  577. // Intersect the destination rectangle with the clipping
  578. // rectangle.
  579. rcl.left = max(prclTrg->left, prcl->left);
  580. rcl.top = max(prclTrg->top, prcl->top);
  581. rcl.right = min(prclTrg->right, prcl->right);
  582. rcl.bottom = min(prclTrg->bottom, prcl->bottom);
  583. if ( (rcl.left < rcl.right) && (rcl.top < rcl.bottom) )
  584. {
  585. // Setup the source offset.
  586. ptl.x = pptlSrc->x + (rcl.left - prclTrg->left);
  587. ptl.y = pptlSrc->y + (rcl.top - prclTrg->top);
  588. // Dispatch the blit.
  589. if (!pfn(psoTrg, psoSrc, pxlo, &rcl, &ptl, ulDRAWBLTDEF))
  590. {
  591. return(FALSE);
  592. }
  593. }
  594. }
  595. }
  596. while (bMore);
  597. }
  598. // Always return TRUE.
  599. return(TRUE);
  600. }
  601. /*****************************************************************************\
  602. * *
  603. * 8 - B P P *
  604. * *
  605. \*****************************************************************************/
  606. /*****************************************************************************\
  607. * DoHost8ToDevice
  608. *
  609. * This routine performs a HostToScreen or HostToDevice blit. The host data
  610. * can be either monochrome, 4-bpp, or 8-bpp. Color translation is supported.
  611. *
  612. * On entry: psoTrg Pointer to target surface object.
  613. * psoSrc Pointer to source surface object.
  614. * pxlo Pointer to translation object.
  615. * prclTrg Destination rectangle.
  616. * pptlSrc Source offset.
  617. * ulDRAWBLTDEF Value for grDRAWBLTDEF register. This value has
  618. * the ROP and the brush flags.
  619. \*****************************************************************************/
  620. BOOL DoHost8ToDevice(
  621. SURFOBJ *psoTrg,
  622. SURFOBJ *psoSrc,
  623. XLATEOBJ *pxlo,
  624. RECTL *prclTrg,
  625. POINTL *pptlSrc,
  626. ULONG ulDRAWBLTDEF
  627. )
  628. {
  629. POINTL ptlDest, ptlSrc;
  630. SIZEL sizl;
  631. PPDEV ppdev;
  632. PBYTE pBits;
  633. LONG lDelta, i, n, lLeadIn, lExtra;
  634. ULONG *pulXlate;
  635. FLONG flXlate;
  636. // Calculate the source offset.
  637. ptlSrc.x = pptlSrc->x;
  638. ptlSrc.y = pptlSrc->y;
  639. // Determine the destination type and calculate the destination offset.
  640. if (psoTrg->iType == STYPE_DEVBITMAP)
  641. {
  642. PDSURF pdsurf = (PDSURF) psoTrg->dhsurf;
  643. ptlDest.x = prclTrg->left + pdsurf->ptl.x;
  644. ptlDest.y = prclTrg->top + pdsurf->ptl.y;
  645. ppdev = pdsurf->ppdev;
  646. }
  647. else
  648. {
  649. ptlDest.x = prclTrg->left;
  650. ptlDest.y = prclTrg->top;
  651. ppdev = (PPDEV) psoTrg->dhpdev;
  652. }
  653. // Calculate the size of the blit.
  654. sizl.cx = prclTrg->right - prclTrg->left;
  655. sizl.cy = prclTrg->bottom - prclTrg->top;
  656. // Get the source variables and offset into source bits.
  657. lDelta = psoSrc->lDelta;
  658. pBits = (PBYTE)psoSrc->pvScan0 + (ptlSrc.y * lDelta);
  659. /* -----------------------------------------------------------------------
  660. Test for monochrome source.
  661. */
  662. if (psoSrc->iBitmapFormat == BMF_1BPP)
  663. {
  664. ULONG bgColor, fgColor;
  665. #if SWAT7
  666. SIZEL sizlTotal;
  667. #endif
  668. // Get the pointer to the translation table.
  669. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  670. if ( (flXlate & XO_TRIVIAL) && !(flXlate & XO_TABLE) )
  671. {
  672. pulXlate = NULL;
  673. }
  674. else if (flXlate & XO_TABLE)
  675. {
  676. pulXlate = pxlo->pulXlate;
  677. }
  678. else if (pxlo->iSrcType == PAL_INDEXED)
  679. {
  680. pulXlate = XLATEOBJ_piVector(pxlo);
  681. }
  682. else
  683. {
  684. // Some kind of translation we don't handle
  685. return FALSE;
  686. }
  687. // Set background and foreground colors.
  688. if (pulXlate == NULL)
  689. {
  690. bgColor = 0x00000000;
  691. fgColor = 0xFFFFFFFF;
  692. }
  693. else
  694. {
  695. bgColor = pulXlate[0];
  696. fgColor = pulXlate[1];
  697. // Expand the colors.
  698. bgColor |= bgColor << 8;
  699. fgColor |= fgColor << 8;
  700. bgColor |= bgColor << 16;
  701. fgColor |= fgColor << 16;
  702. }
  703. //
  704. // Special case: when we are expanding monochrome sources and we
  705. // already have a colored brush, we must make sure the monochrome color
  706. // translation can be achived by setting the saturation bit (expanding
  707. // 0's to 0 and 1's to 1). If the monochrome source also requires color
  708. // translation, we simply punt this blit back to GDI.
  709. //
  710. if (ulDRAWBLTDEF & 0x00040000)
  711. {
  712. if ( (bgColor == 0x00000000) && (fgColor == 0xFFFFFFFF) )
  713. {
  714. // Enable saturation for source (OP1).
  715. ulDRAWBLTDEF |= 0x00008000;
  716. }
  717. #if SOLID_CACHE
  718. else if ( ((ulDRAWBLTDEF & 0x000F0000) == 0x00070000) &&
  719. ppdev->Bcache )
  720. {
  721. CacheSolid(ppdev);
  722. ulDRAWBLTDEF ^= (0x00070000 ^ 0x00090000);
  723. REQUIRE(4);
  724. LL_BGCOLOR(bgColor, 2);
  725. LL_FGCOLOR(fgColor, 2);
  726. }
  727. #endif
  728. else
  729. {
  730. // Punt this call to the GDI.
  731. return(FALSE);
  732. }
  733. }
  734. else
  735. {
  736. REQUIRE(4);
  737. LL_BGCOLOR(bgColor, 2);
  738. LL_FGCOLOR(fgColor, 2);
  739. }
  740. REQUIRE(9);
  741. #if SWAT7
  742. // Setup the Laguna registers for the blit. We also set the bit swizzle
  743. // bit in the grCONTROL register.
  744. ppdev->grCONTROL |= SWIZ_CNTL;
  745. LL16(grCONTROL, ppdev->grCONTROL);
  746. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10600000, 2);
  747. sizlTotal = sizl;
  748. while (sizlTotal.cx)
  749. {
  750. sizl.cx = min(sizlTotal.cx, 864);
  751. sizl.cy = sizlTotal.cy;
  752. #if 1 // SWAT: 08/08/97
  753. // In 8-bpp the 5465AD has a hardware bug when 64 < width < 128.
  754. if (sizl.cx > 64 && sizl.cx < 128)
  755. {
  756. sizl.cx = 64;
  757. }
  758. #endif
  759. #endif
  760. // Calculate the source parameters. We are going to DWORD adjust the
  761. // source, so we must setup the source phase.
  762. lLeadIn = ptlSrc.x & 31;
  763. pBits += (ptlSrc.x >> 3) & ~3;
  764. n = (sizl.cx + lLeadIn + 31) >> 5;
  765. #if !SWAT7
  766. // Setup the Laguna registers for the blit. We also set the bit swizzle
  767. // bit in the grCONTROL register.
  768. ppdev->grCONTROL |= SWIZ_CNTL;
  769. LL16(grCONTROL, ppdev->grCONTROL);
  770. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10600000, 2);
  771. #endif
  772. // Start the blit.
  773. // added REQUIRE above
  774. // REQUIRE(7);
  775. LL_OP1_MONO(lLeadIn, 0);
  776. LL_OP0(ptlDest.x, ptlDest.y);
  777. LL_BLTEXT(sizl.cx, sizl.cy);
  778. // Copy all the bits to the screen, 32-bits at a time. We don't have to
  779. // worry about crossing any boundary since NT is always DWORD aligned.
  780. while (sizl.cy--)
  781. {
  782. WRITE_STRING(pBits, n);
  783. pBits += lDelta;
  784. }
  785. #if SWAT7
  786. sizlTotal.cx -= sizl.cx;
  787. ptlSrc.x += sizl.cx;
  788. ptlDest.x += sizl.cx;
  789. // Reload pBits.
  790. pBits = (PBYTE) psoSrc->pvScan0 + (ptlSrc.y * lDelta);
  791. }
  792. #endif
  793. // Disable the swizzle bit in the grCONTROL register.
  794. ppdev->grCONTROL = ppdev->grCONTROL & ~SWIZ_CNTL;
  795. LL16(grCONTROL, ppdev->grCONTROL);
  796. }
  797. /* -----------------------------------------------------------------------
  798. Test for 4-bpp source.
  799. */
  800. else if (psoSrc->iBitmapFormat == BMF_4BPP)
  801. {
  802. // Get the pointer to the translation table.
  803. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  804. if (flXlate & XO_TRIVIAL)
  805. {
  806. pulXlate = NULL;
  807. }
  808. else if (flXlate & XO_TABLE)
  809. {
  810. pulXlate = pxlo->pulXlate;
  811. }
  812. else if (pxlo->iSrcType == PAL_INDEXED)
  813. {
  814. pulXlate = XLATEOBJ_piVector(pxlo);
  815. }
  816. else
  817. {
  818. // Some kind of translation we don't handle
  819. return FALSE;
  820. }
  821. // Calculate the source parameters. We are going to BYTE adjust the
  822. // source, so we also set the source phase.
  823. lLeadIn = ptlSrc.x & 1;
  824. pBits += ptlSrc.x >> 1;
  825. n = sizl.cx + (ptlSrc.x & 1);
  826. #if ! DRIVER_5465
  827. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  828. // bug.
  829. if (ppdev->dwLgDevID == CL_GD5462)
  830. {
  831. if (MAKE_HD_INDEX(sizl.cx, lLeadIn, ptlDest.x) == 3788)
  832. {
  833. // We have a problem with the HOSTDATA TABLE.
  834. // Punt till we can figure it out.
  835. return FALSE;
  836. }
  837. lExtra = ExtraDwordTable[MAKE_HD_INDEX(sizl.cx, lLeadIn, ptlDest.x)];
  838. }
  839. else
  840. lExtra = 0;
  841. #endif
  842. // Start the blit.
  843. REQUIRE(9);
  844. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  845. LL_OP1_MONO(lLeadIn, 0);
  846. LL_OP0(ptlDest.x, ptlDest.y);
  847. LL_BLTEXT(sizl.cx, sizl.cy);
  848. // If there is no translation table, use the default translation table.
  849. if (pulXlate == NULL)
  850. {
  851. pulXlate = ulXlate;
  852. }
  853. // Now we are ready to copy all the pixels to the hardware.
  854. while (sizl.cy--)
  855. {
  856. BYTE *p = pBits;
  857. BYTE data[4];
  858. // First, we convert 4 pixels at a time to create a 32-bit value to
  859. // write to the hardware.
  860. for (i = n; i >= 4; i -= 4)
  861. {
  862. data[0] = (BYTE) pulXlate[p[0] >> 4];
  863. data[1] = (BYTE) pulXlate[p[0] & 0x0F];
  864. data[2] = (BYTE) pulXlate[p[1] >> 4];
  865. data[3] = (BYTE) pulXlate[p[1] & 0x0F];
  866. REQUIRE(1);
  867. LL32(grHOSTDATA[0], *(DWORD *)data);
  868. p += 2;
  869. }
  870. // Now, write any remaining pixels.
  871. switch (i)
  872. {
  873. case 1:
  874. REQUIRE(1);
  875. LL32(grHOSTDATA[0], pulXlate[p[0] >> 4]);
  876. break;
  877. case 2:
  878. data[0] = (BYTE) pulXlate[p[0] >> 4];
  879. data[1] = (BYTE) pulXlate[p[0] & 0x0F];
  880. REQUIRE(1);
  881. LL32(grHOSTDATA[0], *(DWORD *)data);
  882. break;
  883. case 3:
  884. data[0] = (BYTE) pulXlate[p[0] >> 4];
  885. data[1] = (BYTE) pulXlate[p[0] & 0x0F];
  886. data[2] = (BYTE) pulXlate[p[1] >> 4];
  887. REQUIRE(1);
  888. LL32(grHOSTDATA[0], *(DWORD *)data);
  889. break;
  890. }
  891. #if !DRIVER_5465
  892. // Now, write the extra DWORDS.
  893. REQUIRE(lExtra);
  894. for (i = 0; i < lExtra; i++)
  895. {
  896. LL32(grHOSTDATA[0], 0);
  897. }
  898. #endif
  899. // Next line.
  900. pBits += lDelta;
  901. }
  902. }
  903. /* -----------------------------------------------------------------------
  904. Source is in same color depth as screen.
  905. */
  906. else
  907. {
  908. //
  909. // If color translation is required, attempt to load the translation
  910. // table into the chip.
  911. //
  912. #if COLOR_TRANSLATE
  913. ULONG UseHWxlate = bCacheXlateTable(ppdev, &pulXlate, psoTrg, psoSrc,
  914. pxlo, (BYTE)(ulDRAWBLTDEF & 0xCC));
  915. #else
  916. if ( (pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL) )
  917. {
  918. pulXlate = NULL;
  919. }
  920. else if (pxlo->flXlate & XO_TABLE)
  921. {
  922. pulXlate = pxlo->pulXlate;
  923. }
  924. else if (pxlo->iSrcType == PAL_INDEXED)
  925. {
  926. pulXlate = XLATEOBJ_piVector(pxlo);
  927. }
  928. else
  929. {
  930. // Some kind of translation we don't handle
  931. return FALSE;
  932. }
  933. #endif
  934. // pulXlate == NULL if there is no color translation is required.
  935. // pulXlate == translation table if color translation is required.
  936. // UseHWxlate == FALSE if the hardware will do the xlate for us.
  937. // UseHWxlate == TRUE if we must do the translation in software.
  938. // If we have invalid translation flags, punt the blit.
  939. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  940. if (flXlate & 0x10)
  941. {
  942. return(FALSE);
  943. }
  944. // Calculate the source parameters. We are going to DWORD adjust the
  945. // source, so we also set the source phase.
  946. pBits += ptlSrc.x;
  947. lLeadIn = (DWORD)pBits & 3;
  948. pBits -= lLeadIn;
  949. n = (sizl.cx + lLeadIn + 3) >> 2;
  950. #if !DRIVER_5465
  951. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  952. // bug.
  953. if (ppdev->dwLgDevID == CL_GD5462)
  954. {
  955. if (MAKE_HD_INDEX(sizl.cx, lLeadIn, ptlDest.x) == 3788)
  956. {
  957. // We have a problem with the HOSTDATA TABLE.
  958. // Punt till we can figure it out.
  959. return(FALSE);
  960. }
  961. lExtra =
  962. ExtraDwordTable[MAKE_HD_INDEX(sizl.cx, lLeadIn, ptlDest.x)];
  963. }
  964. else
  965. {
  966. lExtra = 0;
  967. }
  968. #endif
  969. // Setup the Laguna registers.
  970. REQUIRE(9);
  971. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  972. // Start the blit.
  973. LL_OP1_MONO(lLeadIn, 0);
  974. LL_OP0(ptlDest.x, ptlDest.y);
  975. // Test for SW color translation.
  976. #if COLOR_TRANSLATE
  977. if (UseHWxlate)
  978. #else
  979. if (pulXlate == NULL)
  980. #endif
  981. { // HW color translate, or no translate required.
  982. if (pulXlate)
  983. {
  984. DISPDBG((COPYBITS_DBG_LEVEL, "Host8ToDevice: "
  985. "Attempting HW color translation on 8bpp Host to Screen.\n"));
  986. LL_BLTEXT_XLATE(8, sizl.cx, sizl.cy); // HW xlate.
  987. }
  988. else
  989. {
  990. DISPDBG((COPYBITS_DBG_LEVEL, "Host8ToDevice: "
  991. "No color translation required on 8bpp Host to Screen.\n"));
  992. LL_BLTEXT(sizl.cx, sizl.cy); // No xlate.
  993. }
  994. while (sizl.cy--)
  995. {
  996. // Copy all data in 32-bit. We don't have to worry about
  997. // crossing any boundaries, since within NT everything is DWORD
  998. // aligned.
  999. WRITE_STRING(pBits, n);
  1000. #if !DRIVER_5465
  1001. // Now, write the extra DWORDS.
  1002. REQUIRE(lExtra);
  1003. for (i = 0; i < lExtra; i++)
  1004. {
  1005. LL32(grHOSTDATA[0], 0);
  1006. }
  1007. #endif
  1008. // Next line.
  1009. pBits += lDelta;
  1010. }
  1011. }
  1012. else // Software color translation is required.
  1013. {
  1014. DISPDBG((COPYBITS_DBG_LEVEL, "Host8ToDevice: "
  1015. "Attempting SW color translation on 8bpp Host to Screen.\n"));
  1016. ASSERTMSG(pulXlate,
  1017. "Host8ToDevice: No translation table for SW color translation.\n");
  1018. LL_BLTEXT(sizl.cx, sizl.cy);
  1019. while (sizl.cy--)
  1020. {
  1021. BYTE *p = pBits;
  1022. // We copy 4 pixels to fill an entire 32-bit DWORD.
  1023. for (i = 0; i < n; i++)
  1024. {
  1025. BYTE data[4];
  1026. data[0] = (BYTE) pulXlate[p[0]];
  1027. data[1] = (BYTE) pulXlate[p[1]];
  1028. data[2] = (BYTE) pulXlate[p[2]];
  1029. data[3] = (BYTE) pulXlate[p[3]];
  1030. REQUIRE(1);
  1031. LL32(grHOSTDATA[0], *(DWORD *)data);
  1032. p += 4;
  1033. }
  1034. #if !DRIVER_5465
  1035. // Now, write the extra DWORDS.
  1036. REQUIRE(lExtra);
  1037. for (i = 0; i < lExtra; i++)
  1038. {
  1039. LL32(grHOSTDATA[0], 0);
  1040. }
  1041. #endif
  1042. // Next line.
  1043. pBits += lDelta;
  1044. }
  1045. }
  1046. }
  1047. return(TRUE);
  1048. }
  1049. /*****************************************************************************\
  1050. * DoDeviceToHost8
  1051. *
  1052. * This routine performs a DeviceToHost for either monochrome or 8-bpp
  1053. * destinations.
  1054. *
  1055. * On entry: psoTrg Pointer to target surface object.
  1056. * psoSrc Pointer to source surface object.
  1057. * pxlo Pointer to translation object.
  1058. * prclTrg Destination rectangle.
  1059. * pptlSrc Source offset.
  1060. * ulDRAWBLTDEF Value for grDRAWBLTDEF register. This value has
  1061. * the ROP and the brush flags.
  1062. \*****************************************************************************/
  1063. BOOL DoDeviceToHost8(
  1064. SURFOBJ *psoTrg,
  1065. SURFOBJ *psoSrc,
  1066. XLATEOBJ *pxlo,
  1067. RECTL *prclTrg,
  1068. POINTL *pptlSrc,
  1069. ULONG ulDRAWBLTDEF
  1070. )
  1071. {
  1072. POINTL ptlSrc;
  1073. PPDEV ppdev;
  1074. SIZEL sizl;
  1075. PBYTE pBits;
  1076. #if !S2H_USE_ENGINE
  1077. PBYTE pjScreen;
  1078. #endif
  1079. LONG lDelta;
  1080. ULONG i, n;
  1081. // Determine the source type and calculate the offset.
  1082. if (psoSrc->iType == STYPE_DEVBITMAP)
  1083. {
  1084. PDSURF pdsurf = (PDSURF)psoSrc->dhsurf;
  1085. ppdev = pdsurf->ppdev;
  1086. ptlSrc.x = pptlSrc->x + pdsurf->ptl.x;
  1087. ptlSrc.y = pptlSrc->y + pdsurf->ptl.y;
  1088. }
  1089. else
  1090. {
  1091. ppdev = (PPDEV)psoSrc->dhpdev;
  1092. ptlSrc.x = pptlSrc->x;
  1093. ptlSrc.y = pptlSrc->y;
  1094. }
  1095. // Calculate the size of the blit.
  1096. sizl.cx = prclTrg->right - prclTrg->left;
  1097. sizl.cy = prclTrg->bottom - prclTrg->top;
  1098. // Calculate the destination variables.
  1099. lDelta = psoTrg->lDelta;
  1100. pBits = (PBYTE)psoTrg->pvScan0 + (prclTrg->top * lDelta);
  1101. #if S2H_USE_ENGINE
  1102. // Setup the Laguna registers.
  1103. REQUIRE(9);
  1104. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x20100000, 0);
  1105. LL_OP0(0, 0);
  1106. #else
  1107. // Calculate the screen address.
  1108. pjScreen = ppdev->pjScreen + ptlSrc.x + ptlSrc.y * ppdev->lDeltaScreen;
  1109. // Wait for the hardware to become idle.
  1110. while (LLDR_SZ(grSTATUS) != 0) ;
  1111. #endif
  1112. // Test for monochrome destination.
  1113. if (psoTrg->iBitmapFormat == BMF_1BPP)
  1114. {
  1115. BYTE data, leftMask, rightMask, fgColor;
  1116. DWORD *pulXlate;
  1117. LONG leftCount, rightCount, leftSkip;
  1118. #if S2H_USE_ENGINE
  1119. BYTE pixels[4];
  1120. #endif
  1121. // Calculate the monochrome masks.
  1122. pBits += prclTrg->left >> 3;
  1123. leftSkip = prclTrg->left & 7;
  1124. leftCount = (8 - leftSkip) & 7;
  1125. leftMask = 0xFF >> leftSkip;
  1126. rightCount = prclTrg->right & 7;
  1127. rightMask = 0xFF << (8 - rightCount);
  1128. // If we only have pixels in one byte, we combine rightMask with
  1129. // leftMask and set the routines to skip everything but the rightMask.
  1130. if (leftCount > sizl.cx)
  1131. {
  1132. rightMask &= leftMask;
  1133. leftMask = 0xFF;
  1134. n = 0;
  1135. }
  1136. else
  1137. {
  1138. n = (sizl.cx - leftCount) >> 3;
  1139. }
  1140. // Lookup the foreground color in the translation table. We scan from
  1141. // the back since in most cases it will be entry 255.
  1142. pulXlate = pxlo->pulXlate;
  1143. for (fgColor = 255; pulXlate[fgColor] != 1; fgColor--);
  1144. #if S2H_USE_ENGINE
  1145. // Start the blit.
  1146. LL_OP1(ptlSrc.x - leftSkip, ptlSrc.y);
  1147. LL_BLTEXT(sizl.cx + leftSkip, sizl.cy);
  1148. #else
  1149. pjScreen -= leftSkip;
  1150. #endif
  1151. while (sizl.cy--)
  1152. {
  1153. PBYTE pDest = pBits;
  1154. #if !S2H_USE_ENGINE
  1155. PBYTE pSrc = pjScreen;
  1156. #endif
  1157. // If we have a left mask specified, we get the pixels and store
  1158. // them with the destination.
  1159. if (leftMask != 0xFF)
  1160. {
  1161. data = 0;
  1162. #if S2H_USE_ENGINE
  1163. *(ULONG *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1164. if (pixels[0] == fgColor) data |= 0x80;
  1165. if (pixels[1] == fgColor) data |= 0x40;
  1166. if (pixels[2] == fgColor) data |= 0x20;
  1167. if (pixels[3] == fgColor) data |= 0x10;
  1168. *(ULONG *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1169. if (pixels[0] == fgColor) data |= 0x08;
  1170. if (pixels[1] == fgColor) data |= 0x04;
  1171. if (pixels[2] == fgColor) data |= 0x02;
  1172. if (pixels[3] == fgColor) data |= 0x01;
  1173. #else
  1174. if (pSrc[0] == fgColor) data |= 0x80;
  1175. if (pSrc[1] == fgColor) data |= 0x40;
  1176. if (pSrc[2] == fgColor) data |= 0x20;
  1177. if (pSrc[3] == fgColor) data |= 0x10;
  1178. if (pSrc[4] == fgColor) data |= 0x08;
  1179. if (pSrc[5] == fgColor) data |= 0x04;
  1180. if (pSrc[6] == fgColor) data |= 0x02;
  1181. if (pSrc[7] == fgColor) data |= 0x01;
  1182. pSrc += 8;
  1183. #endif
  1184. *pDest++ = (*pDest & ~leftMask) | (data & leftMask);
  1185. }
  1186. // Translate all pixels that don't require masking.
  1187. for (i = 0; i < n; i++)
  1188. {
  1189. data = 0;
  1190. #if S2H_USE_ENGINE
  1191. *(ULONG *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1192. if (pixels[0] == fgColor) data |= 0x80;
  1193. if (pixels[1] == fgColor) data |= 0x40;
  1194. if (pixels[2] == fgColor) data |= 0x20;
  1195. if (pixels[3] == fgColor) data |= 0x10;
  1196. *(ULONG *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1197. if (pixels[0] == fgColor) data |= 0x08;
  1198. if (pixels[1] == fgColor) data |= 0x04;
  1199. if (pixels[2] == fgColor) data |= 0x02;
  1200. if (pixels[3] == fgColor) data |= 0x01;
  1201. #else
  1202. if (pSrc[0] == fgColor) data |= 0x80;
  1203. if (pSrc[1] == fgColor) data |= 0x40;
  1204. if (pSrc[2] == fgColor) data |= 0x20;
  1205. if (pSrc[3] == fgColor) data |= 0x10;
  1206. if (pSrc[4] == fgColor) data |= 0x08;
  1207. if (pSrc[5] == fgColor) data |= 0x04;
  1208. if (pSrc[6] == fgColor) data |= 0x02;
  1209. if (pSrc[7] == fgColor) data |= 0x01;
  1210. pSrc += 8;
  1211. #endif
  1212. *pDest++ = data;
  1213. }
  1214. // If we have a right mask specified, we get the pixels and store
  1215. // them with the destination.
  1216. if (rightMask != 0x00)
  1217. {
  1218. data = 0;
  1219. #if S2H_USE_ENGINE
  1220. *(ULONG *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1221. if (pixels[0] == fgColor) data |= 0x80;
  1222. if (pixels[1] == fgColor) data |= 0x40;
  1223. if (pixels[2] == fgColor) data |= 0x20;
  1224. if (pixels[3] == fgColor) data |= 0x10;
  1225. *(ULONG *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1226. if (pixels[0] == fgColor) data |= 0x08;
  1227. if (pixels[1] == fgColor) data |= 0x04;
  1228. if (pixels[2] == fgColor) data |= 0x02;
  1229. if (pixels[3] == fgColor) data |= 0x01;
  1230. #else
  1231. if (pSrc[0] == fgColor) data |= 0x80;
  1232. if (pSrc[1] == fgColor) data |= 0x40;
  1233. if (pSrc[2] == fgColor) data |= 0x20;
  1234. if (pSrc[3] == fgColor) data |= 0x10;
  1235. if (pSrc[4] == fgColor) data |= 0x08;
  1236. if (pSrc[5] == fgColor) data |= 0x04;
  1237. if (pSrc[6] == fgColor) data |= 0x02;
  1238. if (pSrc[7] == fgColor) data |= 0x01;
  1239. #endif
  1240. *pDest = (*pDest & ~rightMask) | (data & rightMask);
  1241. }
  1242. // Next line.
  1243. #if !S2H_USE_ENGINE
  1244. pjScreen += ppdev->lDeltaScreen;
  1245. #endif
  1246. pBits += lDelta;
  1247. }
  1248. }
  1249. // We only support destination bitmaps with the same color depth and we
  1250. // do not support any color translation.
  1251. else if ( (psoTrg->iBitmapFormat != BMF_8BPP) ||
  1252. (pxlo && !(pxlo->flXlate & XO_TRIVIAL)) )
  1253. {
  1254. return(FALSE);
  1255. }
  1256. /*
  1257. If the GetPixel routine is being called, we get here with both cx and
  1258. cy set to 1 and the ROP to 0xCC (source copy). In this special case we
  1259. read the pixel directly from memory. Of course, we must be sure the
  1260. blit engine is finished working since it may still update the very
  1261. pixel we are going to read! We could use the hardware for this, but it
  1262. seems there is a HARDWARE BUG that doesn't seem to like the 1-pixel
  1263. ScreenToHost very much.
  1264. */
  1265. #if S2H_USE_ENGINE
  1266. else if ( (sizl.cx == 1) && (sizl.cy == 1) && (ulDRAWBLTDEF == 0x000000CC) )
  1267. {
  1268. // Wait for the hardware to become idle.
  1269. while (LLDR_SZ(grSTATUS) != 0) ;
  1270. // Get the pixel from screen.
  1271. pBits[prclTrg->left] =
  1272. ppdev->pjScreen[ptlSrc.x + ptlSrc.y * ppdev->lDeltaScreen];
  1273. }
  1274. #endif
  1275. else
  1276. {
  1277. #if S2H_USE_ENGINE
  1278. // The hardware requires us to get QWORDS.
  1279. BOOL fExtra = ((sizl.cx + 3) >> 2) & 1;
  1280. #endif
  1281. pBits += prclTrg->left;
  1282. #if S2H_USE_ENGINE
  1283. // Start the blit.
  1284. LL_OP1(ptlSrc.x, ptlSrc.y);
  1285. LL_BLTEXT(sizl.cx, sizl.cy);
  1286. #endif
  1287. while (sizl.cy--)
  1288. {
  1289. #if S2H_USE_ENGINE
  1290. DWORD *p = (DWORD *)pBits;
  1291. // First, we get pixels in chunks of 4 so the 32-bit HOSTDATA is
  1292. // happy.
  1293. for (i = sizl.cx; i >= 4; i -= 4)
  1294. {
  1295. *p++ = LLDR_SZ(grHOSTDATA[0]);
  1296. }
  1297. // Then, we have to do the remainig pixel(s).
  1298. switch (i)
  1299. {
  1300. case 1:
  1301. *(BYTE *)p = (BYTE)LLDR_SZ(grHOSTDATA[0]);
  1302. break;
  1303. case 2:
  1304. *(WORD *)p = (WORD)LLDR_SZ(grHOSTDATA[0]);
  1305. break;
  1306. case 3:
  1307. i = LLDR_SZ(grHOSTDATA[0]);
  1308. ((WORD *)p)[0] = (WORD)i;
  1309. ((BYTE *)p)[2] = (BYTE)(i >> 16);
  1310. break;
  1311. }
  1312. // Get the extra pixel required for QWORD alignment.
  1313. if (fExtra)
  1314. {
  1315. LLDR_SZ(grHOSTDATA[0]);
  1316. }
  1317. #else
  1318. // Copy all pixels from screen to memory.
  1319. memcpy(pBits, pjScreen, sizl.cx);
  1320. // Next line.
  1321. pjScreen += ppdev->lDeltaScreen;
  1322. #endif
  1323. pBits += lDelta;
  1324. }
  1325. }
  1326. return(TRUE);
  1327. }
  1328. /*****************************************************************************\
  1329. * *
  1330. * 1 6 - B P P *
  1331. * *
  1332. \*****************************************************************************/
  1333. /*****************************************************************************\
  1334. * DoHost16ToDevice
  1335. *
  1336. * This routine performs a HostToScreen or HostToDevice blit. The host data
  1337. * can be either monochrome, 4-bpp, or 16-bpp. Color translation is only
  1338. * supported for monochrome and 4-bpp modes.
  1339. *
  1340. * On entry: psoTrg Pointer to target surface object.
  1341. * psoSrc Pointer to source surface object.
  1342. * pxlo Pointer to translation object.
  1343. * prclTrg Destination rectangle.
  1344. * pptlSrc Source offset.
  1345. * ulDRAWBLTDEF Value for grDRAWBLTDEF register. This value has
  1346. * the ROP and the brush flags.
  1347. \*****************************************************************************/
  1348. BOOL DoHost16ToDevice(
  1349. SURFOBJ *psoTrg,
  1350. SURFOBJ *psoSrc,
  1351. XLATEOBJ *pxlo,
  1352. RECTL *prclTrg,
  1353. POINTL *pptlSrc,
  1354. ULONG ulDRAWBLTDEF
  1355. )
  1356. {
  1357. POINTL ptlDest, ptlSrc;
  1358. SIZEL sizl;
  1359. PPDEV ppdev;
  1360. PBYTE pBits;
  1361. LONG lDelta, i, n, lLeadIn, lExtra, i1;
  1362. ULONG *pulXlate;
  1363. FLONG flXlate;
  1364. // Calculate te source offset.
  1365. ptlSrc.x = pptlSrc->x;
  1366. ptlSrc.y = pptlSrc->y;
  1367. // Determine the destination type and calculate the destination offset.
  1368. if (psoTrg->iType == STYPE_DEVBITMAP)
  1369. {
  1370. PDSURF pdsurf = (PDSURF) psoTrg->dhsurf;
  1371. ptlDest.x = prclTrg->left + pdsurf->ptl.x;
  1372. ptlDest.y = prclTrg->top + pdsurf->ptl.y;
  1373. ppdev = pdsurf->ppdev;
  1374. }
  1375. else
  1376. {
  1377. ptlDest.x = prclTrg->left;
  1378. ptlDest.y = prclTrg->top;
  1379. ppdev = (PPDEV) psoTrg->dhpdev;
  1380. }
  1381. // Calculate the size of the blit.
  1382. sizl.cx = prclTrg->right - prclTrg->left;
  1383. sizl.cy = prclTrg->bottom - prclTrg->top;
  1384. // Get the source variables and offset into source bits.
  1385. lDelta = psoSrc->lDelta;
  1386. pBits = (PBYTE)psoSrc->pvScan0 + (ptlSrc.y * lDelta);
  1387. /* -----------------------------------------------------------------------
  1388. Test for monochrome source.
  1389. */
  1390. if (psoSrc->iBitmapFormat == BMF_1BPP)
  1391. {
  1392. ULONG bgColor, fgColor;
  1393. #if SWAT7
  1394. SIZEL sizlTotal;
  1395. #endif
  1396. // Get the pointer to the translation table.
  1397. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  1398. if (flXlate & XO_TRIVIAL)
  1399. {
  1400. pulXlate = NULL;
  1401. }
  1402. else if (flXlate & XO_TABLE)
  1403. {
  1404. pulXlate = pxlo->pulXlate;
  1405. }
  1406. else if (pxlo->iSrcType == PAL_INDEXED)
  1407. {
  1408. pulXlate = XLATEOBJ_piVector(pxlo);
  1409. }
  1410. else
  1411. {
  1412. // Some kind of translation we don't handle
  1413. return FALSE;
  1414. }
  1415. // Set background and foreground colors.
  1416. if (pulXlate == NULL)
  1417. {
  1418. bgColor = 0x00000000;
  1419. fgColor = 0xFFFFFFFF;
  1420. }
  1421. else
  1422. {
  1423. bgColor = pulXlate[0];
  1424. fgColor = pulXlate[1];
  1425. // Expand the colors.
  1426. bgColor |= bgColor << 16;
  1427. fgColor |= fgColor << 16;
  1428. }
  1429. //
  1430. // Special case: when we are expanding monochrome sources and we
  1431. // already have a colored brush, we must make sure the monochrome color
  1432. // translation can be achived by setting the saturation bit (expanding
  1433. // 0's to 0 and 1's to 1). If the monochrome source also requires color
  1434. // translation, we simply punt this blit back to GDI.
  1435. //
  1436. if (ulDRAWBLTDEF & 0x00040000)
  1437. {
  1438. if ( (bgColor == 0x00000000) && (fgColor == 0xFFFFFFFF) )
  1439. {
  1440. // Enable saturation for source (OP1).
  1441. ulDRAWBLTDEF |= 0x00008000;
  1442. }
  1443. #if SOLID_CACHE
  1444. else if ( ((ulDRAWBLTDEF & 0x000F0000) == 0x00070000) &&
  1445. ppdev->Bcache )
  1446. {
  1447. CacheSolid(ppdev);
  1448. ulDRAWBLTDEF ^= (0x00070000 ^ 0x00090000);
  1449. REQUIRE(4);
  1450. LL_BGCOLOR(bgColor, 2);
  1451. LL_FGCOLOR(fgColor, 2);
  1452. }
  1453. #endif
  1454. else
  1455. {
  1456. // Punt this call to the GDI.
  1457. return(FALSE);
  1458. }
  1459. }
  1460. else
  1461. {
  1462. REQUIRE(4);
  1463. LL_BGCOLOR(bgColor, 2);
  1464. LL_FGCOLOR(fgColor, 2);
  1465. }
  1466. REQUIRE(9);
  1467. #if SWAT7
  1468. // Setup the Laguna registers for the blit. We also set the bit swizzle
  1469. // bit in the grCONTROL register.
  1470. ppdev->grCONTROL |= SWIZ_CNTL;
  1471. LL16(grCONTROL, ppdev->grCONTROL);
  1472. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10600000, 2);
  1473. sizlTotal = sizl;
  1474. while (sizlTotal.cx)
  1475. {
  1476. sizl.cx = min(sizlTotal.cx, 864);
  1477. sizl.cy = sizlTotal.cy;
  1478. #endif
  1479. // Calculate the source parameters. We are going to DWORD adjust the
  1480. // source, so we must setup the source phase.
  1481. lLeadIn = ptlSrc.x & 31;
  1482. pBits += (ptlSrc.x >> 3) & ~3;
  1483. n = (sizl.cx + lLeadIn + 31) >> 5;
  1484. #if !SWAT7
  1485. // Setup the Laguna registers for the blit. We also set the bit swizzle
  1486. // bit in the grCONTROL register.
  1487. ppdev->grCONTROL |= SWIZ_CNTL;
  1488. LL16(grCONTROL, ppdev->grCONTROL);
  1489. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10600000, 2);
  1490. #endif
  1491. // Start the blit.
  1492. // added REQUIRE above
  1493. // REQUIRE(7);
  1494. LL_OP1_MONO(lLeadIn, 0);
  1495. LL_OP0(ptlDest.x, ptlDest.y);
  1496. LL_BLTEXT(sizl.cx, sizl.cy);
  1497. // Copy all the bits to the screen, 32-bits at a time. We don't have to
  1498. // worry about crossing any boundary since NT is always DWORD aligned.
  1499. while (sizl.cy--)
  1500. {
  1501. WRITE_STRING(pBits, n);
  1502. pBits += lDelta;
  1503. }
  1504. #if SWAT7
  1505. sizlTotal.cx -= sizl.cx;
  1506. ptlSrc.x += sizl.cx;
  1507. ptlDest.x += sizl.cx;
  1508. // Reload pBits.
  1509. pBits = (PBYTE) psoSrc->pvScan0 + (ptlSrc.y * lDelta);
  1510. }
  1511. #endif
  1512. // Disable the swizzle bit in the grCONTROL register.
  1513. ppdev->grCONTROL = ppdev->grCONTROL & ~SWIZ_CNTL;
  1514. LL16(grCONTROL, ppdev->grCONTROL);
  1515. }
  1516. /* -----------------------------------------------------------------------
  1517. Test for 4-bpp source.
  1518. */
  1519. else if (psoSrc->iBitmapFormat == BMF_4BPP)
  1520. {
  1521. // Get the pointer to the translation table.
  1522. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  1523. if (flXlate & XO_TRIVIAL)
  1524. {
  1525. pulXlate = NULL;
  1526. }
  1527. else if (flXlate & XO_TABLE)
  1528. {
  1529. pulXlate = pxlo->pulXlate;
  1530. }
  1531. else if (pxlo->iSrcType == PAL_INDEXED)
  1532. {
  1533. pulXlate = XLATEOBJ_piVector(pxlo);
  1534. }
  1535. else
  1536. {
  1537. // Some kind of translation we don't handle
  1538. return FALSE;
  1539. }
  1540. // Calculate the source parameters. We are going to BYTE adjust the
  1541. // source, so we also set the source phase.
  1542. lLeadIn = (ptlSrc.x & 1) * 2;
  1543. pBits += ptlSrc.x >> 1;
  1544. n = sizl.cx + (ptlSrc.x & 1);
  1545. #if !DRIVER_5465
  1546. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  1547. // bug.
  1548. if (ppdev->dwLgDevID == CL_GD5462)
  1549. {
  1550. if (MAKE_HD_INDEX(sizl.cx * 2, lLeadIn, ptlDest.x * 2) == 3788)
  1551. {
  1552. // We have a problem with the HOSTDATA TABLE.
  1553. // Punt till we can figure it out.
  1554. return FALSE;
  1555. }
  1556. lExtra = ExtraDwordTable[
  1557. MAKE_HD_INDEX(sizl.cx * 2, lLeadIn, ptlDest.x * 2)];
  1558. }
  1559. else
  1560. {
  1561. lExtra = 0;
  1562. }
  1563. #endif
  1564. // Start the blit.
  1565. REQUIRE(9);
  1566. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  1567. LL_OP1_MONO(lLeadIn, 0);
  1568. LL_OP0(ptlDest.x, ptlDest.y);
  1569. LL_BLTEXT(sizl.cx, sizl.cy);
  1570. // If there is no translation table, use the default translation table.
  1571. if (pulXlate == NULL)
  1572. {
  1573. pulXlate = ulXlate;
  1574. }
  1575. // Now we are ready to copy all the pixels to the hardware.
  1576. while (sizl.cy--)
  1577. {
  1578. BYTE *p = pBits;
  1579. // First, we convert 2 pixels at a time to create a 32-bit value
  1580. // to write to the hardware.
  1581. for (i = n; i >= 2; i -= 2)
  1582. {
  1583. REQUIRE(1);
  1584. LL32(grHOSTDATA[0], pulXlate[p[0] >> 4] |
  1585. (pulXlate[p[0] & 0x0F] << 16));
  1586. p++;
  1587. }
  1588. // Now, write any remaining pixel.
  1589. if (i)
  1590. {
  1591. REQUIRE(1);
  1592. LL32(grHOSTDATA[0], pulXlate[p[0] >> 4]);
  1593. }
  1594. #if !DRIVER_5465
  1595. // Now, write the extra DWORDS.
  1596. REQUIRE(lExtra);
  1597. for (i = 0; i < lExtra; i++)
  1598. {
  1599. LL32(grHOSTDATA[0], 0);
  1600. }
  1601. #endif
  1602. // Next line.
  1603. pBits += lDelta;
  1604. }
  1605. }
  1606. /* -----------------------------------------------------------------------
  1607. Test for 8-bpp source.
  1608. */
  1609. else if (psoSrc->iBitmapFormat == BMF_8BPP)
  1610. {
  1611. //
  1612. // Attempt to load the translation table into the chip.
  1613. // After this call:
  1614. // pulXlate == NULL if there is no color translation is required.
  1615. // pulXlate == translation table if color translation is required.
  1616. // UseHWxlate == FALSE if the hardware will do the xlate for us.
  1617. // UseHWxlate == TRUE if we must do the translation in software.
  1618. //
  1619. #if COLOR_TRANSLATE
  1620. ULONG UseHWxlate = bCacheXlateTable(ppdev, &pulXlate, psoTrg, psoSrc,
  1621. pxlo, (BYTE)(ulDRAWBLTDEF&0xCC));
  1622. #else
  1623. if ( (pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL) )
  1624. {
  1625. pulXlate = NULL;
  1626. }
  1627. else if (pxlo->flXlate & XO_TABLE)
  1628. {
  1629. pulXlate = pxlo->pulXlate;
  1630. }
  1631. else if (pxlo->iSrcType == PAL_INDEXED)
  1632. {
  1633. pulXlate = XLATEOBJ_piVector(pxlo);
  1634. }
  1635. else
  1636. {
  1637. // Some kind of translation we don't handle
  1638. return FALSE;
  1639. }
  1640. #endif
  1641. //
  1642. // NVH: 5465 Color XLATE bug!!!
  1643. // Color translation is broken on the 5465 in 16, 24 and 32 bpp.
  1644. //
  1645. #if COLOR_TRANSLATE
  1646. if (UseHWxlate)
  1647. {
  1648. DWORD phase = ( ((DWORD)(pBits + ptlSrc.x)) & 3);
  1649. if (XLATE_IS_BROKEN(sizl.cx, 2, phase))
  1650. UseHWxlate = FALSE; // force SW translation.
  1651. }
  1652. if (UseHWxlate)
  1653. {
  1654. // Use Hardware color translation.
  1655. DISPDBG((COPYBITS_DBG_LEVEL, "Host16ToDevice: "
  1656. "Attempting HW color translation on 8bpp Host to 16bpp Screen.\n"));
  1657. // Calculate the source parameters. We are going to DWORD adjust the
  1658. // source, so we also set the source phase.
  1659. pBits += ptlSrc.x; // Start of source data on the host.
  1660. lLeadIn = (DWORD)pBits & 3; // Source phase.
  1661. pBits -= lLeadIn; // Backup to DWORD boundry.
  1662. n = (sizl.cx + lLeadIn + 3) >> 2;// Number of HOSTDATA per scanline.
  1663. // Start the blit.
  1664. REQUIRE(9);
  1665. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  1666. LL_OP1_MONO(lLeadIn, 0);
  1667. LL_OP0(ptlDest.x, ptlDest.y);
  1668. LL_BLTEXT_XLATE(8, sizl.cx, sizl.cy); // HW xlate.
  1669. while (sizl.cy--)
  1670. {
  1671. // Copy all data in 32-bit. We don't have to worry about
  1672. // crossing any boundaries, since within NT everything is DWORD
  1673. // aligned.
  1674. WRITE_STRING(pBits, n);
  1675. pBits += lDelta;
  1676. }
  1677. }
  1678. else
  1679. #endif
  1680. {
  1681. //
  1682. // Use SW color translation.
  1683. //
  1684. DISPDBG((COPYBITS_DBG_LEVEL, "Host16ToDevice: "
  1685. "Attempting SW color translation on 8bpp Host to 16bpp Screen.\n"));
  1686. // To do 8bpp host to 16bpp screen we must have a translation table.
  1687. ASSERTMSG(pulXlate,
  1688. "Host16ToDevice: No translation table for color translation.\n");
  1689. #if !DRIVER_5465
  1690. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  1691. // bug.
  1692. if (ppdev->dwLgDevID == CL_GD5462)
  1693. {
  1694. if (MAKE_HD_INDEX(sizl.cx * 2, 0, ptlDest.x * 2) == 3788)
  1695. {
  1696. // We have a problem with the HOSTDATA TABLE.
  1697. // Punt till we can figure it out.
  1698. return FALSE;
  1699. }
  1700. lExtra = ExtraDwordTable[
  1701. MAKE_HD_INDEX(sizl.cx * 2, 0, ptlDest.x * 2)];
  1702. }
  1703. else
  1704. {
  1705. lExtra = 0;
  1706. }
  1707. #endif
  1708. // Calculate the source parameters.
  1709. pBits += ptlSrc.x; // Start of source data on the host.
  1710. // Start the blit.
  1711. REQUIRE(9);
  1712. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  1713. LL_OP1_MONO(0, 0);
  1714. LL_OP0(ptlDest.x, ptlDest.y);
  1715. LL_BLTEXT(sizl.cx, sizl.cy);
  1716. while (sizl.cy--)
  1717. {
  1718. BYTE *p = pBits;
  1719. // We need to copy 2 pixels at a time to create a 32-bit value
  1720. // for the HOSTDATA register.
  1721. for (i = sizl.cx; i >= 2; i -= 2)
  1722. {
  1723. REQUIRE(1);
  1724. LL32(grHOSTDATA[0], pulXlate[p[0]] |
  1725. (pulXlate[p[1]] << 16));
  1726. p += 2;
  1727. }
  1728. // Write any remainig pixels.
  1729. if (i)
  1730. {
  1731. REQUIRE(1);
  1732. LL32(grHOSTDATA[0], pulXlate[p[0]]);
  1733. }
  1734. #if !DRIVER_5465
  1735. // Now, write the extra DWORDS.
  1736. REQUIRE(lExtra);
  1737. for (i = 0; i < lExtra; i++)
  1738. {
  1739. LL32(grHOSTDATA[0], 0);
  1740. }
  1741. #endif
  1742. // Next line.
  1743. pBits += lDelta;
  1744. }
  1745. }
  1746. }
  1747. /* -----------------------------------------------------------------------
  1748. Source is in same color depth as screen.
  1749. */
  1750. else
  1751. {
  1752. // Get the pointer to the translation table.
  1753. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  1754. if (flXlate & XO_TRIVIAL)
  1755. {
  1756. pulXlate = NULL;
  1757. }
  1758. else if (flXlate & XO_TABLE)
  1759. {
  1760. pulXlate = pxlo->pulXlate;
  1761. }
  1762. else if (pxlo->iSrcType == PAL_INDEXED)
  1763. {
  1764. pulXlate = XLATEOBJ_piVector(pxlo);
  1765. }
  1766. else
  1767. {
  1768. // Some kind of translation we don't handle
  1769. return FALSE;
  1770. }
  1771. // If we have a translation table, punt it.
  1772. #if _WIN32_WINNT >= 0x0500
  1773. if ( pulXlate || (flXlate & 0x0200) )
  1774. #else
  1775. if ( pulXlate || (flXlate & 0x0010) )
  1776. #endif
  1777. {
  1778. return(FALSE);
  1779. }
  1780. // Calculate the source parameters. We are going to DWORD adjust the
  1781. // source, so we also set the source phase.
  1782. pBits += ptlSrc.x * 2;
  1783. lLeadIn = (DWORD)pBits & 3;
  1784. pBits -= lLeadIn;
  1785. n = ((sizl.cx * 2) + lLeadIn + 3) >> 2;
  1786. #if !DRIVER_5465
  1787. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  1788. // bug.
  1789. if (ppdev->dwLgDevID == CL_GD5462)
  1790. {
  1791. if (MAKE_HD_INDEX(sizl.cx * 2, lLeadIn, ptlDest.x * 2) == 3788)
  1792. {
  1793. // We have a problem with the HOSTDATA TABLE.
  1794. // Punt till we can figure it out.
  1795. return FALSE;
  1796. }
  1797. lExtra = ExtraDwordTable[MAKE_HD_INDEX(sizl.cx * 2, lLeadIn, ptlDest.x * 2)];
  1798. }
  1799. else
  1800. lExtra = 0;
  1801. #endif
  1802. // Setup the Laguna registers.
  1803. REQUIRE(9);
  1804. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  1805. // Start the blit.
  1806. LL_OP1_MONO(lLeadIn, 0);
  1807. LL_OP0(ptlDest.x, ptlDest.y);
  1808. LL_BLTEXT(sizl.cx, sizl.cy);
  1809. // Copy all data in 32-bit. We don't have to worry about crossing any
  1810. // boundaries, since within NT everything is DWORD aligned.
  1811. while (sizl.cy--)
  1812. {
  1813. WRITE_STRING(pBits, n);
  1814. #if !DRIVER_5465
  1815. // Now, write the extra DWORDS.
  1816. REQUIRE(lExtra);
  1817. for (i = 0; i < lExtra; i++)
  1818. {
  1819. LL32(grHOSTDATA[i], 0);
  1820. }
  1821. #endif
  1822. // Next line.
  1823. pBits += lDelta;
  1824. }
  1825. }
  1826. return(TRUE);
  1827. }
  1828. /*****************************************************************************\
  1829. * DoDeviceToHost16
  1830. *
  1831. * This routine performs a DeviceToHost for either monochrome or 16-bpp
  1832. * destinations.
  1833. *
  1834. * On entry: psoTrg Pointer to target surface object.
  1835. * psoSrc Pointer to source surface object.
  1836. * pxlo Pointer to translation object.
  1837. * prclTrg Destination rectangle.
  1838. * pptlSrc Source offset.
  1839. * ulDRAWBLTDEF Value for grDRAWBLTDEF register. This value has
  1840. * the ROP and the brush flags.
  1841. \*****************************************************************************/
  1842. BOOL DoDeviceToHost16(
  1843. SURFOBJ *psoTrg,
  1844. SURFOBJ *psoSrc,
  1845. XLATEOBJ *pxlo,
  1846. RECTL *prclTrg,
  1847. POINTL *pptlSrc,
  1848. ULONG ulDRAWBLTDEF
  1849. )
  1850. {
  1851. POINTL ptlSrc;
  1852. PPDEV ppdev;
  1853. SIZEL sizl;
  1854. PBYTE pBits;
  1855. #if !S2H_USE_ENGINE
  1856. PBYTE pjScreen;
  1857. #endif
  1858. LONG lDelta;
  1859. ULONG i, n;
  1860. // Determine the source type and calculate the offset.
  1861. if (psoSrc->iType == STYPE_DEVBITMAP)
  1862. {
  1863. PDSURF pdsurf = (PDSURF)psoSrc->dhsurf;
  1864. ppdev = pdsurf->ppdev;
  1865. ptlSrc.x = pptlSrc->x + pdsurf->ptl.x;
  1866. ptlSrc.y = pptlSrc->y + pdsurf->ptl.y;
  1867. }
  1868. else
  1869. {
  1870. ppdev = (PPDEV)psoSrc->dhpdev;
  1871. ptlSrc.x = pptlSrc->x;
  1872. ptlSrc.y = pptlSrc->y;
  1873. }
  1874. // Calculate the size of the blit.
  1875. sizl.cx = prclTrg->right - prclTrg->left;
  1876. sizl.cy = prclTrg->bottom - prclTrg->top;
  1877. // Calculate the destination variables.
  1878. lDelta = psoTrg->lDelta;
  1879. pBits = (PBYTE)psoTrg->pvScan0 + (prclTrg->top * lDelta);
  1880. #if S2H_USE_ENGINE
  1881. // Setup the Laguna registers.
  1882. REQUIRE(9);
  1883. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x20100000, 0);
  1884. LL_OP0(0, 0);
  1885. #else
  1886. // Calculate the screen address.
  1887. pjScreen = ppdev->pjScreen + ptlSrc.x * 2 + ptlSrc.y * ppdev->lDeltaScreen;
  1888. // Wait for the hardware to become idle.
  1889. while (LLDR_SZ(grSTATUS) != 0) ;
  1890. #endif
  1891. // Test for monochrome destination.
  1892. if (psoTrg->iBitmapFormat == BMF_1BPP)
  1893. {
  1894. BYTE data, leftMask, rightMask;
  1895. WORD fgColor;
  1896. DWORD *pulXlate;
  1897. LONG leftCount, rightCount, leftSkip;
  1898. #if S2H_USE_ENGINE
  1899. BYTE pixels[4];
  1900. #endif
  1901. // Calculate the monochrome masks.
  1902. pBits += prclTrg->left >> 3;
  1903. leftSkip = prclTrg->left & 7;
  1904. leftCount = (8 - leftSkip) & 7;
  1905. leftMask = 0xFF >> leftSkip;
  1906. rightCount = prclTrg->right & 7;
  1907. rightMask = 0xFF << (8 - rightCount);
  1908. // If we only have pixels in one byte, we combine rightMask with
  1909. // leftMask and set the routines to skip everything but the rightMask.
  1910. if (leftCount > sizl.cx)
  1911. {
  1912. rightMask &= leftMask;
  1913. leftMask = 0xFF;
  1914. n = 0;
  1915. }
  1916. else
  1917. {
  1918. n = (sizl.cx - leftCount) >> 3;
  1919. }
  1920. // Get the the foreground color from the translation table.
  1921. pulXlate = XLATEOBJ_piVector(pxlo);
  1922. fgColor = pulXlate ? (WORD) *pulXlate : 0;
  1923. #if S2H_USE_ENGINE
  1924. // Start the blit.
  1925. LL_OP1(ptlSrc.x - leftSkip, ptlSrc.y);
  1926. LL_BLTEXT(sizl.cx + leftSkip, sizl.cy);
  1927. #else
  1928. pjScreen -= leftSkip * 2;
  1929. #endif
  1930. while (sizl.cy--)
  1931. {
  1932. PBYTE pDest = pBits;
  1933. #if !S2H_USE_ENGINE
  1934. PWORD pSrc = (WORD *)pjScreen;
  1935. #endif
  1936. // If we have a left mask specified, we get the pixels and store
  1937. // them with the destination.
  1938. if (leftMask != 0xFF)
  1939. {
  1940. data = 0;
  1941. #if S2H_USE_ENGINE
  1942. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1943. if (*(WORD *)&pixels[0] == fgColor) data |= 0x80;
  1944. if (*(WORD *)&pixels[1] == fgColor) data |= 0x40;
  1945. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1946. if (*(WORD *)&pixels[0] == fgColor) data |= 0x20;
  1947. if (*(WORD *)&pixels[1] == fgColor) data |= 0x10;
  1948. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1949. if (*(WORD *)&pixels[0] == fgColor) data |= 0x08;
  1950. if (*(WORD *)&pixels[1] == fgColor) data |= 0x04;
  1951. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1952. if (*(WORD *)&pixels[0] == fgColor) data |= 0x02;
  1953. if (*(WORD *)&pixels[1] == fgColor) data |= 0x01;
  1954. #else
  1955. if (pSrc[0] == fgColor) data |= 0x80;
  1956. if (pSrc[1] == fgColor) data |= 0x40;
  1957. if (pSrc[2] == fgColor) data |= 0x20;
  1958. if (pSrc[3] == fgColor) data |= 0x10;
  1959. if (pSrc[4] == fgColor) data |= 0x08;
  1960. if (pSrc[5] == fgColor) data |= 0x04;
  1961. if (pSrc[6] == fgColor) data |= 0x02;
  1962. if (pSrc[7] == fgColor) data |= 0x01;
  1963. pSrc += 8;
  1964. #endif
  1965. *pDest++ = (*pDest & ~leftMask) | (data & leftMask);
  1966. }
  1967. // Translate all pixels that don't require masking.
  1968. for (i = 0; i < n; i++)
  1969. {
  1970. data = 0;
  1971. #if S2H_USE_ENGINE
  1972. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1973. if (*(WORD *)&pixels[0] == fgColor) data |= 0x80;
  1974. if (*(WORD *)&pixels[1] == fgColor) data |= 0x40;
  1975. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1976. if (*(WORD *)&pixels[0] == fgColor) data |= 0x20;
  1977. if (*(WORD *)&pixels[1] == fgColor) data |= 0x10;
  1978. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1979. if (*(WORD *)&pixels[0] == fgColor) data |= 0x08;
  1980. if (*(WORD *)&pixels[1] == fgColor) data |= 0x04;
  1981. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  1982. if (*(WORD *)&pixels[0] == fgColor) data |= 0x02;
  1983. if (*(WORD *)&pixels[1] == fgColor) data |= 0x01;
  1984. #else
  1985. if (pSrc[0] == fgColor) data |= 0x80;
  1986. if (pSrc[1] == fgColor) data |= 0x40;
  1987. if (pSrc[2] == fgColor) data |= 0x20;
  1988. if (pSrc[3] == fgColor) data |= 0x10;
  1989. if (pSrc[4] == fgColor) data |= 0x08;
  1990. if (pSrc[5] == fgColor) data |= 0x04;
  1991. if (pSrc[6] == fgColor) data |= 0x02;
  1992. if (pSrc[7] == fgColor) data |= 0x01;
  1993. pSrc += 8;
  1994. #endif
  1995. *pDest++ = data;
  1996. }
  1997. // If we have a right mask specified, we get the pixels and store
  1998. // them with the destination.
  1999. if (rightMask != 0x00)
  2000. {
  2001. data = 0;
  2002. #if S2H_USE_ENGINE
  2003. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  2004. if (*(WORD *)&pixels[0] == fgColor) data |= 0x80;
  2005. if (*(WORD *)&pixels[1] == fgColor) data |= 0x40;
  2006. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  2007. if (*(WORD *)&pixels[0] == fgColor) data |= 0x20;
  2008. if (*(WORD *)&pixels[1] == fgColor) data |= 0x10;
  2009. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  2010. if (*(WORD *)&pixels[0] == fgColor) data |= 0x08;
  2011. if (*(WORD *)&pixels[1] == fgColor) data |= 0x04;
  2012. *(DWORD *)pixels = LLDR_SZ(grHOSTDATA[0]);
  2013. if (*(WORD *)&pixels[0] == fgColor) data |= 0x02;
  2014. if (*(WORD *)&pixels[1] == fgColor) data |= 0x01;
  2015. #else
  2016. if (pSrc[0] == fgColor) data |= 0x80;
  2017. if (pSrc[1] == fgColor) data |= 0x40;
  2018. if (pSrc[2] == fgColor) data |= 0x20;
  2019. if (pSrc[3] == fgColor) data |= 0x10;
  2020. if (pSrc[4] == fgColor) data |= 0x08;
  2021. if (pSrc[5] == fgColor) data |= 0x04;
  2022. if (pSrc[6] == fgColor) data |= 0x02;
  2023. if (pSrc[7] == fgColor) data |= 0x01;
  2024. #endif
  2025. *pDest = (*pDest & ~rightMask) | (data & rightMask);
  2026. }
  2027. // Next line.
  2028. #if !S2H_USE_ENGINE
  2029. pjScreen += ppdev->lDeltaScreen;
  2030. #endif
  2031. pBits += lDelta;
  2032. }
  2033. }
  2034. // We only support destination bitmaps with the same color depth and we
  2035. // do not support any color translation.
  2036. else if ( (psoTrg->iBitmapFormat != BMF_16BPP) ||
  2037. (pxlo && !(pxlo->flXlate & XO_TRIVIAL)) )
  2038. {
  2039. return(FALSE);
  2040. }
  2041. /*
  2042. If the GetPixel routine is being called, we get here with both cx and
  2043. cy set to 1 and the ROP to 0xCC (source copy). In this special case we
  2044. read the pixel directly from memory. Of course, we must be sure the
  2045. blit engine is finished working since it may still update the very
  2046. pixel we are going to read! We could use the hardware for this, but it
  2047. seems there is a HARDWARE BUG that doesn't seem to like the 1-pixel
  2048. ScreenToHost very much.
  2049. */
  2050. #if S2H_USE_ENGINE
  2051. else if ( (sizl.cx == 1) && (sizl.cy == 1) && (ulDRAWBLTDEF == 0x000000CC) )
  2052. {
  2053. // Wait for the hardware to become idle.
  2054. while (LLDR_SZ(grSTATUS) != 0) ;
  2055. // Get the pixel from screen.
  2056. *(WORD *)pBits[prclTrg->left] = *(WORD *)
  2057. &ppdev->pjScreen[ptlSrc.x * 2 + ptlSrc.y * ppdev->lDeltaScreen];
  2058. }
  2059. #endif
  2060. else
  2061. {
  2062. #if S2H_USE_ENGINE
  2063. // The hardware requires us to get QWORDS.
  2064. BOOL fExtra = ((sizl.cx * 2 + 3) >> 2) & 1;
  2065. #endif
  2066. pBits += prclTrg->left * 2;
  2067. #if S2H_USE_ENGINE
  2068. // Start the blit.
  2069. LL_OP1(ptlSrc.x, ptlSrc.y);
  2070. LL_BLTEXT(sizl.cx, sizl.cy);
  2071. #endif
  2072. while (sizl.cy--)
  2073. {
  2074. #if S2H_USE_ENGINE
  2075. DWORD *p = (DWORD *)pBits;
  2076. // First, we get pixels in chunks of 2 so the 32-bit HOSTDATA is
  2077. // happy.
  2078. for (i = sizl.cx; i >= 2; i -= 2)
  2079. {
  2080. *p++ = LLDR_SZ(grHOSTDATA[0]);
  2081. }
  2082. // Then, we have to do the remainig pixel.
  2083. if (i)
  2084. {
  2085. *(WORD *)p = (WORD)LLDR_SZ(grHOSTDATA[0]);
  2086. }
  2087. // Get the extra pixel required for QWORD alignment.
  2088. if (fExtra)
  2089. {
  2090. LLDR_SZ(grHOSTDATA[0]);
  2091. }
  2092. #else
  2093. // Copy all pixels from screen to memory.
  2094. memcpy(pBits, pjScreen, sizl.cx * 2);
  2095. // Next line.
  2096. pjScreen += ppdev->lDeltaScreen;
  2097. #endif
  2098. pBits += lDelta;
  2099. }
  2100. }
  2101. return(TRUE);
  2102. }
  2103. /*****************************************************************************\
  2104. * *
  2105. * 2 4 - B P P *
  2106. * *
  2107. \*****************************************************************************/
  2108. /*****************************************************************************\
  2109. * DoHost24ToDevice
  2110. *
  2111. * This routine performs a HostToScreen or HostToDevice blit. The host data
  2112. * can be either monochrome, 4-bpp, or 24-bpp. Color translation is only
  2113. * supported for monochrome and 4-bpp modes.
  2114. *
  2115. * On entry: psoTrg Pointer to target surface object.
  2116. * psoSrc Pointer to source surface object.
  2117. * pxlo Pointer to translation object.
  2118. * prclTrg Destination rectangle.
  2119. * pptlSrc Source offset.
  2120. * ulDRAWBLTDEF Value for grDRAWBLTDEF register. This value has
  2121. * the ROP and the brush flags.
  2122. \*****************************************************************************/
  2123. BOOL DoHost24ToDevice(
  2124. SURFOBJ *psoTrg,
  2125. SURFOBJ *psoSrc,
  2126. XLATEOBJ *pxlo,
  2127. RECTL *prclTrg,
  2128. POINTL *pptlSrc,
  2129. ULONG ulDRAWBLTDEF
  2130. )
  2131. {
  2132. POINTL ptlDest, ptlSrc;
  2133. SIZEL sizl;
  2134. PPDEV ppdev;
  2135. PBYTE pBits;
  2136. LONG lDelta, i, n, lLeadIn, lExtra, i1;
  2137. ULONG *pulXlate;
  2138. FLONG flXlate;
  2139. // Calculate te source offset.
  2140. ptlSrc.x = pptlSrc->x;
  2141. ptlSrc.y = pptlSrc->y;
  2142. // Determine the destination type and calculate the destination offset.
  2143. if (psoTrg->iType == STYPE_DEVBITMAP)
  2144. {
  2145. PDSURF pdsurf = (PDSURF) psoTrg->dhsurf;
  2146. ptlDest.x = prclTrg->left + pdsurf->ptl.x;
  2147. ptlDest.y = prclTrg->top + pdsurf->ptl.y;
  2148. ppdev = pdsurf->ppdev;
  2149. }
  2150. else
  2151. {
  2152. ptlDest.x = prclTrg->left;
  2153. ptlDest.y = prclTrg->top;
  2154. ppdev = (PPDEV) psoTrg->dhpdev;
  2155. }
  2156. // Calculate the size of the blit.
  2157. sizl.cx = prclTrg->right - prclTrg->left;
  2158. sizl.cy = prclTrg->bottom - prclTrg->top;
  2159. // Get the source variables and ofsfet into source bits.
  2160. lDelta = psoSrc->lDelta;
  2161. pBits = (PBYTE)psoSrc->pvScan0 + (ptlSrc.y * lDelta);
  2162. /* -----------------------------------------------------------------------
  2163. Test for monochrome source.
  2164. */
  2165. if (psoSrc->iBitmapFormat == BMF_1BPP)
  2166. {
  2167. ULONG bgColor, fgColor;
  2168. #if SWAT7
  2169. SIZEL sizlTotal;
  2170. #endif
  2171. // Get the pointer to the translation table.
  2172. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  2173. if (flXlate & XO_TRIVIAL)
  2174. {
  2175. pulXlate = NULL;
  2176. }
  2177. else if (flXlate & XO_TABLE)
  2178. {
  2179. pulXlate = pxlo->pulXlate;
  2180. }
  2181. else if (pxlo->iSrcType == PAL_INDEXED)
  2182. {
  2183. pulXlate = XLATEOBJ_piVector(pxlo);
  2184. }
  2185. else
  2186. {
  2187. // Some kind of translation we don't handle
  2188. return FALSE;
  2189. }
  2190. // Set background and foreground colors.
  2191. if (pulXlate == NULL)
  2192. {
  2193. bgColor = 0x00000000;
  2194. fgColor = 0x00FFFFFF;
  2195. }
  2196. else
  2197. {
  2198. bgColor = pulXlate[0] & 0x00FFFFFF;
  2199. fgColor = pulXlate[1] & 0x00FFFFFF;
  2200. }
  2201. //
  2202. // Special case: when we are expanding monochrome sources and we
  2203. // already have a colored brush, we must make sure the monochrome color
  2204. // translation can be achived by setting the saturation bit (expanding
  2205. // 0's to 0 and 1's to 1). If the monochrome source also requires color
  2206. // translation, we simply punt this blit back to GDI.
  2207. //
  2208. if (ulDRAWBLTDEF & 0x00040000)
  2209. {
  2210. if ( (bgColor == 0x00000000) && (fgColor == 0x00FFFFFF) )
  2211. {
  2212. // Enable saturation for source (OP1).
  2213. ulDRAWBLTDEF |= 0x00008000;
  2214. }
  2215. #if SOLID_CACHE
  2216. else if ( ((ulDRAWBLTDEF & 0x000F0000) == 0x00070000) &&
  2217. ppdev->Bcache )
  2218. {
  2219. CacheSolid(ppdev);
  2220. ulDRAWBLTDEF ^= (0x00070000 ^ 0x00090000);
  2221. REQUIRE(4);
  2222. LL_BGCOLOR(bgColor, 2);
  2223. LL_FGCOLOR(fgColor, 2);
  2224. }
  2225. #endif
  2226. else
  2227. {
  2228. // Punt this call to the GDI.
  2229. return(FALSE);
  2230. }
  2231. }
  2232. else
  2233. {
  2234. REQUIRE(4);
  2235. LL_BGCOLOR(bgColor, 2);
  2236. LL_FGCOLOR(fgColor, 2);
  2237. }
  2238. REQUIRE(9);
  2239. #if SWAT7
  2240. // Setup the Laguna registers for the blit. We also set the bit swizzle
  2241. // bit in the grCONTROL register.
  2242. ppdev->grCONTROL |= SWIZ_CNTL;
  2243. LL16(grCONTROL, ppdev->grCONTROL);
  2244. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10600000, 2);
  2245. sizlTotal = sizl;
  2246. while (sizlTotal.cx)
  2247. {
  2248. sizl.cx = min(sizlTotal.cx, 864);
  2249. sizl.cy = sizlTotal.cy;
  2250. #endif
  2251. // Calculate the source parameters. We are going to BYTE
  2252. // adjust the source, so we must setup the source phase.
  2253. lLeadIn = ptlSrc.x & 7;
  2254. pBits += ptlSrc.x >> 3;
  2255. n = (sizl.cx + lLeadIn + 7) >> 3;
  2256. #if !SWAT7
  2257. //
  2258. // Chip bug. Laguna locks with more than 15 dwords HOSTDATA
  2259. //
  2260. if (n > 120) // 15 qwords = 120 bytes
  2261. {
  2262. return FALSE;
  2263. }
  2264. // Setup the Laguna registers for the blit. We also set the bit swizzle
  2265. // bit in the grCONTROL register.
  2266. ppdev->grCONTROL |= SWIZ_CNTL;
  2267. LL16(grCONTROL, ppdev->grCONTROL);
  2268. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10600000, 2);
  2269. #endif
  2270. // Start the blit.
  2271. // added REQUIRE above
  2272. // REQUIRE(7);
  2273. LL_OP1_MONO(lLeadIn, 0);
  2274. LL_OP0(ptlDest.x, ptlDest.y);
  2275. LL_BLTEXT(sizl.cx, sizl.cy);
  2276. // Copy all the bits to the screen, 32-bits at a time. We don't have to
  2277. // worry about crossing any boundary since NT is always DWORD aligned.
  2278. while (sizl.cy--)
  2279. {
  2280. BYTE *p = pBits;
  2281. BYTE pixels[4];
  2282. // First, we draw 32-pixels at a time to keep HOSTDATA happy.
  2283. for (i = n; i >= 4; i -= 4)
  2284. {
  2285. REQUIRE(1);
  2286. LL32(grHOSTDATA[0], *(DWORD *)p);
  2287. p += 4;
  2288. }
  2289. // Draw any remainig pixls.
  2290. switch (i)
  2291. {
  2292. case 1:
  2293. REQUIRE(1);
  2294. LL32(grHOSTDATA[0], *p);
  2295. break;
  2296. case 2:
  2297. REQUIRE(1);
  2298. LL32(grHOSTDATA[0], *(WORD *)p);
  2299. break;
  2300. case 3:
  2301. pixels[0] = p[0];
  2302. pixels[1] = p[1];
  2303. pixels[2] = p[2];
  2304. REQUIRE(1);
  2305. LL32(grHOSTDATA[0], *(DWORD *)pixels);
  2306. break;
  2307. }
  2308. // Next line.
  2309. pBits += lDelta;
  2310. }
  2311. #if SWAT7
  2312. sizlTotal.cx -= sizl.cx;
  2313. ptlSrc.x += sizl.cx;
  2314. ptlDest.x += sizl.cx;
  2315. #if 1 // SWAT: 08/08/97
  2316. // Reload pBits.
  2317. pBits = (PBYTE) psoSrc->pvScan0 + (ptlSrc.y * lDelta);
  2318. #endif
  2319. }
  2320. #endif
  2321. // Disable the swizzle bit in the grCONTROL register.
  2322. ppdev->grCONTROL = ppdev->grCONTROL & ~SWIZ_CNTL;
  2323. LL16(grCONTROL, ppdev->grCONTROL);
  2324. }
  2325. /* -----------------------------------------------------------------------
  2326. Test for 4-bpp source.
  2327. */
  2328. else if (psoSrc->iBitmapFormat == BMF_4BPP)
  2329. {
  2330. // Get the pointer to the translation table.
  2331. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  2332. if (flXlate & XO_TRIVIAL)
  2333. {
  2334. pulXlate = NULL;
  2335. }
  2336. else if (flXlate & XO_TABLE)
  2337. {
  2338. pulXlate = pxlo->pulXlate;
  2339. }
  2340. else if (pxlo->iSrcType == PAL_INDEXED)
  2341. {
  2342. pulXlate = XLATEOBJ_piVector(pxlo);
  2343. }
  2344. else
  2345. {
  2346. // Some kind of translation we don't handle
  2347. return FALSE;
  2348. }
  2349. // Calculate the source parameters. We are going to BYTE adjust the
  2350. // source, so we also set the source phase.
  2351. lLeadIn = (ptlSrc.x & 1) * 3;
  2352. pBits += ptlSrc.x >> 1;
  2353. n = sizl.cx + (ptlSrc.x & 1);
  2354. #if !DRIVER_5465
  2355. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  2356. // bug.
  2357. if (ppdev->dwLgDevID == CL_GD5462)
  2358. {
  2359. if (MAKE_HD_INDEX(sizl.cx * 3, lLeadIn, ptlDest.x * 3) == 3788)
  2360. {
  2361. // We have a problem with the HOSTDATA TABLE.
  2362. // Punt till we can figure it out.
  2363. return FALSE;
  2364. }
  2365. lExtra = ExtraDwordTable[MAKE_HD_INDEX(sizl.cx * 3, lLeadIn, ptlDest.x * 3)];
  2366. }
  2367. else
  2368. lExtra = 0;
  2369. #endif
  2370. // Start the blit.
  2371. REQUIRE(9);
  2372. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  2373. LL_OP1_MONO(lLeadIn, 0);
  2374. LL_OP0(ptlDest.x, ptlDest.y);
  2375. LL_BLTEXT(sizl.cx, sizl.cy);
  2376. // If there is no translation table, use the default translation table.
  2377. if (pulXlate == NULL)
  2378. {
  2379. pulXlate = ulXlate;
  2380. }
  2381. // Now we are ready to copy all the pixels to the hardware.
  2382. while (sizl.cy--)
  2383. {
  2384. BYTE *p = pBits;
  2385. ULONG pixels[4];
  2386. // First, we convert 4 pixels at a time to create three 32-bit
  2387. // values to write to the hardware.
  2388. for (i = n; i >= 4; i -= 4)
  2389. {
  2390. pixels[0] = pulXlate[p[0] >> 4];
  2391. pixels[1] = pulXlate[p[0] & 0x0F];
  2392. pixels[2] = pulXlate[p[1] >> 4];
  2393. pixels[3] = pulXlate[p[1] & 0x0F];
  2394. // 1000
  2395. REQUIRE(3);
  2396. LL32(grHOSTDATA[0], pixels[0] | (pixels[1] << 24));
  2397. // 2211
  2398. LL32(grHOSTDATA[1], (pixels[1] >> 8) | (pixels[2] << 16));
  2399. // 3332
  2400. LL32(grHOSTDATA[2], (pixels[2] >> 16) | (pixels[3] << 8));
  2401. p += 2;
  2402. }
  2403. // Now, write any remaining pixels.
  2404. switch (i)
  2405. {
  2406. case 1:
  2407. // x000
  2408. REQUIRE(1);
  2409. LL32(grHOSTDATA[0], pulXlate[p[0] >> 4]);
  2410. break;
  2411. case 2:
  2412. pixels[0] = pulXlate[p[0] >> 4];
  2413. pixels[1] = pulXlate[p[0] & 0x0F];
  2414. // 1000
  2415. REQUIRE(2);
  2416. LL32(grHOSTDATA[0], pixels[0] | (pixels[1] << 24));
  2417. // xx11
  2418. LL32(grHOSTDATA[1], pixels[1] >> 8);
  2419. break;
  2420. case 3:
  2421. pixels[0] = pulXlate[p[0] >> 4];
  2422. pixels[1] = pulXlate[p[0] & 0x0F];
  2423. pixels[2] = pulXlate[p[1] >> 4];
  2424. // 1000
  2425. REQUIRE(3);
  2426. LL32(grHOSTDATA[0], pixels[0] | (pixels[1] << 24));
  2427. // 2211
  2428. LL32(grHOSTDATA[1], (pixels[1] >> 8) | (pixels[2] << 16));
  2429. // xxx2
  2430. LL32(grHOSTDATA[2], pixels[2] >> 16);
  2431. break;
  2432. }
  2433. #if !DRIVER_5465
  2434. // Now, write the extra DWORDS.
  2435. REQUIRE(lExtra);
  2436. for (i = 0; i < lExtra; i++)
  2437. {
  2438. LL32(grHOSTDATA[0], 0);
  2439. }
  2440. #endif
  2441. // Next line.
  2442. pBits += lDelta;
  2443. }
  2444. }
  2445. /* -----------------------------------------------------------------------
  2446. Test for 8-bpp source.
  2447. */
  2448. else if (psoSrc->iBitmapFormat == BMF_8BPP)
  2449. {
  2450. //
  2451. // Attempt to load the translation table into the chip.
  2452. // After this call:
  2453. // pulXlate == NULL if there is no color translation is required.
  2454. // pulXlate == translation table if color translation is required.
  2455. // UseHWxlate == FALSE if the hardware will do the xlate for us.
  2456. // UseHWxlate == TRUE if we must do the translation in software.
  2457. //
  2458. #if COLOR_TRANSLATE
  2459. ULONG UseHWxlate = bCacheXlateTable(ppdev, &pulXlate, psoTrg, psoSrc,
  2460. pxlo, (BYTE)(ulDRAWBLTDEF&0xCC));
  2461. #else
  2462. if ( (pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL) )
  2463. {
  2464. pulXlate = NULL;
  2465. }
  2466. else if (pxlo->flXlate & XO_TABLE)
  2467. {
  2468. pulXlate = pxlo->pulXlate;
  2469. }
  2470. else if (pxlo->iSrcType == PAL_INDEXED)
  2471. {
  2472. pulXlate = XLATEOBJ_piVector(pxlo);
  2473. }
  2474. else
  2475. {
  2476. // Some kind of translation we don't handle
  2477. return FALSE;
  2478. }
  2479. #endif
  2480. // A translation table is required.
  2481. // "Well, DUH!" you might say, but I've seen it missing before...
  2482. if (!pulXlate)
  2483. {
  2484. DISPDBG((0, "\n\nHost24ToDevice: !!! WARNING !!! 8BPP source "
  2485. "bitmap does not have a translation table. Punting!\n\n"));
  2486. return FALSE;
  2487. }
  2488. #if COLOR_TRANSLATE
  2489. //
  2490. // NVH: 5465 Color XLATE bug!!!
  2491. // Color translation is broken on the 5465 in 16, 24 and 32 bpp.
  2492. //
  2493. if (UseHWxlate)
  2494. {
  2495. DWORD phase = ( ((DWORD)(pBits + ptlSrc.x)) & 3);
  2496. if (XLATE_IS_BROKEN(sizl.cx, 3, phase))
  2497. UseHWxlate = FALSE; // force SW translation.
  2498. }
  2499. if (UseHWxlate)
  2500. {
  2501. // Use Hardware color translation.
  2502. DISPDBG((COPYBITS_DBG_LEVEL, "Host24ToDevice: "
  2503. "Attempting HW color translation on 8bpp Host to 24bpp Screen.\n"));
  2504. // Calculate the source parameters. We are going to DWORD adjust the
  2505. // source, so we also set the source phase.
  2506. pBits += ptlSrc.x; // Start of source data on the host.
  2507. lLeadIn = (DWORD)pBits & 3; // Source phase.
  2508. pBits -= lLeadIn; // Backup to DWORD boundry.
  2509. n = (sizl.cx + lLeadIn + 3) >> 2;// Number of HOSTDATA per scanline.
  2510. // Start the blit.
  2511. REQUIRE(9);
  2512. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  2513. LL_OP1_MONO(lLeadIn, 0);
  2514. LL_OP0(ptlDest.x, ptlDest.y);
  2515. LL_BLTEXT_XLATE(8, sizl.cx, sizl.cy); // HW xlate.
  2516. while (sizl.cy--)
  2517. {
  2518. // Copy all data in 32-bit. We don't have to worry about
  2519. // crossing any boundaries, since within NT everything is DWORD
  2520. // aligned.
  2521. WRITE_STRING(pBits, n);
  2522. pBits += lDelta;
  2523. }
  2524. }
  2525. else
  2526. #endif
  2527. {
  2528. //
  2529. // Use SW color translation.
  2530. //
  2531. // Calculate the source parameters.
  2532. pBits += ptlSrc.x;
  2533. #if !DRIVER_5465
  2534. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  2535. // bug.
  2536. if (ppdev->dwLgDevID == CL_GD5462)
  2537. {
  2538. if (MAKE_HD_INDEX(sizl.cx * 3, 0, ptlDest.x * 3) == 3788)
  2539. {
  2540. // We have a problem with the HOSTDATA TABLE.
  2541. // Punt till we can figure it out.
  2542. return FALSE;
  2543. }
  2544. lExtra = ExtraDwordTable[MAKE_HD_INDEX(sizl.cx * 3, 0, ptlDest.x * 3)];
  2545. }
  2546. else
  2547. {
  2548. lExtra = 0;
  2549. }
  2550. #endif
  2551. // Setup the Laguna registers.
  2552. REQUIRE(9);
  2553. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  2554. // Start the blit.
  2555. LL_OP1_MONO(0, 0);
  2556. LL_OP0(ptlDest.x, ptlDest.y);
  2557. LL_BLTEXT(sizl.cx, sizl.cy);
  2558. while (sizl.cy--)
  2559. {
  2560. BYTE *p = pBits;
  2561. // We need to copy 4 pixels at a time to create three 32-bit values
  2562. // for the HOSTDATA register and stay in sync.
  2563. for (i = sizl.cx; i >= 4; i -= 4)
  2564. {
  2565. REQUIRE(3);
  2566. LL32(grHOSTDATA[0],
  2567. pulXlate[p[0]] | (pulXlate[p[1]] << 24));
  2568. LL32(grHOSTDATA[1],
  2569. (pulXlate[p[1]] >> 8) | (pulXlate[p[2]] << 16));
  2570. LL32(grHOSTDATA[2],
  2571. (pulXlate[p[2]] >> 16) | (pulXlate[p[3]] << 8));
  2572. p += 4;
  2573. }
  2574. // Write any remainig pixels.
  2575. switch (i)
  2576. {
  2577. case 1:
  2578. REQUIRE(1);
  2579. LL32(grHOSTDATA[0], pulXlate[p[0]]);
  2580. break;
  2581. case 2:
  2582. REQUIRE(2);
  2583. LL32(grHOSTDATA[0],
  2584. pulXlate[p[0]] | (pulXlate[p[1]] << 24));
  2585. LL32(grHOSTDATA[1], pulXlate[p[1]] >> 8);
  2586. break;
  2587. case 3:
  2588. REQUIRE(3);
  2589. LL32(grHOSTDATA[0],
  2590. pulXlate[p[0]] | (pulXlate[p[1]] << 24));
  2591. LL32(grHOSTDATA[1],
  2592. (pulXlate[p[1]] >> 8) | (pulXlate[p[2]] << 16));
  2593. LL32(grHOSTDATA[2], pulXlate[p[2]] >> 16);
  2594. break;
  2595. }
  2596. #if !DRIVER_5465
  2597. // Now, write the extra DWORDS.
  2598. REQUIRE(lExtra);
  2599. for (i = 0; i < lExtra; i++)
  2600. {
  2601. LL32(grHOSTDATA[0], 0);
  2602. }
  2603. #endif
  2604. // Next line.
  2605. pBits += lDelta;
  2606. }
  2607. }
  2608. }
  2609. /* -----------------------------------------------------------------------
  2610. Source is in same color depth as screen.
  2611. */
  2612. else
  2613. {
  2614. // Get the pointer to the translation table.
  2615. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  2616. if (flXlate & XO_TRIVIAL)
  2617. {
  2618. pulXlate = NULL;
  2619. }
  2620. else if (flXlate & XO_TABLE)
  2621. {
  2622. pulXlate = pxlo->pulXlate;
  2623. }
  2624. else if (pxlo->iSrcType == PAL_INDEXED)
  2625. {
  2626. pulXlate = XLATEOBJ_piVector(pxlo);
  2627. }
  2628. else
  2629. {
  2630. // Some kind of translation we don't handle
  2631. return FALSE;
  2632. }
  2633. // If we have a translation table, punt it.
  2634. if ( pulXlate || (flXlate & 0x10) )
  2635. {
  2636. return(FALSE);
  2637. }
  2638. // Calculate the source parameters. We are going to DWORD adjust the
  2639. // source, so we also set the source phase.
  2640. pBits += ptlSrc.x * 3;
  2641. lLeadIn = (DWORD)pBits & 3;
  2642. pBits -= lLeadIn;
  2643. n = (sizl.cx * 3 + lLeadIn + 3) >> 2;
  2644. #if !DRIVER_5465
  2645. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  2646. // bug.
  2647. if (ppdev->dwLgDevID == CL_GD5462)
  2648. {
  2649. if (MAKE_HD_INDEX(sizl.cx * 3, lLeadIn, ptlDest.x * 3) == 3788)
  2650. {
  2651. // We have a problem with the HOSTDATA TABLE.
  2652. // Punt till we can figure it out.
  2653. return FALSE;
  2654. }
  2655. lExtra = ExtraDwordTable[MAKE_HD_INDEX(sizl.cx * 3, lLeadIn, ptlDest.x * 3)];
  2656. }
  2657. else
  2658. lExtra = 0;
  2659. #endif
  2660. // Setup the Laguna registers.
  2661. REQUIRE(9);
  2662. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  2663. // Start the blit.
  2664. LL_OP1_MONO(lLeadIn, 0);
  2665. LL_OP0(ptlDest.x, ptlDest.y);
  2666. LL_BLTEXT(sizl.cx, sizl.cy);
  2667. // Copy all data in 32-bit. We don't have to worry about crossing any
  2668. // boundaries, since within NT everything is DWORD aligned.
  2669. while (sizl.cy--)
  2670. {
  2671. WRITE_STRING(pBits, n);
  2672. #if !DRIVER_5465
  2673. // Now, write the extra DWORDS.
  2674. REQUIRE(lExtra);
  2675. for (i = 0; i < lExtra; i++)
  2676. {
  2677. LL32(grHOSTDATA[0], 0);
  2678. }
  2679. #endif
  2680. // Next line.
  2681. pBits += lDelta;
  2682. }
  2683. }
  2684. return(TRUE);
  2685. }
  2686. /*****************************************************************************\
  2687. * DoDeviceToHost24
  2688. *
  2689. * This routine performs a DeviceToHost for either monochrome or 24-bpp
  2690. * destinations.
  2691. *
  2692. * On entry: psoTrg Pointer to target surface object.
  2693. * psoSrc Pointer to source surface object.
  2694. * pxlo Pointer to translation object.
  2695. * prclTrg Destination rectangle.
  2696. * pptlSrc Source offset.
  2697. * ulDRAWBLTDEF Value for grDRAWBLTDEF register. This value has
  2698. * the ROP and the brush flags.
  2699. \*****************************************************************************/
  2700. BOOL DoDeviceToHost24(
  2701. SURFOBJ *psoTrg,
  2702. SURFOBJ *psoSrc,
  2703. XLATEOBJ *pxlo,
  2704. RECTL *prclTrg,
  2705. POINTL *pptlSrc,
  2706. ULONG ulDRAWBLTDEF
  2707. )
  2708. {
  2709. POINTL ptlSrc;
  2710. PPDEV ppdev;
  2711. SIZEL sizl;
  2712. PBYTE pBits;
  2713. #if !S2H_USE_ENGINE
  2714. PBYTE pjScreen;
  2715. #endif
  2716. LONG lDelta;
  2717. ULONG i, n;
  2718. // Determine the source type and calculate the offset.
  2719. if (psoSrc->iType == STYPE_DEVBITMAP)
  2720. {
  2721. PDSURF pdsurf = (PDSURF)psoSrc->dhsurf;
  2722. ppdev = pdsurf->ppdev;
  2723. ptlSrc.x = pptlSrc->x + pdsurf->ptl.x;
  2724. ptlSrc.y = pptlSrc->y + pdsurf->ptl.y;
  2725. }
  2726. else
  2727. {
  2728. ppdev = (PPDEV)psoSrc->dhpdev;
  2729. ptlSrc.x = pptlSrc->x;
  2730. ptlSrc.y = pptlSrc->y;
  2731. }
  2732. // Calculate the size of the blit.
  2733. sizl.cx = prclTrg->right - prclTrg->left;
  2734. sizl.cy = prclTrg->bottom - prclTrg->top;
  2735. // Calculate the destination variables.
  2736. lDelta = psoTrg->lDelta;
  2737. pBits = (PBYTE)psoTrg->pvScan0 + (prclTrg->top * lDelta);
  2738. #if S2H_USE_ENGINE
  2739. // Setup the Laguna registers.
  2740. REQUIRE(9);
  2741. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x20100000, 0);
  2742. LL_OP0(0, 0);
  2743. #else
  2744. // Calculate the screen address.
  2745. pjScreen = ppdev->pjScreen + ptlSrc.x * 3 + ptlSrc.y * ppdev->lDeltaScreen;
  2746. // Wait for the hardware to become idle.
  2747. while (LLDR_SZ(grSTATUS) != 0) ;
  2748. #endif
  2749. // Test for a monochrome destination.
  2750. if (psoTrg->iBitmapFormat == BMF_1BPP)
  2751. {
  2752. BYTE data, leftMask, rightMask;
  2753. ULONG fgColor;
  2754. DWORD *pulXlate;
  2755. LONG leftCount, rightCount, leftSkip;
  2756. BYTE pixels[12];
  2757. // Calculate the monochrome masks.
  2758. pBits += prclTrg->left >> 3;
  2759. leftSkip = prclTrg->left & 7;
  2760. leftCount = (8 - leftSkip) & 7;
  2761. leftMask = 0xFF >> leftSkip;
  2762. rightCount = prclTrg->right & 7;
  2763. rightMask = 0xFF << (8 - rightCount);
  2764. // If we only have pixels in one byte, we combine rightMask with
  2765. // leftMask and set the routine to skip everything but the rightMask.
  2766. if (leftCount > sizl.cx)
  2767. {
  2768. rightMask &= leftMask;
  2769. leftMask = 0xFF;
  2770. n = 0;
  2771. }
  2772. else
  2773. {
  2774. n = (sizl.cx - leftCount) >> 3;
  2775. }
  2776. // Get the foreground color from the translation table.
  2777. pulXlate = XLATEOBJ_piVector(pxlo);
  2778. fgColor = pulXlate ? *pulXlate : 0;
  2779. #if S2H_USE_ENGINE
  2780. // Start the blit.
  2781. LL_OP1(ptlSrc.x - leftSkip, ptlSrc.y);
  2782. LL_BLTEXT(sizl.cx + leftSkip, sizl.cy);
  2783. #else
  2784. pjScreen -= leftSkip * 3;
  2785. #endif
  2786. while (sizl.cy--)
  2787. {
  2788. PBYTE pDest = pBits;
  2789. #if !S2H_USE_ENGINE
  2790. DWORD *pSrc = (DWORD *)pjScreen;
  2791. #endif
  2792. // If we have a leftMask specified, we get the pixels and store
  2793. // them in the destination.
  2794. if (leftMask != 0xFF)
  2795. {
  2796. data = 0;
  2797. #if S2H_USE_ENGINE
  2798. *(DWORD *)&pixels[0] = LLDR_SZ(grHOSTDATA[0]);
  2799. *(DWORD *)&pixels[4] = LLDR_SZ(grHOSTDATA[0]);
  2800. *(DWORD *)&pixels[8] = LLDR_SZ(grHOSTDATA[0]);
  2801. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2802. data |= 0x80;
  2803. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2804. data |= 0x40;
  2805. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2806. data |= 0x20;
  2807. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2808. data |= 0x10;
  2809. *(DWORD *)&pixels[0] = LLDR_SZ(grHOSTDATA[0]);
  2810. *(DWORD *)&pixels[4] = LLDR_SZ(grHOSTDATA[0]);
  2811. *(DWORD *)&pixels[8] = LLDR_SZ(grHOSTDATA[0]);
  2812. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2813. data |= 0x08;
  2814. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2815. data |= 0x04;
  2816. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2817. data |= 0x02;
  2818. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2819. data |= 0x01;
  2820. #else
  2821. *(DWORD *)&pixels[0] = pSrc[0];
  2822. *(DWORD *)&pixels[4] = pSrc[1];
  2823. *(DWORD *)&pixels[8] = pSrc[2];
  2824. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2825. data |= 0x80;
  2826. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2827. data |= 0x40;
  2828. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2829. data |= 0x20;
  2830. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2831. data |= 0x10;
  2832. *(DWORD *)&pixels[0] = pSrc[3];
  2833. *(DWORD *)&pixels[4] = pSrc[4];
  2834. *(DWORD *)&pixels[8] = pSrc[5];
  2835. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2836. data |= 0x08;
  2837. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2838. data |= 0x04;
  2839. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2840. data |= 0x02;
  2841. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2842. data |= 0x01;
  2843. pSrc += 6;
  2844. #endif
  2845. *pDest++ = (*pDest & ~leftMask) | (data & leftMask);
  2846. }
  2847. // Translate all pixels that don't require masking.
  2848. for (i = 0; i < n; i++)
  2849. {
  2850. data = 0;
  2851. #if S2H_USE_ENGINE
  2852. *(DWORD *)&pixels[0] = LLDR_SZ(grHOSTDATA[0]);
  2853. *(DWORD *)&pixels[4] = LLDR_SZ(grHOSTDATA[0]);
  2854. *(DWORD *)&pixels[8] = LLDR_SZ(grHOSTDATA[0]);
  2855. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2856. data |= 0x80;
  2857. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2858. data |= 0x40;
  2859. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2860. data |= 0x20;
  2861. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2862. data |= 0x10;
  2863. *(DWORD *)&pixels[0] = LLDR_SZ(grHOSTDATA[0]);
  2864. *(DWORD *)&pixels[4] = LLDR_SZ(grHOSTDATA[0]);
  2865. *(DWORD *)&pixels[8] = LLDR_SZ(grHOSTDATA[0]);
  2866. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2867. data |= 0x08;
  2868. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2869. data |= 0x04;
  2870. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2871. data |= 0x02;
  2872. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2873. data |= 0x01;
  2874. #else
  2875. *(DWORD *)&pixels[0] = pSrc[0];
  2876. *(DWORD *)&pixels[4] = pSrc[1];
  2877. *(DWORD *)&pixels[8] = pSrc[2];
  2878. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2879. data |= 0x80;
  2880. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2881. data |= 0x40;
  2882. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2883. data |= 0x20;
  2884. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2885. data |= 0x10;
  2886. *(DWORD *)&pixels[0] = pSrc[3];
  2887. *(DWORD *)&pixels[4] = pSrc[4];
  2888. *(DWORD *)&pixels[8] = pSrc[5];
  2889. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2890. data |= 0x08;
  2891. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2892. data |= 0x04;
  2893. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2894. data |= 0x02;
  2895. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2896. data |= 0x01;
  2897. pSrc += 6;
  2898. #endif
  2899. *pDest++ = data;
  2900. }
  2901. // If we have a rightMask specified, we get the pixels and store
  2902. // them in the destination.
  2903. if (rightMask != 0x00)
  2904. {
  2905. data = 0;
  2906. #if S2H_USE_ENGINE
  2907. *(DWORD *)&pixels[0] = LLDR_SZ(grHOSTDATA[0]);
  2908. *(DWORD *)&pixels[4] = LLDR_SZ(grHOSTDATA[0]);
  2909. *(DWORD *)&pixels[8] = LLDR_SZ(grHOSTDATA[0]);
  2910. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2911. data |= 0x80;
  2912. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2913. data |= 0x40;
  2914. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2915. data |= 0x20;
  2916. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2917. data |= 0x10;
  2918. *(DWORD *)&pixels[0] = LLDR_SZ(grHOSTDATA[0]);
  2919. *(DWORD *)&pixels[4] = LLDR_SZ(grHOSTDATA[0]);
  2920. *(DWORD *)&pixels[8] = LLDR_SZ(grHOSTDATA[0]);
  2921. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2922. data |= 0x08;
  2923. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2924. data |= 0x04;
  2925. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2926. data |= 0x02;
  2927. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2928. data |= 0x01;
  2929. #else
  2930. *(DWORD *)&pixels[0] = pSrc[0];
  2931. *(DWORD *)&pixels[4] = pSrc[1];
  2932. *(DWORD *)&pixels[8] = pSrc[2];
  2933. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2934. data |= 0x80;
  2935. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2936. data |= 0x40;
  2937. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2938. data |= 0x20;
  2939. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2940. data |= 0x10;
  2941. *(DWORD *)&pixels[0] = pSrc[3];
  2942. *(DWORD *)&pixels[4] = pSrc[4];
  2943. *(DWORD *)&pixels[8] = pSrc[5];
  2944. if ( (*(DWORD *)&pixels[0] & 0x00FFFFFF) == fgColor )
  2945. data |= 0x08;
  2946. if ( (*(DWORD *)&pixels[3] & 0x00FFFFFF) == fgColor )
  2947. data |= 0x04;
  2948. if ( (*(DWORD *)&pixels[6] & 0x00FFFFFF) == fgColor )
  2949. data |= 0x02;
  2950. if ( (*(DWORD *)&pixels[9] & 0x00FFFFFF) == fgColor )
  2951. data |= 0x01;
  2952. #endif
  2953. *pDest = (*pDest & ~rightMask) | (data & rightMask);
  2954. }
  2955. // Next line.
  2956. #if !S2H_USE_ENGINE
  2957. pjScreen += ppdev->lDeltaScreen;
  2958. #endif
  2959. pBits += lDelta;
  2960. }
  2961. }
  2962. // We only support destination bitmaps with the same color depth and we
  2963. // do not support any color translation.
  2964. else if ( (psoTrg->iBitmapFormat != BMF_24BPP) ||
  2965. (pxlo && !(pxlo->flXlate & XO_TRIVIAL)) )
  2966. {
  2967. return(FALSE);
  2968. }
  2969. /*
  2970. If the GetPixel routine is being called, we get here with both cx and
  2971. cy set to 1 and the ROP to 0xCC (source copy). In this special case we
  2972. read the pixel directly from memory. Of course, we must be sure the
  2973. blit engine is finished working since it may still update the very
  2974. pixel we are going to read! We could use the hardware for this, but it
  2975. seems there is a HARDWARE BUG that doesn't seem like the 1-pixel
  2976. ScreenToHost very much.
  2977. */
  2978. #if S2H_USE_ENGINE
  2979. else if ( (sizl.cx == 1) && (sizl.cy == 1) && (ulDRAWBLTDEF == 0x000000CC) )
  2980. {
  2981. DWORD data;
  2982. // Wait for the hardware to become idle.
  2983. while (LLDR_SZ(grSTATUS) != 0) ;
  2984. // Get the pixel from screen.
  2985. pBits += prclTrg->left * 3;
  2986. data = *(DWORD *)
  2987. &ppdev->pjScreen[ptlSrc.x * 3 + ptlSrc.y * ppdev->lDeltaScreen];
  2988. *(WORD *)&pBits[0] = (WORD)data;
  2989. *(BYTE *)&pBits[2] = (BYTE)(data >> 16);
  2990. }
  2991. #endif
  2992. else
  2993. {
  2994. #if S2H_USE_ENGINE
  2995. // The hardware requires us to get QWORDS.
  2996. BOOL fExtra = ((sizl.cx * 3 + 3) >> 2) & 1;
  2997. #endif
  2998. pBits += prclTrg->left * 3;
  2999. #if S2H_USE_ENGINE
  3000. // Start the blit.
  3001. LL_OP1(ptlSrc.x, ptlSrc.y);
  3002. LL_BLTEXT(sizl.cx, sizl.cy);
  3003. #endif
  3004. while (sizl.cy--)
  3005. {
  3006. #if S2H_USE_ENGINE
  3007. DWORD *p = (DWORD *)pBits;
  3008. // First, we get pixels in chunks of 4 so the 32-bit HOSTDATA is
  3009. // happy and we are still in phase.
  3010. for (i = sizl.cx; i >= 4; i -= 4)
  3011. {
  3012. *p++ = LLDR_SZ(grHOSTDATA[0]);
  3013. *p++ = LLDR_SZ(grHOSTDATA[0]);
  3014. *p++ = LLDR_SZ(grHOSTDATA[0]);
  3015. }
  3016. // Then, we have to do the remaining pixel(s).
  3017. switch (i)
  3018. {
  3019. case 1:
  3020. i = LLDR_SZ(grHOSTDATA[0]);
  3021. ((WORD *)p)[0] = (WORD)i;
  3022. ((BYTE *)p)[2] = (BYTE)(i >> 16);
  3023. break;
  3024. case 2:
  3025. *p++ = LLDR_SZ(grHOSTDATA[0]);
  3026. *(WORD *)p = (WORD)LLDR_SZ(grHOSTDATA[0]);
  3027. break;
  3028. case 3:
  3029. *p++ = LLDR_SZ(grHOSTDATA[0]);
  3030. *p++ = LLDR_SZ(grHOSTDATA[0]);
  3031. *(BYTE *)p = (BYTE)LLDR_SZ(grHOSTDATA[0]);
  3032. break;
  3033. }
  3034. // Get the extra pixel required for QWORD alignment.
  3035. if (fExtra)
  3036. {
  3037. LLDR_SZ(grHOSTDATA[0]);
  3038. }
  3039. #else
  3040. // Copy all pixels from screen to memory.
  3041. memcpy(pBits, pjScreen, sizl.cx * 3);
  3042. // Next line.
  3043. pjScreen += ppdev->lDeltaScreen;
  3044. #endif
  3045. pBits += lDelta;
  3046. }
  3047. }
  3048. return(TRUE);
  3049. }
  3050. /*****************************************************************************\
  3051. * *
  3052. * 3 2 - B P P *
  3053. * *
  3054. \*****************************************************************************/
  3055. /*****************************************************************************\
  3056. * DoHost32ToDevice
  3057. *
  3058. * This routine performs a HostToScreen or HostToDevice blit. The host data
  3059. * can be either monochrome, 4-bpp, or 32-bpp. Color translation is only
  3060. * supported for monochrome and 4-bpp modes.
  3061. *
  3062. * On entry: psoTrg Pointer to target surface object.
  3063. * psoSrc Pointer to source surface object.
  3064. * pxlo Pointer to translation object.
  3065. * prclTrg Destination rectangle.
  3066. * pptlSrc Source offset.
  3067. * ulDRAWBLTDEF Value for grDRAWBLTDEF register. This value has
  3068. * the ROP and the brush flags.
  3069. \*****************************************************************************/
  3070. BOOL DoHost32ToDevice(
  3071. SURFOBJ *psoTrg,
  3072. SURFOBJ *psoSrc,
  3073. XLATEOBJ *pxlo,
  3074. RECTL *prclTrg,
  3075. POINTL *pptlSrc,
  3076. ULONG ulDRAWBLTDEF
  3077. )
  3078. {
  3079. POINTL ptlDest, ptlSrc;
  3080. SIZEL sizl;
  3081. PPDEV ppdev;
  3082. PBYTE pBits;
  3083. LONG lDelta, i, n, lLeadIn, lExtra, i1;
  3084. ULONG *pulXlate;
  3085. FLONG flXlate;
  3086. // Calculate te source offset.
  3087. ptlSrc.x = pptlSrc->x;
  3088. ptlSrc.y = pptlSrc->y;
  3089. // Determine the destination type and calculate the destination offset.
  3090. if (psoTrg->iType == STYPE_DEVBITMAP)
  3091. {
  3092. PDSURF pdsurf = (PDSURF) psoTrg->dhsurf;
  3093. ptlDest.x = prclTrg->left + pdsurf->ptl.x;
  3094. ptlDest.y = prclTrg->top + pdsurf->ptl.y;
  3095. ppdev = pdsurf->ppdev;
  3096. }
  3097. else
  3098. {
  3099. ptlDest.x = prclTrg->left;
  3100. ptlDest.y = prclTrg->top;
  3101. ppdev = (PPDEV) psoTrg->dhpdev;
  3102. }
  3103. // Calculate the size of the blit.
  3104. sizl.cx = prclTrg->right - prclTrg->left;
  3105. sizl.cy = prclTrg->bottom - prclTrg->top;
  3106. // Get the source variables and ofFset into source bits.
  3107. lDelta = psoSrc->lDelta;
  3108. pBits = (PBYTE)psoSrc->pvScan0 + (ptlSrc.y * lDelta);
  3109. /* -----------------------------------------------------------------------
  3110. Test for monochrome source.
  3111. */
  3112. if (psoSrc->iBitmapFormat == BMF_1BPP)
  3113. {
  3114. ULONG bgColor, fgColor;
  3115. #if SWAT7
  3116. SIZEL sizlTotal;
  3117. #endif
  3118. // Get the pointer to the translation table.
  3119. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  3120. if (flXlate & XO_TRIVIAL)
  3121. {
  3122. pulXlate = NULL;
  3123. }
  3124. else if (flXlate & XO_TABLE)
  3125. {
  3126. pulXlate = pxlo->pulXlate;
  3127. }
  3128. else if (pxlo->iSrcType == PAL_INDEXED)
  3129. {
  3130. pulXlate = XLATEOBJ_piVector(pxlo);
  3131. }
  3132. else
  3133. {
  3134. // Some kind of translation we don't handle
  3135. return FALSE;
  3136. }
  3137. // Set background and foreground colors.
  3138. if (pulXlate == NULL)
  3139. {
  3140. bgColor = 0x00000000;
  3141. fgColor = 0xFFFFFFFF;
  3142. }
  3143. else
  3144. {
  3145. bgColor = pulXlate[0];
  3146. fgColor = pulXlate[1];
  3147. }
  3148. //
  3149. // Special case: when we are expanding monochrome sources and we
  3150. // already have a colored brush, we must make sure the monochrome color
  3151. // translation can be achived by setting the saturation bit (expanding
  3152. // 0's to 0 and 1's to 1). If the monochrome source also requires color
  3153. // translation, we simply punt this blit back to GDI.
  3154. //
  3155. if (ulDRAWBLTDEF & 0x00040000)
  3156. {
  3157. if ( (bgColor == 0x00000000) &&
  3158. ((fgColor & 0x00FFFFFF) == 0x00FFFFFF) )
  3159. {
  3160. // Enable saturation for source (OP1).
  3161. ulDRAWBLTDEF |= 0x00008000;
  3162. }
  3163. #if SOLID_CACHE
  3164. else if ( ((ulDRAWBLTDEF & 0x000F0000) == 0x00070000) &&
  3165. ppdev->Bcache )
  3166. {
  3167. CacheSolid(ppdev);
  3168. ulDRAWBLTDEF ^= (0x00070000 ^ 0x00090000);
  3169. REQUIRE(4);
  3170. LL_BGCOLOR(bgColor, 2);
  3171. LL_FGCOLOR(fgColor, 2);
  3172. }
  3173. #endif
  3174. else
  3175. {
  3176. // Punt this call to the GDI.
  3177. return(FALSE);
  3178. }
  3179. }
  3180. else
  3181. {
  3182. REQUIRE(4);
  3183. LL_BGCOLOR(bgColor, 2);
  3184. LL_FGCOLOR(fgColor, 2);
  3185. }
  3186. REQUIRE(9);
  3187. #if SWAT7
  3188. // Setup the Laguna registers for the blit. We also set the bit swizzle
  3189. // bit in the grCONTROL register.
  3190. ppdev->grCONTROL |= SWIZ_CNTL;
  3191. LL16(grCONTROL, ppdev->grCONTROL);
  3192. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10600000, 2);
  3193. sizlTotal = sizl;
  3194. while (sizlTotal.cx)
  3195. {
  3196. sizl.cx = min(sizlTotal.cx, 864);
  3197. sizl.cy = sizlTotal.cy;
  3198. #endif
  3199. // Calculate the source parameters. We are going to DWORD adjust the
  3200. // source, so we must setup the source phase.
  3201. lLeadIn = ptlSrc.x & 31;
  3202. pBits += (ptlSrc.x >> 3) & ~3;
  3203. n = (sizl.cx + lLeadIn + 31) >> 5;
  3204. #if !SWAT7
  3205. //
  3206. // Chip bug. Laguna locks with more than 14 dwords HOSTDATA
  3207. //
  3208. if (n > 28) // 14 qwords = 28 dwords
  3209. {
  3210. return FALSE;
  3211. }
  3212. // Setup the Laguna registers for the blit. We also set the bit swizzle
  3213. // bit in the grCONTROL register.
  3214. ppdev->grCONTROL |= SWIZ_CNTL;
  3215. LL16(grCONTROL, ppdev->grCONTROL);
  3216. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10600000, 2);
  3217. #endif
  3218. // Start the blit.
  3219. // added REQUIRE above
  3220. // REQUIRE(7);
  3221. LL_OP1_MONO(lLeadIn, 0);
  3222. LL_OP0(ptlDest.x, ptlDest.y);
  3223. LL_BLTEXT(sizl.cx, sizl.cy);
  3224. // Copy all the bits to the screen, 32-bits at a time. We don't have to
  3225. // worry about crossing any boundary since NT is always DWORD aligned.
  3226. while (sizl.cy--)
  3227. {
  3228. WRITE_STRING(pBits, n);
  3229. pBits += lDelta;
  3230. }
  3231. #if SWAT7
  3232. sizlTotal.cx -= sizl.cx;
  3233. ptlSrc.x += sizl.cx;
  3234. ptlDest.x += sizl.cx;
  3235. // Reload pBits.
  3236. pBits = (PBYTE) psoSrc->pvScan0 + (ptlSrc.y * lDelta);
  3237. }
  3238. #endif
  3239. // Disable the swizzle bit in the grCONTROL register.
  3240. ppdev->grCONTROL = ppdev->grCONTROL & ~SWIZ_CNTL;
  3241. LL16(grCONTROL, ppdev->grCONTROL);
  3242. }
  3243. /* -----------------------------------------------------------------------
  3244. Test for 4-bpp source.
  3245. */
  3246. else if (psoSrc->iBitmapFormat == BMF_4BPP)
  3247. {
  3248. // Get the pointer to the translation table.
  3249. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  3250. if (flXlate & XO_TRIVIAL)
  3251. {
  3252. pulXlate = NULL;
  3253. }
  3254. else if (flXlate & XO_TABLE)
  3255. {
  3256. pulXlate = pxlo->pulXlate;
  3257. }
  3258. else if (pxlo->iSrcType == PAL_INDEXED)
  3259. {
  3260. pulXlate = XLATEOBJ_piVector(pxlo);
  3261. }
  3262. else
  3263. {
  3264. // Some kind of translation we don't handle
  3265. return FALSE;
  3266. }
  3267. // Calculate the source parameters.
  3268. pBits += ptlSrc.x >> 1;
  3269. #if !DRIVER_5465
  3270. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  3271. // bug.
  3272. if (ppdev->dwLgDevID == CL_GD5462)
  3273. {
  3274. if (MAKE_HD_INDEX(sizl.cx * 4, 0, ptlDest.x * 4) == 3788)
  3275. {
  3276. // We have a problem with the HOSTDATA TABLE.
  3277. // Punt till we can figure it out.
  3278. return FALSE;
  3279. }
  3280. lExtra = ExtraDwordTable[MAKE_HD_INDEX(sizl.cx * 4, 0, ptlDest.x * 4)];
  3281. }
  3282. else
  3283. lExtra = 0;
  3284. #endif
  3285. // Start the blit.
  3286. REQUIRE(9);
  3287. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  3288. LL_OP1_MONO(0, 0);
  3289. LL_OP0(ptlDest.x, ptlDest.y);
  3290. LL_BLTEXT(sizl.cx, sizl.cy);
  3291. // If there is no translation table, use the default translation table.
  3292. if (pulXlate == NULL)
  3293. {
  3294. pulXlate = ulXlate;
  3295. }
  3296. // Now we are ready to copy all the pixels to the hardware.
  3297. while (sizl.cy--)
  3298. {
  3299. BYTE *p = pBits;
  3300. // First, we must align the source to a BYTE boundary.
  3301. if (ptlSrc.x & 1)
  3302. {
  3303. // We convert 2 pixels at a time to create two 32-bit values
  3304. // to write to the hardware.
  3305. for (i = sizl.cx; i >= 2; i -= 2)
  3306. {
  3307. REQUIRE(2);
  3308. LL32(grHOSTDATA[0], pulXlate[p[0] & 0x0F]);
  3309. LL32(grHOSTDATA[1], pulXlate[p[1] >> 4]);
  3310. p++;
  3311. }
  3312. // Now, write any remaining pixel.
  3313. if (i)
  3314. {
  3315. REQUIRE(1);
  3316. LL32(grHOSTDATA[0], pulXlate[*p & 0x0F]);
  3317. }
  3318. }
  3319. else
  3320. {
  3321. // We convert 2 pixels at a time to create two 32-bit values
  3322. // to write to the hardware.
  3323. for (i = sizl.cx; i >= 2; i -= 2)
  3324. {
  3325. REQUIRE(2);
  3326. LL32(grHOSTDATA[0], pulXlate[p[0] >> 4]);
  3327. LL32(grHOSTDATA[1], pulXlate[p[0] & 0x0F]);
  3328. p++;
  3329. }
  3330. // Now, write any remaining pixel.
  3331. if (i)
  3332. {
  3333. REQUIRE(1);
  3334. LL32(grHOSTDATA[0], pulXlate[*p >> 4]);
  3335. }
  3336. }
  3337. #if !DRIVER_5465
  3338. // Now, write the extra DWORDS.
  3339. REQUIRE(lExtra);
  3340. for (i = 0; i < lExtra; i++)
  3341. {
  3342. LL32(grHOSTDATA[0], 0);
  3343. }
  3344. #endif
  3345. // Next line.
  3346. pBits += lDelta;
  3347. }
  3348. }
  3349. /* -----------------------------------------------------------------------
  3350. Test for 8-bpp source.
  3351. */
  3352. else if (psoSrc->iBitmapFormat == BMF_8BPP)
  3353. {
  3354. //
  3355. // Attempt to load the translation table into the chip.
  3356. // After this call:
  3357. // pulXlate == NULL if there is no color translation is required.
  3358. // pulXlate == translation table if color translation is required.
  3359. // UseHWxlate == FALSE if the hardware will do the xlate for us.
  3360. // UseHWxlate == TRUE if we must do the translation in software.
  3361. //
  3362. #if COLOR_TRANSLATE
  3363. ULONG UseHWxlate = bCacheXlateTable(ppdev, &pulXlate, psoTrg, psoSrc,
  3364. pxlo, (BYTE)(ulDRAWBLTDEF&0xCC));
  3365. #else
  3366. if ( (pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL) )
  3367. {
  3368. pulXlate = NULL;
  3369. }
  3370. else if (pxlo->flXlate & XO_TABLE)
  3371. {
  3372. pulXlate = pxlo->pulXlate;
  3373. }
  3374. else if (pxlo->iSrcType == PAL_INDEXED)
  3375. {
  3376. pulXlate = XLATEOBJ_piVector(pxlo);
  3377. }
  3378. else
  3379. {
  3380. // Some kind of translation we don't handle
  3381. return FALSE;
  3382. }
  3383. #endif
  3384. // A translation table is required.
  3385. // "Well, DUH!" you might say, but I've seen it missing before...
  3386. if (!pulXlate)
  3387. {
  3388. DISPDBG((0, "\n\nHost32ToDevice: !!! WARNING !!! 8BPP source "
  3389. "bitmap does not have a translation table. Punting!\n\n"));
  3390. return FALSE;
  3391. }
  3392. #if COLOR_TRANSLATE
  3393. //
  3394. // NVH: 5465 Color XLATE bug!!!
  3395. // Color translation is broken on the 5465 in 16, 24 and 32 bpp.
  3396. //
  3397. if (UseHWxlate)
  3398. {
  3399. DWORD phase = ( ((DWORD)(pBits + ptlSrc.x)) & 3);
  3400. if (XLATE_IS_BROKEN(sizl.cx, 4, phase))
  3401. UseHWxlate = FALSE; // force SW translation.
  3402. }
  3403. if (UseHWxlate)
  3404. {
  3405. // Use Hardware color translation.
  3406. DISPDBG((COPYBITS_DBG_LEVEL, "Host32ToDevice: "
  3407. "Attempting HW color translation on 8bpp Host to 32bpp Screen.\n"));
  3408. // Calculate the source parameters. We are going to DWORD adjust the
  3409. // source, so we also set the source phase.
  3410. pBits += ptlSrc.x; // Start of source data on the host.
  3411. lLeadIn = (DWORD)pBits & 3; // Source phase.
  3412. pBits -= lLeadIn; // Backup to DWORD boundry.
  3413. n = (sizl.cx + lLeadIn + 3) >> 2;// Number of HOSTDATA per scanline.
  3414. // Start the blit.
  3415. REQUIRE(9);
  3416. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  3417. LL_OP1_MONO(lLeadIn, 0);
  3418. LL_OP0(ptlDest.x, ptlDest.y);
  3419. LL_BLTEXT_XLATE(8, sizl.cx, sizl.cy); // HW xlate.
  3420. while (sizl.cy--)
  3421. {
  3422. // Copy all data in 32-bit. We don't have to worry about
  3423. // crossing any boundaries, since within NT everything is DWORD
  3424. // aligned.
  3425. WRITE_STRING(pBits, n);
  3426. pBits += lDelta;
  3427. }
  3428. }
  3429. else
  3430. #endif
  3431. {
  3432. //
  3433. // Use SW color translation.
  3434. //
  3435. DISPDBG((COPYBITS_DBG_LEVEL, "Host32ToDevice: "
  3436. "Attempting SW color translation on 8bpp Host to 32bpp Screen.\n"));
  3437. // To do 8bpp host to 32bpp screen we must have a translation table.
  3438. ASSERTMSG(pulXlate,
  3439. "Host32ToDevice: No translation table for color translation.\n");
  3440. // Calculate the source parameters.
  3441. pBits += ptlSrc.x; // Start of source data on the host.
  3442. #if !DRIVER_5465
  3443. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  3444. // bug.
  3445. if (ppdev->dwLgDevID == CL_GD5462)
  3446. {
  3447. if (MAKE_HD_INDEX(sizl.cx * 4, 0, ptlDest.x * 4) == 3788)
  3448. {
  3449. // We have a problem with the HOSTDATA TABLE.
  3450. // Punt till we can figure it out.
  3451. return FALSE;
  3452. }
  3453. lExtra = ExtraDwordTable[MAKE_HD_INDEX(sizl.cx * 4, 0, ptlDest.x * 4)];
  3454. }
  3455. else
  3456. {
  3457. lExtra = 0;
  3458. }
  3459. #endif
  3460. // Setup the Laguna registers.
  3461. REQUIRE(9);
  3462. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  3463. // Start the blit.
  3464. LL_OP1_MONO(0, 0);
  3465. LL_OP0(ptlDest.x, ptlDest.y);
  3466. LL_BLTEXT(sizl.cx, sizl.cy);
  3467. while (sizl.cy--)
  3468. {
  3469. BYTE *p = pBits;
  3470. // Copy the pixels.
  3471. for (i = sizl.cx; i > 0; i--)
  3472. {
  3473. REQUIRE(1);
  3474. LL32(grHOSTDATA[0], pulXlate[*p]);
  3475. p++;
  3476. }
  3477. #if !DRIVER_5465
  3478. // Now, write the extra DWORDS.
  3479. REQUIRE(lExtra);
  3480. for (i = 0; i < lExtra; i++)
  3481. {
  3482. LL32(grHOSTDATA[0], 0);
  3483. }
  3484. #endif
  3485. // Next line.
  3486. pBits += lDelta;
  3487. }
  3488. }
  3489. }
  3490. /* -----------------------------------------------------------------------
  3491. Source is in same color depth as screen.
  3492. */
  3493. else
  3494. {
  3495. // Get the pointer to the translation table.
  3496. flXlate = pxlo ? pxlo->flXlate : XO_TRIVIAL;
  3497. if (flXlate & XO_TRIVIAL)
  3498. {
  3499. pulXlate = NULL;
  3500. }
  3501. else if (flXlate & XO_TABLE)
  3502. {
  3503. pulXlate = pxlo->pulXlate;
  3504. }
  3505. else if (pxlo->iSrcType == PAL_INDEXED)
  3506. {
  3507. pulXlate = XLATEOBJ_piVector(pxlo);
  3508. }
  3509. else
  3510. {
  3511. // Some kind of translation we don't handle
  3512. return FALSE;
  3513. }
  3514. // If we have a translation table, punt it.
  3515. if ( pulXlate || (flXlate & 0x10) )
  3516. {
  3517. return(FALSE);
  3518. }
  3519. // Calculate the source parameters.
  3520. pBits += ptlSrc.x * 4;
  3521. #if !DRIVER_5465
  3522. // Get the number of extra DWORDS per line for the HOSTDATA hardware
  3523. // bug.
  3524. if (ppdev->dwLgDevID == CL_GD5462)
  3525. {
  3526. if (MAKE_HD_INDEX(sizl.cx * 4, 0, ptlDest.x * 4) == 3788)
  3527. {
  3528. // We have a problem with the HOSTDATA TABLE.
  3529. // Punt till we can figure it out.
  3530. return FALSE;
  3531. }
  3532. lExtra = ExtraDwordTable[MAKE_HD_INDEX(sizl.cx * 4, 0, ptlDest.x * 4)];
  3533. }
  3534. else
  3535. lExtra = 0;
  3536. #endif
  3537. // Setup the Laguna registers.
  3538. REQUIRE(9);
  3539. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x10200000, 0);
  3540. // Start the blit.
  3541. LL_OP1_MONO(0, 0);
  3542. LL_OP0(ptlDest.x, ptlDest.y);
  3543. LL_BLTEXT(sizl.cx, sizl.cy);
  3544. while (sizl.cy--)
  3545. {
  3546. WRITE_STRING(pBits, sizl.cx);
  3547. #if !DRIVER_5465
  3548. // Now, write the extra DWORDS.
  3549. REQUIRE(lExtra);
  3550. for (i = 0; i < lExtra; i++)
  3551. {
  3552. LL32(grHOSTDATA[0], 0);
  3553. }
  3554. #endif
  3555. // Next line.
  3556. pBits += lDelta;
  3557. }
  3558. }
  3559. return(TRUE);
  3560. }
  3561. /*****************************************************************************\
  3562. * DoDeviceToHost32
  3563. *
  3564. * This routine performs a DeviceToHost for either monochrome or 32-bpp
  3565. * destinations.
  3566. *
  3567. * On entry: psoTrg Pointer to target surface object.
  3568. * psoSrc Pointer to source surface object.
  3569. * pxlo Pointer to translation object.
  3570. * prclTrg Destination rectangle.
  3571. * pptlSrc Source offset.
  3572. * ulDRAWBLTDEF Value for grDRAWBLTDEF register. This value has
  3573. * the ROP and the brush flags.
  3574. \*****************************************************************************/
  3575. BOOL DoDeviceToHost32(
  3576. SURFOBJ *psoTrg,
  3577. SURFOBJ *psoSrc,
  3578. XLATEOBJ *pxlo,
  3579. RECTL *prclTrg,
  3580. POINTL *pptlSrc,
  3581. ULONG ulDRAWBLTDEF
  3582. )
  3583. {
  3584. POINTL ptlSrc;
  3585. PPDEV ppdev;
  3586. SIZEL sizl;
  3587. PBYTE pBits;
  3588. #if !S2H_USE_ENGINE
  3589. PBYTE pjScreen;
  3590. #endif
  3591. LONG lDelta;
  3592. ULONG i, n;
  3593. // Determine the source type and calculate the offset.
  3594. if (psoSrc->iType == STYPE_DEVBITMAP)
  3595. {
  3596. PDSURF pdsurf = (PDSURF)psoSrc->dhsurf;
  3597. ppdev = pdsurf->ppdev;
  3598. ptlSrc.x = pptlSrc->x + pdsurf->ptl.x;
  3599. ptlSrc.y = pptlSrc->y + pdsurf->ptl.y;
  3600. }
  3601. else
  3602. {
  3603. ppdev = (PPDEV)psoSrc->dhpdev;
  3604. ptlSrc.x = pptlSrc->x;
  3605. ptlSrc.y = pptlSrc->y;
  3606. }
  3607. // Calculate the size of the blit.
  3608. sizl.cx = prclTrg->right - prclTrg->left;
  3609. sizl.cy = prclTrg->bottom - prclTrg->top;
  3610. // Calculate the destination variables.
  3611. lDelta = psoTrg->lDelta;
  3612. pBits = (PBYTE)psoTrg->pvScan0 + (prclTrg->top * lDelta);
  3613. #if S2H_USE_ENGINE
  3614. // Setup the Laguna registers.
  3615. REQUIRE(9);
  3616. LL_DRAWBLTDEF(ulDRAWBLTDEF | 0x20100000, 0);
  3617. LL_OP0(0, 0);
  3618. #else
  3619. // Calculate the screen address.
  3620. pjScreen = ppdev->pjScreen + ptlSrc.x * 4 + ptlSrc.y * ppdev->lDeltaScreen;
  3621. // Wait for the hardware to become idle.
  3622. while (LLDR_SZ(grSTATUS) != 0) ;
  3623. #endif
  3624. // Test for a monochrome destination.
  3625. if (psoTrg->iBitmapFormat == BMF_1BPP)
  3626. {
  3627. BYTE data, leftMask, rightMask;
  3628. ULONG fgColor;
  3629. DWORD *pulXlate;
  3630. LONG leftCount, rightCount, leftSkip;
  3631. // Calculate the monochrome masks.
  3632. pBits += prclTrg->left >> 3;
  3633. leftSkip = prclTrg->left & 7;
  3634. leftCount = (8 - leftSkip) & 7;
  3635. leftMask = 0xFF >> leftSkip;
  3636. rightCount = prclTrg->right & 7;
  3637. rightMask = 0xFF << (8 - rightCount);
  3638. // If we only have pixels in one byte, we combine rightMask with
  3639. // leftMask and set the routine to skip everything but the rightMask.
  3640. if (leftCount > sizl.cx)
  3641. {
  3642. rightMask &= leftMask;
  3643. leftMask = 0xFF;
  3644. n = 0;
  3645. }
  3646. else
  3647. {
  3648. n = (sizl.cx - leftCount) >> 3;
  3649. }
  3650. // Get the foreground color from the translation table.
  3651. pulXlate = XLATEOBJ_piVector(pxlo);
  3652. fgColor = pulXlate ? *pulXlate : 0;
  3653. #if S2H_USE_ENGINE
  3654. // Start the blit.
  3655. LL_OP1(ptlSrc.x - leftSkip, ptlSrc.y);
  3656. LL_BLTEXT(sizl.cx + leftSkip, sizl.cy);
  3657. #else
  3658. pjScreen -= leftSkip * 4;
  3659. #endif
  3660. while (sizl.cy--)
  3661. {
  3662. PBYTE pDest = pBits;
  3663. #if !S2H_USE_ENGINE
  3664. DWORD *pSrc = (DWORD *)pjScreen;
  3665. #endif
  3666. // If we have a left mask specified, we get the pixels and store
  3667. // them in the destination.
  3668. if (leftMask != 0xFF)
  3669. {
  3670. data = 0;
  3671. #if S2H_USE_ENGINE
  3672. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x80;
  3673. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x40;
  3674. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x20;
  3675. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x10;
  3676. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x08;
  3677. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x04;
  3678. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x02;
  3679. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x01;
  3680. #else
  3681. if (pSrc[0] == fgColor) data |= 0x80;
  3682. if (pSrc[1] == fgColor) data |= 0x40;
  3683. if (pSrc[2] == fgColor) data |= 0x20;
  3684. if (pSrc[3] == fgColor) data |= 0x10;
  3685. if (pSrc[4] == fgColor) data |= 0x08;
  3686. if (pSrc[5] == fgColor) data |= 0x04;
  3687. if (pSrc[6] == fgColor) data |= 0x02;
  3688. if (pSrc[7] == fgColor) data |= 0x01;
  3689. pSrc += 8;
  3690. #endif
  3691. *pDest++ = (*pDest & ~leftMask) | (data & leftMask);
  3692. }
  3693. // Translate all pixels that don't require masking.
  3694. for (i = 0; i < n; i++)
  3695. {
  3696. data = 0;
  3697. #if S2H_USE_ENGINE
  3698. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x80;
  3699. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x40;
  3700. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x20;
  3701. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x10;
  3702. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x08;
  3703. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x04;
  3704. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x02;
  3705. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x01;
  3706. #else
  3707. if (pSrc[0] == fgColor) data |= 0x80;
  3708. if (pSrc[1] == fgColor) data |= 0x40;
  3709. if (pSrc[2] == fgColor) data |= 0x20;
  3710. if (pSrc[3] == fgColor) data |= 0x10;
  3711. if (pSrc[4] == fgColor) data |= 0x08;
  3712. if (pSrc[5] == fgColor) data |= 0x04;
  3713. if (pSrc[6] == fgColor) data |= 0x02;
  3714. if (pSrc[7] == fgColor) data |= 0x01;
  3715. pSrc += 8;
  3716. #endif
  3717. *pDest++ = data;
  3718. }
  3719. // If we have a right mask specified, we get the pixels and store
  3720. // them in the destination.
  3721. if (rightMask != 0x00)
  3722. {
  3723. data = 0;
  3724. #if S2H_USE_ENGINE
  3725. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x80;
  3726. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x40;
  3727. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x20;
  3728. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x10;
  3729. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x08;
  3730. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x04;
  3731. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x02;
  3732. if (LLDR_SZ(grHOSTDATA[0]) == fgColor) data |= 0x01;
  3733. #else
  3734. if (pSrc[0] == fgColor) data |= 0x80;
  3735. if (pSrc[1] == fgColor) data |= 0x40;
  3736. if (pSrc[2] == fgColor) data |= 0x20;
  3737. if (pSrc[3] == fgColor) data |= 0x10;
  3738. if (pSrc[4] == fgColor) data |= 0x08;
  3739. if (pSrc[5] == fgColor) data |= 0x04;
  3740. if (pSrc[6] == fgColor) data |= 0x02;
  3741. if (pSrc[7] == fgColor) data |= 0x01;
  3742. #endif
  3743. *pDest = (*pDest & ~rightMask) | (data & rightMask);
  3744. }
  3745. // Next line.
  3746. #if !S2H_USE_ENGINE
  3747. pjScreen += ppdev->lDeltaScreen;
  3748. #endif
  3749. pBits += lDelta;
  3750. }
  3751. }
  3752. // We only support destination bitmaps with the same color depth and we
  3753. // do not support any color translation.
  3754. else if ( (psoTrg->iBitmapFormat != BMF_32BPP) ||
  3755. (pxlo && !(pxlo->flXlate & XO_TRIVIAL)) )
  3756. {
  3757. return(FALSE);
  3758. }
  3759. /*
  3760. If the GetPixel routine is being called, we get here with both cx and
  3761. cy set to 1 and the ROP to 0xCC (source copy). In this special case we
  3762. read the pixel directly from memory. Of course, we must be sure the
  3763. blit engine is finished working since it may still update the very
  3764. pixel we are going to read! We could use the hardware for this, but it
  3765. seems there is a HARDWARE BUG that doesn't seem to like the 1-pixel
  3766. ScreenToHost very much.
  3767. */
  3768. #if S2H_USE_ENGINE
  3769. else if ( (sizl.cx == 1) && (sizl.cy == 1) && (ulDRAWBLTDEF == 0x000000CC) )
  3770. {
  3771. // Wait for the hardware to become idle.
  3772. while (LLDR_SZ(grSTATUS) != 0) ;
  3773. // Get the pixel from screen.
  3774. *(DWORD *)pBits[prclTrg->left] = *(DWORD *)
  3775. &ppdev->pjScreen[ptlSrc.x * 4 + ptlSrc.y * ppdev->lDeltaScreen];
  3776. }
  3777. #endif
  3778. else
  3779. {
  3780. #if S2H_USE_ENGINE
  3781. // The hardware requires us to get QWORDS.
  3782. BOOL fExtra = sizl.cx & 1;
  3783. #endif
  3784. pBits += prclTrg->left * 4;
  3785. #if S2H_USE_ENGINE
  3786. // Start the bit.
  3787. LL_OP1(ptlSrc.x, ptlSrc.y);
  3788. LL_BLTEXT(sizl.cx, sizl.cy);
  3789. #endif
  3790. while (sizl.cy--)
  3791. {
  3792. #if S2H_USE_ENGINE
  3793. DWORD *p = (DWORD *)pBits;
  3794. // Copy all pixels from screen to memory.
  3795. for (i = sizl.cx; i >= 1; i -= 1)
  3796. {
  3797. *p++ = LLDR_SZ(grHOSTDATA[0]);
  3798. }
  3799. // Get the extra pixel required for QWORD alignment.
  3800. if (fExtra)
  3801. {
  3802. LLDR_SZ(grHOSTDATA[0]);
  3803. }
  3804. #else
  3805. // Copy all pixels from screen to memory.
  3806. memcpy(pBits, pjScreen, sizl.cx * 4);
  3807. // Next line.
  3808. pjScreen += ppdev->lDeltaScreen;
  3809. #endif
  3810. pBits += lDelta;
  3811. }
  3812. }
  3813. return(TRUE);
  3814. }