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.

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