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.

430 lines
13 KiB

  1. /******************************Module*Header***********************************\
  2. *
  3. * Module Name: Xlate.c
  4. * Author: Noel VanHook
  5. * Purpose: Handles hardware color translation.
  6. *
  7. * Copyright (c) 1997 Cirrus Logic, Inc.
  8. *
  9. * $Log: X:/log/laguna/nt35/displays/cl546x/xlate.c $
  10. *
  11. * Rev 1.9 Mar 04 1998 15:51:04 frido
  12. * Added new shadow macros.
  13. *
  14. * Rev 1.8 Nov 04 1997 09:50:38 frido
  15. * Only include the code if COLOR_TRANSLATE switch is enabled.
  16. *
  17. * Rev 1.7 Nov 03 1997 09:34:22 frido
  18. * Added REQUIRE and WRITE_STRING macros.
  19. *
  20. * Rev 1.6 15 Oct 1997 14:40:40 noelv
  21. * Moved ODD[] from xlate.h to xlate.c
  22. *
  23. * Rev 1.5 15 Oct 1997 12:04:52 noelv
  24. *
  25. * Test ROP code (only SRCCPY is supported)
  26. * Add switch to disable frame buffer caching.
  27. *
  28. * Rev 1.4 02 Oct 1997 09:42:22 noelv
  29. * re-enabled color translation.
  30. *
  31. * Rev 1.3 23 Sep 1997 17:35:14 FRIDO
  32. *
  33. * I have disabled color translation for now until we know what is the real
  34. * cause.
  35. *
  36. * Rev 1.2 17 Apr 1997 14:38:14 noelv
  37. * Changed 16 bit writes to 32 bit writes in BLTDRAWDEF
  38. *
  39. * Rev 1.1 19 Feb 1997 13:07:18 noelv
  40. * Added translation table cache
  41. *
  42. * Rev 1.0 06 Feb 1997 10:35:48 noelv
  43. * Initial revision.
  44. */
  45. /*
  46. Color translation occures under two conditions:
  47. 1) The source bitmap has a different color depth than the destination.
  48. 2) The source bitmap had a different palette than the destination.
  49. Color translation is done with a translation table. A translation table
  50. is simply an array of DWORDS. Source "pixels" are used as indices into
  51. the translation table. Translation table entries are used as destination
  52. pixels.
  53. An example will clarify. Suppose we are doing a host to screen source
  54. copy operation. The host bitmap is a 4bpp bitmap. The current screen
  55. mode is 8 bpp. This operation will require color translation, so NT will
  56. supply a translation table. Since a 4bpp bitmap can have 16 different
  57. colors, the translation table will have 16 entries. Since the destination
  58. is an 8bpp bitmap, each entry will be an 8 bit color (1 byte). Since
  59. translation tables are always arrays of DWORDs, the 1 byte color will be
  60. followed by 3 bytes of padding.
  61. */
  62. #include "PreComp.h"
  63. #define XLATE_DBG_LEVEL 1
  64. #define CACHE_XLATE_TABLE 0
  65. //
  66. // Default 4-bpp translation table.
  67. //
  68. ULONG ulXlate[16] =
  69. {
  70. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  71. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  72. };
  73. #if COLOR_TRANSLATE // Only include the next code if color translation is on.
  74. //
  75. // Table for determining bad BLTs. See XLATE.H
  76. //
  77. char ODD[] = {0,1,1,1, 1,0,0,0, 0,1,1,1, 1,0,0,0};
  78. //
  79. // Chip bug in 5465-AA and AB
  80. // Bring the chip to a known state before blitting to SRAM2
  81. //
  82. #define SRAM2_5465_WORKAROUND() \
  83. { \
  84. WORD temp; \
  85. while(LLDR_SZ (grSTATUS)); /* Wait for idle. */ \
  86. temp = LLDR_SZ (grPERFORMANCE); /* get the performance register. */ \
  87. LL16(grPERFORMANCE, (temp|0x8000)); /* toggle RES_FIFO_FLUSH */ \
  88. LL16(grPERFORMANCE, temp ); /* restore the performance register. */\
  89. }
  90. // ============================================================================
  91. //
  92. // vInvalidateXlateCache(PPDEV)
  93. //
  94. // Invalidates color translation cache
  95. //
  96. // ============================================================================
  97. void vInvalidateXlateCache(PPDEV ppdev)
  98. {
  99. DISPDBG((XLATE_DBG_LEVEL, "vInvalidateXlateCache: Entry.\n"));
  100. //
  101. // Whatever translation table that may have been stored in the cache has
  102. // been lost. Mark the cache as empty.
  103. //
  104. ppdev->XlateCacheId = 0;
  105. DISPDBG((XLATE_DBG_LEVEL, "vInvalidateXlateCache: Exit.\n"));
  106. }
  107. // ============================================================================
  108. //
  109. // vInitHwXlate(PPDEV)
  110. //
  111. // Allocate and init scan line cache and xlate table cache.
  112. //
  113. // ============================================================================
  114. void vInitHwXlate(PPDEV ppdev)
  115. {
  116. DISPDBG((XLATE_DBG_LEVEL, "vInitHwXlate: Entry.\n"));
  117. //
  118. // Mark the cache as empty.
  119. //
  120. ppdev->XlateCacheId = 0;
  121. #if DRIVER_5465 // The 62 and 64 don't do HW xlate.
  122. #if CACHE_XLATE_TABLE
  123. //
  124. // Allocate a cache for color translation tables.
  125. //
  126. if (ppdev->XlateCache == NULL)
  127. {
  128. SIZEL sizl;
  129. sizl.cy = 1;
  130. sizl.cx = 1024/ppdev->iBytesPerPixel;
  131. if (ppdev->iBytesPerPixel == 3) ++sizl.cx;
  132. ppdev->XlateCache = AllocOffScnMem(ppdev,
  133. &sizl,
  134. PIXEL_AlIGN,
  135. NULL);
  136. }
  137. #endif
  138. #endif
  139. DISPDBG((XLATE_DBG_LEVEL, "vInitHwXlate: Exit.\n"));
  140. }
  141. // ============================================================================
  142. //
  143. // bCacheXlateTable()
  144. //
  145. // Caches a color translation table in SRAM.
  146. // If the table is sucessfully cached, the chip is set up for hardware xlate.
  147. //
  148. // Returns TRUE if:
  149. // + There is no color translation required,
  150. // + or the color translation can be handled by hardware.
  151. //
  152. // Returns FALSE if:
  153. // + Color translation is required,
  154. // + and the color translation must be done in software.
  155. //
  156. // If a color translation table exists, *ppulXlate will be set to point to it.
  157. // This is how we pass the translation table back to the caller.
  158. //
  159. // ============================================================================
  160. BOOLEAN bCacheXlateTable(struct _PDEV *ppdev,
  161. unsigned long **ppulXlate,
  162. SURFOBJ *psoTrg,
  163. SURFOBJ *psoSrc,
  164. XLATEOBJ *pxlo,
  165. BYTE rop)
  166. {
  167. unsigned long i, src_fmt, dst_fmt, stretch_ctrl;
  168. unsigned long *pulXlate;
  169. DISPDBG((XLATE_DBG_LEVEL, "bCacheXlateTable: Entry.\n"));
  170. //
  171. // Get the translation vector.
  172. //
  173. if ( (pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL) )
  174. pulXlate = NULL;
  175. else if (pxlo->flXlate & XO_TABLE)
  176. pulXlate = pxlo->pulXlate;
  177. else if (pxlo->iSrcType == PAL_INDEXED)
  178. pulXlate = XLATEOBJ_piVector(pxlo);
  179. else
  180. {
  181. // Some kind of translation we don't handle
  182. return FALSE;
  183. }
  184. //
  185. // Pass the translation table back to the caller.
  186. //
  187. *ppulXlate = pulXlate;
  188. //
  189. // If there is no color translation necessary, then we're done.
  190. //
  191. if (pulXlate == NULL)
  192. {
  193. DISPDBG((XLATE_DBG_LEVEL, "bCacheXlateTable: No color translation necessary.\n"));
  194. return TRUE;
  195. }
  196. //
  197. // The 5462 and 5464 don't do hardware color translation.
  198. //
  199. #if ! DRIVER_5465
  200. DISPDBG((XLATE_DBG_LEVEL,
  201. "bCacheXlateTable: Chip doesn't support hardware translation.\n"));
  202. return FALSE;
  203. #endif
  204. //
  205. // The 5465 only does hardware translation for rop code CC.
  206. //
  207. if (rop != 0xCC)
  208. {
  209. DISPDBG((XLATE_DBG_LEVEL,
  210. "bCacheXlateTable: Can't color translate ROP 0x%X.\n",
  211. rop));
  212. return FALSE;
  213. }
  214. //
  215. // Make sure we have an INDEXED palette
  216. //
  217. if (pxlo->iSrcType == PAL_BITFIELDS)
  218. {
  219. // I don't think we should get any of these.
  220. RIP("Panic!: bCacheXlateTable has PAL_BITFIELDS iSrcType.\n");
  221. return FALSE;
  222. }
  223. if (pxlo->iDstType == PAL_BITFIELDS)
  224. {
  225. // I don't think we should get any of these.
  226. RIP ("Panic!: bCacheXlateTable has PAL_BITFIELDS iDstType.\n");
  227. return FALSE;
  228. }
  229. //
  230. // What is the source format?
  231. //
  232. ASSERTMSG(psoSrc,"bCacheXlateTable has no source object.\n");
  233. switch (psoSrc->iBitmapFormat)
  234. {
  235. case BMF_4BPP: src_fmt = 5; break;
  236. case BMF_8BPP: src_fmt = 6; break;
  237. default:
  238. // I don't think we should get any of these.
  239. RIP("Panic! bCacheXlateTable: Bad source format.\n");
  240. return FALSE;
  241. }
  242. //
  243. // What is the destination format?
  244. //
  245. ASSERTMSG(psoTrg,"bCacheXlateTable has no destination object.\n");
  246. switch (psoTrg->iBitmapFormat)
  247. {
  248. case BMF_8BPP: dst_fmt = 0; break;
  249. case BMF_16BPP: dst_fmt = 2; break;
  250. case BMF_24BPP: dst_fmt = 3; break;
  251. case BMF_32BPP: dst_fmt = 4; break;
  252. default:
  253. // I don't think we should get any of these.
  254. RIP("Panic! bCacheXlateTable: Bad destination format.\n");
  255. return FALSE;
  256. }
  257. #if CACHE_XLATE_TABLE
  258. //
  259. // Have we cached this table already?
  260. //
  261. if (ppdev->XlateCacheId == pxlo->iUniq)
  262. {
  263. ULONG num_dwords = ( (pxlo->cEntries == 16) ? 64 : 256);
  264. DISPDBG((XLATE_DBG_LEVEL,
  265. "bCacheXlateTable: Table is already cached. ID=%d.\n", pxlo->iUniq));
  266. // Yep. Refresh SRAM2 in case it was destroyed.
  267. // Blt from frame buffer cache into SRAM2
  268. ASSERTMSG( (ppdev->XlateCache != NULL),
  269. "bCacheXlateTable: Xlate cache pointer is NULL.\n");
  270. // Blt the table from the frame buffer cache to SRAM2
  271. SRAM2_5465_WORKAROUND();
  272. REQUIRE(9);
  273. LL_DRAWBLTDEF(0x601000CC, 2); // SRC COPY
  274. LL_OP0(0,0); // Dest location
  275. LL_OP1(ppdev->XlateCache->x,ppdev->XlateCache->y); // Src location
  276. LL_MBLTEXT( num_dwords, 1);
  277. }
  278. //
  279. // If not, can we cache it?
  280. //
  281. else if (ppdev->XlateCache != NULL)
  282. {
  283. DISPDBG((XLATE_DBG_LEVEL,
  284. "bCacheXlateTable: Caching table. ID = %d.\n", pxlo->iUniq));
  285. // Store the translation table in the offscreen cache,
  286. REQUIRE(9);
  287. LL_DRAWBLTDEF(0x102000CC, 2); // SRC COPY
  288. LL_OP0(ppdev->XlateCache->x,ppdev->XlateCache->y); // Dest
  289. LL_OP1(0,0); // Source Phase.
  290. LL_MBLTEXT( (pxlo->cEntries*4), 1); // 4 bytes per table entry
  291. WRITE_STRING(pulXlate, pxlo->cEntries);
  292. // Make sure the table is the expected size.
  293. if ((pxlo->cEntries != 16) && (pxlo->cEntries != 256))
  294. {
  295. // Since we only do 4 and 8 bpp source, this shouldn't happen.
  296. RIP("Panic! bCacheXlateTable: Wrong number of entries in the table.\n");
  297. return FALSE;
  298. }
  299. // Blt the table from the frame buffer cache to SRAM2
  300. SRAM2_5465_WORKAROUND();
  301. REQUIRE(9);
  302. LL_DRAWBLTDEF(0x601000CC, 2); // SRC COPY
  303. LL_OP0(0,0); // Dest location
  304. LL_OP1(ppdev->XlateCache->x,ppdev->XlateCache->y); // Src location
  305. LL_MBLTEXT( (pxlo->cEntries*4), 1); // 4 bytes per table entry
  306. // Store the ID.
  307. ppdev->XlateCacheId = pxlo->iUniq;
  308. }
  309. //
  310. // Nope. Skip the frame buffer cache.
  311. //
  312. else
  313. #endif
  314. {
  315. DISPDBG((XLATE_DBG_LEVEL, "bCacheXlateTable: Bypassing cache.\n"));
  316. //
  317. // There is no xlate table cache in the frame buffer.
  318. // Load the table directly from the host to the SRAM.
  319. //
  320. // Make sure the table is the expected size.
  321. ASSERTMSG( ((pxlo->cEntries==16) || (pxlo->cEntries == 256)),
  322. "XLATE.C: XLATE table has wrong number of entries.\n");
  323. //if ((pxlo->cEntries != 16) && (pxlo->cEntries != 256))
  324. //{
  325. // // Since we only do 4 and 8 bpp source, this shouldn't happen.
  326. // RIP("Panic! bCacheXlateTable: Wrong number of entries in the table.\n");
  327. // return FALSE;
  328. //}
  329. // BLT the translation table into SRAM2 on the chip.
  330. SRAM2_5465_WORKAROUND();
  331. REQUIRE(9);
  332. LL32_DRAWBLTDEF(0x602000CC, 2); // SRC COPY
  333. LL_OP0(0,0); // SRAM location
  334. LL_OP1(0,0); // Source Phase.
  335. LL_MBLTEXT( (pxlo->cEntries*4), 1); // 4 bytes per table entry
  336. // Now supply the table.
  337. WRITE_STRING(pulXlate, pxlo->cEntries);
  338. }
  339. //
  340. // Cache successful.
  341. // Set up the chip to use hardware xlate.
  342. //
  343. stretch_ctrl = 0 // Use NT style table.
  344. | (src_fmt << 12) // source pixel format
  345. | (dst_fmt << 8); // destination pixel format.
  346. REQUIRE(2);
  347. LL16(grSTRETCH_CNTL, stretch_ctrl);
  348. LL16(grCHROMA_CNTL, 0); // disable chroma compare.
  349. DISPDBG((XLATE_DBG_LEVEL, "bCacheXlateTable: Exit - success.\n"));
  350. return TRUE;
  351. }
  352. #endif //!COLOR_TRANSLATE