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.

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