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.

1390 lines
47 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-1995 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
  71. 0, // ulBltAlignment
  72. 0, // ulPanningHorzRes
  73. 0, // ulPanningVertRes
  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 MULTI_BOARDS
  128. // Multi-board support has its own thunks...
  129. DRVFN gadrvfn[] = {
  130. { INDEX_DrvEnablePDEV, (PFN) MulEnablePDEV },
  131. { INDEX_DrvCompletePDEV, (PFN) MulCompletePDEV },
  132. { INDEX_DrvDisablePDEV, (PFN) MulDisablePDEV },
  133. { INDEX_DrvEnableSurface, (PFN) MulEnableSurface },
  134. { INDEX_DrvDisableSurface, (PFN) MulDisableSurface },
  135. { INDEX_DrvAssertMode, (PFN) MulAssertMode },
  136. { INDEX_DrvMovePointer, (PFN) MulMovePointer },
  137. { INDEX_DrvSetPointerShape, (PFN) MulSetPointerShape },
  138. { INDEX_DrvDitherColor, (PFN) MulDitherColor },
  139. { INDEX_DrvSetPalette, (PFN) MulSetPalette },
  140. { INDEX_DrvCopyBits, (PFN) MulCopyBits },
  141. { INDEX_DrvBitBlt, (PFN) MulBitBlt },
  142. { INDEX_DrvTextOut, (PFN) MulTextOut },
  143. { INDEX_DrvGetModes, (PFN) MulGetModes },
  144. { INDEX_DrvStrokePath, (PFN) MulStrokePath },
  145. { INDEX_DrvFillPath, (PFN) MulFillPath },
  146. { INDEX_DrvPaint, (PFN) MulPaint },
  147. { INDEX_DrvRealizeBrush, (PFN) MulRealizeBrush },
  148. { INDEX_DrvDestroyFont, (PFN) MulDestroyFont },
  149. // Note that DrvCreateDeviceBitmap is not supported for multi-boards
  150. // Note that DrvDeleteDeviceBitmap is not supported for multi-boards
  151. // Note that DrvStretchBlt is not supported for multi-boards
  152. // Note that DrvEscape is not supported for multi-boards
  153. };
  154. #elif DBG || !SYNCHRONIZEACCESS_WORKS
  155. // On Checked builds, or when we have to synchronize access, thunk
  156. // everything through Dbg calls...
  157. DRVFN gadrvfn[] = {
  158. { INDEX_DrvEnablePDEV, (PFN) DbgEnablePDEV },
  159. { INDEX_DrvCompletePDEV, (PFN) DbgCompletePDEV },
  160. { INDEX_DrvDisablePDEV, (PFN) DbgDisablePDEV },
  161. { INDEX_DrvEnableSurface, (PFN) DbgEnableSurface },
  162. { INDEX_DrvDisableSurface, (PFN) DbgDisableSurface },
  163. { INDEX_DrvAssertMode, (PFN) DbgAssertMode },
  164. { INDEX_DrvMovePointer, (PFN) DbgMovePointer },
  165. { INDEX_DrvSetPointerShape, (PFN) DbgSetPointerShape },
  166. { INDEX_DrvDitherColor, (PFN) DbgDitherColor },
  167. { INDEX_DrvSetPalette, (PFN) DbgSetPalette },
  168. { INDEX_DrvCopyBits, (PFN) DbgCopyBits },
  169. { INDEX_DrvBitBlt, (PFN) DbgBitBlt },
  170. { INDEX_DrvTextOut, (PFN) DbgTextOut },
  171. { INDEX_DrvGetModes, (PFN) DbgGetModes },
  172. { INDEX_DrvStrokePath, (PFN) DbgStrokePath },
  173. { INDEX_DrvFillPath, (PFN) DbgFillPath },
  174. { INDEX_DrvPaint, (PFN) DbgPaint },
  175. { INDEX_DrvRealizeBrush, (PFN) DbgRealizeBrush },
  176. { INDEX_DrvCreateDeviceBitmap, (PFN) DbgCreateDeviceBitmap },
  177. { INDEX_DrvDeleteDeviceBitmap, (PFN) DbgDeleteDeviceBitmap },
  178. { INDEX_DrvStretchBlt, (PFN) DbgStretchBlt },
  179. { INDEX_DrvEscape, (PFN) DbgEscape },
  180. { INDEX_DrvDestroyFont, (PFN) DbgDestroyFont },
  181. };
  182. #else
  183. // On Free builds, directly call the appropriate functions...
  184. DRVFN gadrvfn[] = {
  185. { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
  186. { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
  187. { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
  188. { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
  189. { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
  190. { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
  191. { INDEX_DrvMovePointer, (PFN) DrvMovePointer },
  192. { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape },
  193. { INDEX_DrvDitherColor, (PFN) DrvDitherColor },
  194. { INDEX_DrvSetPalette, (PFN) DrvSetPalette },
  195. { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
  196. { INDEX_DrvBitBlt, (PFN) DrvBitBlt },
  197. { INDEX_DrvTextOut, (PFN) DrvTextOut },
  198. { INDEX_DrvGetModes, (PFN) DrvGetModes },
  199. { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
  200. { INDEX_DrvFillPath, (PFN) DrvFillPath },
  201. { INDEX_DrvPaint, (PFN) DrvPaint },
  202. { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush },
  203. { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap },
  204. { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap },
  205. { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt },
  206. { INDEX_DrvEscape, (PFN) DrvEscape },
  207. { INDEX_DrvDestroyFont, (PFN) DrvDestroyFont },
  208. };
  209. #endif
  210. ULONG gcdrvfn = sizeof(gadrvfn) / sizeof(DRVFN);
  211. /******************************Public*Routine******************************\
  212. * BOOL DrvEnableDriver
  213. *
  214. * Enables the driver by retrieving the drivers function table and version.
  215. *
  216. \**************************************************************************/
  217. BOOL DrvEnableDriver(
  218. ULONG iEngineVersion,
  219. ULONG cj,
  220. DRVENABLEDATA* pded)
  221. {
  222. // Engine Version is passed down so future drivers can support previous
  223. // engine versions. A next generation driver can support both the old
  224. // and new engine conventions if told what version of engine it is
  225. // working with. For the first version the driver does nothing with it.
  226. // Fill in as much as we can.
  227. if (cj >= sizeof(DRVENABLEDATA))
  228. pded->pdrvfn = gadrvfn;
  229. if (cj >= (sizeof(ULONG) * 2))
  230. pded->c = gcdrvfn;
  231. // DDI version this driver was targeted for is passed back to engine.
  232. // Future graphic's engine may break calls down to old driver format.
  233. if (cj >= sizeof(ULONG))
  234. pded->iDriverVersion = DDI_DRIVER_VERSION;
  235. return(TRUE);
  236. }
  237. /******************************Public*Routine******************************\
  238. * VOID DrvDisableDriver
  239. *
  240. * Tells the driver it is being disabled. Release any resources allocated in
  241. * DrvEnableDriver.
  242. *
  243. \**************************************************************************/
  244. VOID DrvDisableDriver(VOID)
  245. {
  246. return;
  247. }
  248. /******************************Public*Routine******************************\
  249. * DHPDEV DrvEnablePDEV
  250. *
  251. * Initializes a bunch of fields for GDI, based on the mode we've been asked
  252. * to do. This is the first thing called after DrvEnableDriver, when GDI
  253. * wants to get some information about us.
  254. *
  255. * (This function mostly returns back information; DrvEnableSurface is used
  256. * for initializing the hardware and driver components.)
  257. *
  258. \**************************************************************************/
  259. DHPDEV DrvEnablePDEV(
  260. DEVMODEW* pdm, // Contains data pertaining to requested mode
  261. PWSTR pwszLogAddr, // Logical address
  262. ULONG cPat, // Count of standard patterns
  263. HSURF* phsurfPatterns, // Buffer for standard patterns
  264. ULONG cjCaps, // Size of buffer for device caps 'pdevcaps'
  265. ULONG* pdevcaps, // Buffer for device caps, also known as 'gdiinfo'
  266. ULONG cjDevInfo, // Number of bytes in device info 'pdi'
  267. DEVINFO* pdi, // Device information
  268. HDEV hdev, // HDEV, used for callbacks
  269. PWSTR pwszDeviceName, // Device name
  270. HANDLE hDriver) // Kernel driver handle
  271. {
  272. PDEV* ppdev;
  273. // Future versions of NT had better supply 'devcaps' and 'devinfo'
  274. // structures that are the same size or larger than the current
  275. // structures:
  276. if ((cjCaps < sizeof(GDIINFO)) || (cjDevInfo < sizeof(DEVINFO)))
  277. {
  278. DISPDBG((0, "DrvEnablePDEV - Buffer size too small"));
  279. goto ReturnFailure0;
  280. }
  281. // Allocate a physical device structure. Note that we definitely
  282. // rely on the zero initialization:
  283. ppdev = (PDEV*) EngAllocMem(FL_ZERO_MEMORY, sizeof(PDEV), ALLOC_TAG);
  284. if (ppdev == NULL)
  285. {
  286. DISPDBG((0, "DrvEnablePDEV - Failed EngAllocMem"));
  287. goto ReturnFailure0;
  288. }
  289. ppdev->hDriver = hDriver;
  290. // Initialize hardware pointer.
  291. if (!bInitializePointer(ppdev))
  292. {
  293. DISPDBG((0, "DrvEnablePDEV - Failed bInitializePointer"));
  294. goto ReturnFailure1;
  295. }
  296. // Get the current screen mode information. Set up device caps and
  297. // devinfo:
  298. if (!bInitializeModeFields(ppdev, (GDIINFO*) pdevcaps, pdi, pdm))
  299. {
  300. DISPDBG((0, "DrvEnablePDEV - Failed bInitializeModeFields"));
  301. goto ReturnFailure1;
  302. }
  303. // Initialize palette information.
  304. if (!bInitializePalette(ppdev, pdi))
  305. {
  306. DISPDBG((0, "DrvEnablePDEV - Failed bInitializePalette"));
  307. goto ReturnFailure1;
  308. }
  309. return((DHPDEV) ppdev);
  310. ReturnFailure1:
  311. DrvDisablePDEV((DHPDEV) ppdev);
  312. ReturnFailure0:
  313. DISPDBG((0, "Failed DrvEnablePDEV"));
  314. return(0);
  315. }
  316. /******************************Public*Routine******************************\
  317. * DrvDisablePDEV
  318. *
  319. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  320. * enabled DrvDisableSurface will have already been called.
  321. *
  322. * Note that this function will be called when previewing modes in the
  323. * Display Applet, but not at system shutdown. If you need to reset the
  324. * hardware at shutdown, you can do it in the miniport by providing a
  325. * 'HwResetHw' entry point in the VIDEO_HW_INITIALIZATION_DATA structure.
  326. *
  327. * Note: In an error, we may call this before DrvEnablePDEV is done.
  328. *
  329. \**************************************************************************/
  330. VOID DrvDisablePDEV(
  331. DHPDEV dhpdev)
  332. {
  333. PDEV* ppdev;
  334. ppdev = (PDEV*) dhpdev;
  335. vUninitializePalette(ppdev);
  336. vUninitializePointer(ppdev);
  337. EngFreeMem(ppdev);
  338. }
  339. /******************************Public*Routine******************************\
  340. * VOID DrvCompletePDEV
  341. *
  342. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  343. *
  344. \**************************************************************************/
  345. VOID DrvCompletePDEV(
  346. DHPDEV dhpdev,
  347. HDEV hdev)
  348. {
  349. ((PDEV*) dhpdev)->hdevEng = hdev;
  350. }
  351. /******************************Public*Routine******************************\
  352. * HSURF DrvEnableSurface
  353. *
  354. * Creates the drawing surface, initializes the hardware, and initializes
  355. * driver components. This function is called after DrvEnablePDEV, and
  356. * performs the final device initialization.
  357. *
  358. \**************************************************************************/
  359. HSURF DrvEnableSurface(
  360. DHPDEV dhpdev)
  361. {
  362. PDEV* ppdev;
  363. HSURF hsurf;
  364. SIZEL sizl;
  365. DSURF* pdsurf;
  366. VOID* pvTmpBuffer;
  367. ppdev = (PDEV*) dhpdev;
  368. /////////////////////////////////////////////////////////////////////
  369. // First enable all the subcomponents.
  370. //
  371. // Note that the order in which these 'Enable' functions are called
  372. // may be significant in low off-screen memory conditions, because
  373. // the off-screen heap manager may fail some of the later
  374. // allocations...
  375. if (!bEnableHardware(ppdev))
  376. goto ReturnFailure;
  377. if (!bEnableBanking(ppdev))
  378. goto ReturnFailure;
  379. if (!bEnableOffscreenHeap(ppdev))
  380. goto ReturnFailure;
  381. if (!bEnablePointer(ppdev))
  382. goto ReturnFailure;
  383. if (!bEnableText(ppdev))
  384. goto ReturnFailure;
  385. if (!bEnableBrushCache(ppdev))
  386. goto ReturnFailure;
  387. if (!bEnablePalette(ppdev))
  388. goto ReturnFailure;
  389. if (!bEnableRx(ppdev))
  390. goto ReturnFailure;
  391. /////////////////////////////////////////////////////////////////////
  392. // Now create our private surface structure.
  393. //
  394. // Whenever we get a call to draw directly to the screen, we'll get
  395. // passed a pointer to a SURFOBJ whose 'dhpdev' field will point
  396. // to our PDEV structure, and whose 'dhsurf' field will point to the
  397. // following DSURF structure.
  398. //
  399. // Every device bitmap we create in DrvCreateDeviceBitmap will also
  400. // have its own unique DSURF structure allocated (but will share the
  401. // same PDEV). To make our code more polymorphic for handling drawing
  402. // to either the screen or an off-screen bitmap, we have the same
  403. // structure for both.
  404. pdsurf = EngAllocMem(FL_ZERO_MEMORY, sizeof(DSURF), ALLOC_TAG);
  405. if (pdsurf == NULL)
  406. {
  407. DISPDBG((0, "DrvEnableSurface - Failed pdsurf EngAllocMem"));
  408. goto ReturnFailure;
  409. }
  410. ppdev->pdsurfScreen = pdsurf; // Remember it for clean-up
  411. pdsurf->poh = ppdev->pohFrontBuffer;// The screen is a surface, too
  412. pdsurf->dt = DT_SCREEN; // Not to be confused with a DIB
  413. pdsurf->sizl.cx = ppdev->cxScreen;
  414. pdsurf->sizl.cy = ppdev->cyScreen;
  415. pdsurf->ppdev = ppdev;
  416. /////////////////////////////////////////////////////////////////////
  417. // Next, have GDI create the actual SURFOBJ.
  418. //
  419. // Our drawing surface is going to be 'device-managed', meaning that
  420. // GDI cannot draw on the framebuffer bits directly, and as such we
  421. // create the surface via EngCreateDeviceSurface. By doing this, we ensure
  422. // that GDI will only ever access the bitmaps bits via the Drv calls
  423. // that we've HOOKed.
  424. //
  425. // If we could map the entire framebuffer linearly into main memory
  426. // (i.e., we didn't have to go through a 64k aperture), it would be
  427. // beneficial to create the surface via EngCreateBitmap, giving GDI a
  428. // pointer to the framebuffer bits. When we pass a call on to GDI
  429. // where it can't directly read/write to the surface bits because the
  430. // surface is device managed, it has to create a temporary bitmap and
  431. // call our DrvCopyBits routine to get/set a copy of the affected bits.
  432. // Fer example, the OpenGL component prefers to be able to write on the
  433. // framebuffer bits directly.
  434. sizl.cx = ppdev->cxScreen;
  435. sizl.cy = ppdev->cyScreen;
  436. hsurf = EngCreateDeviceSurface((DHSURF) pdsurf, sizl, ppdev->iBitmapFormat);
  437. if (hsurf == 0)
  438. {
  439. DISPDBG((0, "DrvEnableSurface - Failed EngCreateDeviceSurface"));
  440. goto ReturnFailure;
  441. }
  442. ppdev->hsurfScreen = hsurf; // Remember it for clean-up
  443. ppdev->bEnabled = TRUE; // We'll soon be in graphics mode
  444. /////////////////////////////////////////////////////////////////////
  445. // Now associate the surface and the PDEV.
  446. //
  447. // We have to associate the surface we just created with our physical
  448. // device so that GDI can get information related to the PDEV when
  449. // it's drawing to the surface (such as, for example, the length of
  450. // styles on the device when simulating styled lines).
  451. //
  452. if (!EngAssociateSurface(hsurf, ppdev->hdevEng, ppdev->flHooks))
  453. {
  454. DISPDBG((0, "DrvEnableSurface - Failed EngAssociateSurface"));
  455. goto ReturnFailure;
  456. }
  457. // Create our generic temporary buffer, which may be used by any
  458. // component.
  459. pvTmpBuffer = EngAllocMem(0, TMP_BUFFER_SIZE, ALLOC_TAG);
  460. if (pvTmpBuffer == NULL)
  461. {
  462. DISPDBG((0, "DrvEnableSurface - Failed EngAllocMem"));
  463. goto ReturnFailure;
  464. }
  465. ppdev->pvTmpBuffer = pvTmpBuffer;
  466. DISPDBG((5, "Passed DrvEnableSurface"));
  467. return(hsurf);
  468. ReturnFailure:
  469. DrvDisableSurface((DHPDEV) ppdev);
  470. DISPDBG((0, "Failed DrvEnableSurface"));
  471. return(0);
  472. }
  473. /******************************Public*Routine******************************\
  474. * VOID DrvDisableSurface
  475. *
  476. * Free resources allocated by DrvEnableSurface. Release the surface.
  477. *
  478. * Note that this function will be called when previewing modes in the
  479. * Display Applet, but not at system shutdown. If you need to reset the
  480. * hardware at shutdown, you can do it in the miniport by providing a
  481. * 'HwResetHw' entry point in the VIDEO_HW_INITIALIZATION_DATA structure.
  482. *
  483. * Note: In an error case, we may call this before DrvEnableSurface is
  484. * completely done.
  485. *
  486. \**************************************************************************/
  487. VOID DrvDisableSurface(
  488. DHPDEV dhpdev)
  489. {
  490. PDEV* ppdev;
  491. ppdev = (PDEV*) dhpdev;
  492. // Note: In an error case, some of the following relies on the
  493. // fact that the PDEV is zero-initialized, so fields like
  494. // 'hsurfScreen' will be zero unless the surface has been
  495. // sucessfully initialized, and makes the assumption that
  496. // EngDeleteSurface can take '0' as a parameter.
  497. vDisableRx(ppdev);
  498. vDisablePalette(ppdev);
  499. vDisableBrushCache(ppdev);
  500. vDisableText(ppdev);
  501. vDisablePointer(ppdev);
  502. vDisableOffscreenHeap(ppdev);
  503. vDisableBanking(ppdev);
  504. vDisableHardware(ppdev);
  505. EngFreeMem(ppdev->pvTmpBuffer);
  506. EngDeleteSurface(ppdev->hsurfScreen);
  507. EngFreeMem(ppdev->pdsurfScreen);
  508. }
  509. /******************************Public*Routine******************************\
  510. * VOID DrvAssertMode
  511. *
  512. * This asks the device to reset itself to the mode of the pdev passed in.
  513. *
  514. \**************************************************************************/
  515. BOOL DrvAssertMode(
  516. DHPDEV dhpdev,
  517. BOOL bEnable)
  518. {
  519. PDEV* ppdev;
  520. ppdev = (PDEV*) dhpdev;
  521. if (!bEnable)
  522. {
  523. //////////////////////////////////////////////////////////////
  524. // Disable - Switch to full-screen mode
  525. vAssertModeRx(ppdev, FALSE);
  526. vAssertModePalette(ppdev, FALSE);
  527. vAssertModeBrushCache(ppdev, FALSE);
  528. vAssertModeText(ppdev, FALSE);
  529. vAssertModePointer(ppdev, FALSE);
  530. if (bAssertModeOffscreenHeap(ppdev, FALSE))
  531. {
  532. vAssertModeBanking(ppdev, FALSE);
  533. if (bAssertModeHardware(ppdev, FALSE))
  534. {
  535. ppdev->bEnabled = FALSE;
  536. return(TRUE);
  537. }
  538. //////////////////////////////////////////////////////////
  539. // We failed to switch to full-screen. So undo everything:
  540. vAssertModeBanking(ppdev, TRUE);
  541. bAssertModeOffscreenHeap(ppdev, TRUE); // We don't need to check
  542. } // return code with TRUE
  543. vAssertModePointer(ppdev, TRUE);
  544. vAssertModeText(ppdev, TRUE);
  545. vAssertModeBrushCache(ppdev, TRUE);
  546. vAssertModePalette(ppdev, TRUE);
  547. vAssertModeRx(ppdev, TRUE);
  548. }
  549. else
  550. {
  551. //////////////////////////////////////////////////////////////
  552. // Enable - Switch back to graphics mode
  553. // We have to enable every subcomponent in the reverse order
  554. // in which it was disabled:
  555. if (bAssertModeHardware(ppdev, TRUE))
  556. {
  557. vAssertModeBanking(ppdev, TRUE);
  558. bAssertModeOffscreenHeap(ppdev, TRUE); // We don't need to check
  559. // return code with TRUE
  560. vAssertModePointer(ppdev, TRUE);
  561. vAssertModeText(ppdev, TRUE);
  562. vAssertModeBrushCache(ppdev, TRUE);
  563. vAssertModePalette(ppdev, TRUE);
  564. vAssertModeRx(ppdev, TRUE);
  565. ppdev->bEnabled = TRUE;
  566. return(TRUE);
  567. }
  568. }
  569. return(FALSE);
  570. }
  571. /******************************Public*Routine******************************\
  572. * ULONG DrvGetModes
  573. *
  574. * Returns the list of available modes for the device.
  575. *
  576. \**************************************************************************/
  577. ULONG DrvGetModes(
  578. HANDLE hDriver,
  579. ULONG cjSize,
  580. DEVMODEW* pdm)
  581. {
  582. DWORD cModes;
  583. DWORD cbOutputSize;
  584. PVIDEO_MODE_INFORMATION pVideoModeInformation;
  585. PVIDEO_MODE_INFORMATION pVideoTemp;
  586. DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  587. DWORD cbModeSize;
  588. cModes = getAvailableModes(hDriver,
  589. (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
  590. &cbModeSize);
  591. if (cModes == 0)
  592. {
  593. DISPDBG((0, "DrvGetModes failed to get mode information"));
  594. return(0);
  595. }
  596. if (pdm == NULL)
  597. {
  598. cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  599. }
  600. else
  601. {
  602. //
  603. // Now copy the information for the supported modes back into the
  604. // output buffer
  605. //
  606. cbOutputSize = 0;
  607. pVideoTemp = pVideoModeInformation;
  608. do
  609. {
  610. if (pVideoTemp->Length != 0)
  611. {
  612. if (cOutputModes == 0)
  613. {
  614. break;
  615. }
  616. //
  617. // Zero the entire structure to start off with.
  618. //
  619. memset(pdm, 0, sizeof(DEVMODEW));
  620. //
  621. // Set the name of the device to the name of the DLL.
  622. //
  623. memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
  624. pdm->dmSpecVersion = DM_SPECVERSION;
  625. pdm->dmDriverVersion = DM_SPECVERSION;
  626. pdm->dmSize = sizeof(DEVMODEW);
  627. pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
  628. pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
  629. pVideoTemp->BitsPerPlane;
  630. pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
  631. pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
  632. pdm->dmDisplayFrequency = pVideoTemp->Frequency;
  633. pdm->dmDisplayFlags = 0;
  634. pdm->dmFields = DM_BITSPERPEL |
  635. DM_PELSWIDTH |
  636. DM_PELSHEIGHT |
  637. DM_DISPLAYFREQUENCY |
  638. DM_DISPLAYFLAGS ;
  639. //
  640. // Go to the next DEVMODE entry in the buffer.
  641. //
  642. cOutputModes--;
  643. pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW)
  644. + DRIVER_EXTRA_SIZE);
  645. cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  646. }
  647. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  648. (((PUCHAR)pVideoTemp) + cbModeSize);
  649. } while (--cModes);
  650. }
  651. EngFreeMem(pVideoModeInformation);
  652. return(cbOutputSize);
  653. }
  654. /******************************Public*Routine******************************\
  655. * BOOL bAssertModeHardware
  656. *
  657. * Sets the appropriate hardware state for graphics mode or full-screen.
  658. *
  659. \**************************************************************************/
  660. BOOL bAssertModeHardware(
  661. PDEV* ppdev,
  662. BOOL bEnable)
  663. {
  664. DWORD ReturnedDataLength;
  665. if (bEnable)
  666. {
  667. // Call the miniport via an IOCTL to set the graphics mode.
  668. if (EngDeviceIoControl(ppdev->hDriver,
  669. IOCTL_VIDEO_SET_CURRENT_MODE,
  670. &ppdev->ulMode, // input buffer
  671. sizeof(DWORD),
  672. NULL,
  673. 0,
  674. &ReturnedDataLength))
  675. {
  676. DISPDBG((0, "bAssertModeHardware - Failed VIDEO_SET_CURRENT_MODE"));
  677. return(FALSE);
  678. }
  679. }
  680. else
  681. {
  682. // Call the kernel driver to reset the device to a known state.
  683. // NTVDM will take things from there:
  684. if (EngDeviceIoControl(ppdev->hDriver,
  685. IOCTL_VIDEO_RESET_DEVICE,
  686. NULL,
  687. 0,
  688. NULL,
  689. 0,
  690. &ReturnedDataLength))
  691. {
  692. DISPDBG((0, "bAssertModeHardware - Failed reset IOCTL"));
  693. return(FALSE);
  694. }
  695. else
  696. {
  697. return(TRUE);
  698. }
  699. }
  700. DISPDBG((5, "Passed bAssertModeHardware"));
  701. return(TRUE);
  702. }
  703. /******************************Public*Routine******************************\
  704. * BOOL bEnableHardware
  705. *
  706. * Puts the hardware in the requested mode and initializes it.
  707. *
  708. * Note: Should be called before any access is done to the hardware from
  709. * the display driver.
  710. *
  711. \**************************************************************************/
  712. BOOL bEnableHardware(
  713. PDEV* ppdev)
  714. {
  715. VIDEO_PUBLIC_ACCESS_RANGES VideoAccessRange[1];
  716. DWORD ReturnedDataLength;
  717. VIDEO_MEMORY VideoMemory;
  718. VIDEO_MEMORY_INFORMATION VideoMemoryInfo;
  719. VIDEO_MODE_INFORMATION VideoModeInfo;
  720. ppdev->pjMmBase = NULL;
  721. ppdev->pjIoBase = NULL;
  722. // Map io ports into virtual memory:
  723. if (EngDeviceIoControl(ppdev->hDriver,
  724. IOCTL_VIDEO_QUERY_PUBLIC_ACCESS_RANGES,
  725. NULL, // input buffer
  726. 0,
  727. &VideoAccessRange[0], // output buffer
  728. sizeof(VideoAccessRange),
  729. &ReturnedDataLength))
  730. {
  731. RIP("bEnableHardware - Initialization error mapping IO port base");
  732. goto ReturnFalse;
  733. }
  734. #if defined(i386)
  735. {
  736. ppdev->pjMmBase = (BYTE*) VideoAccessRange[0].VirtualAddress;
  737. }
  738. #else
  739. {
  740. ppdev->pjIoBase = VideoAccessRange[0].VirtualAddress;
  741. }
  742. #endif
  743. // Now we can set the mode.
  744. if (!bAssertModeHardware(ppdev, TRUE))
  745. goto ReturnFalse;
  746. //
  747. // Now map the memory for the mode.
  748. //
  749. // Get the linear memory address range.
  750. VideoMemory.RequestedVirtualAddress = NULL;
  751. if (EngDeviceIoControl(ppdev->hDriver,
  752. IOCTL_VIDEO_MAP_VIDEO_MEMORY,
  753. &VideoMemory, // input buffer
  754. sizeof(VIDEO_MEMORY),
  755. &VideoMemoryInfo, // output buffer
  756. sizeof(VideoMemoryInfo),
  757. &ReturnedDataLength))
  758. {
  759. DISPDBG((0, "bEnableHardware - Error mapping buffer address"));
  760. goto ReturnFalse;
  761. }
  762. if (EngDeviceIoControl(ppdev->hDriver,
  763. IOCTL_VIDEO_QUERY_CURRENT_MODE,
  764. NULL,
  765. 0,
  766. &VideoModeInfo,
  767. sizeof(VideoModeInfo),
  768. &ReturnedDataLength))
  769. {
  770. DISPDBG((0, "bAssertModeHardware - failed VIDEO_QUERY_CURRENT_MODE"));
  771. goto ReturnFalse;
  772. }
  773. #if DEBUG_HEAP
  774. VideoModeInfo.VideoMemoryBitmapWidth = VideoModeInfo.VisScreenWidth;
  775. VideoModeInfo.VideoMemoryBitmapHeight = VideoModeInfo.VisScreenHeight;
  776. #endif
  777. // The following variables are determined only after the initial
  778. // modeset:
  779. ppdev->lDelta = VideoModeInfo.ScreenStride;
  780. ppdev->flCaps = VideoModeInfo.AttributeFlags;
  781. ppdev->cxMemory = ppdev->lDelta / ppdev->cjPel;
  782. ppdev->pjScreen = (BYTE*) VideoMemoryInfo.FrameBufferBase;
  783. ppdev->cyMemory = VideoMemoryInfo.VideoRamLength / ppdev->lDelta;
  784. // If we're using the original QVision-compatible I/O routines,
  785. // we're constrained to the original QVision's coordinate limit:
  786. if (ppdev->pjMmBase == NULL)
  787. ppdev->cyMemory = min(ppdev->cyMemory, 1024);
  788. #if defined(i386)
  789. ppdev->cjBank = 0x10000; // Hardcoded 64k for x86
  790. #else
  791. ppdev->cjBank = 0x100000; // Hardcoded 1 MB for Alpha
  792. #endif
  793. // Do some paramater checking on the values that the miniport
  794. // returned to us:
  795. ASSERTDD(ppdev->cxMemory >= ppdev->cxScreen, "Invalid cxMemory");
  796. ASSERTDD(ppdev->cyMemory >= ppdev->cyScreen, "Invalid cyMemory");
  797. //
  798. // Set the function pointers.
  799. //
  800. if (ppdev->pjMmBase == NULL)
  801. {
  802. // Have to do IN/OUTs:
  803. ppdev->pfnFillSolid = vIoFillSolid;
  804. ppdev->pfnFillPat = vIoFillPat;
  805. ppdev->pfnXfer1bpp = vIoXfer1bpp;
  806. ppdev->pfnCopyBlt = vIoCopyBlt;
  807. ppdev->pfnTextOut = vIoTextOut;
  808. }
  809. else
  810. {
  811. ppdev->pfnFillSolid = vMmFillSolid;
  812. ppdev->pfnFillPat = vMmFillPat;
  813. ppdev->pfnXfer1bpp = vMmXfer1bpp;
  814. ppdev->pfnCopyBlt = vMmCopyBlt;
  815. ppdev->pfnTextOut = vMmTextOut;
  816. }
  817. DISPDBG((0, "%lix%li / %lix%li @ 0x%lxx%li cjBank: 0x%lx flCaps: 0x%lx",
  818. ppdev->cxScreen, ppdev->cyScreen, ppdev->cxMemory, ppdev->cyMemory,
  819. ppdev->pjScreen, ppdev->lDelta, ppdev->cjBank, ppdev->flCaps));
  820. DISPDBG((5, "Passed bEnableHardware"));
  821. return(TRUE);
  822. ReturnFalse:
  823. DISPDBG((0, "Failed bEnableHardware"));
  824. return(FALSE);
  825. }
  826. /******************************Public*Routine******************************\
  827. * VOID vDisableHardware
  828. *
  829. * Undoes anything done in bEnableHardware.
  830. *
  831. * Note: In an error case, we may call this before bEnableHardware is
  832. * completely done.
  833. *
  834. \**************************************************************************/
  835. VOID vDisableHardware(
  836. PDEV* ppdev)
  837. {
  838. DWORD ReturnedDataLength;
  839. VIDEO_MEMORY VideoMemory[1];
  840. VideoMemory[0].RequestedVirtualAddress = ppdev->pjScreen;
  841. if (EngDeviceIoControl(ppdev->hDriver,
  842. IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
  843. VideoMemory,
  844. sizeof(VIDEO_MEMORY),
  845. NULL,
  846. 0,
  847. &ReturnedDataLength))
  848. {
  849. DISPDBG((0, "vDisableHardware failed IOCTL_VIDEO_UNMAP_VIDEO"));
  850. }
  851. #if defined(i386)
  852. VideoMemory[0].RequestedVirtualAddress = ppdev->pjMmBase;
  853. #else
  854. VideoMemory[0].RequestedVirtualAddress = ppdev->pjIoBase;
  855. #endif
  856. if (EngDeviceIoControl(ppdev->hDriver,
  857. IOCTL_VIDEO_FREE_PUBLIC_ACCESS_RANGES,
  858. VideoMemory,
  859. sizeof(VideoMemory),
  860. NULL,
  861. 0,
  862. &ReturnedDataLength))
  863. {
  864. DISPDBG((0, "vDisableHardware failed IOCTL_VIDEO_FREE_PUBLIC_ACCESS"));
  865. }
  866. }
  867. /******************************Public*Routine******************************\
  868. * BOOL bInitializeModeFields
  869. *
  870. * Initializes a bunch of fields in the pdev, devcaps (aka gdiinfo), and
  871. * devinfo based on the requested mode.
  872. *
  873. \**************************************************************************/
  874. BOOL bInitializeModeFields(
  875. PDEV* ppdev,
  876. GDIINFO* pgdi,
  877. DEVINFO* pdi,
  878. DEVMODEW* pdm)
  879. {
  880. ULONG cModes;
  881. PVIDEO_MODE_INFORMATION pVideoBuffer;
  882. PVIDEO_MODE_INFORMATION pVideoModeSelected;
  883. PVIDEO_MODE_INFORMATION pVideoTemp;
  884. BOOL bSelectDefault;
  885. VIDEO_MODE_INFORMATION VideoModeInformation;
  886. ULONG cbModeSize;
  887. // Call the miniport to get mode information
  888. cModes = getAvailableModes(ppdev->hDriver, &pVideoBuffer, &cbModeSize);
  889. if (cModes == 0)
  890. goto ReturnFalse;
  891. // Now see if the requested mode has a match in that table.
  892. pVideoModeSelected = NULL;
  893. pVideoTemp = pVideoBuffer;
  894. if ((pdm->dmPelsWidth == 0) &&
  895. (pdm->dmPelsHeight == 0) &&
  896. (pdm->dmBitsPerPel == 0) &&
  897. (pdm->dmDisplayFrequency == 0))
  898. {
  899. DISPDBG((1, "Default mode requested"));
  900. bSelectDefault = TRUE;
  901. }
  902. else
  903. {
  904. DISPDBG((1, "Requested mode..."));
  905. DISPDBG((1, " Screen width -- %li", pdm->dmPelsWidth));
  906. DISPDBG((1, " Screen height -- %li", pdm->dmPelsHeight));
  907. DISPDBG((1, " Bits per pel -- %li", pdm->dmBitsPerPel));
  908. DISPDBG((1, " Frequency -- %li", pdm->dmDisplayFrequency));
  909. bSelectDefault = FALSE;
  910. }
  911. while (cModes--)
  912. {
  913. if (pVideoTemp->Length != 0)
  914. {
  915. DISPDBG((8, " Checking against miniport mode:"));
  916. DISPDBG((8, " Screen width -- %li", pVideoTemp->VisScreenWidth));
  917. DISPDBG((8, " Screen height -- %li", pVideoTemp->VisScreenHeight));
  918. DISPDBG((8, " Bits per pel -- %li", pVideoTemp->BitsPerPlane *
  919. pVideoTemp->NumberOfPlanes));
  920. DISPDBG((8, " Frequency -- %li", pVideoTemp->Frequency));
  921. if (bSelectDefault ||
  922. ((pVideoTemp->VisScreenWidth == pdm->dmPelsWidth) &&
  923. (pVideoTemp->VisScreenHeight == pdm->dmPelsHeight) &&
  924. (pVideoTemp->BitsPerPlane *
  925. pVideoTemp->NumberOfPlanes == pdm->dmBitsPerPel) &&
  926. (pVideoTemp->Frequency == pdm->dmDisplayFrequency)))
  927. {
  928. pVideoModeSelected = pVideoTemp;
  929. DISPDBG((1, "...Found a mode match!"));
  930. break;
  931. }
  932. }
  933. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  934. (((PUCHAR)pVideoTemp) + cbModeSize);
  935. }
  936. // If no mode has been found, return an error
  937. if (pVideoModeSelected == NULL)
  938. {
  939. DISPDBG((1, "...Couldn't find a mode match!"));
  940. EngFreeMem(pVideoBuffer);
  941. goto ReturnFalse;
  942. }
  943. // We have chosen the one we want. Save it in a stack buffer and
  944. // get rid of allocated memory before we forget to free it.
  945. VideoModeInformation = *pVideoModeSelected;
  946. EngFreeMem(pVideoBuffer);
  947. #if DEBUG_HEAP
  948. VideoModeInformation.VisScreenWidth = 640;
  949. VideoModeInformation.VisScreenHeight = 480;
  950. #endif
  951. // Set up screen information from the mini-port:
  952. ppdev->ulMode = VideoModeInformation.ModeIndex;
  953. ppdev->cxScreen = VideoModeInformation.VisScreenWidth;
  954. ppdev->cyScreen = VideoModeInformation.VisScreenHeight;
  955. DISPDBG((1, "ScreenStride: %lx", VideoModeInformation.ScreenStride));
  956. ppdev->flHooks = (HOOK_BITBLT |
  957. HOOK_TEXTOUT |
  958. HOOK_COPYBITS |
  959. HOOK_STROKEPATH |
  960. HOOK_PAINT |
  961. HOOK_FILLPATH);
  962. // !!! HOOK_STRETCHBLT);
  963. // Fill in the GDIINFO data structure with the default 8bpp values:
  964. *pgdi = ggdiDefault;
  965. // Now overwrite the defaults with the relevant information returned
  966. // from the kernel driver:
  967. pgdi->ulHorzSize = VideoModeInformation.XMillimeter;
  968. pgdi->ulVertSize = VideoModeInformation.YMillimeter;
  969. pgdi->ulHorzRes = VideoModeInformation.VisScreenWidth;
  970. pgdi->ulVertRes = VideoModeInformation.VisScreenHeight;
  971. pgdi->ulPanningHorzRes = VideoModeInformation.VisScreenWidth;
  972. pgdi->ulPanningVertRes = VideoModeInformation.VisScreenHeight;
  973. pgdi->cBitsPixel = VideoModeInformation.BitsPerPlane;
  974. pgdi->cPlanes = VideoModeInformation.NumberOfPlanes;
  975. pgdi->ulVRefresh = VideoModeInformation.Frequency;
  976. pgdi->ulDACRed = VideoModeInformation.NumberRedBits;
  977. pgdi->ulDACGreen = VideoModeInformation.NumberGreenBits;
  978. pgdi->ulDACBlue = VideoModeInformation.NumberBlueBits;
  979. pgdi->ulLogPixelsX = pdm->dmLogPixels;
  980. pgdi->ulLogPixelsY = pdm->dmLogPixels;
  981. // Fill in the devinfo structure with the default 8bpp values:
  982. *pdi = gdevinfoDefault;
  983. if (ppdev->PointerCapabilities.Flags & VIDEO_MODE_ASYNC_POINTER)
  984. pdi->flGraphicsCaps |= GCAPS_ASYNCMOVE;
  985. if (VideoModeInformation.BitsPerPlane == 8)
  986. {
  987. ppdev->cPelSize = 0;
  988. ppdev->cjPel = 1;
  989. ppdev->iBitmapFormat = BMF_8BPP;
  990. ppdev->ulWhite = 0xff;
  991. // Assuming palette is orthogonal - all colors are same size.
  992. ppdev->cPaletteShift = 8 - pgdi->ulDACRed;
  993. DISPDBG((3, "palette shift = %d\n", ppdev->cPaletteShift));
  994. }
  995. else if ((VideoModeInformation.BitsPerPlane == 16) ||
  996. (VideoModeInformation.BitsPerPlane == 15))
  997. {
  998. ppdev->cPelSize = 1;
  999. ppdev->cjPel = 2;
  1000. ppdev->iBitmapFormat = BMF_16BPP;
  1001. ppdev->ulWhite = 0xffff;
  1002. ppdev->flRed = VideoModeInformation.RedMask;
  1003. ppdev->flGreen = VideoModeInformation.GreenMask;
  1004. ppdev->flBlue = VideoModeInformation.BlueMask;
  1005. pgdi->ulNumColors = (ULONG) -1;
  1006. pgdi->ulNumPalReg = 0;
  1007. pgdi->ulHTOutputFormat = HT_FORMAT_16BPP;
  1008. pdi->iDitherFormat = BMF_16BPP;
  1009. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1010. }
  1011. else
  1012. {
  1013. ASSERTDD(VideoModeInformation.BitsPerPlane == 32,
  1014. "This driver supports only 8, 16 and 32bpp");
  1015. ppdev->cPelSize = 2;
  1016. ppdev->cjPel = 4;
  1017. ppdev->iBitmapFormat = BMF_32BPP;
  1018. ppdev->ulWhite = 0xffffffff;
  1019. ppdev->flRed = VideoModeInformation.RedMask;
  1020. ppdev->flGreen = VideoModeInformation.GreenMask;
  1021. ppdev->flBlue = VideoModeInformation.BlueMask;
  1022. pgdi->ulNumColors = (ULONG) -1;
  1023. pgdi->ulNumPalReg = 0;
  1024. pgdi->ulHTOutputFormat = HT_FORMAT_32BPP;
  1025. pdi->iDitherFormat = BMF_32BPP;
  1026. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1027. }
  1028. DISPDBG((5, "Passed bInitializeModeFields"));
  1029. return(TRUE);
  1030. ReturnFalse:
  1031. DISPDBG((0, "Failed bInitializeModeFields"));
  1032. return(FALSE);
  1033. }
  1034. /******************************Public*Routine******************************\
  1035. * DWORD getAvailableModes
  1036. *
  1037. * Calls the miniport to get the list of modes supported by the kernel driver,
  1038. * and returns the list of modes supported by the diplay driver among those
  1039. *
  1040. * returns the number of entries in the videomode buffer.
  1041. * 0 means no modes are supported by the miniport or that an error occured.
  1042. *
  1043. * NOTE: the buffer must be freed up by the caller.
  1044. *
  1045. \**************************************************************************/
  1046. DWORD getAvailableModes(
  1047. HANDLE hDriver,
  1048. PVIDEO_MODE_INFORMATION* modeInformation,
  1049. DWORD* cbModeSize)
  1050. {
  1051. ULONG ulTemp;
  1052. VIDEO_NUM_MODES modes;
  1053. PVIDEO_MODE_INFORMATION pVideoTemp;
  1054. //
  1055. // Get the number of modes supported by the mini-port
  1056. //
  1057. if (EngDeviceIoControl(hDriver,
  1058. IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
  1059. NULL,
  1060. 0,
  1061. &modes,
  1062. sizeof(VIDEO_NUM_MODES),
  1063. &ulTemp))
  1064. {
  1065. DISPDBG((0, "getAvailableModes - Failed VIDEO_QUERY_NUM_AVAIL_MODES"));
  1066. return(0);
  1067. }
  1068. *cbModeSize = modes.ModeInformationLength;
  1069. //
  1070. // Allocate the buffer for the mini-port to write the modes in.
  1071. //
  1072. *modeInformation = (PVIDEO_MODE_INFORMATION)
  1073. EngAllocMem(FL_ZERO_MEMORY,
  1074. modes.NumModes *
  1075. modes.ModeInformationLength, ALLOC_TAG);
  1076. if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
  1077. {
  1078. DISPDBG((0, "getAvailableModes - Failed EngAllocMem"));
  1079. return 0;
  1080. }
  1081. //
  1082. // Ask the mini-port to fill in the available modes.
  1083. //
  1084. if (EngDeviceIoControl(hDriver,
  1085. IOCTL_VIDEO_QUERY_AVAIL_MODES,
  1086. NULL,
  1087. 0,
  1088. *modeInformation,
  1089. modes.NumModes * modes.ModeInformationLength,
  1090. &ulTemp))
  1091. {
  1092. DISPDBG((0, "getAvailableModes - Failed VIDEO_QUERY_AVAIL_MODES"));
  1093. EngFreeMem(*modeInformation);
  1094. *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
  1095. return(0);
  1096. }
  1097. //
  1098. // Now see which of these modes are supported by the display driver.
  1099. // As an internal mechanism, set the length to 0 for the modes we
  1100. // DO NOT support.
  1101. //
  1102. ulTemp = modes.NumModes;
  1103. pVideoTemp = *modeInformation;
  1104. //
  1105. // Mode is rejected if it is not one plane, or not graphics, or is not
  1106. // one of 8, 15, 16 or 32 bits per pel.
  1107. //
  1108. while (ulTemp--)
  1109. {
  1110. if ((pVideoTemp->NumberOfPlanes != 1 ) ||
  1111. !(pVideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
  1112. ((pVideoTemp->BitsPerPlane != 8) &&
  1113. (pVideoTemp->BitsPerPlane != 15) &&
  1114. (pVideoTemp->BitsPerPlane != 16) &&
  1115. (pVideoTemp->BitsPerPlane != 32)))
  1116. {
  1117. DISPDBG((2, "Rejecting miniport mode:"));
  1118. DISPDBG((2, " Screen width -- %li", pVideoTemp->VisScreenWidth));
  1119. DISPDBG((2, " Screen height -- %li", pVideoTemp->VisScreenHeight));
  1120. DISPDBG((2, " Bits per pel -- %li", pVideoTemp->BitsPerPlane *
  1121. pVideoTemp->NumberOfPlanes));
  1122. DISPDBG((2, " Frequency -- %li", pVideoTemp->Frequency));
  1123. pVideoTemp->Length = 0;
  1124. }
  1125. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  1126. (((PUCHAR)pVideoTemp) + modes.ModeInformationLength);
  1127. }
  1128. return(modes.NumModes);
  1129. }