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.

1368 lines
38 KiB

  1. /******************************Module*Header*******************************\
  2. *
  3. * Module Name: screen.c
  4. *
  5. * Initializes the GDIINFO and DEVINFO structures for DrvEnablePDEV.
  6. *
  7. * Copyright (c) 1992 Microsoft Corporation
  8. * Copyright (c) 1995 Cirrus Logic, Inc.
  9. *
  10. * $Log: X:/log/laguna/nt35/displays/cl546x/SCREEN.C $
  11. *
  12. * Rev 1.68 Mar 04 1998 15:33:44 frido
  13. * Added new shadow macros.
  14. *
  15. * Rev 1.67 Mar 04 1998 14:45:02 frido
  16. * Added initialization of shadowFGCOLOR register.
  17. *
  18. * Rev 1.66 Feb 27 1998 17:00:46 frido
  19. * Added zeroing of shadowQFREE register.
  20. *
  21. * Rev 1.65 Feb 03 1998 10:43:32 frido
  22. * There was a (not yet reported) bug in the shadow registers. When the
  23. * mode was reset after a DOS box the shadow registers need to be initialized.
  24. *
  25. * Rev 1.64 Dec 10 1997 13:32:20 frido
  26. * Merged from 1.62 branch.
  27. *
  28. * Rev 1.63.1.0 Nov 14 1997 13:48:02 frido
  29. * PDR#10750: Moved the allocation of the font cache down. It caused
  30. * fragmentation of the off-screen memory heap in certain modes.
  31. *
  32. * Rev 1.63 Nov 04 1997 09:50:02 frido
  33. * Added COLOR_TRANSLATE switches around hardware color translation code.
  34. *
  35. * Rev 1.62 Nov 03 1997 11:20:40 frido
  36. * Added REQUIRE macros.
  37. *
  38. * Rev 1.61 12 Sep 1997 12:00:28 bennyn
  39. *
  40. * Added PDEV and DRIVERDATA structure signature initialization.
  41. *
  42. * Rev 1.60 12 Aug 1997 16:55:46 bennyn
  43. * Added DD scratch buffer allocation
  44. *
  45. * Rev 1.59 22 Jul 1997 12:32:52 bennyn
  46. *
  47. * Added dwLgVenID to PDEV
  48. *
  49. * Rev 1.58 02 Jul 1997 15:57:12 noelv
  50. * Added LgMatchDriverToChip() function. Moved driver/chip match from bin
  51. * from binitSurface to DrvEnablePdev()
  52. *
  53. * Rev 1.57 20 Jun 1997 13:38:16 bennyn
  54. *
  55. * Eliminated power manager initialization
  56. *
  57. * Rev 1.56 16 Jun 1997 16:17:58 noelv
  58. * Fixed conversion warning line 539
  59. *
  60. * Rev 1.55 23 May 1997 15:41:00 noelv
  61. *
  62. * Added chip revision id to pdev
  63. *
  64. * Rev 1.54 15 May 1997 15:57:54 noelv
  65. *
  66. * moved swat4 stuff to miniport
  67. *
  68. * Rev 1.53 29 Apr 1997 16:28:48 noelv
  69. *
  70. * Merged in new SWAT code.
  71. * SWAT:
  72. * SWAT: Rev 1.5 24 Apr 1997 11:28:00 frido
  73. * SWAT: NT140b09 merge.
  74. * SWAT:
  75. * SWAT: Rev 1.4 19 Apr 1997 16:40:26 frido
  76. * SWAT: Added 4-way interleave.
  77. * SWAT: Added Frame Buffer Bursting.
  78. * SWAT: Added SWAT.h include file.
  79. * SWAT:
  80. * SWAT: Rev 1.3 18 Apr 1997 00:15:26 frido
  81. * SWAT: NT140b07 merge.
  82. * SWAT:
  83. * SWAT: Rev 1.2 10 Apr 1997 14:09:00 frido
  84. * SWAT: Added hardware optimizations SWAT4.
  85. * SWAT:
  86. * SWAT: Rev 1.1 09 Apr 1997 17:32:02 frido
  87. * SWAT: Called vAssertModeText during first time initialization.
  88. *
  89. * Rev 1.52 23 Apr 1997 07:40:20 SueS
  90. * Moved VS_CONTROL_HACK to laguna.h. Send message to miniport to
  91. * enable MMIO access to PCI registers before use.
  92. *
  93. * Rev 1.51 22 Apr 1997 11:03:54 noelv
  94. * Changed chip detect to allow 5465 driver to load on 5465 and later chips.
  95. *
  96. * Rev 1.50 17 Apr 1997 14:40:24 noelv
  97. *
  98. * Added hack for VS_CONTROL reg.
  99. *
  100. * Rev 1.49 07 Apr 1997 10:25:10 SueS
  101. * Removed sw_test_flag and unreferenced #if USE_FLAG.
  102. *
  103. * Rev 1.48 19 Feb 1997 13:11:02 noelv
  104. *
  105. * Moved brush cache invalidation to it's own function
  106. *
  107. * Rev 1.47 28 Jan 1997 11:14:16 noelv
  108. *
  109. * Removed extra dword requirements from 5465 driver.
  110. *
  111. * Rev 1.46 28 Jan 1997 10:52:00 noelv
  112. *
  113. * Match driver type to chip type.
  114. *
  115. * Rev 1.45 23 Jan 1997 17:22:28 bennyn
  116. *
  117. * Added #ifdef DRIVER_5465
  118. *
  119. * Rev 1.44 16 Jan 1997 11:43:00 bennyn
  120. *
  121. * Added power manager init call
  122. *
  123. * Rev 1.43 10 Dec 1996 13:30:10 bennyn
  124. *
  125. * Added update the ulFreq in PDEV
  126. *
  127. * Rev 1.42 27 Nov 1996 11:32:40 noelv
  128. * Disabled Magic Bitmap. Yeah!!!
  129. *
  130. * Rev 1.41 18 Nov 1996 10:15:50 bennyn
  131. *
  132. * Added grFormat to PDEV
  133. *
  134. * Rev 1.40 13 Nov 1996 16:59:38 SueS
  135. * Changed WriteFile calls to WriteLogFile.
  136. *
  137. * Rev 1.39 13 Nov 1996 08:16:52 noelv
  138. *
  139. * Added hooks for bus mastered host to screen.
  140. *
  141. * Rev 1.38 31 Oct 1996 11:15:16 noelv
  142. *
  143. * Split common buffer into two buffers.
  144. *
  145. * Rev 1.37 24 Oct 1996 14:40:04 noelv
  146. *
  147. * Get the loations of the bus master common buffer from the miniport.
  148. *
  149. * Rev 1.36 04 Oct 1996 16:53:24 bennyn
  150. * Added DirectDraw YUV support
  151. *
  152. * Rev 1.35 18 Sep 1996 13:58:16 bennyn
  153. *
  154. * Save the DeviceID into PDEV
  155. *
  156. * Rev 1.34 21 Aug 1996 16:43:38 noelv
  157. *
  158. * Turned on the GoFast bit.
  159. *
  160. * Rev 1.33 20 Aug 1996 11:04:22 noelv
  161. * Bugfix release from Frido 8-19-96
  162. *
  163. * Rev 1.2 17 Aug 1996 13:54:18 frido
  164. * New release from Bellevue.
  165. *
  166. * Rev 1.1 15 Aug 1996 11:36:08 frido
  167. * Added precompiled header.
  168. *
  169. * Rev 1.0 14 Aug 1996 17:16:30 frido
  170. * Initial revision.
  171. *
  172. * Rev 1.31 25 Jul 1996 15:57:14 bennyn
  173. *
  174. * Modified for DirectDraw
  175. *
  176. * Rev 1.30 11 Jul 1996 15:54:42 bennyn
  177. *
  178. * Added DirectDraw support
  179. *
  180. * Rev 1.29 04 Jun 1996 16:00:00 noelv
  181. * Added debug information.
  182. *
  183. * Rev 1.28 17 May 1996 12:56:08 bennyn
  184. *
  185. * Fixed the problem NT40 allocate 400x90 twice
  186. *
  187. * Rev 1.27 16 May 1996 15:00:22 bennyn
  188. * Add PIXEL_ALIGN to allocoffscnmem()
  189. *
  190. * Rev 1.26 13 May 1996 16:01:26 bennyn
  191. * Fill ExtraDwordTable with 0 if 5464 is detected
  192. *
  193. * Rev 1.25 08 May 1996 17:02:58 noelv
  194. *
  195. * Preallocate device bitmap
  196. *
  197. * Rev 1.24 08 May 1996 10:31:08 BENNYN
  198. *
  199. * Added version display for NT4.0
  200. *
  201. * Rev 1.23 03 May 1996 15:18:58 noelv
  202. *
  203. * Added switch to turn font caching off in low memory situations.
  204. * Moved driver version to a header file.
  205. *
  206. * Rev 1.22 01 May 1996 11:01:28 bennyn
  207. *
  208. * Modified for NT4.0
  209. *
  210. * Rev 1.21 25 Apr 1996 22:41:58 noelv
  211. * clean-up
  212. *
  213. * Rev 1.20 16 Apr 1996 22:48:26 noelv
  214. * label 3.5.17
  215. *
  216. * Rev 1.19 14 Apr 1996 11:49:06 noelv
  217. * Optimized device to device xlate some.
  218. *
  219. * Rev 1.18 13 Apr 1996 17:57:52 noelv
  220. *
  221. *
  222. * Rev 1.17 12 Apr 1996 17:24:00 noelv
  223. * I *knew* I should have skipped rev 13...
  224. *
  225. * Rev 1.16 12 Apr 1996 10:08:54 noelv
  226. *
  227. *
  228. * Rev 1.15 10 Apr 1996 14:15:04 NOELV
  229. *
  230. * Made version 3.5.12
  231. *
  232. * Rev 1.17 08 Apr 1996 16:41:14 frido
  233. * Cleared brush cache on mode re-init.
  234. *
  235. * Rev 1.16 02 Apr 1996 09:12:02 frido
  236. * Bellevue lg102b04 release.
  237. *
  238. * Rev 1.15 28 Mar 1996 20:26:00 frido
  239. * New bellevue release.
  240. *
  241. * Rev 1.14 27 Mar 1996 13:12:32 frido
  242. * Added FILL support for all color resolutions.
  243. *
  244. * Rev 1.13 25 Mar 1996 12:07:44 frido
  245. * Removed warning message.
  246. *
  247. * Rev 1.12 25 Mar 1996 11:50:34 frido
  248. * Bellevue 102B03.
  249. *
  250. * Rev 1.9 20 Mar 1996 16:12:00 noelv
  251. * Bumped rev
  252. *
  253. * Rev 1.8 15 Mar 1996 09:39:04 andys
  254. * Bracketed BITMASK setting with set/clear of enable bit in DRAWDEF
  255. * .
  256. *
  257. * Rev 1.7 14 Mar 1996 09:37:02 andys
  258. *
  259. * Added code to calculate Tile Width in Pixels and SRAM Width in Pixels at
  260. * switch instead of each pass
  261. *
  262. * Rev 1.6 12 Mar 1996 15:46:14 noelv
  263. * Added support file Stroke and Fill
  264. *
  265. * Rev 1.5 07 Mar 1996 18:23:14 bennyn
  266. *
  267. * Removed read/modify/write on CONTROL reg
  268. *
  269. * Rev 1.4 06 Mar 1996 12:56:42 noelv
  270. *
  271. * Set version number to 3.5.0
  272. *
  273. * Rev 1.3 05 Mar 1996 12:01:34 noelv
  274. * Frido version 19
  275. *
  276. * Rev 1.10 26 Feb 1996 23:38:46 frido
  277. * Added initialization of new function pointers.
  278. *
  279. * Rev 1.9 17 Feb 1996 21:45:38 frido
  280. *
  281. *
  282. * Rev 1.8 13 Feb 1996 16:50:24 frido
  283. * Changed the layout of the PDEV structure.
  284. *
  285. * Rev 1.7 10 Feb 1996 21:43:22 frido
  286. * Split monochrome and colored translation tables.
  287. *
  288. * Rev 1.6 08 Feb 1996 00:18:04 frido
  289. * Changed reinitialization of XLATE cache.
  290. *
  291. * Rev 1.5 05 Feb 1996 17:35:44 frido
  292. * Added translation cache.
  293. *
  294. * Rev 1.4 03 Feb 1996 13:43:18 frido
  295. * Use the compile switch "-Dfrido=0" to disable my extensions.
  296. *
  297. * Rev 1.3 25 Jan 1996 12:46:30 frido
  298. * Added initialization of dither cache and font counter ID after mode switch.
  299. *
  300. * Rev 1.2 20 Jan 1996 22:14:10 frido
  301. * Added GCAPS_DITHERONREALIZE.
  302. *
  303. \**************************************************************************/
  304. #include "precomp.h"
  305. #include "version.h"
  306. #include "clioctl.h"
  307. #include "SWAT.h" // SWAT optimizations.
  308. VOID InitPointerHW (PPDEV ppdev);
  309. #if !DRIVER_5465
  310. extern unsigned char ExtraDwordTable[1];
  311. #endif
  312. #define SYSTM_LOGFONT {16,7,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH | FF_DONTCARE,L"System"}
  313. #define HELVE_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_STROKE_PRECIS,PROOF_QUALITY,VARIABLE_PITCH | FF_DONTCARE,L"MS Sans Serif"}
  314. #define COURI_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_STROKE_PRECIS,PROOF_QUALITY,FIXED_PITCH | FF_DONTCARE, L"Courier"}
  315. // This is the basic devinfo for a default driver. This is used as a base and customized based
  316. // on information passed back from the miniport driver.
  317. const DEVINFO gDevInfoFrameBuffer =
  318. {
  319. GCAPS_OPAQUERECT // flGraphicsCaps
  320. #ifdef WINNT_VER40
  321. | GCAPS_DIRECTDRAW
  322. #endif
  323. | GCAPS_DITHERONREALIZE
  324. | GCAPS_ALTERNATEFILL
  325. | GCAPS_WINDINGFILL
  326. | GCAPS_MONO_DITHER,
  327. SYSTM_LOGFONT, // lfDefaultFont
  328. HELVE_LOGFONT, // lfAnsiVarFont
  329. COURI_LOGFONT, // lfAnsiFixFont
  330. 0, // cFonts
  331. 0, // iDitherFotmat
  332. 8, // cxDither
  333. 8, // cyDither
  334. 0 // hpalDefault
  335. };
  336. COPYFN DoHost8ToDevice;
  337. COPYFN DoDeviceToHost8;
  338. COPYFN DoHost16ToDevice;
  339. COPYFN DoDeviceToHost16;
  340. COPYFN DoHost24ToDevice;
  341. COPYFN DoDeviceToHost24;
  342. COPYFN DoHost32ToDevice;
  343. COPYFN DoDeviceToHost32;
  344. //
  345. // Array of HostToScreen routines for each resolution.
  346. // These host to screen functions use the HOSTDATA port.
  347. //
  348. COPYFN *afnHostToScreen[4] =
  349. {
  350. DoHost8ToDevice,
  351. DoHost16ToDevice,
  352. DoHost24ToDevice,
  353. DoHost32ToDevice
  354. };
  355. //
  356. // Array of ScreenToHost routines for eache resolution.
  357. // These host to screen functions use the HOSTDATA port.
  358. //
  359. COPYFN *afnScreenToHost[4] =
  360. {
  361. DoDeviceToHost8,
  362. DoDeviceToHost16,
  363. DoDeviceToHost24,
  364. DoDeviceToHost32
  365. };
  366. #if BUS_MASTER
  367. COPYFN BusMasterBufferedHost8ToDevice;
  368. //
  369. // Array of HostToScreen routines for each resolution.
  370. // These host to screen functions use bus mastering through a buffer.
  371. //
  372. COPYFN *afnBusMasterBufferedHostToScreen[4] =
  373. {
  374. BusMasterBufferedHost8ToDevice,
  375. DoHost16ToDevice,
  376. DoHost24ToDevice,
  377. DoHost32ToDevice
  378. };
  379. #endif
  380. #define LG_SRAM_SIZE 120
  381. /******************************Public*Routine******************************\
  382. * bInitSURF
  383. *
  384. * Enables the surface. Maps the frame buffer into memory.
  385. *
  386. \**************************************************************************/
  387. BOOL bInitSURF(PPDEV ppdev, BOOL bFirst)
  388. {
  389. WORD DeviceID;
  390. DWORD returnedDataLength;
  391. VIDEO_MEMORY videoMemory;
  392. VIDEO_MEMORY_INFORMATION videoMemoryInformation;
  393. VIDEO_PUBLIC_ACCESS_RANGES VideoAccessRanges[2];
  394. DISPDBG((1,"bInitSurf: Entry.\n"));
  395. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  396. IOCTL_VIDEO_SET_CURRENT_MODE,
  397. &(ppdev->ulMode),
  398. sizeof(ULONG),
  399. NULL,
  400. 0,
  401. &returnedDataLength,
  402. NULL))
  403. {
  404. RIP("DISP bInitSURF failed IOCTL_SET_MODE\n");
  405. return(FALSE);
  406. }
  407. // Initialize the shadow registers.
  408. ppdev->shadowFGCOLOR = 0xDEADBEEF;
  409. ppdev->shadowBGCOLOR = 0xDEADBEEF;
  410. ppdev->shadowDRAWBLTDEF = 0xDEADBEEF;
  411. ppdev->shadowQFREE = 0;
  412. //
  413. // If this is the first time we enable the surface we need to map in the
  414. // memory also.
  415. //
  416. if (bFirst)
  417. {
  418. videoMemory.RequestedVirtualAddress = NULL;
  419. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  420. IOCTL_VIDEO_MAP_VIDEO_MEMORY,
  421. &videoMemory,
  422. sizeof(VIDEO_MEMORY),
  423. &videoMemoryInformation,
  424. sizeof(VIDEO_MEMORY_INFORMATION),
  425. &returnedDataLength,
  426. NULL))
  427. {
  428. RIP("DISP bInitSURF failed IOCTL_VIDEO_MAP_VIDEO_MEMORY.\n");
  429. return(FALSE);
  430. }
  431. ppdev->pjScreen = (PBYTE)(videoMemoryInformation.FrameBufferBase);
  432. ppdev->lTotalMem = videoMemoryInformation.FrameBufferLength;
  433. DISPDBG((1,"FrameBufferSize: %d.\n", ppdev->lTotalMem));
  434. //
  435. // Calculate start of off screen memory.
  436. //
  437. ppdev->pjOffScreen = ppdev->pjScreen +
  438. (ppdev->cxScreen * ppdev->cyScreen * (ppdev->iBytesPerPixel));
  439. //
  440. // Map graphics registers into memory.
  441. //
  442. DISPDBG((1,"bInitSurf: Getting pointer to LgREGS from miniport.\n"));
  443. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  444. IOCTL_VIDEO_QUERY_PUBLIC_ACCESS_RANGES,
  445. NULL, // input buffer
  446. 0,
  447. (PVOID) VideoAccessRanges, // output buffer
  448. sizeof (VideoAccessRanges),
  449. &returnedDataLength,
  450. NULL))
  451. {
  452. RIP("bInitSURF - QUERY_PUBLIC_ACCESS_RANGES ioctl failed!\n");
  453. return (FALSE);
  454. }
  455. ppdev->pLgREGS = (GAR*) VideoAccessRanges[0].VirtualAddress;
  456. ppdev->pLgREGS_real = (GAR*) VideoAccessRanges[0].VirtualAddress;
  457. DISPDBG((1,"bInitSurf: Got pointer to registers.\n"));
  458. //
  459. // Map common bus master data buffer.
  460. // If the chip can't do bus mastering, then the size of
  461. // the data buffer will be 0.
  462. //
  463. #if BUS_MASTER
  464. {
  465. // Must match structure in Miniport:CIRRUS.H
  466. struct {
  467. PVOID PhysAddress;
  468. PVOID VirtAddress;
  469. ULONG Length;
  470. } CommonBufferInfo;
  471. DISPDBG((1,"bInitSurf: Getting the common buffer.\n"));
  472. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  473. IOCTL_CL_GET_COMMON_BUFFER,
  474. NULL, // Input buffer.
  475. 0,
  476. &CommonBufferInfo, // Output buffer.
  477. sizeof(CommonBufferInfo),
  478. &returnedDataLength,
  479. NULL))
  480. {
  481. RIP("bInitSURF - GET_COMMON_BUFFER ioctl failed!\n");
  482. return (FALSE);
  483. }
  484. //
  485. // Split the buffer in half and store it in the PDEV
  486. //
  487. ppdev->Buf1VirtAddr = CommonBufferInfo.VirtAddress;
  488. ppdev->Buf1PhysAddr = CommonBufferInfo.PhysAddress;
  489. ppdev->BufLength = CommonBufferInfo.Length/2;
  490. ppdev->Buf2VirtAddr = ppdev->Buf1VirtAddr + ppdev->BufLength;
  491. ppdev->Buf2PhysAddr = ppdev->Buf1PhysAddr + ppdev->BufLength;
  492. DISPDBG((1,"bInitSurf: Got the common buffer.\n"
  493. " Virtual: 0x%08X\n"
  494. " Physical: 0x%08X\n"
  495. " Length: %d\n",
  496. CommonBufferInfo.VirtAddress,
  497. CommonBufferInfo.PhysAddress,
  498. CommonBufferInfo.Length
  499. ));
  500. // ppdev->BufLength = 0;
  501. }
  502. #endif
  503. // DirectDraw initalization
  504. ppdev->DriverData.DrvSemaphore = 0;
  505. ppdev->DriverData.VideoSemaphore = 0;
  506. ppdev->DriverData.YUVTop = 0;
  507. ppdev->DriverData.YUVLeft = 0;
  508. ppdev->DriverData.YUVXExt = 0;
  509. ppdev->DriverData.YUVYExt = 0;
  510. //
  511. // The following is "good practice" for GRX setup.
  512. //
  513. DISPDBG((1,"bInitSurf: Beginning register init.\n"));
  514. REQUIRE(13);
  515. LL16(grOP0_opRDRAM.pt.X, 0); //# Set host phase 0
  516. LL16(grOP1_opRDRAM.pt.X, 0); //# Set host phase 0
  517. LL16(grOP2_opRDRAM.pt.X, 0); //# Set host phase 0
  518. LL16(grOP0_opSRAM, 0); //# Point to start of SRAM0
  519. LL16(grOP1_opSRAM, 0); //# Point to start of SRAM1
  520. LL16(grOP2_opSRAM, 0); //# Point to start of SRAM2
  521. LL16(grOP1_opMSRAM, 0); //# Point to start of mono SRAM1
  522. LL16(grOP2_opMSRAM, 0); //# Point to start of mono SRAM2
  523. LL16(grPATOFF.w, 0); //# All patterns aligned to 0,0
  524. LL_BGCOLOR(0xFFFFFFFF, 0); //# Background color is White
  525. LL_FGCOLOR(0x00000000, 0); //# Foreground color is Black
  526. #if (VS_CONTROL_HACK && DRIVER_5465)
  527. {
  528. DWORD ReturnedDataLength;
  529. DISPDBG((1,"bInitSurf: Enable MMIO for PCI config regs.\n"));
  530. // Send message to miniport to enable MMIO access of PCI registers
  531. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  532. IOCTL_VIDEO_ENABLE_PCI_MMIO,
  533. NULL,
  534. 0,
  535. NULL,
  536. 0,
  537. &ReturnedDataLength,
  538. NULL))
  539. {
  540. RIP("bInitSurf failed IOCTL_VIDEO_ENABLE_PCI_MMIO");
  541. }
  542. }
  543. #endif
  544. //
  545. // Get the chip ID.
  546. //
  547. ppdev->dwLgVenID = (DWORD) LLDR_SZ (grVendor_ID);
  548. DeviceID = (WORD) LLDR_SZ (grDevice_ID);
  549. ppdev->dwLgDevID = DeviceID;
  550. ppdev->dwLgDevRev = (DWORD) LLDR_SZ (grRevision_ID);
  551. #if !(DRIVER_5465)
  552. //
  553. // If it is not a 5462 chip, fill ExtraDwordTable with zero
  554. //
  555. if (ppdev->dwLgDevID != CL_GD5462)
  556. {
  557. memset(&ExtraDwordTable[0], 0, 0x8000);
  558. memset(&ExtraDwordTable[0x8000], 0, 0x8000);
  559. //
  560. // Turn on the GoFast(tm) bit (bit 7 of OP0_opSRAM).
  561. //
  562. REQUIRE(1);
  563. LL16(grOP0_opSRAM, 0x0080);
  564. }
  565. #endif
  566. // Bit 13 must be on for BITMASK to happen
  567. REQUIRE(4);
  568. LL16 (grDRAWDEF, LLDR_SZ(grDRAWDEF) | 0x2000);
  569. LL32 (grBITMASK.dw,0xFFFFFFFF); //# Turn on all bits
  570. LL16 (grDRAWDEF, LLDR_SZ(grDRAWDEF) & ~0x2000);
  571. DISPDBG((1,"bInitSurf: Register init complete.\n"));
  572. //
  573. // Get the tile size and offset_2D informations
  574. // *** Note: ***
  575. // Temporary set, should read from Laguna OFFSET_2D register
  576. ppdev->lOffset_2D = 0;
  577. ppdev->grFORMAT = (DWORD) LLDR_SZ (grFormat);
  578. ppdev->grCONTROL = (DWORD) LLDR_SZ (grCONTROL);
  579. ppdev->grVS_CONTROL = (DWORD) LLDR_SZ (grVS_Control);
  580. if (ppdev->grCONTROL & 0x1000)
  581. {
  582. DISPDBG((1,"Tiling not enabled!\n"));
  583. return(FALSE);
  584. }
  585. ppdev->lTileSize = (ppdev->grCONTROL & 0x0800) ? 256 : 128;
  586. // Initialize Some variable for stroke and fill
  587. if (ppdev->iBytesPerPixel == 3)
  588. {
  589. ppdev->dcTileWidth = (USHORT) (ppdev->lTileSize / (ppdev->iBytesPerPixel + 1));
  590. ppdev->dcSRAMWidth = (USHORT) (LG_SRAM_SIZE / (ppdev->iBytesPerPixel + 1));
  591. }
  592. else
  593. {
  594. ppdev->dcTileWidth = (USHORT) (ppdev->lTileSize / ppdev->iBytesPerPixel);
  595. ppdev->dcSRAMWidth = (USHORT) (LG_SRAM_SIZE / ppdev->iBytesPerPixel);
  596. }
  597. //
  598. // HACK!!! for VS_CONTROL bit 0
  599. //
  600. #if (VS_CONTROL_HACK && DRIVER_5465)
  601. {
  602. DISPDBG((1,"bInitSurf: Disable MMIO for PCI config regs.\n"));
  603. ppdev->grVS_CONTROL &= 0xFFFFFFFE; // Clear bit 0
  604. LL32 (grVS_Control, ppdev->grVS_CONTROL);
  605. }
  606. #endif
  607. // Initialize the offscreen manager
  608. if (!InitOffScnMem(ppdev))
  609. {
  610. DISPDBG((1,"bInitSurf: Fail off screen memory init. Exit.\n"));
  611. return(FALSE);
  612. }
  613. // Allocate a 1x(lDeltaScreen/bpp) block offscreen mem as
  614. // DD scratch buffer
  615. {
  616. DRIVERDATA* pDriverData = (DRIVERDATA*) &ppdev->DriverData;
  617. SIZEL sizl;
  618. if (pDriverData->ScratchBufferOrg == 0)
  619. {
  620. sizl.cx = ppdev->lDeltaScreen/BYTESPERPIXEL;
  621. sizl.cy = 1;
  622. ppdev->DDScratchBufHandle = AllocOffScnMem(ppdev, &sizl, PIXEL_AlIGN, NULL);
  623. if (ppdev->DDScratchBufHandle != NULL)
  624. {
  625. pDriverData->ScratchBufferOrg = (DWORD) ((ppdev->DDScratchBufHandle->aligned_y << 16) |
  626. ppdev->DDScratchBufHandle->aligned_x);
  627. };
  628. };
  629. }
  630. // Initialize the cursor information.
  631. InitPointer(ppdev);
  632. //
  633. // Initialize the brush cache.
  634. //
  635. vInitBrushCache(ppdev);
  636. #if COLOR_TRANSLATE
  637. //
  638. // Initialize the color translation cache.
  639. //
  640. vInitHwXlate(ppdev);
  641. #endif
  642. #if SWAT3
  643. // Enable font cache.
  644. vAssertModeText(ppdev, TRUE);
  645. #endif
  646. #if BUS_MASTER
  647. if (ppdev->BufLength != 0)
  648. {
  649. ppdev->pfnHostToScreen =
  650. afnBusMasterBufferedHostToScreen[ppdev->iBytesPerPixel - 1];
  651. ppdev->pfnScreenToHost =
  652. afnScreenToHost[ppdev->iBytesPerPixel - 1];
  653. }
  654. else
  655. #endif
  656. {
  657. ppdev->pfnHostToScreen =
  658. afnHostToScreen[ppdev->iBytesPerPixel - 1];
  659. ppdev->pfnScreenToHost =
  660. afnScreenToHost[ppdev->iBytesPerPixel - 1];
  661. }
  662. } // END bFirst
  663. else // The surface is being re-initialized for some reason.
  664. { // Usually this means the user is switching back from a
  665. // full-screen DOS box back to Windows.
  666. int i;
  667. // get cursor HW going again
  668. InitPointerHW (ppdev);
  669. //
  670. // The following is "good practice" for GRX setup.
  671. //
  672. REQUIRE(13);
  673. LL16(grOP0_opRDRAM.pt.X, 0); //# Set host phase 0
  674. LL16(grOP1_opRDRAM.pt.X, 0); //# Set host phase 0
  675. LL16(grOP2_opRDRAM.pt.X, 0); //# Set host phase 0
  676. LL16(grOP0_opSRAM, 0); //# Point to start of SRAM0
  677. LL16(grOP1_opSRAM, 0); //# Point to start of SRAM1
  678. LL16(grOP2_opSRAM, 0); //# Point to start of SRAM2
  679. LL16(grOP1_opMSRAM, 0); //# Point to start of mono SRAM1
  680. LL16(grOP2_opMSRAM, 0); //# Point to start of mono SRAM2
  681. LL16(grPATOFF.w, 0); //# All patterns aligned to 0,0
  682. LL_BGCOLOR(0xFFFFFFFF, 0); //# Background color is White
  683. LL_FGCOLOR(0x00000000, 0); //# Foreground color is Black (~FGC)
  684. // Bit 13 must be on for BITMASK to happen
  685. REQUIRE(4);
  686. LL16 (grDRAWDEF, LLDR_SZ(grDRAWDEF) | 0x2000);
  687. LL32 (grBITMASK.dw,0xFFFFFFFF); //# Turn on all bits
  688. LL16 (grDRAWDEF, LLDR_SZ(grDRAWDEF) & ~0x2000);
  689. #if COLOR_TRANSLATE
  690. // Invalidate the color translation cache
  691. vInvalidateXlateCache(ppdev);
  692. #endif
  693. // Invalidate the brush cache.
  694. vInvalidateBrushCache(ppdev);
  695. // Invalidate all cached fonts.
  696. ppdev->ulFontCount++;
  697. // Release the pointer buffers
  698. if (ppdev->PtrImageHandle != NULL)
  699. {
  700. FreeOffScnMem(ppdev, ppdev->PtrImageHandle);
  701. ppdev->PtrImageHandle = NULL;
  702. };
  703. if (ppdev->PtrABltHandle != NULL)
  704. {
  705. FreeOffScnMem(ppdev, ppdev->PtrABltHandle);
  706. ppdev->PtrABltHandle = NULL;
  707. };
  708. ppdev->CursorHidden = TRUE;
  709. }
  710. #if HW_PRESET_BUG
  711. {
  712. ULONG ultmp;
  713. //
  714. // Enable the HW cursor once, then leave it on.
  715. // Turn it "off" by moving it off the screen.
  716. //
  717. LL16 (grCursor_X, (WORD)0xFFFF);
  718. LL16 (grCursor_Y, (WORD)0xFFFF);
  719. ultmp = LLDR_SZ (grCursor_Control);
  720. if ((ultmp & 1) == 0)
  721. {
  722. ultmp |= 0x0001;
  723. LL16 (grCursor_Control, ultmp);
  724. }
  725. }
  726. #endif
  727. //
  728. // Decide whether to use the font cache or not.
  729. // In low offscreen memory situations, we want to ensure we
  730. // have enough off screen memory for device bitmaps.
  731. //
  732. ppdev->UseFontCache = 1; // Enable it.
  733. #if 0
  734. // Now disable it if we don't have much memory.
  735. if (ppdev->lTotalMem == 4*1024*1024) // 4 meg board.
  736. {
  737. ; // Leave it enabled.
  738. }
  739. else if (ppdev->lTotalMem == 2*1024*1024) // 2 meg board.
  740. {
  741. switch (ppdev->iBytesPerPixel)
  742. {
  743. case 1: // 8 bpp, Lots of memory, leave it on.
  744. break;
  745. case 2: // 16 bpp.
  746. if (ppdev->cxScreen >= 1024)
  747. ppdev->UseFontCache = 1;
  748. break;
  749. case 3: // 24 bpp
  750. if (ppdev->cxScreen == 800)
  751. ppdev->UseFontCache = 0;
  752. break;
  753. case 4: // 32 bpp.
  754. if (ppdev->cxScreen == 640)
  755. ppdev->UseFontCache = 0;
  756. break;
  757. }
  758. }
  759. else if (ppdev->lTotalMem == 1*1024*1024) // 1 meg board.
  760. {
  761. ; // leave it on.
  762. }
  763. else
  764. {
  765. RIP("Error determining memory on board.\n");
  766. }
  767. #endif
  768. #if WINBENCH96
  769. {
  770. //
  771. // Pre allocate a small chunk of off screen memory for device bitmaps.
  772. // Otherwise the font cache quickly consumes all offscreen memory on
  773. // 1 and 2 meg boards.
  774. //
  775. SIZEL sizl;
  776. sizl.cx = MAGIC_SIZEX;
  777. sizl.cy = MAGIC_SIZEY;
  778. if (!ppdev->pofmMagic)
  779. {
  780. DISPDBG((1,"Allocating magic bitmap.\n"));
  781. ppdev->pofmMagic = AllocOffScnMem(ppdev, &sizl, PIXEL_AlIGN, NULL);
  782. ppdev->bMagicUsed = 0; // We've allocated it, but we haven't used it.
  783. };
  784. }
  785. #endif
  786. DISPDBG((1,"bInitSurf: Exit.\n"));
  787. return TRUE;
  788. }
  789. /******************************Public*Routine******************************\
  790. * vDisableSURF
  791. *
  792. * Disable the surface. Un-Maps the frame in memory.
  793. *
  794. \**************************************************************************/
  795. VOID vDisableSURF(PPDEV ppdev)
  796. {
  797. DWORD returnedDataLength;
  798. VIDEO_MEMORY videoMemory;
  799. DISPDBG((1,"vDisableSURF: Entry.\n"));
  800. videoMemory.RequestedVirtualAddress = (PVOID) ppdev->pjScreen;
  801. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  802. IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
  803. &videoMemory,
  804. sizeof(VIDEO_MEMORY),
  805. NULL,
  806. 0,
  807. &returnedDataLength,
  808. NULL))
  809. {
  810. RIP("DISP vDisableSURF failed IOCTL_VIDEO_UNMAP\n");
  811. }
  812. DISPDBG((1,"vDisableSurface: Exit.\n"));
  813. }
  814. /******************************Public*Routine******************************\
  815. * bInitPDEV
  816. *
  817. * Determine the mode we should be in based on the DEVMODE passed in.
  818. * Query mini-port to get information needed to fill in the DevInfo and the
  819. * GdiInfo .
  820. *
  821. \**************************************************************************/
  822. BOOL bInitPDEV(
  823. PPDEV ppdev,
  824. DEVMODEW *pDevMode,
  825. GDIINFO *pGdiInfo,
  826. DEVINFO *pDevInfo)
  827. {
  828. ULONG cModes;
  829. PVIDEO_MODE_INFORMATION pVideoBuffer, pVideoModeSelected, pVideoTemp;
  830. VIDEO_COLOR_CAPABILITIES colorCapabilities;
  831. ULONG ulTemp;
  832. BOOL bSelectDefault;
  833. ULONG cbModeSize;
  834. //
  835. // calls the miniport to get mode information.
  836. //
  837. DISPDBG((1,"bInitPDEV: Entry.\n"));
  838. cModes = getAvailableModes(ppdev->hDriver, &pVideoBuffer, &cbModeSize);
  839. if (cModes == 0)
  840. {
  841. DISPDBG((1,"bInitPDEV: Exit. cModes==0.\n"));
  842. return(FALSE);
  843. }
  844. //
  845. // Determine if we are looking for a default mode.
  846. //
  847. if ( ((pDevMode->dmPelsWidth) ||
  848. (pDevMode->dmPelsHeight) ||
  849. (pDevMode->dmBitsPerPel) ||
  850. (pDevMode->dmDisplayFlags) ||
  851. (pDevMode->dmDisplayFrequency)) == 0)
  852. {
  853. bSelectDefault = TRUE;
  854. }
  855. else
  856. {
  857. bSelectDefault = FALSE;
  858. }
  859. //
  860. // Now see if the requested mode has a match in that table.
  861. //
  862. pVideoModeSelected = NULL;
  863. pVideoTemp = pVideoBuffer;
  864. while (cModes--)
  865. {
  866. if (pVideoTemp->Length != 0)
  867. {
  868. if (bSelectDefault ||
  869. ((pVideoTemp->VisScreenWidth == pDevMode->dmPelsWidth) &&
  870. (pVideoTemp->VisScreenHeight == pDevMode->dmPelsHeight) &&
  871. (pVideoTemp->BitsPerPlane *
  872. pVideoTemp->NumberOfPlanes == pDevMode->dmBitsPerPel) &&
  873. ((pVideoTemp->Frequency == pDevMode->dmDisplayFrequency) ||
  874. (pDevMode->dmDisplayFrequency == 0)) ) )
  875. {
  876. pVideoModeSelected = pVideoTemp;
  877. break;
  878. }
  879. }
  880. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  881. (((PUCHAR)pVideoTemp) + cbModeSize);
  882. }
  883. //
  884. // If no mode has been found, return an error
  885. //
  886. if (pVideoModeSelected == NULL)
  887. {
  888. MEMORY_FREE(pVideoBuffer);
  889. DISPDBG((1,"DISP bInitPDEV failed - no valid modes\n"));
  890. return(FALSE);
  891. }
  892. // Fill in signature for PDEV and DriverData structures
  893. {
  894. DRIVERDATA* pDriverData = (DRIVERDATA*) &ppdev->DriverData;
  895. ppdev->signature = 0x12345678;
  896. pDriverData->signature = 0x9abcdef0;
  897. }
  898. //
  899. // Fill in the GDIINFO data structure with the information returned from
  900. // the kernel driver.
  901. //
  902. ppdev->ulFreq = pVideoModeSelected->Frequency;
  903. ppdev->ulMode = pVideoModeSelected->ModeIndex;
  904. ppdev->cxScreen = pVideoModeSelected->VisScreenWidth-OFFSCREEN_COLS;
  905. ppdev->cyScreen = pVideoModeSelected->VisScreenHeight-OFFSCREEN_LINES;
  906. ppdev->cxMemory = pVideoModeSelected->VideoMemoryBitmapWidth;
  907. ppdev->cyMemory = pVideoModeSelected->VideoMemoryBitmapHeight;
  908. ppdev->ulBitCount = pVideoModeSelected->BitsPerPlane *
  909. pVideoModeSelected->NumberOfPlanes;
  910. ppdev->lDeltaScreen = pVideoModeSelected->ScreenStride;
  911. ppdev->iBytesPerPixel = ppdev->ulBitCount/8;
  912. DISPDBG((1, "DISP bInitPDEV: Screen size = %d x %d.\n",ppdev->cxScreen,ppdev->cyScreen));
  913. DISPDBG((1, "DISP bInitPDEV: Color depth = %d bpp.\n",ppdev->ulBitCount));
  914. DISPDBG((1, "DISP bInitPDEV: Screen Delta = %d bpp.\n",ppdev->lDeltaScreen));
  915. ppdev->flRed = pVideoModeSelected->RedMask;
  916. ppdev->flGreen = pVideoModeSelected->GreenMask;
  917. ppdev->flBlue = pVideoModeSelected->BlueMask;
  918. // pGdiInfo->ulVersion = 0x1019; // Our driver is verion 3.5.00
  919. #ifdef WINNT_VER40
  920. pGdiInfo->ulVersion = GDI_DRIVER_VERSION | (VER_REV & 0xFF);
  921. #else
  922. pGdiInfo->ulVersion = (((VER_MAJ) & 0xF) << 12) |
  923. (((VER_MIN) & 0xF) << 8 ) |
  924. (((VER_REV) & 0xFFFF) ) ;
  925. #endif
  926. pGdiInfo->ulTechnology = DT_RASDISPLAY;
  927. pGdiInfo->ulHorzSize = pVideoModeSelected->XMillimeter;
  928. pGdiInfo->ulVertSize = pVideoModeSelected->YMillimeter;
  929. pGdiInfo->ulHorzRes = ppdev->cxScreen;
  930. pGdiInfo->ulVertRes = ppdev->cyScreen;
  931. #ifdef WINNT_VER40
  932. pGdiInfo->ulPanningHorzRes = ppdev->cxScreen;
  933. pGdiInfo->ulPanningVertRes = ppdev->cyScreen;
  934. #else
  935. pGdiInfo->ulDesktopHorzRes = ppdev->cxScreen;
  936. pGdiInfo->ulDesktopVertRes = ppdev->cyScreen;
  937. #endif
  938. pGdiInfo->cBitsPixel = pVideoModeSelected->BitsPerPlane;
  939. pGdiInfo->cPlanes = pVideoModeSelected->NumberOfPlanes;
  940. pGdiInfo->ulVRefresh = pVideoModeSelected->Frequency;
  941. pGdiInfo->ulBltAlignment = 0; // We have accelerated screen-to-screen.
  942. pGdiInfo->ulLogPixelsX = pDevMode->dmLogPixels;
  943. pGdiInfo->ulLogPixelsY = pDevMode->dmLogPixels;
  944. pGdiInfo->flTextCaps = TC_RA_ABLE;
  945. pGdiInfo->flRaster = 0; // flRaster is reserved by DDI
  946. pGdiInfo->ulDACRed = pVideoModeSelected->NumberRedBits;
  947. pGdiInfo->ulDACGreen = pVideoModeSelected->NumberGreenBits;
  948. pGdiInfo->ulDACBlue = pVideoModeSelected->NumberBlueBits;
  949. pGdiInfo->ulAspectX = 0x24; // One-to-one aspect ratio
  950. pGdiInfo->ulAspectY = 0x24;
  951. pGdiInfo->ulAspectXY = 0x33;
  952. pGdiInfo->xStyleStep = 1; // A style unit is 3 pels
  953. pGdiInfo->yStyleStep = 1;
  954. pGdiInfo->denStyleStep = 3;
  955. pGdiInfo->ptlPhysOffset.x = 0;
  956. pGdiInfo->ptlPhysOffset.y = 0;
  957. pGdiInfo->szlPhysSize.cx = 0;
  958. pGdiInfo->szlPhysSize.cy = 0;
  959. // RGB and CMY color info.
  960. // try to get it from the miniport.
  961. // if the miniport doesn ot support this feature, use defaults.
  962. if (!DEVICE_IO_CTRL(ppdev->hDriver,
  963. IOCTL_VIDEO_QUERY_COLOR_CAPABILITIES,
  964. NULL,
  965. 0,
  966. &colorCapabilities,
  967. sizeof(VIDEO_COLOR_CAPABILITIES),
  968. &ulTemp,
  969. NULL))
  970. {
  971. DISPDBG((1, "DISP getcolorCapabilities failed \n"));
  972. pGdiInfo->ciDevice.Red.x = 6700;
  973. pGdiInfo->ciDevice.Red.y = 3300;
  974. pGdiInfo->ciDevice.Red.Y = 0;
  975. pGdiInfo->ciDevice.Green.x = 2100;
  976. pGdiInfo->ciDevice.Green.y = 7100;
  977. pGdiInfo->ciDevice.Green.Y = 0;
  978. pGdiInfo->ciDevice.Blue.x = 1400;
  979. pGdiInfo->ciDevice.Blue.y = 800;
  980. pGdiInfo->ciDevice.Blue.Y = 0;
  981. pGdiInfo->ciDevice.AlignmentWhite.x = 3127;
  982. pGdiInfo->ciDevice.AlignmentWhite.y = 3290;
  983. pGdiInfo->ciDevice.AlignmentWhite.Y = 0;
  984. pGdiInfo->ciDevice.RedGamma = 20000;
  985. pGdiInfo->ciDevice.GreenGamma = 20000;
  986. pGdiInfo->ciDevice.BlueGamma = 20000;
  987. }
  988. else
  989. {
  990. pGdiInfo->ciDevice.Red.x = colorCapabilities.RedChromaticity_x;
  991. pGdiInfo->ciDevice.Red.y = colorCapabilities.RedChromaticity_y;
  992. pGdiInfo->ciDevice.Red.Y = 0;
  993. pGdiInfo->ciDevice.Green.x = colorCapabilities.GreenChromaticity_x;
  994. pGdiInfo->ciDevice.Green.y = colorCapabilities.GreenChromaticity_y;
  995. pGdiInfo->ciDevice.Green.Y = 0;
  996. pGdiInfo->ciDevice.Blue.x = colorCapabilities.BlueChromaticity_x;
  997. pGdiInfo->ciDevice.Blue.y = colorCapabilities.BlueChromaticity_y;
  998. pGdiInfo->ciDevice.Blue.Y = 0;
  999. pGdiInfo->ciDevice.AlignmentWhite.x = colorCapabilities.WhiteChromaticity_x;
  1000. pGdiInfo->ciDevice.AlignmentWhite.y = colorCapabilities.WhiteChromaticity_y;
  1001. pGdiInfo->ciDevice.AlignmentWhite.Y = colorCapabilities.WhiteChromaticity_Y;
  1002. // if we have a color device store the three color gamma values,
  1003. // otherwise store the unique gamma value in all three.
  1004. if (colorCapabilities.AttributeFlags & VIDEO_DEVICE_COLOR)
  1005. {
  1006. pGdiInfo->ciDevice.RedGamma = colorCapabilities.RedGamma;
  1007. pGdiInfo->ciDevice.GreenGamma = colorCapabilities.GreenGamma;
  1008. pGdiInfo->ciDevice.BlueGamma = colorCapabilities.BlueGamma;
  1009. }
  1010. else
  1011. {
  1012. pGdiInfo->ciDevice.RedGamma = colorCapabilities.WhiteGamma;
  1013. pGdiInfo->ciDevice.GreenGamma = colorCapabilities.WhiteGamma;
  1014. pGdiInfo->ciDevice.BlueGamma = colorCapabilities.WhiteGamma;
  1015. }
  1016. };
  1017. pGdiInfo->ciDevice.Cyan.x = 0;
  1018. pGdiInfo->ciDevice.Cyan.y = 0;
  1019. pGdiInfo->ciDevice.Cyan.Y = 0;
  1020. pGdiInfo->ciDevice.Magenta.x = 0;
  1021. pGdiInfo->ciDevice.Magenta.y = 0;
  1022. pGdiInfo->ciDevice.Magenta.Y = 0;
  1023. pGdiInfo->ciDevice.Yellow.x = 0;
  1024. pGdiInfo->ciDevice.Yellow.y = 0;
  1025. pGdiInfo->ciDevice.Yellow.Y = 0;
  1026. // No dye correction for raster displays.
  1027. pGdiInfo->ciDevice.MagentaInCyanDye = 0;
  1028. pGdiInfo->ciDevice.YellowInCyanDye = 0;
  1029. pGdiInfo->ciDevice.CyanInMagentaDye = 0;
  1030. pGdiInfo->ciDevice.YellowInMagentaDye = 0;
  1031. pGdiInfo->ciDevice.CyanInYellowDye = 0;
  1032. pGdiInfo->ciDevice.MagentaInYellowDye = 0;
  1033. pGdiInfo->ulDevicePelsDPI = 0; // For printers only
  1034. pGdiInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
  1035. // This should be modified to take into account the size
  1036. // of the display and the resolution.
  1037. pGdiInfo->ulHTPatternSize = HT_PATSIZE_4x4_M;
  1038. pGdiInfo->flHTFlags = HT_FLAG_ADDITIVE_PRIMS;
  1039. // Fill in the basic devinfo structure
  1040. *pDevInfo = gDevInfoFrameBuffer;
  1041. // Fill in the rest of the devinfo and GdiInfo structures.
  1042. if (ppdev->ulBitCount == 8)
  1043. {
  1044. // It is Palette Managed.
  1045. pGdiInfo->ulNumColors = 20;
  1046. pGdiInfo->ulNumPalReg = 1 << ppdev->ulBitCount;
  1047. pDevInfo->flGraphicsCaps |= GCAPS_PALMANAGED | GCAPS_COLOR_DITHER;
  1048. pGdiInfo->ulHTOutputFormat = HT_FORMAT_8BPP;
  1049. pDevInfo->iDitherFormat = BMF_8BPP;
  1050. // Assuming palette is orthogonal - all colors are same size.
  1051. ppdev->cPaletteShift = 8 - pGdiInfo->ulDACRed;
  1052. }
  1053. else
  1054. {
  1055. pGdiInfo->ulNumColors = (ULONG) (-1);
  1056. pGdiInfo->ulNumPalReg = 0;
  1057. if (ppdev->ulBitCount == 16)
  1058. {
  1059. pGdiInfo->ulHTOutputFormat = HT_FORMAT_16BPP;
  1060. pDevInfo->iDitherFormat = BMF_16BPP;
  1061. }
  1062. else if (ppdev->ulBitCount == 24)
  1063. {
  1064. pGdiInfo->ulHTOutputFormat = HT_FORMAT_24BPP;
  1065. pDevInfo->iDitherFormat = BMF_24BPP;
  1066. }
  1067. else
  1068. {
  1069. pGdiInfo->ulHTOutputFormat = HT_FORMAT_32BPP;
  1070. pDevInfo->iDitherFormat = BMF_32BPP;
  1071. }
  1072. }
  1073. MEMORY_FREE(pVideoBuffer);
  1074. DISPDBG((1,"bInitPDEV: Exit.\n"));
  1075. return(TRUE);
  1076. }
  1077. /******************************Public*Routine******************************\
  1078. * getAvailableModes
  1079. *
  1080. * Calls the miniport to get the list of modes supported by the kernel driver,
  1081. * and returns the list of modes supported by the diplay driver among those
  1082. *
  1083. * returns the number of entries in the videomode buffer.
  1084. * 0 means no modes are supported by the miniport or that an error occured.
  1085. *
  1086. * NOTE: the buffer must be freed up by the caller.
  1087. *
  1088. \**************************************************************************/
  1089. DWORD getAvailableModes(
  1090. HANDLE hDriver,
  1091. PVIDEO_MODE_INFORMATION *modeInformation,
  1092. DWORD *cbModeSize)
  1093. {
  1094. ULONG ulTemp;
  1095. VIDEO_NUM_MODES modes;
  1096. PVIDEO_MODE_INFORMATION pVideoTemp;
  1097. //
  1098. // Get the number of modes supported by the mini-port
  1099. //
  1100. DISPDBG((1,"getAvailableModes: Entry.\n"));
  1101. if (!DEVICE_IO_CTRL(hDriver,
  1102. IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
  1103. NULL,
  1104. 0,
  1105. &modes,
  1106. sizeof(VIDEO_NUM_MODES),
  1107. &ulTemp,
  1108. NULL))
  1109. {
  1110. DISPDBG((1, "framebuf.dll getAvailableModes failed VIDEO_QUERY_NUM_AVAIL_MODES\n"));
  1111. return(0);
  1112. }
  1113. *cbModeSize = modes.ModeInformationLength;
  1114. //
  1115. // Allocate the buffer for the mini-port to write the modes in.
  1116. //
  1117. *modeInformation = (PVIDEO_MODE_INFORMATION)
  1118. #ifdef WINNT_VER40
  1119. MEM_ALLOC(FL_ZERO_MEMORY,
  1120. modes.NumModes *
  1121. modes.ModeInformationLength, ALLOC_TAG);
  1122. #else
  1123. MEM_ALLOC(LMEM_FIXED | LMEM_ZEROINIT,
  1124. modes.NumModes *
  1125. modes.ModeInformationLength);
  1126. #endif
  1127. if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
  1128. {
  1129. DISPDBG((1, "framebuf.dll getAvailableModes failed LocalAlloc\n"));
  1130. return 0;
  1131. }
  1132. //
  1133. // Ask the mini-port to fill in the available modes.
  1134. //
  1135. if (!DEVICE_IO_CTRL(hDriver,
  1136. IOCTL_VIDEO_QUERY_AVAIL_MODES,
  1137. NULL,
  1138. 0,
  1139. *modeInformation,
  1140. modes.NumModes * modes.ModeInformationLength,
  1141. &ulTemp,
  1142. NULL))
  1143. {
  1144. DISPDBG((1, "framebuf.dll getAvailableModes failed VIDEO_QUERY_AVAIL_MODES\n"));
  1145. MEMORY_FREE(*modeInformation);
  1146. *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
  1147. return(0);
  1148. }
  1149. //
  1150. // Now see which of these modes are supported by the display driver.
  1151. // As an internal mechanism, set the length to 0 for the modes we
  1152. // DO NOT support.
  1153. //
  1154. ulTemp = modes.NumModes;
  1155. pVideoTemp = *modeInformation;
  1156. //
  1157. // Mode is rejected if it is not one plane, or not graphics, or is not
  1158. // one of 8, 16 or 32 bits per pel.
  1159. //
  1160. while (ulTemp--)
  1161. {
  1162. if ((pVideoTemp->NumberOfPlanes != 1 ) ||
  1163. !(pVideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
  1164. ((pVideoTemp->BitsPerPlane != 8) &&
  1165. (pVideoTemp->BitsPerPlane != 16) &&
  1166. (pVideoTemp->BitsPerPlane != 24) &&
  1167. (pVideoTemp->BitsPerPlane != 32)))
  1168. {
  1169. pVideoTemp->Length = 0;
  1170. }
  1171. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  1172. (((PUCHAR)pVideoTemp) + modes.ModeInformationLength);
  1173. }
  1174. DISPDBG((1,"getAvailableModes: Exit.\n"));
  1175. return modes.NumModes;
  1176. }
  1177.