Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1356 lines
44 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: enable.c
  3. *
  4. * This module contains the functions that enable and disable the
  5. * driver, the pdev, and the surface.
  6. *
  7. * Copyright (c) 1992-1994 Microsoft Corporation
  8. \**************************************************************************/
  9. #include "precomp.h"
  10. /******************************Public*Structure****************************\
  11. * GDIINFO ggdiDefault
  12. *
  13. * This contains the default GDIINFO fields that are passed back to GDI
  14. * during DrvEnablePDEV.
  15. *
  16. * NOTE: This structure defaults to values for an 8bpp palette device.
  17. * Some fields are overwritten for different colour depths.
  18. \**************************************************************************/
  19. GDIINFO ggdiDefault = {
  20. GDI_DRIVER_VERSION,
  21. DT_RASDISPLAY, // ulTechnology
  22. 0, // ulHorzSize (filled in later)
  23. 0, // ulVertSize (filled in later)
  24. 0, // ulHorzRes (filled in later)
  25. 0, // ulVertRes (filled in later)
  26. 0, // cBitsPixel (filled in later)
  27. 0, // cPlanes (filled in later)
  28. 20, // ulNumColors (palette managed)
  29. 0, // flRaster (DDI reserved field)
  30. 0, // ulLogPixelsX (filled in later)
  31. 0, // ulLogPixelsY (filled in later)
  32. TC_RA_ABLE, // flTextCaps -- If we had wanted console windows
  33. // to scroll by repainting the entire window,
  34. // instead of doing a screen-to-screen blt, we
  35. // would have set TC_SCROLLBLT (yes, the flag is
  36. // bass-ackwards).
  37. 0, // ulDACRed (filled in later)
  38. 0, // ulDACGreen (filled in later)
  39. 0, // ulDACBlue (filled in later)
  40. 0x0024, // ulAspectX
  41. 0x0024, // ulAspectY
  42. 0x0033, // ulAspectXY (one-to-one aspect ratio)
  43. 1, // xStyleStep
  44. 1, // yStyleSte;
  45. 3, // denStyleStep -- Styles have a one-to-one aspect
  46. // ratio, and every 'dot' is 3 pixels long
  47. { 0, 0 }, // ptlPhysOffset
  48. { 0, 0 }, // szlPhysSize
  49. 256, // ulNumPalReg
  50. // These fields are for halftone initialization. The actual values are
  51. // a bit magic, but seem to work well on our display.
  52. { // ciDevice
  53. { 6700, 3300, 0 }, // Red
  54. { 2100, 7100, 0 }, // Green
  55. { 1400, 800, 0 }, // Blue
  56. { 1750, 3950, 0 }, // Cyan
  57. { 4050, 2050, 0 }, // Magenta
  58. { 4400, 5200, 0 }, // Yellow
  59. { 3127, 3290, 0 }, // AlignmentWhite
  60. 20000, // RedGamma
  61. 20000, // GreenGamma
  62. 20000, // BlueGamma
  63. 0, 0, 0, 0, 0, 0 // No dye correction for raster displays
  64. },
  65. 0, // ulDevicePelsDPI (for printers only)
  66. PRIMARY_ORDER_CBA, // ulPrimaryOrder
  67. HT_PATSIZE_4x4_M, // ulHTPatternSize
  68. HT_FORMAT_8BPP, // ulHTOutputFormat
  69. HT_FLAG_ADDITIVE_PRIMS, // flHTFlags
  70. 0, // ulVRefresh (filled in later)
  71. 0, // ulBltAlignment
  72. 0, // ulPanningHorzRes (filled in later)
  73. 0, // ulPanningVertRes (filled in later)
  74. };
  75. /******************************Public*Structure****************************\
  76. * DEVINFO gdevinfoDefault
  77. *
  78. * This contains the default DEVINFO fields that are passed back to GDI
  79. * during DrvEnablePDEV.
  80. *
  81. * NOTE: This structure defaults to values for an 8bpp palette device.
  82. * Some fields are overwritten for different colour depths.
  83. \**************************************************************************/
  84. #define SYSTM_LOGFONT {16,7,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  85. CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,\
  86. VARIABLE_PITCH | FF_DONTCARE,L"System"}
  87. #define HELVE_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  88. CLIP_STROKE_PRECIS,PROOF_QUALITY,\
  89. VARIABLE_PITCH | FF_DONTCARE,L"MS Sans Serif"}
  90. #define COURI_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  91. CLIP_STROKE_PRECIS,PROOF_QUALITY,\
  92. FIXED_PITCH | FF_DONTCARE, L"Courier"}
  93. DEVINFO gdevinfoDefault = {
  94. (GCAPS_OPAQUERECT |
  95. GCAPS_DITHERONREALIZE |
  96. GCAPS_PALMANAGED |
  97. GCAPS_ALTERNATEFILL |
  98. GCAPS_WINDINGFILL |
  99. GCAPS_MONO_DITHER |
  100. GCAPS_COLOR_DITHER),
  101. // flGraphicsFlags
  102. SYSTM_LOGFONT, // lfDefaultFont
  103. HELVE_LOGFONT, // lfAnsiVarFont
  104. COURI_LOGFONT, // lfAnsiFixFont
  105. 0, // cFonts
  106. BMF_8BPP, // iDitherFormat
  107. 8, // cxDither
  108. 8, // cyDither
  109. 0 // hpalDefault (filled in later)
  110. };
  111. /******************************Public*Structure****************************\
  112. * DFVFN gadrvfn[]
  113. *
  114. * Build the driver function table gadrvfn with function index/address
  115. * pairs. This table tells GDI which DDI calls we support, and their
  116. * location (GDI does an indirect call through this table to call us).
  117. *
  118. * Why haven't we implemented DrvSaveScreenBits? To save code.
  119. *
  120. * When the driver doesn't hook DrvSaveScreenBits, USER simulates on-
  121. * the-fly by creating a temporary device-format-bitmap, and explicitly
  122. * calling DrvCopyBits to save/restore the bits. Since we already hook
  123. * DrvCreateDeviceBitmap, we'll end up using off-screen memory to store
  124. * the bits anyway (which would have been the main reason for implementing
  125. * DrvSaveScreenBits). So we may as well save some working set.
  126. \**************************************************************************/
  127. #if DBG || !SYNCHRONIZEACCESS_WORKS
  128. // On Checked builds, or when we have to synchronize access, thunk
  129. // everything through Dbg calls...
  130. DRVFN gadrvfn[] = {
  131. { INDEX_DrvEnablePDEV, (PFN) DbgEnablePDEV },
  132. { INDEX_DrvCompletePDEV, (PFN) DbgCompletePDEV },
  133. { INDEX_DrvDisablePDEV, (PFN) DbgDisablePDEV },
  134. { INDEX_DrvEnableSurface, (PFN) DbgEnableSurface },
  135. { INDEX_DrvDisableSurface, (PFN) DbgDisableSurface },
  136. { INDEX_DrvAssertMode, (PFN) DbgAssertMode },
  137. { INDEX_DrvMovePointer, (PFN) DbgMovePointer },
  138. { INDEX_DrvSetPointerShape, (PFN) DbgSetPointerShape },
  139. { INDEX_DrvDitherColor, (PFN) DbgDitherColor },
  140. { INDEX_DrvSetPalette, (PFN) DbgSetPalette },
  141. { INDEX_DrvCopyBits, (PFN) DbgCopyBits },
  142. { INDEX_DrvBitBlt, (PFN) DbgBitBlt },
  143. { INDEX_DrvTextOut, (PFN) DbgTextOut },
  144. { INDEX_DrvGetModes, (PFN) DbgGetModes },
  145. { INDEX_DrvStrokePath, (PFN) DbgStrokePath },
  146. { INDEX_DrvFillPath, (PFN) DbgFillPath },
  147. { INDEX_DrvPaint, (PFN) DbgPaint },
  148. { INDEX_DrvRealizeBrush, (PFN) DbgRealizeBrush },
  149. { INDEX_DrvCreateDeviceBitmap, (PFN) DbgCreateDeviceBitmap },
  150. { INDEX_DrvDeleteDeviceBitmap, (PFN) DbgDeleteDeviceBitmap },
  151. { INDEX_DrvStretchBlt, (PFN) DbgStretchBlt },
  152. };
  153. #else
  154. // On Free builds, directly call the appropriate functions...
  155. DRVFN gadrvfn[] = {
  156. { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
  157. { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
  158. { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
  159. { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
  160. { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
  161. { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
  162. { INDEX_DrvMovePointer, (PFN) DrvMovePointer },
  163. { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape },
  164. { INDEX_DrvDitherColor, (PFN) DrvDitherColor },
  165. { INDEX_DrvSetPalette, (PFN) DrvSetPalette },
  166. { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
  167. { INDEX_DrvBitBlt, (PFN) DrvBitBlt },
  168. { INDEX_DrvTextOut, (PFN) DrvTextOut },
  169. { INDEX_DrvGetModes, (PFN) DrvGetModes },
  170. { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
  171. { INDEX_DrvFillPath, (PFN) DrvFillPath },
  172. { INDEX_DrvPaint, (PFN) DrvPaint },
  173. { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush },
  174. { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap },
  175. { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap },
  176. { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt },
  177. };
  178. #endif
  179. ULONG gcdrvfn = sizeof(gadrvfn) / sizeof(DRVFN);
  180. /******************************Public*Routine******************************\
  181. * BOOL DrvEnableDriver
  182. *
  183. * Enables the driver by retrieving the drivers function table and version.
  184. *
  185. \**************************************************************************/
  186. BOOL DrvEnableDriver(
  187. ULONG iEngineVersion,
  188. ULONG cj,
  189. DRVENABLEDATA* pded)
  190. {
  191. // Engine Version is passed down so future drivers can support previous
  192. // engine versions. A next generation driver can support both the old
  193. // and new engine conventions if told what version of engine it is
  194. // working with. For the first version the driver does nothing with it.
  195. // Fill in as much as we can.
  196. if (cj >= sizeof(DRVENABLEDATA))
  197. pded->pdrvfn = gadrvfn;
  198. if (cj >= (sizeof(ULONG) * 2))
  199. pded->c = gcdrvfn;
  200. // DDI version this driver was targeted for is passed back to engine.
  201. // Future graphic's engine may break calls down to old driver format.
  202. if (cj >= sizeof(ULONG))
  203. pded->iDriverVersion = DDI_DRIVER_VERSION_NT4;
  204. return(TRUE);
  205. }
  206. /******************************Public*Routine******************************\
  207. * VOID DrvDisableDriver
  208. *
  209. * Tells the driver it is being disabled. Release any resources allocated in
  210. * DrvEnableDriver.
  211. *
  212. \**************************************************************************/
  213. VOID DrvDisableDriver(VOID)
  214. {
  215. return;
  216. }
  217. /******************************Public*Routine******************************\
  218. * DHPDEV DrvEnablePDEV
  219. *
  220. * Initializes a bunch of fields for GDI, based on the mode we've been asked
  221. * to do. This is the first thing called after DrvEnableDriver, when GDI
  222. * wants to get some information about us.
  223. *
  224. \**************************************************************************/
  225. DHPDEV DrvEnablePDEV(
  226. DEVMODEW* pdm, // Contains data pertaining to requested mode
  227. PWSTR pwszLogAddr, // Logical address
  228. ULONG cPat, // Count of standard patterns
  229. HSURF* phsurfPatterns, // Buffer for standard patterns
  230. ULONG cjCaps, // Size of buffer for device caps 'pdevcaps'
  231. ULONG* pdevcaps, // Buffer for device caps, also known as 'gdiinfo'
  232. ULONG cjDevInfo, // Number of bytes in device info 'pdi'
  233. DEVINFO* pdi, // Device information
  234. HDEV hdev, // HDEV, used for callbacks
  235. PWSTR pwszDeviceName, // Device name
  236. HANDLE hDriver) // Kernel driver handle
  237. {
  238. PDEV* ppdev;
  239. // Future versions of NT had better supply 'devcaps' and 'devinfo'
  240. // structures that are the same size or larger than the current
  241. // structures:
  242. if ((cjCaps < sizeof(GDIINFO)) || (cjDevInfo < sizeof(DEVINFO)))
  243. {
  244. DISPDBG((0, "DrvEnablePDEV - Buffer size too small"));
  245. goto ReturnFailure0;
  246. }
  247. // Allocate a physical device structure. Note that we definitely
  248. // rely on the zero initialization:
  249. ppdev = (PDEV*) EngAllocMem(FL_ZERO_MEMORY, sizeof(PDEV), ALLOC_TAG);
  250. if (ppdev == NULL)
  251. {
  252. DISPDBG((0, "DrvEnablePDEV - Failed EngAllocMem"));
  253. goto ReturnFailure0;
  254. }
  255. ppdev->hDriver = hDriver;
  256. // Get the current screen mode information. Set up device caps and
  257. // devinfo:
  258. if (!bInitializeModeFields(ppdev, (GDIINFO*) pdevcaps, pdi, pdm))
  259. {
  260. DISPDBG((0, "DrvEnablePDEV - Failed bInitializeModeFields"));
  261. goto ReturnFailure1;
  262. }
  263. // Initialize palette information.
  264. if (!bInitializePalette(ppdev, pdi))
  265. {
  266. DISPDBG((0, "DrvEnablePDEV - Failed bInitializePalette"));
  267. goto ReturnFailure1;
  268. }
  269. return((DHPDEV) ppdev);
  270. ReturnFailure1:
  271. DrvDisablePDEV((DHPDEV) ppdev);
  272. ReturnFailure0:
  273. DISPDBG((0, "Failed DrvEnablePDEV"));
  274. return(0);
  275. }
  276. /******************************Public*Routine******************************\
  277. * DrvDisablePDEV
  278. *
  279. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  280. * enabled DrvDisableSurface will have already been called.
  281. *
  282. * Note: In an error, we may call this before DrvEnablePDEV is done.
  283. *
  284. \**************************************************************************/
  285. VOID DrvDisablePDEV(
  286. DHPDEV dhpdev)
  287. {
  288. PDEV* ppdev;
  289. ppdev = (PDEV*) dhpdev;
  290. vUninitializePalette(ppdev);
  291. EngFreeMem(ppdev);
  292. }
  293. /******************************Public*Routine******************************\
  294. * VOID DrvCompletePDEV
  295. *
  296. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  297. *
  298. \**************************************************************************/
  299. VOID DrvCompletePDEV(
  300. DHPDEV dhpdev,
  301. HDEV hdev)
  302. {
  303. ((PDEV*) dhpdev)->hdevEng = hdev;
  304. }
  305. /******************************Public*Routine******************************\
  306. * HSURF DrvEnableSurface
  307. *
  308. * Creates the drawing surface and initializes the hardware. This is called
  309. * after DrvEnablePDEV, and performs the final device initialization.
  310. *
  311. \**************************************************************************/
  312. HSURF DrvEnableSurface(
  313. DHPDEV dhpdev)
  314. {
  315. PDEV* ppdev;
  316. HSURF hsurf;
  317. SIZEL sizl;
  318. DSURF* pdsurf;
  319. VOID* pvTmpBuffer;
  320. ppdev = (PDEV*) dhpdev;
  321. /////////////////////////////////////////////////////////////////////
  322. // First, create our private surface structure.
  323. //
  324. // Whenever we get a call to draw directly to the screen, we'll get
  325. // passed a pointer to a SURFOBJ whose 'dhpdev' field will point
  326. // to our PDEV structure, and whose 'dhsurf' field will point to the
  327. // following DSURF structure.
  328. //
  329. // Every device bitmap we create in DrvCreateDeviceBitmap will also
  330. // have its own unique DSURF structure allocated (but will share the
  331. // same PDEV). To make our code more polymorphic for handling drawing
  332. // to either the screen or an off-screen bitmap, we have the same
  333. // structure for both.
  334. pdsurf = EngAllocMem(FL_ZERO_MEMORY, sizeof(DSURF), ALLOC_TAG);
  335. if (pdsurf == NULL)
  336. {
  337. DISPDBG((0, "DrvEnableSurface - Failed pdsurf EngAllocMem"));
  338. goto ReturnFailure;
  339. }
  340. ppdev->pdsurfScreen = pdsurf; // Remember it for clean-up
  341. pdsurf->poh = &ppdev->heap.ohDfb;// The only thing we use this OH node
  342. pdsurf->poh->x = 0; // for is its (x, y) location, and
  343. pdsurf->poh->y = 0; // 'ohDfb' is otherwise unused
  344. pdsurf->dt = DT_SCREEN; // Not to be confused with a DIB DFB
  345. pdsurf->sizl.cx = ppdev->cxScreen;
  346. pdsurf->sizl.cy = ppdev->cyScreen;
  347. pdsurf->ppdev = ppdev;
  348. /////////////////////////////////////////////////////////////////////
  349. // Next, have GDI create the actual SURFOBJ.
  350. //
  351. // Our drawing surface is going to be 'device-managed', meaning that
  352. // GDI cannot draw on the framebuffer bits directly, and as such we
  353. // create the surface via EngCreateDeviceSurface. By doing this, we ensure
  354. // that GDI will only ever access the bitmaps bits via the Drv calls
  355. // that we've HOOKed.
  356. //
  357. // If we could map the entire framebuffer linearly into main memory
  358. // (i.e., we didn't have to go through a 64k aperture), it would be
  359. // beneficial to create the surface via EngCreateBitmap, giving GDI a
  360. // pointer to the framebuffer bits. When we pass a call on to GDI
  361. // where it can't directly read/write to the surface bits because the
  362. // surface is device managed, it has to create a temporary bitmap and
  363. // call our DrvCopyBits routine to get/set a copy of the affected bits.
  364. // Fer example, the OpenGl component prefers to be able to write on the
  365. // framebuffer bits directly.
  366. sizl.cx = ppdev->cxScreen;
  367. sizl.cy = ppdev->cyScreen;
  368. hsurf = EngCreateDeviceSurface((DHSURF) pdsurf, sizl, ppdev->iBitmapFormat);
  369. if (hsurf == 0)
  370. {
  371. DISPDBG((0, "DrvEnableSurface - Failed EngCreateDeviceSurface"));
  372. goto ReturnFailure;
  373. }
  374. ppdev->hsurfScreen = hsurf; // Remember it for clean-up
  375. ppdev->bEnabled = TRUE; // We'll soon be in graphics mode
  376. /////////////////////////////////////////////////////////////////////
  377. // Now associate the surface and the PDEV.
  378. //
  379. // We have to associate the surface we just created with our physical
  380. // device so that it works.
  381. //
  382. if (!EngAssociateSurface(hsurf, ppdev->hdevEng, ppdev->flHooks))
  383. {
  384. DISPDBG((0, "DrvEnableSurface - Failed EngAssociateSurface"));
  385. goto ReturnFailure;
  386. }
  387. // Create our generic temporary buffer, which may be used by any
  388. // component. Because this may get swapped out of memory any time
  389. // the driver is not active, we want to minimize the number of pages
  390. // it takes up. We use 'VirtualAlloc' to get an exactly page-aligned
  391. // allocation (which 'EngAllocMem' will not do):
  392. pvTmpBuffer = EngAllocMem(0, TMP_BUFFER_SIZE, ALLOC_TAG);
  393. if (pvTmpBuffer == NULL)
  394. {
  395. DISPDBG((0, "DrvEnableSurface - Failed EngAllocMem"));
  396. goto ReturnFailure;
  397. }
  398. ppdev->pvTmpBuffer = pvTmpBuffer;
  399. /////////////////////////////////////////////////////////////////////
  400. // Now enable all the subcomponents.
  401. //
  402. // Note that the order in which these 'Enable' functions are called
  403. // may be significant in low off-screen memory conditions, because
  404. // the off-screen heap manager may fail some of the later
  405. // allocations...
  406. // NOTE: It isn't until bEnableHardware that cyMemory is correctly set.
  407. if (!bEnableHardware(ppdev))
  408. goto ReturnFailure;
  409. if (!bEnableOffscreenHeap(ppdev))
  410. goto ReturnFailure;
  411. if (!bEnablePointer(ppdev))
  412. goto ReturnFailure;
  413. if (!bEnableText(ppdev))
  414. goto ReturnFailure;
  415. if (!bEnableBrushCache(ppdev))
  416. goto ReturnFailure;
  417. if (!bEnablePalette(ppdev))
  418. goto ReturnFailure;
  419. DISPDBG((5, "Passed DrvEnableSurface"));
  420. return(hsurf);
  421. ReturnFailure:
  422. DrvDisableSurface((DHPDEV) ppdev);
  423. DISPDBG((0, "Failed DrvEnableSurface"));
  424. return(0);
  425. }
  426. /******************************Public*Routine******************************\
  427. * VOID DrvDisableSurface
  428. *
  429. * Free resources allocated by DrvEnableSurface. Release the surface.
  430. *
  431. * Note: In an error case, we may call this before DrvEnableSurface is
  432. * completely done.
  433. *
  434. \**************************************************************************/
  435. VOID DrvDisableSurface(
  436. DHPDEV dhpdev)
  437. {
  438. PDEV* ppdev;
  439. ppdev = (PDEV*) dhpdev;
  440. // Note: In an error case, some of the following relies on the
  441. // fact that the PDEV is zero-initialized, so fields like
  442. // 'hsurfScreen' will be zero unless the surface has been
  443. // sucessfully initialized, and makes the assumption that
  444. // EngDeleteSurface can take '0' as a parameter.
  445. vDisablePalette(ppdev);
  446. vDisableBrushCache(ppdev);
  447. vDisableText(ppdev);
  448. vDisablePointer(ppdev);
  449. vDisableOffscreenHeap(ppdev);
  450. vDisableHardware(ppdev);
  451. EngFreeMem(ppdev->pvTmpBuffer);
  452. EngDeleteSurface(ppdev->hsurfScreen);
  453. EngFreeMem(ppdev->pdsurfScreen);
  454. }
  455. /******************************Public*Routine******************************\
  456. * VOID DrvAssertMode
  457. *
  458. * This asks the device to reset itself to the mode of the pdev passed in.
  459. *
  460. \**************************************************************************/
  461. BOOL DrvAssertMode(
  462. DHPDEV dhpdev,
  463. BOOL bEnable)
  464. {
  465. PDEV* ppdev;
  466. ppdev = (PDEV*) dhpdev;
  467. if (!bEnable)
  468. {
  469. //////////////////////////////////////////////////////////////
  470. // Disable - Switch to full-screen mode
  471. vAssertModePalette(ppdev, FALSE);
  472. vAssertModeBrushCache(ppdev, FALSE);
  473. vAssertModeText(ppdev, FALSE);
  474. vAssertModePointer(ppdev, FALSE);
  475. if (bAssertModeOffscreenHeap(ppdev, FALSE))
  476. {
  477. if (bAssertModeHardware(ppdev, FALSE))
  478. {
  479. ppdev->bEnabled = FALSE;
  480. return(TRUE);
  481. }
  482. //////////////////////////////////////////////////////////
  483. // We failed to switch to full-screen. So undo everything:
  484. bAssertModeOffscreenHeap(ppdev, TRUE); // We don't need to check
  485. } // return code with TRUE
  486. vAssertModePointer(ppdev, TRUE);
  487. vAssertModeText(ppdev, TRUE);
  488. vAssertModeBrushCache(ppdev, TRUE);
  489. vAssertModePalette(ppdev, TRUE);
  490. }
  491. else
  492. {
  493. //////////////////////////////////////////////////////////////
  494. // Enable - Switch back to graphics mode
  495. // We have to enable every subcomponent in the reverse order
  496. // in which it was disabled:
  497. if (bAssertModeHardware(ppdev, TRUE))
  498. {
  499. bAssertModeOffscreenHeap(ppdev, TRUE); // We don't need to check
  500. // return code with TRUE
  501. vAssertModePointer(ppdev, TRUE);
  502. vAssertModeText(ppdev, TRUE);
  503. vAssertModeBrushCache(ppdev, TRUE);
  504. vAssertModePalette(ppdev, TRUE);
  505. ppdev->bEnabled = TRUE;
  506. return(TRUE);
  507. }
  508. }
  509. return(FALSE);
  510. }
  511. /******************************Public*Routine******************************\
  512. * ULONG DrvGetModes
  513. *
  514. * Returns the list of available modes for the device.
  515. *
  516. \**************************************************************************/
  517. ULONG DrvGetModes(
  518. HANDLE hDriver,
  519. ULONG cjSize,
  520. DEVMODEW* pdm)
  521. {
  522. DWORD cModes;
  523. DWORD cbOutputSize;
  524. PVIDEO_MODE_INFORMATION pVideoModeInformation;
  525. PVIDEO_MODE_INFORMATION pVideoTemp;
  526. DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  527. DWORD cbModeSize;
  528. cModes = getAvailableModes(hDriver,
  529. (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
  530. &cbModeSize);
  531. if (cModes == 0)
  532. {
  533. DISPDBG((0, "DrvGetModes failed to get mode information"));
  534. return(0);
  535. }
  536. if (pdm == NULL)
  537. {
  538. cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  539. }
  540. else
  541. {
  542. //
  543. // Now copy the information for the supported modes back into the
  544. // output buffer
  545. //
  546. cbOutputSize = 0;
  547. pVideoTemp = pVideoModeInformation;
  548. do
  549. {
  550. if (pVideoTemp->Length != 0)
  551. {
  552. if (cOutputModes == 0)
  553. {
  554. break;
  555. }
  556. //
  557. // Zero the entire structure to start off with.
  558. //
  559. memset(pdm, 0, sizeof(DEVMODEW));
  560. //
  561. // Set the name of the device to the name of the DLL.
  562. //
  563. memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
  564. pdm->dmSpecVersion = DM_SPECVERSION;
  565. pdm->dmDriverVersion = DM_SPECVERSION;
  566. pdm->dmSize = sizeof(DEVMODEW);
  567. pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
  568. pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
  569. pVideoTemp->BitsPerPlane;
  570. pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
  571. pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
  572. pdm->dmDisplayFrequency = pVideoTemp->Frequency;
  573. pdm->dmDisplayFlags = 0;
  574. pdm->dmFields = DM_BITSPERPEL |
  575. DM_PELSWIDTH |
  576. DM_PELSHEIGHT |
  577. DM_DISPLAYFREQUENCY |
  578. DM_DISPLAYFLAGS ;
  579. //
  580. // Go to the next DEVMODE entry in the buffer.
  581. //
  582. cOutputModes--;
  583. pdm = (LPDEVMODEW) ( ((ULONG)pdm) + sizeof(DEVMODEW) +
  584. DRIVER_EXTRA_SIZE);
  585. cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  586. }
  587. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  588. (((PUCHAR)pVideoTemp) + cbModeSize);
  589. } while (--cModes);
  590. }
  591. EngFreeMem(pVideoModeInformation);
  592. return(cbOutputSize);
  593. }
  594. /******************************Public*Routine******************************\
  595. * BOOL bAssertModeHardware
  596. *
  597. * Sets the appropriate hardware state for graphics mode or full-screen.
  598. *
  599. \**************************************************************************/
  600. BOOL bAssertModeHardware(
  601. PDEV* ppdev,
  602. BOOL bEnable)
  603. {
  604. DWORD ReturnedDataLength;
  605. ULONG ulReturn;
  606. if (bEnable)
  607. {
  608. // Call the miniport via an IOCTL to set the graphics mode.
  609. if (EngDeviceIoControl(ppdev->hDriver,
  610. IOCTL_VIDEO_SET_CURRENT_MODE,
  611. &ppdev->ulMode, // input buffer
  612. sizeof(DWORD),
  613. NULL,
  614. 0,
  615. &ReturnedDataLength))
  616. {
  617. DISPDBG((0, "bAssertModeHardware - Failed set IOCTL"));
  618. return FALSE;
  619. }
  620. // Then set the rest of the default registers:
  621. vResetClipping(ppdev);
  622. IO_FIFO_WAIT(ppdev, 1);
  623. IO_WRT_MASK(ppdev, -1);
  624. }
  625. else
  626. {
  627. // Call the kernel driver to reset the device to a known state.
  628. // NTVDM will take things from there:
  629. if (EngDeviceIoControl(ppdev->hDriver,
  630. IOCTL_VIDEO_RESET_DEVICE,
  631. NULL,
  632. 0,
  633. NULL,
  634. 0,
  635. &ulReturn))
  636. {
  637. DISPDBG((0, "bAssertModeHardware - Failed reset IOCTL"));
  638. return FALSE;
  639. }
  640. }
  641. DISPDBG((5, "Passed bAssertModeHardware"));
  642. return(TRUE);
  643. }
  644. /******************************Public*Routine******************************\
  645. * BOOL bAtiAccelerator
  646. *
  647. * Returns TRUE if we're running on a Mach8 or compatible accelerator.
  648. * This algorithm was taken from "Programmer's Guide to the Mach-8 Extended
  649. * Registers Supplement," 1992, ATI Technologies Inc, p. 5-2.
  650. *
  651. * It seems like a pretty goofy test to me, but it's what they prescribe
  652. * to 'specifically detect an ATI accelerator product.'
  653. *
  654. \**************************************************************************/
  655. BOOL bAtiAccelerator(
  656. PDEV* ppdev)
  657. {
  658. ULONG ulSave;
  659. BOOL bAti;
  660. bAti = FALSE;
  661. ulSave = INPW(0x52ee);
  662. OUTPW(0x52ee, 0x5555);
  663. IO_GP_WAIT(ppdev);
  664. if (INPW(0x52ee) == 0x5555)
  665. {
  666. OUTPW(0x52ee, 0x2a2a);
  667. IO_GP_WAIT(ppdev);
  668. if (INPW(0x52ee) == 0x2a2a)
  669. {
  670. bAti = TRUE;
  671. }
  672. }
  673. // Restore the register's original contents:
  674. OUTPW(0x52ee, ulSave);
  675. return(bAti);
  676. }
  677. /******************************Public*Routine******************************\
  678. * BOOL bEnableHardware
  679. *
  680. * Puts the hardware in the requested mode and initializes it. Also
  681. * sets ppdev->cyMemory.
  682. *
  683. \**************************************************************************/
  684. BOOL bEnableHardware(
  685. PDEV* ppdev)
  686. {
  687. VIDEO_MEMORY VideoMemory;
  688. VIDEO_MEMORY_INFORMATION VideoMemoryInfo;
  689. DWORD ReturnedDataLength;
  690. // Set all the register addresses (to allow easier porting of code
  691. // from the S3):
  692. ppdev->ioCur_y = CUR_Y;
  693. ppdev->ioCur_x = CUR_X;
  694. ppdev->ioDesty_axstp = DEST_Y;
  695. ppdev->ioDestx_diastp = DEST_X;
  696. ppdev->ioErr_term = ERR_TERM;
  697. ppdev->ioMaj_axis_pcnt = MAJ_AXIS_PCNT;
  698. ppdev->ioGp_stat_cmd = CMD;
  699. ppdev->ioShort_stroke = SHORT_STROKE;
  700. ppdev->ioBkgd_color = BKGD_COLOR;
  701. ppdev->ioFrgd_color = FRGD_COLOR;
  702. ppdev->ioWrt_mask = WRT_MASK;
  703. ppdev->ioRd_mask = RD_MASK;
  704. ppdev->ioColor_cmp = COLOR_CMP;
  705. ppdev->ioBkgd_mix = BKGD_MIX;
  706. ppdev->ioFrgd_mix = FRGD_MIX;
  707. ppdev->ioMulti_function = MULTIFUNC_CNTL;
  708. ppdev->ioPix_trans = PIX_TRANS;
  709. // Now we can set the mode, unlock the accelerator, and reset the
  710. // clipping:
  711. if (!bAssertModeHardware(ppdev, TRUE))
  712. goto ReturnFalse;
  713. // Get the linear memory address range.
  714. VideoMemory.RequestedVirtualAddress = NULL;
  715. // About this IOCTL_VIDEO_MAP_VIDEO_MEMORY call.
  716. //
  717. // Since we're an 8514/A driver, we don't care squat about any stinking
  718. // frame buffer mapping. The only reason we're calling this IOCTL
  719. // is because we may be running as an 8514/A using the ATI miniport.
  720. // And this IOCTL is the only way to get the ATI miniport to return
  721. // the total number of scans of video memory. 'cyMemory' is needed
  722. // so we can take advantage of as much off-screen memory as possible
  723. // for the 2-d heap. It's also conceivable that we're running at
  724. // 640x480x256 using the ATI miniport on a 512k card, in which case
  725. // we can't just assume that 'cyMemory' was 1024.
  726. //
  727. // So all we're interested in is the 'VideoRamLength' field returned
  728. // in 'VideoMemoryInfo'. Currently, any other side effects of
  729. // making this call with the ATI miniport (such as the actual memory
  730. // mapping) are inoccuous, and hopefully this will remain to be so in
  731. // future ATI miniports.
  732. //
  733. // If we're running with the 8514/A miniport, this call does nothing
  734. // but return 1 meg for the 'FrameLength' size:
  735. if (EngDeviceIoControl(ppdev->hDriver,
  736. IOCTL_VIDEO_MAP_VIDEO_MEMORY,
  737. &VideoMemory, // input buffer
  738. sizeof(VIDEO_MEMORY),
  739. &VideoMemoryInfo, // output buffer
  740. sizeof(VideoMemoryInfo),
  741. &ReturnedDataLength))
  742. {
  743. DISPDBG((0, "bEnableHardware - Error mapping buffer address"));
  744. goto ReturnFalse;
  745. }
  746. // All we were interested in is 'VideoMemoryInfo', so unmap the buffer
  747. // straight away:
  748. VideoMemory.RequestedVirtualAddress = VideoMemoryInfo.FrameBufferBase;
  749. EngDeviceIoControl(ppdev->hDriver,
  750. IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
  751. &VideoMemory,
  752. sizeof(VIDEO_MEMORY),
  753. NULL,
  754. 0,
  755. &ReturnedDataLength);
  756. // Note that 8514/A registers cannot handle coordinates any larger
  757. // than 1535:
  758. ppdev->cyMemory = VideoMemoryInfo.VideoRamLength / ppdev->lDelta;
  759. ppdev->cyMemory = min(ppdev->cyMemory, 1535);
  760. DISPDBG((0, "Memory size %li x %li.", ppdev->cxMemory, ppdev->cyMemory));
  761. // Set up the jump vectors to our low-level blt routines (which ones are
  762. // used depends on whether we can do memory-mapped IO or not):
  763. // Have to do IN/OUTs:
  764. ppdev->pfnFillSolid = vIoFillSolid;
  765. ppdev->pfnFillPat = vIoFillPatSlow;
  766. ppdev->pfnXfer4bpp = vIoXfer4bpp;
  767. ppdev->pfnXferNative = vIoXferNative;
  768. ppdev->pfnCopyBlt = vIoCopyBlt;
  769. ppdev->pfnFastLine = vIoFastLine;
  770. ppdev->pfnFastFill = bIoFastFill;
  771. if (!bAtiAccelerator(ppdev))
  772. {
  773. ppdev->pfnXfer1bpp = vIoXfer1bpp;
  774. }
  775. else
  776. {
  777. DISPDBG((0, "ATI extensions enabled."));
  778. // Disable vIoMaskCopy() for fixing bug 143531.
  779. // ppdev->flCaps |= CAPS_MASKBLT_CAPABLE;
  780. ppdev->pfnMaskCopy = vIoMaskCopy;
  781. ppdev->pfnXfer1bpp = vIoXfer1bppPacked;
  782. }
  783. DISPDBG((5, "Passed bEnableHardware"));
  784. return(TRUE);
  785. ReturnFalse:
  786. DISPDBG((0, "Failed bEnableHardware"));
  787. return(FALSE);
  788. }
  789. /******************************Public*Routine******************************\
  790. * VOID vDisableHardware
  791. *
  792. * Undoes anything done in bEnableHardware.
  793. *
  794. * Note: In an error case, we may call this before bEnableHardware is
  795. * completely done.
  796. *
  797. \**************************************************************************/
  798. VOID vDisableHardware(
  799. PDEV* ppdev)
  800. {
  801. }
  802. /******************************Public*Routine******************************\
  803. * BOOL bDetect8514A
  804. *
  805. * Detects whether or not an 8514/A compatible adapter is present.
  806. *
  807. * This code was stolen from the 8514/A miniport. It simply checks to see
  808. * if the line-drawing error term register is readable/writable.
  809. *
  810. \**************************************************************************/
  811. BOOL bDetect8514A()
  812. {
  813. USHORT SubSysCntlRegisterValue;
  814. USHORT ErrTermRegisterValue;
  815. USHORT ErrTerm5555;
  816. USHORT ErrTermAAAA;
  817. BOOL b8514A;
  818. //
  819. // Remember the original value of any registers we'll muck with.
  820. //
  821. SubSysCntlRegisterValue = INPW(SUBSYS_CNTL);
  822. ErrTermRegisterValue = INPW(ERR_TERM);
  823. //
  824. // Reset the draw engine.
  825. //
  826. OUTPW(SUBSYS_CNTL, 0x9000);
  827. OUTPW(SUBSYS_CNTL, 0x5000);
  828. //
  829. // We detect an 8514/A by writing a value to the error term register,
  830. // and reading it back to see if it's the same value we wrote.
  831. //
  832. OUTPW(ERR_TERM, 0x5555);
  833. ErrTerm5555 = INPW(ERR_TERM);
  834. OUTPW(ERR_TERM, 0xAAAA);
  835. ErrTermAAAA = INPW(ERR_TERM);
  836. b8514A = ((ErrTerm5555 == 0x5555) && (ErrTermAAAA == 0xAAAA));
  837. //
  838. // Now that we're done mucking with the hardware state, we have to
  839. // restore everything to the way it was.
  840. //
  841. OUTPW(ERR_TERM, ErrTermRegisterValue);
  842. //
  843. // Since the SUBSYS_CNTL register is not readable on a true 8514/A,
  844. // don't try to restore it:
  845. //
  846. if (!b8514A)
  847. {
  848. OUTPW(SUBSYS_CNTL, SubSysCntlRegisterValue);
  849. }
  850. return(b8514A);
  851. }
  852. /******************************Public*Routine******************************\
  853. * BOOL bInitializeModeFields
  854. *
  855. * Initializes a bunch of fields in the pdev, devcaps (aka gdiinfo), and
  856. * devinfo based on the requested mode.
  857. *
  858. \**************************************************************************/
  859. BOOL bInitializeModeFields(
  860. PDEV* ppdev,
  861. GDIINFO* pgdi,
  862. DEVINFO* pdi,
  863. DEVMODEW* pdm)
  864. {
  865. ULONG cModes;
  866. PVIDEO_MODE_INFORMATION pVideoBuffer;
  867. PVIDEO_MODE_INFORMATION pVideoModeSelected;
  868. PVIDEO_MODE_INFORMATION pVideoTemp;
  869. BOOL bSelectDefault;
  870. VIDEO_MODE_INFORMATION VideoModeInformation;
  871. ULONG cbModeSize;
  872. // Verify that we have an 8514/A display. We do this because we can
  873. // work with the ATI miniport, which supports some cards (notably the
  874. // Mach64) that aren't 8514/A compatible.
  875. if (!bDetect8514A())
  876. {
  877. DISPDBG((0, "bInitializeModeFields - 8514/A not detected"));
  878. goto ReturnFalse;
  879. }
  880. // Call the miniport to get mode information
  881. cModes = getAvailableModes(ppdev->hDriver, &pVideoBuffer, &cbModeSize);
  882. if (cModes == 0)
  883. goto ReturnFalse;
  884. // Now see if the requested mode has a match in that table.
  885. pVideoModeSelected = NULL;
  886. pVideoTemp = pVideoBuffer;
  887. if ((pdm->dmPelsWidth == 0) &&
  888. (pdm->dmPelsHeight == 0) &&
  889. (pdm->dmBitsPerPel == 0) &&
  890. (pdm->dmDisplayFrequency == 0))
  891. {
  892. DISPDBG((1, "Default mode requested"));
  893. bSelectDefault = TRUE;
  894. }
  895. else
  896. {
  897. DISPDBG((1, "Requested mode..."));
  898. DISPDBG((1, " Screen width -- %li", pdm->dmPelsWidth));
  899. DISPDBG((1, " Screen height -- %li", pdm->dmPelsHeight));
  900. DISPDBG((1, " Bits per pel -- %li", pdm->dmBitsPerPel));
  901. DISPDBG((1, " Frequency -- %li", pdm->dmDisplayFrequency));
  902. bSelectDefault = FALSE;
  903. }
  904. while (cModes--)
  905. {
  906. if (pVideoTemp->Length != 0)
  907. {
  908. DISPDBG((2, " Checking against miniport mode:"));
  909. DISPDBG((2, " Screen width -- %li", pVideoTemp->VisScreenWidth));
  910. DISPDBG((2, " Screen height -- %li", pVideoTemp->VisScreenHeight));
  911. DISPDBG((2, " Bits per pel -- %li", pVideoTemp->BitsPerPlane *
  912. pVideoTemp->NumberOfPlanes));
  913. DISPDBG((2, " Frequency -- %li", pVideoTemp->Frequency));
  914. if (bSelectDefault ||
  915. ((pVideoTemp->VisScreenWidth == pdm->dmPelsWidth) &&
  916. (pVideoTemp->VisScreenHeight == pdm->dmPelsHeight) &&
  917. (pVideoTemp->BitsPerPlane *
  918. pVideoTemp->NumberOfPlanes == pdm->dmBitsPerPel) &&
  919. (pVideoTemp->Frequency == pdm->dmDisplayFrequency)))
  920. {
  921. pVideoModeSelected = pVideoTemp;
  922. DISPDBG((1, "...Found a mode match!"));
  923. break;
  924. }
  925. }
  926. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  927. (((PUCHAR)pVideoTemp) + cbModeSize);
  928. }
  929. // If no mode has been found, return an error
  930. if (pVideoModeSelected == NULL)
  931. {
  932. DISPDBG((1, "...Couldn't find a mode match!"));
  933. EngFreeMem(pVideoBuffer);
  934. goto ReturnFalse;
  935. }
  936. // We have chosen the one we want. Save it in a stack buffer and
  937. // get rid of allocated memory before we forget to free it.
  938. VideoModeInformation = *pVideoModeSelected;
  939. EngFreeMem(pVideoBuffer);
  940. #if DEBUG_HEAP
  941. VideoModeInformation.VisScreenWidth = 640;
  942. VideoModeInformation.VisScreenHeight = 480;
  943. #endif
  944. // Set up screen information from the mini-port:
  945. ppdev->ulMode = VideoModeInformation.ModeIndex;
  946. ppdev->cxScreen = VideoModeInformation.VisScreenWidth;
  947. ppdev->cyScreen = VideoModeInformation.VisScreenHeight;
  948. ppdev->lDelta = VideoModeInformation.ScreenStride;
  949. ppdev->flCaps = 0; // We've have no capabilities
  950. // Note that 8514/A registers cannot handle coordinates any larger
  951. // than 1535:
  952. ppdev->cxMemory = min(VideoModeInformation.ScreenStride, 1535);
  953. // Note: We compute 'cyMemory' later at DrvEnableSurface time. For now,
  954. // set cyMemory to an interesting value to aid in debugging:
  955. ppdev->cyMemory = 0xdeadbeef;
  956. DISPDBG((1, "ScreenStride: %lx", VideoModeInformation.ScreenStride));
  957. ppdev->flHooks = (HOOK_BITBLT |
  958. HOOK_TEXTOUT |
  959. HOOK_FILLPATH |
  960. HOOK_COPYBITS |
  961. HOOK_STROKEPATH |
  962. HOOK_PAINT |
  963. HOOK_STRETCHBLT);
  964. // Fill in the GDIINFO data structure with the default 8bpp values:
  965. *pgdi = ggdiDefault;
  966. // Now overwrite the defaults with the relevant information returned
  967. // from the kernel driver:
  968. pgdi->ulHorzSize = VideoModeInformation.XMillimeter;
  969. pgdi->ulVertSize = VideoModeInformation.YMillimeter;
  970. pgdi->ulHorzRes = VideoModeInformation.VisScreenWidth;
  971. pgdi->ulVertRes = VideoModeInformation.VisScreenHeight;
  972. pgdi->ulPanningHorzRes = VideoModeInformation.VisScreenWidth;
  973. pgdi->ulPanningVertRes = VideoModeInformation.VisScreenHeight;
  974. pgdi->cBitsPixel = VideoModeInformation.BitsPerPlane;
  975. pgdi->cPlanes = VideoModeInformation.NumberOfPlanes;
  976. pgdi->ulVRefresh = VideoModeInformation.Frequency;
  977. pgdi->ulDACRed = VideoModeInformation.NumberRedBits;
  978. pgdi->ulDACGreen = VideoModeInformation.NumberGreenBits;
  979. pgdi->ulDACBlue = VideoModeInformation.NumberBlueBits;
  980. pgdi->ulLogPixelsX = pdm->dmLogPixels;
  981. pgdi->ulLogPixelsY = pdm->dmLogPixels;
  982. // Fill in the devinfo structure with the default 8bpp values:
  983. *pdi = gdevinfoDefault;
  984. ppdev->cPelSize = 0;
  985. ppdev->iBitmapFormat = BMF_8BPP;
  986. ppdev->ulWhite = 0xff;
  987. // Assuming palette is orthogonal - all colors are same size.
  988. ppdev->cPaletteShift = 8 - pgdi->ulDACRed;
  989. DISPDBG((5, "Passed bInitializeModeFields"));
  990. return(TRUE);
  991. ReturnFalse:
  992. DISPDBG((0, "Failed bInitializeModeFields"));
  993. return(FALSE);
  994. }
  995. /******************************Public*Routine******************************\
  996. * DWORD getAvailableModes
  997. *
  998. * Calls the miniport to get the list of modes supported by the kernel driver,
  999. * and returns the list of modes supported by the diplay driver among those
  1000. *
  1001. * returns the number of entries in the videomode buffer.
  1002. * 0 means no modes are supported by the miniport or that an error occured.
  1003. *
  1004. * NOTE: the buffer must be freed up by the caller.
  1005. *
  1006. \**************************************************************************/
  1007. DWORD getAvailableModes(
  1008. HANDLE hDriver,
  1009. PVIDEO_MODE_INFORMATION* modeInformation,
  1010. DWORD* cbModeSize)
  1011. {
  1012. ULONG ulTemp;
  1013. VIDEO_NUM_MODES modes;
  1014. PVIDEO_MODE_INFORMATION pVideoTemp;
  1015. //
  1016. // Get the number of modes supported by the mini-port
  1017. //
  1018. if (EngDeviceIoControl(hDriver,
  1019. IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
  1020. NULL,
  1021. 0,
  1022. &modes,
  1023. sizeof(VIDEO_NUM_MODES),
  1024. &ulTemp))
  1025. {
  1026. DISPDBG((0, "getAvailableModes - Failed VIDEO_QUERY_NUM_AVAIL_MODES"));
  1027. return(0);
  1028. }
  1029. *cbModeSize = modes.ModeInformationLength;
  1030. //
  1031. // Allocate the buffer for the mini-port to write the modes in.
  1032. //
  1033. *modeInformation = (PVIDEO_MODE_INFORMATION)
  1034. EngAllocMem(FL_ZERO_MEMORY,
  1035. modes.NumModes *
  1036. modes.ModeInformationLength, ALLOC_TAG);
  1037. if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
  1038. {
  1039. DISPDBG((0, "getAvailableModes - Failed EngAllocMem"));
  1040. return 0;
  1041. }
  1042. //
  1043. // Ask the mini-port to fill in the available modes.
  1044. //
  1045. if (EngDeviceIoControl(hDriver,
  1046. IOCTL_VIDEO_QUERY_AVAIL_MODES,
  1047. NULL,
  1048. 0,
  1049. *modeInformation,
  1050. modes.NumModes * modes.ModeInformationLength,
  1051. &ulTemp))
  1052. {
  1053. DISPDBG((0, "getAvailableModes - Failed VIDEO_QUERY_AVAIL_MODES"));
  1054. EngFreeMem(*modeInformation);
  1055. *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
  1056. return(0);
  1057. }
  1058. //
  1059. // Now see which of these modes are supported by the display driver.
  1060. // As an internal mechanism, set the length to 0 for the modes we
  1061. // DO NOT support.
  1062. //
  1063. ulTemp = modes.NumModes;
  1064. pVideoTemp = *modeInformation;
  1065. //
  1066. // Mode is rejected if it is not one plane, or not graphics, or is not
  1067. // 8 bits per pel.
  1068. //
  1069. while (ulTemp--)
  1070. {
  1071. if ((pVideoTemp->NumberOfPlanes != 1 ) ||
  1072. !(pVideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
  1073. (pVideoTemp->BitsPerPlane != 8))
  1074. {
  1075. DISPDBG((2, "Rejecting miniport mode:"));
  1076. DISPDBG((2, " Screen width -- %li", pVideoTemp->VisScreenWidth));
  1077. DISPDBG((2, " Screen height -- %li", pVideoTemp->VisScreenHeight));
  1078. DISPDBG((2, " Bits per pel -- %li", pVideoTemp->BitsPerPlane *
  1079. pVideoTemp->NumberOfPlanes));
  1080. DISPDBG((2, " Frequency -- %li", pVideoTemp->Frequency));
  1081. pVideoTemp->Length = 0;
  1082. }
  1083. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  1084. (((PUCHAR)pVideoTemp) + modes.ModeInformationLength);
  1085. }
  1086. return(modes.NumModes);
  1087. }