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.

1885 lines
64 KiB

  1. /******************************Module*Header*******************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: enable.c
  8. *
  9. * This module contains the functions that enable and disable the
  10. * driver, the pdev, and the surface.
  11. *
  12. * Copyright (c) 1992-1998 Microsoft Corporation
  13. \**************************************************************************/
  14. #include "precomp.h"
  15. // Useful for visualizing the off-screen heap when set to '1':
  16. #define DEBUG_HEAP 0
  17. /******************************Public*Structure****************************\
  18. * GDIINFO ggdiDefault
  19. *
  20. * This contains the default GDIINFO fields that are passed back to GDI
  21. * during DrvEnablePDEV.
  22. *
  23. * NOTE: This structure defaults to values for an 8bpp palette device.
  24. * Some fields are overwritten for different colour depths.
  25. \**************************************************************************/
  26. GDIINFO ggdiDefault = {
  27. GDI_DRIVER_VERSION,
  28. DT_RASDISPLAY, // ulTechnology
  29. 0, // ulHorzSize (filled in later)
  30. 0, // ulVertSize (filled in later)
  31. 0, // ulHorzRes (filled in later)
  32. 0, // ulVertRes (filled in later)
  33. 0, // cBitsPixel (filled in later)
  34. 0, // cPlanes (filled in later)
  35. 20, // ulNumColors (palette managed)
  36. 0, // flRaster (DDI reserved field)
  37. 0, // ulLogPixelsX (filled in later)
  38. 0, // ulLogPixelsY (filled in later)
  39. TC_RA_ABLE, // flTextCaps -- If we had wanted console windows
  40. // to scroll by repainting the entire window,
  41. // instead of doing a screen-to-screen blt, we
  42. // would have set TC_SCROLLBLT (yes, the flag is
  43. // bass-ackwards).
  44. 0, // ulDACRed (filled in later)
  45. 0, // ulDACGreen (filled in later)
  46. 0, // ulDACBlue (filled in later)
  47. 0x0024, // ulAspectX
  48. 0x0024, // ulAspectY
  49. 0x0033, // ulAspectXY (one-to-one aspect ratio)
  50. 1, // xStyleStep
  51. 1, // yStyleSte;
  52. 3, // denStyleStep -- Styles have a one-to-one aspect
  53. // ratio, and every 'dot' is 3 pixels long
  54. { 0, 0 }, // ptlPhysOffset
  55. { 0, 0 }, // szlPhysSize
  56. 256, // ulNumPalReg
  57. // These fields are for halftone initialization. The actual values are
  58. // a bit magic, but seem to work well on our display.
  59. { // ciDevice
  60. { 6700, 3300, 0 }, // Red
  61. { 2100, 7100, 0 }, // Green
  62. { 1400, 800, 0 }, // Blue
  63. { 1750, 3950, 0 }, // Cyan
  64. { 4050, 2050, 0 }, // Magenta
  65. { 4400, 5200, 0 }, // Yellow
  66. { 3127, 3290, 0 }, // AlignmentWhite
  67. 20000, // RedGamma
  68. 20000, // GreenGamma
  69. 20000, // BlueGamma
  70. 0, 0, 0, 0, 0, 0 // No dye correction for raster displays
  71. },
  72. 0, // ulDevicePelsDPI (for printers only)
  73. PRIMARY_ORDER_CBA, // ulPrimaryOrder
  74. HT_PATSIZE_4x4_M, // ulHTPatternSize
  75. HT_FORMAT_8BPP, // ulHTOutputFormat
  76. HT_FLAG_ADDITIVE_PRIMS, // flHTFlags
  77. 0, // ulVRefresh
  78. 0, // ulPanningHorzRes
  79. 0, // ulPanningVertRes
  80. 0, // ulBltAlignment
  81. };
  82. /******************************Public*Structure****************************\
  83. * DEVINFO gdevinfoDefault
  84. *
  85. * This contains the default DEVINFO fields that are passed back to GDI
  86. * during DrvEnablePDEV.
  87. *
  88. * NOTE: This structure defaults to values for an 8bpp palette device.
  89. * Some fields are overwritten for different colour depths.
  90. \**************************************************************************/
  91. #define SYSTM_LOGFONT {16,7,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  92. CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,\
  93. VARIABLE_PITCH | FF_DONTCARE,L"System"}
  94. #define HELVE_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  95. CLIP_STROKE_PRECIS,PROOF_QUALITY,\
  96. VARIABLE_PITCH | FF_DONTCARE,L"MS Sans Serif"}
  97. #define COURI_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
  98. CLIP_STROKE_PRECIS,PROOF_QUALITY,\
  99. FIXED_PITCH | FF_DONTCARE, L"Courier"}
  100. DEVINFO gdevinfoDefault = {
  101. (GCAPS_OPAQUERECT |
  102. GCAPS_DITHERONREALIZE |
  103. GCAPS_PALMANAGED |
  104. GCAPS_ALTERNATEFILL |
  105. GCAPS_WINDINGFILL |
  106. GCAPS_MONO_DITHER |
  107. GCAPS_COLOR_DITHER |
  108. GCAPS_DIRECTDRAW |
  109. GCAPS_ASYNCMOVE), // NOTE: Only enable ASYNCMOVE if your code
  110. // and hardware can handle DrvMovePointer
  111. // calls at any time, even while another
  112. // thread is in the middle of a drawing
  113. // call such as DrvBitBlt.
  114. // flGraphicsFlags
  115. SYSTM_LOGFONT, // lfDefaultFont
  116. HELVE_LOGFONT, // lfAnsiVarFont
  117. COURI_LOGFONT, // lfAnsiFixFont
  118. 0, // cFonts
  119. BMF_8BPP, // iDitherFormat
  120. 8, // cxDither
  121. 8, // cyDither
  122. 0 // hpalDefault (filled in later)
  123. };
  124. /******************************Public*Structure****************************\
  125. * DFVFN gadrvfn[]
  126. *
  127. * Build the driver function table gadrvfn with function index/address
  128. * pairs. This table tells GDI which DDI calls we support, and their
  129. * location (GDI does an indirect call through this table to call us).
  130. *
  131. * Why haven't we implemented DrvSaveScreenBits? To save code.
  132. *
  133. * When the driver doesn't hook DrvSaveScreenBits, USER simulates on-
  134. * the-fly by creating a temporary device-format-bitmap, and explicitly
  135. * calling DrvCopyBits to save/restore the bits. Since we already hook
  136. * DrvCreateDeviceBitmap, we'll end up using off-screen memory to store
  137. * the bits anyway (which would have been the main reason for implementing
  138. * DrvSaveScreenBits). So we may as well save some working set.
  139. \**************************************************************************/
  140. DRVFN gadrvfn[] = {
  141. { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
  142. { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
  143. { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
  144. { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
  145. { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
  146. { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
  147. { INDEX_DrvMovePointer, (PFN) DrvMovePointer },
  148. { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape },
  149. { INDEX_DrvSetPalette, (PFN) DrvSetPalette },
  150. { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
  151. { INDEX_DrvBitBlt, (PFN) DrvBitBlt },
  152. { INDEX_DrvTextOut, (PFN) DrvTextOut },
  153. { INDEX_DrvGetModes, (PFN) DrvGetModes },
  154. { INDEX_DrvLineTo, (PFN) DrvLineTo },
  155. { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
  156. { INDEX_DrvFillPath, (PFN) DrvFillPath },
  157. { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush },
  158. { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap },
  159. { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap },
  160. { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt },
  161. { INDEX_DrvDestroyFont, (PFN) DrvDestroyFont },
  162. { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo },
  163. { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw },
  164. { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw },
  165. { INDEX_DrvSynchronize, (PFN) DrvSynchronize },
  166. { INDEX_DrvTransparentBlt, (PFN) DrvTransparentBlt },
  167. { INDEX_DrvDeriveSurface, (PFN) DrvDeriveSurface },
  168. { INDEX_DrvIcmSetDeviceGammaRamp, (PFN) DrvIcmSetDeviceGammaRamp },
  169. };
  170. ULONG gcdrvfn = sizeof(gadrvfn) / sizeof(DRVFN);
  171. /******************************Public*Routine******************************\
  172. * BOOL DrvEnableDriver
  173. *
  174. * Enables the driver by retrieving the drivers function table and version.
  175. *
  176. \**************************************************************************/
  177. BOOL DrvEnableDriver(
  178. ULONG iEngineVersion,
  179. ULONG cj,
  180. DRVENABLEDATA* pded)
  181. {
  182. // Engine Version is passed down so future drivers can support previous
  183. // engine versions. A next generation driver can support both the old
  184. // and new engine conventions if told what version of engine it is
  185. // working with. For the first version the driver does nothing with it.
  186. // Fill in as much as we can.
  187. if (cj >= sizeof(DRVENABLEDATA))
  188. pded->pdrvfn = gadrvfn;
  189. if (cj >= (sizeof(ULONG) * 2))
  190. pded->c = gcdrvfn;
  191. // DDI version this driver was targeted for is passed back to engine.
  192. // Future graphic's engine may break calls down to old driver format.
  193. if (cj >= sizeof(ULONG))
  194. pded->iDriverVersion = DDI_DRIVER_VERSION_NT4;
  195. return(TRUE);
  196. }
  197. /******************************Public*Routine******************************\
  198. * VOID DrvDisableDriver
  199. *
  200. * Tells the driver it is being disabled. Release any resources allocated in
  201. * DrvEnableDriver.
  202. *
  203. \**************************************************************************/
  204. VOID DrvDisableDriver(VOID)
  205. {
  206. return;
  207. }
  208. /******************************Public*Routine******************************\
  209. * DHPDEV DrvEnablePDEV
  210. *
  211. * Initializes a bunch of fields for GDI, based on the mode we've been asked
  212. * to do. This is the first thing called after DrvEnableDriver, when GDI
  213. * wants to get some information about us.
  214. *
  215. * (This function mostly returns back information; DrvEnableSurface is used
  216. * for initializing the hardware and driver components.)
  217. *
  218. \**************************************************************************/
  219. DHPDEV DrvEnablePDEV(
  220. DEVMODEW* pdm, // Contains data pertaining to requested mode
  221. PWSTR pwszLogAddr, // Logical address
  222. ULONG cPat, // Count of standard patterns
  223. HSURF* phsurfPatterns, // Buffer for standard patterns
  224. ULONG cjCaps, // Size of buffer for device caps 'pdevcaps'
  225. ULONG* pdevcaps, // Buffer for device caps, also known as 'gdiinfo'
  226. ULONG cjDevInfo, // Number of bytes in device info 'pdi'
  227. DEVINFO* pdi, // Device information
  228. HDEV hdev, // HDEV, used for callbacks
  229. PWSTR pwszDeviceName, // Device name
  230. HANDLE hDriver) // Kernel driver handle
  231. {
  232. PDEV* ppdev;
  233. // Future versions of NT had better supply 'devcaps' and 'devinfo'
  234. // structures that are the same size or larger than the current
  235. // structures:
  236. if ((cjCaps < sizeof(GDIINFO)) || (cjDevInfo < sizeof(DEVINFO)))
  237. {
  238. DISPDBG((0, "DrvEnablePDEV - Buffer size too small"));
  239. goto ReturnFailure0;
  240. }
  241. // Allocate a physical device structure. Note that we definitely
  242. // rely on the zero initialization:
  243. ppdev = EngAllocMem(FL_ZERO_MEMORY, sizeof(PDEV), ALLOC_TAG);
  244. if (ppdev == NULL)
  245. {
  246. DISPDBG((0, "DrvEnablePDEV - Failed EngAllocMem"));
  247. goto ReturnFailure0;
  248. }
  249. ppdev->hDriver = hDriver;
  250. // Get the current screen mode information. Set up device caps and
  251. // devinfo:
  252. if (!bInitializeModeFields(ppdev, (GDIINFO*) pdevcaps, pdi, pdm))
  253. {
  254. DISPDBG((0, "DrvEnablePDEV - Failed bInitializeModeFields"));
  255. goto ReturnFailure1;
  256. }
  257. // Initialize palette information.
  258. if (!bInitializePalette(ppdev, pdi))
  259. {
  260. DISPDBG((0, "DrvEnablePDEV - Failed bInitializePalette"));
  261. goto ReturnFailure1;
  262. }
  263. return((DHPDEV) ppdev);
  264. ReturnFailure1:
  265. DrvDisablePDEV((DHPDEV) ppdev);
  266. ReturnFailure0:
  267. DISPDBG((0, "Failed DrvEnablePDEV"));
  268. return(0);
  269. }
  270. /******************************Public*Routine******************************\
  271. * DrvDisablePDEV
  272. *
  273. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  274. * enabled DrvDisableSurface will have already been called.
  275. *
  276. * Note that this function will be called when previewing modes in the
  277. * Display Applet, but not at system shutdown. If you need to reset the
  278. * hardware at shutdown, you can do it in the miniport by providing a
  279. * 'HwResetHw' entry point in the VIDEO_HW_INITIALIZATION_DATA structure.
  280. *
  281. * Note: In an error, we may call this before DrvEnablePDEV is done.
  282. *
  283. \**************************************************************************/
  284. VOID DrvDisablePDEV(
  285. DHPDEV dhpdev)
  286. {
  287. PDEV* ppdev;
  288. ppdev = (PDEV*) dhpdev;
  289. vUninitializePalette(ppdev);
  290. EngFreeMem(ppdev);
  291. }
  292. /******************************Public*Routine******************************\
  293. * VOID DrvCompletePDEV
  294. *
  295. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  296. *
  297. \**************************************************************************/
  298. VOID DrvCompletePDEV(
  299. DHPDEV dhpdev,
  300. HDEV hdev)
  301. {
  302. ((PDEV*) dhpdev)->hdevEng = hdev;
  303. }
  304. /******************************Public*Routine******************************\
  305. * HSURF DrvEnableSurface
  306. *
  307. * Creates the drawing surface, initializes the hardware, and initializes
  308. * driver components. This function is called after DrvEnablePDEV, and
  309. * performs the final device initialization.
  310. *
  311. \**************************************************************************/
  312. HSURF DrvEnableSurface(
  313. DHPDEV dhpdev)
  314. {
  315. PDEV* ppdev;
  316. HSURF hsurf;
  317. SIZEL sizl;
  318. DSURF* pdsurf;
  319. VOID* pvTmpBuffer;
  320. BYTE* pjScreen;
  321. LONG lDelta;
  322. FLONG flHooks;
  323. ppdev = (PDEV*) dhpdev;
  324. /////////////////////////////////////////////////////////////////////
  325. // First enable all the subcomponents.
  326. //
  327. // Note that the order in which these 'Enable' functions are called
  328. // may be significant in low off-screen memory conditions, because
  329. // the off-screen heap manager may fail some of the later
  330. // allocations...
  331. if (!bEnableHardware(ppdev))
  332. goto ReturnFailure;
  333. if (!bEnableBanking(ppdev))
  334. goto ReturnFailure;
  335. if (!bEnableOffscreenHeap(ppdev))
  336. goto ReturnFailure;
  337. if (!bEnablePointer(ppdev))
  338. goto ReturnFailure;
  339. if (!bEnableText(ppdev))
  340. goto ReturnFailure;
  341. if (!bEnableBrushCache(ppdev))
  342. goto ReturnFailure;
  343. if (!bEnablePalette(ppdev))
  344. goto ReturnFailure;
  345. if (!bEnableDirectDraw(ppdev))
  346. goto ReturnFailure;
  347. /////////////////////////////////////////////////////////////////////
  348. // Now create our private surface structure.
  349. //
  350. // Whenever we get a call to draw directly to the screen, we'll get
  351. // passed a pointer to a SURFOBJ whose 'dhpdev' field will point
  352. // to our PDEV structure, and whose 'dhsurf' field will point to the
  353. // following DSURF structure.
  354. //
  355. // Every device bitmap we create in DrvCreateDeviceBitmap will also
  356. // have its own unique DSURF structure allocated (but will share the
  357. // same PDEV). To make our code more polymorphic for handling drawing
  358. // to either the screen or an off-screen bitmap, we have the same
  359. // structure for both.
  360. pdsurf = &ppdev->dsurfScreen;
  361. pdsurf->dt = 0;
  362. pdsurf->x = 0;
  363. pdsurf->y = 0;
  364. pdsurf->fpVidMem = 0;
  365. pdsurf->ppdev = ppdev;
  366. /////////////////////////////////////////////////////////////////////
  367. // Next, have GDI create the actual surface SURFOBJ structure.
  368. sizl.cx = ppdev->cxScreen;
  369. sizl.cy = ppdev->cyScreen;
  370. // Create the primary surface. This defaults to a 'device-managed'
  371. // surface, but EngModifySurface can change that.
  372. hsurf = EngCreateDeviceSurface((DHSURF) pdsurf,
  373. sizl,
  374. ppdev->iBitmapFormat);
  375. if (hsurf == 0)
  376. {
  377. DISPDBG((0, "DrvEnableSurface - Failed EngCreateDeviceSurface"));
  378. goto ReturnFailure;
  379. }
  380. if ((ppdev->flCaps & CAPS_NEW_MMIO) &&
  381. !(ppdev->flCaps & CAPS_NO_DIRECT_ACCESS))
  382. {
  383. // On all cards where we linearly map the frame buffer, create our
  384. // drawing surface as a GDI-managed surface, meaning that we give
  385. // GDI a pointer to the framebuffer and GDI can draw on the bits
  386. // directly. This will allow us good performance with drawing such
  387. // as GradientFills, even though our hardware can't accelerate the
  388. // drawing and so we don't hook DrvGradientFill. This way GDI can
  389. // do write-combined writes directly to the framebuffer and still be
  390. // very fast.
  391. //
  392. // Note that this requires that we hook DrvSynchronize and
  393. // set HOOK_SYNCHRONIZE.
  394. pjScreen = ppdev->pjScreen;
  395. lDelta = ppdev->lDelta;
  396. flHooks = ppdev->flHooks | HOOK_SYNCHRONIZE;
  397. }
  398. else
  399. {
  400. // Ugh, we're running on an ancient S3 card where we can't completely
  401. // map the entire frame buffer into memory. We have to create the
  402. // primary surface as a 'GDI-opaque' device-managed surface, and GDI
  403. // will be forced to go through only Drv calls that we've hooked.
  404. // (In this case, drawing such as GradientFills will be pathetically
  405. // slow.)
  406. pjScreen = NULL;
  407. lDelta = 0;
  408. flHooks = ppdev->flHooks;
  409. }
  410. // Note that this call is new to NT5, and takes the place of
  411. // EngAssociateSurface.
  412. if (!EngModifySurface(hsurf,
  413. ppdev->hdevEng,
  414. flHooks,
  415. MS_NOTSYSTEMMEMORY, // It's in video memory
  416. (DHSURF) pdsurf,
  417. pjScreen,
  418. lDelta,
  419. NULL))
  420. {
  421. DISPDBG((0, "DrvEnableSurface - Failed EngModifySurface"));
  422. goto ReturnFailure;
  423. }
  424. ppdev->hsurfScreen = hsurf; // Remember it for clean-up
  425. ppdev->bEnabled = TRUE; // We'll soon be in graphics mode
  426. // Create our generic temporary buffer, which may be used by any
  427. // component.
  428. pvTmpBuffer = EngAllocMem(0, TMP_BUFFER_SIZE, ALLOC_TAG);
  429. if (pvTmpBuffer == NULL)
  430. {
  431. DISPDBG((0, "DrvEnableSurface - Failed VirtualAlloc"));
  432. goto ReturnFailure;
  433. }
  434. ppdev->pvTmpBuffer = pvTmpBuffer;
  435. DISPDBG((5, "Passed DrvEnableSurface"));
  436. return(hsurf);
  437. ReturnFailure:
  438. DrvDisableSurface((DHPDEV) ppdev);
  439. DISPDBG((0, "Failed DrvEnableSurface"));
  440. return(0);
  441. }
  442. /******************************Public*Routine******************************\
  443. * VOID DrvDisableSurface
  444. *
  445. * Free resources allocated by DrvEnableSurface. Release the surface.
  446. *
  447. * Note that this function will be called when previewing modes in the
  448. * Display Applet, but not at system shutdown. If you need to reset the
  449. * hardware at shutdown, you can do it in the miniport by providing a
  450. * 'HwResetHw' entry point in the VIDEO_HW_INITIALIZATION_DATA structure.
  451. *
  452. * Note: In an error case, we may call this before DrvEnableSurface is
  453. * completely done.
  454. *
  455. \**************************************************************************/
  456. VOID DrvDisableSurface(
  457. DHPDEV dhpdev)
  458. {
  459. PDEV* ppdev;
  460. ppdev = (PDEV*) dhpdev;
  461. // Note: In an error case, some of the following relies on the
  462. // fact that the PDEV is zero-initialized, so fields like
  463. // 'hsurfScreen' will be zero unless the surface has been
  464. // sucessfully initialized, and makes the assumption that
  465. // EngDeleteSurface can take '0' as a parameter.
  466. vDisableDirectDraw(ppdev);
  467. vDisablePalette(ppdev);
  468. vDisableBrushCache(ppdev);
  469. vDisableText(ppdev);
  470. vDisablePointer(ppdev);
  471. vDisableOffscreenHeap(ppdev);
  472. vDisableBanking(ppdev);
  473. vDisableHardware(ppdev);
  474. EngFreeMem(ppdev->pvTmpBuffer);
  475. EngDeleteSurface(ppdev->hsurfScreen);
  476. }
  477. /******************************Public*Routine******************************\
  478. * BOOL DrvGetDirectDrawInfo
  479. *
  480. * Will be called after DrvEnablesurface. Will be called twice before
  481. * DrvEnableDirectDraw is called.
  482. *
  483. \**************************************************************************/
  484. BOOL DrvGetDirectDrawInfo(
  485. DHPDEV dhpdev,
  486. DD_HALINFO* pHalInfo,
  487. DWORD* pdwNumHeaps,
  488. VIDEOMEMORY* pvmList, // Will be NULL on first call
  489. DWORD* pdwNumFourCC,
  490. DWORD* pdwFourCC) // Will be NULL on first call
  491. {
  492. PDEV* ppdev;
  493. LONGLONG li;
  494. DWORD cProcessors;
  495. DWORD cHeaps;
  496. ppdev = (PDEV*) dhpdev;
  497. *pdwNumFourCC = 0;
  498. *pdwNumHeaps = 0;
  499. // We may not support DirectDraw on this card.
  500. //
  501. // The 765 (Trio64V+) has a bug such that writing to the frame
  502. // buffer during an accelerator operation may cause a hang if
  503. // you do the write soon enough after starting the blt. (There is
  504. // a small window of opportunity.) On UP machines, the context
  505. // switch time seems to be enough to avoid the problem. However,
  506. // on MP machines, we'll have to disable direct draw.
  507. //
  508. // NOTE: We can identify the 765 since it is the only chip with
  509. // the CAPS_STREAMS_CAPABLE flag.
  510. if (ppdev->flCaps & CAPS_STREAMS_CAPABLE)
  511. {
  512. if (!EngQuerySystemAttribute(EngNumberOfProcessors, &cProcessors) ||
  513. (cProcessors != 1))
  514. {
  515. return(FALSE);
  516. }
  517. }
  518. if (!(ppdev->flCaps & CAPS_NEW_MMIO) ||
  519. (ppdev->flCaps & CAPS_NO_DIRECT_ACCESS))
  520. {
  521. return(FALSE);
  522. }
  523. pHalInfo->dwSize = sizeof(*pHalInfo);
  524. // Current primary surface attributes. Since HalInfo is zero-initialized
  525. // by GDI, we only have to fill in the fields which should be non-zero:
  526. pHalInfo->vmiData.pvPrimary = ppdev->pjScreen;
  527. pHalInfo->vmiData.dwDisplayWidth = ppdev->cxScreen;
  528. pHalInfo->vmiData.dwDisplayHeight = ppdev->cyScreen;
  529. pHalInfo->vmiData.lDisplayPitch = ppdev->lDelta;
  530. pHalInfo->vmiData.ddpfDisplay.dwSize = sizeof(DDPIXELFORMAT);
  531. pHalInfo->vmiData.ddpfDisplay.dwFlags = DDPF_RGB;
  532. pHalInfo->vmiData.ddpfDisplay.dwRGBBitCount = 8 * ppdev->cjPelSize;
  533. if (ppdev->iBitmapFormat == BMF_8BPP)
  534. {
  535. pHalInfo->vmiData.ddpfDisplay.dwFlags |= DDPF_PALETTEINDEXED8;
  536. }
  537. // These masks will be zero at 8bpp:
  538. pHalInfo->vmiData.ddpfDisplay.dwRBitMask = ppdev->flRed;
  539. pHalInfo->vmiData.ddpfDisplay.dwGBitMask = ppdev->flGreen;
  540. pHalInfo->vmiData.ddpfDisplay.dwBBitMask = ppdev->flBlue;
  541. // The S3 has to do everything using 'rectangular' memory, because
  542. // the accelerator doesn't know how to set arbitrary strides.
  543. cHeaps = 0;
  544. // Snag a pointer to the video-memory list so that we can use it to
  545. // call back to DirectDraw to allocate video memory:
  546. ppdev->pvmList = pvmList;
  547. // Create one heap to describe the unused portion of video
  548. // memory to the right of the visible screen (if any):
  549. if (ppdev->cxScreen < ppdev->cxHeap)
  550. {
  551. cHeaps++;
  552. if (pvmList != NULL)
  553. {
  554. pvmList->dwFlags = VIDMEM_ISRECTANGULAR;
  555. pvmList->fpStart = ppdev->cxScreen * ppdev->cjPelSize;
  556. pvmList->dwWidth = (ppdev->cxHeap - ppdev->cxScreen)
  557. * ppdev->cjPelSize;
  558. pvmList->dwHeight = ppdev->cyScreen;
  559. pvmList->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  560. pvmList++;
  561. }
  562. }
  563. // Create another heap to describe the unused portion of video
  564. // memory below the visible screen (if any):
  565. if (ppdev->cyScreen < ppdev->cyHeap)
  566. {
  567. cHeaps++;
  568. if (pvmList != NULL)
  569. {
  570. pvmList->dwFlags = VIDMEM_ISRECTANGULAR;
  571. pvmList->fpStart = ppdev->cyScreen * ppdev->lDelta;
  572. pvmList->dwWidth = ppdev->cxHeap * ppdev->cjPelSize;
  573. pvmList->dwHeight = ppdev->cyHeap - ppdev->cyScreen;
  574. pvmList->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  575. pvmList++;
  576. }
  577. }
  578. // Update the number of heaps:
  579. ppdev->cHeaps = cHeaps;
  580. *pdwNumHeaps = cHeaps;
  581. // dword alignment must be guaranteed for off-screen surfaces:
  582. pHalInfo->vmiData.dwOffscreenAlign = 4;
  583. // Capabilities supported:
  584. pHalInfo->ddCaps.dwCaps = DDCAPS_BLT
  585. | DDCAPS_BLTCOLORFILL
  586. | DDCAPS_COLORKEY;
  587. pHalInfo->ddCaps.dwCKeyCaps = DDCKEYCAPS_SRCBLT;
  588. pHalInfo->ddCaps.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN
  589. | DDSCAPS_PRIMARYSURFACE
  590. | DDSCAPS_FLIP;
  591. // The Trio 64V+ has overlay streams capabilities which are a superset
  592. // of the above:
  593. if (ppdev->flCaps & CAPS_STREAMS_CAPABLE)
  594. {
  595. // Overlays need 8-byte alignment. Note that if 24bpp overlays are
  596. // ever supported, this will have to change to compensate:
  597. pHalInfo->vmiData.dwOverlayAlign = 8;
  598. pHalInfo->ddCaps.dwCaps |= DDCAPS_OVERLAY
  599. | DDCAPS_OVERLAYSTRETCH
  600. | DDCAPS_OVERLAYFOURCC
  601. | DDCAPS_OVERLAYCANTCLIP;
  602. pHalInfo->ddCaps.dwFXCaps |= DDFXCAPS_OVERLAYSTRETCHX
  603. | DDFXCAPS_OVERLAYSTRETCHY;
  604. // We support only destination colour keying because that's the
  605. // only permutation we've had a chance to test.
  606. pHalInfo->ddCaps.dwCKeyCaps |= DDCKEYCAPS_DESTOVERLAY;
  607. pHalInfo->ddCaps.ddsCaps.dwCaps |= DDSCAPS_OVERLAY;
  608. *pdwNumFourCC = 1;
  609. if (pdwFourCC)
  610. {
  611. pdwFourCC[0] = FOURCC_YUY2;
  612. }
  613. pHalInfo->ddCaps.dwMaxVisibleOverlays = 1;
  614. pHalInfo->ddCaps.dwMinOverlayStretch = ppdev->ulMinOverlayStretch;
  615. pHalInfo->ddCaps.dwMinLiveVideoStretch = ppdev->ulMinOverlayStretch;
  616. pHalInfo->ddCaps.dwMinHwCodecStretch = ppdev->ulMinOverlayStretch;
  617. pHalInfo->ddCaps.dwMaxOverlayStretch = 9999;
  618. pHalInfo->ddCaps.dwMaxLiveVideoStretch = 9999;
  619. pHalInfo->ddCaps.dwMaxHwCodecStretch = 9999;
  620. }
  621. // The 868 and 968 have a pixel formatter which is capable of doing
  622. // colour space conversions and hardware stretching from off-screen
  623. // surfaces:
  624. else if (ppdev->flCaps & CAPS_PIXEL_FORMATTER)
  625. {
  626. pHalInfo->ddCaps.dwCaps |= DDCAPS_BLTSTRETCH;
  627. pHalInfo->ddCaps.dwFXCaps |= DDFXCAPS_BLTSTRETCHX
  628. | DDFXCAPS_BLTSTRETCHY;
  629. // YUV is supported only above 8bpp:
  630. if (ppdev->iBitmapFormat != BMF_8BPP)
  631. {
  632. pHalInfo->ddCaps.dwCaps |= DDCAPS_BLTFOURCC;
  633. *pdwNumFourCC = 1;
  634. if (pdwFourCC)
  635. {
  636. *pdwFourCC = FOURCC_YUY2;
  637. }
  638. }
  639. }
  640. // Tell DirectDraw that we support additional callbacks via
  641. // DdGetDriverInfo:
  642. pHalInfo->GetDriverInfo = DdGetDriverInfo;
  643. pHalInfo->dwFlags |= DDHALINFO_GETDRIVERINFOSET;
  644. return(TRUE);
  645. }
  646. /******************************Public*Routine******************************\
  647. * BOOL DrvEnableDirectDraw
  648. *
  649. * This function is called by GDI when a new mode is set, immediately after
  650. * it calls our DrvEnableSurface and DrvGetDirectDrawInfo.
  651. *
  652. \**************************************************************************/
  653. BOOL DrvEnableDirectDraw(
  654. DHPDEV dhpdev,
  655. DD_CALLBACKS* pCallBacks,
  656. DD_SURFACECALLBACKS* pSurfaceCallBacks,
  657. DD_PALETTECALLBACKS* pPaletteCallBacks)
  658. {
  659. PDEV* ppdev;
  660. ppdev = (PDEV*) dhpdev;
  661. pCallBacks->WaitForVerticalBlank = DdWaitForVerticalBlank;
  662. pCallBacks->MapMemory = DdMapMemory;
  663. pCallBacks->dwFlags = DDHAL_CB32_WAITFORVERTICALBLANK
  664. | DDHAL_CB32_MAPMEMORY;
  665. pSurfaceCallBacks->Blt = DdBlt;
  666. pSurfaceCallBacks->Flip = DdFlip;
  667. pSurfaceCallBacks->Lock = DdLock;
  668. pSurfaceCallBacks->GetBltStatus = DdGetBltStatus;
  669. pSurfaceCallBacks->GetFlipStatus = DdGetFlipStatus;
  670. pSurfaceCallBacks->dwFlags = DDHAL_SURFCB32_BLT
  671. | DDHAL_SURFCB32_FLIP
  672. | DDHAL_SURFCB32_LOCK
  673. | DDHAL_SURFCB32_GETBLTSTATUS
  674. | DDHAL_SURFCB32_GETFLIPSTATUS;
  675. // We can do overlays only when the Streams processor is enabled:
  676. if (ppdev->flCaps & CAPS_STREAMS_CAPABLE)
  677. {
  678. pCallBacks->CreateSurface = DdCreateSurface;
  679. pCallBacks->CanCreateSurface = DdCanCreateSurface;
  680. pCallBacks->dwFlags |= DDHAL_CB32_CREATESURFACE
  681. | DDHAL_CB32_CANCREATESURFACE;
  682. pSurfaceCallBacks->SetColorKey = DdSetColorKey;
  683. pSurfaceCallBacks->UpdateOverlay = DdUpdateOverlay;
  684. pSurfaceCallBacks->SetOverlayPosition = DdSetOverlayPosition;
  685. pSurfaceCallBacks->dwFlags |= DDHAL_SURFCB32_SETCOLORKEY
  686. | DDHAL_SURFCB32_UPDATEOVERLAY
  687. | DDHAL_SURFCB32_SETOVERLAYPOSITION;
  688. ppdev->ulColorKey = 0;
  689. }
  690. // We can do blts with funky surface formats only when the pixel
  691. // formatter is enabled:
  692. else if (ppdev->flCaps & CAPS_PIXEL_FORMATTER)
  693. {
  694. pCallBacks->CreateSurface = DdCreateSurface;
  695. pCallBacks->CanCreateSurface = DdCanCreateSurface;
  696. pCallBacks->dwFlags |= DDHAL_CB32_CREATESURFACE
  697. | DDHAL_CB32_CANCREATESURFACE;
  698. }
  699. return(TRUE);
  700. }
  701. /******************************Public*Routine******************************\
  702. * VOID DrvDisableDirectDraw
  703. *
  704. * This function is called by GDI when the driver is to be disabled, just
  705. * before it calls DrvDisableSurface.
  706. *
  707. \**************************************************************************/
  708. VOID DrvDisableDirectDraw(
  709. DHPDEV dhpdev)
  710. {
  711. }
  712. /******************************Public*Routine******************************\
  713. * VOID DrvAssertMode
  714. *
  715. * This asks the device to reset itself to the mode of the pdev passed in.
  716. *
  717. \**************************************************************************/
  718. BOOL DrvAssertMode(
  719. DHPDEV dhpdev,
  720. BOOL bEnable)
  721. {
  722. PDEV* ppdev;
  723. ppdev = (PDEV*) dhpdev;
  724. if (!bEnable)
  725. {
  726. //////////////////////////////////////////////////////////////
  727. // Disable - Switch to full-screen mode
  728. vAssertModeDirectDraw(ppdev, FALSE);
  729. vAssertModePalette(ppdev, FALSE);
  730. vAssertModeBrushCache(ppdev, FALSE);
  731. vAssertModeText(ppdev, FALSE);
  732. vAssertModePointer(ppdev, FALSE);
  733. if (bAssertModeOffscreenHeap(ppdev, FALSE))
  734. {
  735. vAssertModeBanking(ppdev, FALSE);
  736. if (bAssertModeHardware(ppdev, FALSE))
  737. {
  738. ppdev->bEnabled = FALSE;
  739. return(TRUE);
  740. }
  741. //////////////////////////////////////////////////////////
  742. // We failed to switch to full-screen. So undo everything:
  743. vAssertModeBanking(ppdev, TRUE);
  744. bAssertModeOffscreenHeap(ppdev, TRUE); // We don't need to check
  745. } // return code with TRUE
  746. // there is HW setup in bEnablePointer that needs to be done at assert time too
  747. // coming back from full-screen DOS or hibernate so call enablepointer which
  748. // then calls vAssertModePointer itself. In 8bpp, the DAC resolution was not
  749. // being set correctly after FSdos or Hib. causing screen to be dim
  750. bEnablePointer(ppdev);
  751. vAssertModeText(ppdev, TRUE);
  752. vAssertModeBrushCache(ppdev, TRUE);
  753. vAssertModePalette(ppdev, TRUE);
  754. vAssertModeDirectDraw(ppdev, TRUE);
  755. }
  756. else
  757. {
  758. //////////////////////////////////////////////////////////////
  759. // Enable - Switch back to graphics mode
  760. // We have to enable every subcomponent in the reverse order
  761. // in which it was disabled:
  762. if (bAssertModeHardware(ppdev, TRUE))
  763. {
  764. vAssertModeBanking(ppdev, TRUE);
  765. bAssertModeOffscreenHeap(ppdev, TRUE); // We don't need to check
  766. // return code with TRUE
  767. bEnablePointer(ppdev);
  768. vAssertModeText(ppdev, TRUE);
  769. vAssertModeBrushCache(ppdev, TRUE);
  770. vAssertModePalette(ppdev, TRUE);
  771. vAssertModeDirectDraw(ppdev, TRUE);
  772. ppdev->bEnabled = TRUE;
  773. return(TRUE);
  774. }
  775. }
  776. return(FALSE);
  777. }
  778. /******************************Public*Routine******************************\
  779. * ULONG DrvGetModes
  780. *
  781. * Returns the list of available modes for the device.
  782. *
  783. \**************************************************************************/
  784. ULONG DrvGetModes(
  785. HANDLE hDriver,
  786. ULONG cjSize,
  787. DEVMODEW* pdm)
  788. {
  789. DWORD cModes;
  790. DWORD cbOutputSize;
  791. PVIDEO_MODE_INFORMATION pVideoModeInformation;
  792. PVIDEO_MODE_INFORMATION pVideoTemp;
  793. DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  794. DWORD cbModeSize;
  795. cModes = getAvailableModes(hDriver,
  796. (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
  797. &cbModeSize);
  798. if (cModes == 0)
  799. {
  800. DISPDBG((0, "DrvGetModes failed to get mode information"));
  801. return(0);
  802. }
  803. if (pdm == NULL)
  804. {
  805. cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  806. }
  807. else
  808. {
  809. //
  810. // Now copy the information for the supported modes back into the
  811. // output buffer
  812. //
  813. cbOutputSize = 0;
  814. pVideoTemp = pVideoModeInformation;
  815. do
  816. {
  817. if (pVideoTemp->Length != 0)
  818. {
  819. if (cOutputModes == 0)
  820. {
  821. break;
  822. }
  823. //
  824. // Zero the entire structure to start off with.
  825. //
  826. memset(pdm, 0, sizeof(DEVMODEW));
  827. //
  828. // Set the name of the device to the name of the DLL.
  829. //
  830. memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
  831. pdm->dmSpecVersion = DM_SPECVERSION;
  832. pdm->dmDriverVersion = DM_SPECVERSION;
  833. pdm->dmSize = sizeof(DEVMODEW);
  834. pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
  835. pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
  836. pVideoTemp->BitsPerPlane;
  837. pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
  838. pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
  839. pdm->dmDisplayFrequency = pVideoTemp->Frequency;
  840. pdm->dmDisplayFlags = 0;
  841. pdm->dmFields = DM_BITSPERPEL |
  842. DM_PELSWIDTH |
  843. DM_PELSHEIGHT |
  844. DM_DISPLAYFREQUENCY |
  845. DM_DISPLAYFLAGS ;
  846. //
  847. // Go to the next DEVMODE entry in the buffer.
  848. //
  849. cOutputModes--;
  850. pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW) +
  851. DRIVER_EXTRA_SIZE);
  852. cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  853. }
  854. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  855. (((PUCHAR)pVideoTemp) + cbModeSize);
  856. } while (--cModes);
  857. }
  858. EngFreeMem(pVideoModeInformation);
  859. return(cbOutputSize);
  860. }
  861. /******************************Public*Routine******************************\
  862. * BOOL bAssertModeHardware
  863. *
  864. * Sets the appropriate hardware state for graphics mode or full-screen.
  865. *
  866. \**************************************************************************/
  867. BOOL bAssertModeHardware(
  868. PDEV* ppdev,
  869. BOOL bEnable)
  870. {
  871. BYTE* pjIoBase;
  872. BYTE* pjMmBase;
  873. DWORD ReturnedDataLength;
  874. ULONG ulReturn;
  875. BYTE jExtendedMemoryControl;
  876. VIDEO_MODE_INFORMATION VideoModeInfo;
  877. LONG cjEndOfFrameBuffer;
  878. LONG cjPointerOffset;
  879. LONG lDelta;
  880. ULONG ulMiscState;
  881. pjIoBase = ppdev->pjIoBase;
  882. pjMmBase = ppdev->pjMmBase;
  883. if (bEnable)
  884. {
  885. // Call the miniport via an IOCTL to set the graphics mode.
  886. if (EngDeviceIoControl(ppdev->hDriver,
  887. IOCTL_VIDEO_SET_CURRENT_MODE,
  888. &ppdev->ulMode, // input buffer
  889. sizeof(DWORD),
  890. NULL,
  891. 0,
  892. &ReturnedDataLength))
  893. {
  894. DISPDBG((0, "bAssertModeHardware - Failed VIDEO_SET_CURRENT_MODE"));
  895. goto ReturnFalse;
  896. }
  897. if (EngDeviceIoControl(ppdev->hDriver,
  898. IOCTL_VIDEO_QUERY_CURRENT_MODE,
  899. NULL,
  900. 0,
  901. &VideoModeInfo,
  902. sizeof(VideoModeInfo),
  903. &ReturnedDataLength))
  904. {
  905. DISPDBG((0, "bAssertModeHardware - failed VIDEO_QUERY_CURRENT_MODE"));
  906. goto ReturnFalse;
  907. }
  908. #if DEBUG_HEAP
  909. VideoModeInfo.VideoMemoryBitmapWidth = VideoModeInfo.VisScreenWidth;
  910. VideoModeInfo.VideoMemoryBitmapHeight = VideoModeInfo.VisScreenHeight;
  911. #endif
  912. // The following variables are determined only after the initial
  913. // modeset:
  914. ppdev->lDelta = VideoModeInfo.ScreenStride;
  915. ppdev->flCaps = VideoModeInfo.DriverSpecificAttributeFlags;
  916. ppdev->cxMemory = VideoModeInfo.VideoMemoryBitmapWidth;
  917. ppdev->cxHeap = VideoModeInfo.VideoMemoryBitmapWidth;
  918. ppdev->cyMemory = VideoModeInfo.VideoMemoryBitmapHeight;
  919. ppdev->cyHeap = VideoModeInfo.VideoMemoryBitmapHeight;
  920. ppdev->bMmIo = ((ppdev->flCaps & CAPS_MM_IO) > 0);
  921. // If we're using the S3 hardware pointer, reserve the last 1k of
  922. // the frame buffer to store the pointer shape:
  923. if (!(ppdev->flCaps & (CAPS_SW_POINTER | CAPS_DAC_POINTER)))
  924. {
  925. // Byte offset from start of frame buffer to end:
  926. cjEndOfFrameBuffer = ppdev->cyMemory * ppdev->lDelta;
  927. // We'll reserve the end of off-screen memory for the hardware
  928. // pointer shape. Unfortunately, the S3 chips have a bug
  929. // where the shape has to be stored on a 1K multiple,
  930. // regardless of what the current screen stride is.
  931. cjPointerOffset = (cjEndOfFrameBuffer - HW_POINTER_TOTAL_SIZE)
  932. & ~(HW_POINTER_TOTAL_SIZE - 1);
  933. // Figure out the coordinate where the pointer shape starts:
  934. lDelta = ppdev->lDelta;
  935. ppdev->cjPointerOffset = cjPointerOffset;
  936. ppdev->yPointerShape = (cjPointerOffset / lDelta);
  937. ppdev->xPointerShape =
  938. CONVERT_FROM_BYTES((cjPointerOffset % lDelta), ppdev);
  939. if (ppdev->yPointerShape >= ppdev->cyScreen)
  940. {
  941. // There's enough room for the pointer shape at the
  942. // bottom of off-screen memory; reserve its room by
  943. // lying about how much off-screen memory there is:
  944. ppdev->cyMemory = ppdev->yPointerShape;
  945. }
  946. else
  947. {
  948. // There's not enough room for the pointer shape in
  949. // off-screen memory; we'll have to simulate:
  950. ppdev->flCaps |= CAPS_SW_POINTER;
  951. }
  952. }
  953. // Do some parameter checking on the values that the miniport
  954. // returned to us:
  955. ASSERTDD(ppdev->cxMemory >= ppdev->cxScreen, "Invalid cxMemory");
  956. ASSERTDD(ppdev->cyMemory >= ppdev->cyScreen, "Invalid cyMemory");
  957. ASSERTDD((ppdev->flCaps &
  958. (CAPS_NEW_BANK_CONTROL | CAPS_NEWER_BANK_CONTROL)) ||
  959. ((ppdev->cxMemory <= 1024) && (ppdev->cyMemory <= 1024)),
  960. "Have to have new bank control if more than 1meg memory");
  961. ASSERTDD((ppdev->flCaps & (CAPS_SW_POINTER | CAPS_DAC_POINTER)) !=
  962. (CAPS_SW_POINTER | CAPS_DAC_POINTER),
  963. "Should not set both Software and DAC cursor flags");
  964. ASSERTDD(!(ppdev->flCaps & CAPS_MM_IO) ||
  965. (ppdev->flCaps & (CAPS_MM_TRANSFER | CAPS_MM_32BIT_TRANSFER)),
  966. "Must enable memory-mapped transfer if memory-mapped I/O");
  967. // First thing we do is unlock the accelerator registers:
  968. ACQUIRE_CRTC_CRITICAL_SECTION(ppdev);
  969. OUTPW(pjIoBase, CRTC_INDEX, ((SYSCTL_UNLOCK << 8) | CR39));
  970. OUTPW(pjIoBase, CRTC_INDEX, ((REG_UNLOCK_1 << 8) | S3R8));
  971. // Enable memory-mapped IO. Note that ulMiscState should not be
  972. // read on non-memory mapped I/O S3's because it does not exist
  973. // on 911/924's.
  974. if (ppdev->flCaps & CAPS_MM_IO)
  975. {
  976. OUTP(pjIoBase, CRTC_INDEX, 0x53);
  977. jExtendedMemoryControl = INP(pjIoBase, CRTC_DATA);
  978. OUTP(pjIoBase, CRTC_DATA, jExtendedMemoryControl | 0x10);
  979. // Read the default MULTI_MISC register state.
  980. IO_GP_WAIT(ppdev); // Wait so we don't interfere with any
  981. // pending commands waiting on the
  982. // FIFO
  983. IO_READ_SEL(ppdev, 6); // We'll be reading index 0xE
  984. IO_GP_WAIT(ppdev); // Wait until that's processed
  985. IO_RD_REG_DT(ppdev, ulMiscState); // Read ulMiscState
  986. // Make the colour and mask registers '32-bit'.
  987. //
  988. // NOTE: This is what precludes enabling MM I/O on 928 boards.
  989. ulMiscState |= 0x0200;
  990. IO_MULT_MISC(ppdev, ulMiscState);
  991. ppdev->ulMiscState = ulMiscState;
  992. }
  993. RELEASE_CRTC_CRITICAL_SECTION(ppdev);
  994. // Then set the rest of the default registers:
  995. vResetClipping(ppdev);
  996. if (ppdev->flCaps & CAPS_MM_IO)
  997. {
  998. IO_FIFO_WAIT(ppdev, 1);
  999. MM_WRT_MASK(ppdev, pjMmBase, -1);
  1000. }
  1001. else
  1002. {
  1003. if (DEPTH32(ppdev))
  1004. {
  1005. IO_FIFO_WAIT(ppdev, 2);
  1006. IO_WRT_MASK32(ppdev, -1);
  1007. }
  1008. else
  1009. {
  1010. IO_FIFO_WAIT(ppdev, 1);
  1011. IO_WRT_MASK(ppdev, -1);
  1012. }
  1013. }
  1014. }
  1015. else
  1016. {
  1017. // Call the kernel driver to reset the device to a known state.
  1018. // NTVDM will take things from there:
  1019. if (EngDeviceIoControl(ppdev->hDriver,
  1020. IOCTL_VIDEO_RESET_DEVICE,
  1021. NULL,
  1022. 0,
  1023. NULL,
  1024. 0,
  1025. &ulReturn))
  1026. {
  1027. DISPDBG((0, "bAssertModeHardware - Failed reset IOCTL"));
  1028. goto ReturnFalse;
  1029. }
  1030. }
  1031. DISPDBG((5, "Passed bAssertModeHardware"));
  1032. return(TRUE);
  1033. ReturnFalse:
  1034. DISPDBG((0, "Failed bAssertModeHardware"));
  1035. return(FALSE);
  1036. }
  1037. /******************************Public*Routine******************************\
  1038. * BOOL bEnableHardware
  1039. *
  1040. * Puts the hardware in the requested mode and initializes it.
  1041. *
  1042. * Note: Should be called before any access is done to the hardware from
  1043. * the display driver.
  1044. *
  1045. \**************************************************************************/
  1046. BOOL bEnableHardware(
  1047. PDEV* ppdev)
  1048. {
  1049. BYTE* pjIoBase;
  1050. VIDEO_PUBLIC_ACCESS_RANGES VideoAccessRange[2];
  1051. VIDEO_MEMORY VideoMemory;
  1052. VIDEO_MEMORY_INFORMATION VideoMemoryInfo;
  1053. DWORD ReturnedDataLength;
  1054. UCHAR* pj;
  1055. USHORT* pw;
  1056. ULONG* pd;
  1057. ULONG i;
  1058. // We need a critical section merely because of some S3 weirdness:
  1059. // both the bank control registers and the cursor registers have
  1060. // to be accessed through the shared CRTC registers. We want to
  1061. // set the GCAPS_ASYNCMOVE flag to allow the cursor to move even
  1062. // while we're using the bank registers for a blt -- so we have to
  1063. // synchronize all accesses to the CRTC registers.
  1064. //
  1065. // (Note that in the case of GCAPS_ASYNCMOVE, GDI automatically
  1066. // synchronizes with DrvSetPalette, so you don't have to worry
  1067. // about overlap between asynchronous cursor moves and the palette
  1068. // registers.)
  1069. ppdev->csCrtc = EngCreateSemaphore();
  1070. if (ppdev->csCrtc == 0)
  1071. {
  1072. DISPDBG((0, "bEnableHardware - Error creating CRTC semaphore"));
  1073. goto ReturnFalse;
  1074. }
  1075. // Map io ports into virtual memory:
  1076. if (EngDeviceIoControl(ppdev->hDriver,
  1077. IOCTL_VIDEO_QUERY_PUBLIC_ACCESS_RANGES,
  1078. NULL, // input buffer
  1079. 0,
  1080. &VideoAccessRange, // output buffer
  1081. sizeof(VideoAccessRange),
  1082. &ReturnedDataLength))
  1083. {
  1084. DISPDBG((0, "bEnableHardware - Initialization error mapping IO port base"));
  1085. goto ReturnFalse;
  1086. }
  1087. ppdev->pjIoBase = (UCHAR*) VideoAccessRange[0].VirtualAddress;
  1088. ppdev->pjMmBase = (BYTE*) VideoAccessRange[1].VirtualAddress;
  1089. pjIoBase = ppdev->pjIoBase;
  1090. // Get the linear memory address range.
  1091. VideoMemory.RequestedVirtualAddress = NULL;
  1092. if (EngDeviceIoControl(ppdev->hDriver,
  1093. IOCTL_VIDEO_MAP_VIDEO_MEMORY,
  1094. &VideoMemory, // input buffer
  1095. sizeof(VIDEO_MEMORY),
  1096. &VideoMemoryInfo, // output buffer
  1097. sizeof(VideoMemoryInfo),
  1098. &ReturnedDataLength))
  1099. {
  1100. DISPDBG((0, "bEnableHardware - Error mapping buffer address"));
  1101. goto ReturnFalse;
  1102. }
  1103. // Record the Frame Buffer Linear Address.
  1104. ppdev->pjScreen = (BYTE*) VideoMemoryInfo.FrameBufferBase;
  1105. ppdev->cjBank = VideoMemoryInfo.FrameBufferLength;
  1106. DISPDBG((1, "pjScreen: %lx pjMmBase: %lx", ppdev->pjScreen, ppdev->pjMmBase));
  1107. // Set all the register addresses.
  1108. ppdev->ioCur_y = pjIoBase + CUR_Y;
  1109. ppdev->ioCur_x = pjIoBase + CUR_X;
  1110. ppdev->ioDesty_axstp = pjIoBase + DEST_Y;
  1111. ppdev->ioDestx_diastp = pjIoBase + DEST_X;
  1112. ppdev->ioErr_term = pjIoBase + ERR_TERM;
  1113. ppdev->ioMaj_axis_pcnt = pjIoBase + MAJ_AXIS_PCNT;
  1114. ppdev->ioGp_stat_cmd = pjIoBase + CMD;
  1115. ppdev->ioShort_stroke = pjIoBase + SHORT_STROKE;
  1116. ppdev->ioBkgd_color = pjIoBase + BKGD_COLOR;
  1117. ppdev->ioFrgd_color = pjIoBase + FRGD_COLOR;
  1118. ppdev->ioWrt_mask = pjIoBase + WRT_MASK;
  1119. ppdev->ioRd_mask = pjIoBase + RD_MASK;
  1120. ppdev->ioColor_cmp = pjIoBase + COLOR_CMP;
  1121. ppdev->ioBkgd_mix = pjIoBase + BKGD_MIX;
  1122. ppdev->ioFrgd_mix = pjIoBase + FRGD_MIX;
  1123. ppdev->ioMulti_function = pjIoBase + MULTIFUNC_CNTL;
  1124. ppdev->ioPix_trans = pjIoBase + PIX_TRANS;
  1125. for (pw = (USHORT*) ppdev->pjMmBase, i = 0; i < XFER_BUFFERS; i++, pw += 2)
  1126. {
  1127. ppdev->apwMmXfer[i] = pw;
  1128. }
  1129. for (pd = (ULONG*) ppdev->pjMmBase, i = 0; i < XFER_BUFFERS; i++, pd++)
  1130. {
  1131. ppdev->apdMmXfer[i] = pd;
  1132. }
  1133. // Now we can set the mode, unlock the accelerator, and reset the
  1134. // clipping:
  1135. if (!bAssertModeHardware(ppdev, TRUE))
  1136. goto ReturnFalse;
  1137. if (ppdev->flCaps & CAPS_MM_IO)
  1138. {
  1139. // Can do memory-mapped IO:
  1140. ppdev->pfnFillSolid = vMmFillSolid;
  1141. ppdev->pfnFillPat = vMmFillPatFast;
  1142. ppdev->pfnXfer1bpp = vMmXfer1bpp;
  1143. ppdev->pfnXfer4bpp = vMmXfer4bpp;
  1144. ppdev->pfnXferNative = vMmXferNative;
  1145. ppdev->pfnCopyBlt = vMmCopyBlt;
  1146. ppdev->pfnFastPatRealize = vMmFastPatRealize;
  1147. ppdev->pfnTextOut = bMmTextOut;
  1148. ppdev->pfnLineToTrivial = vMmLineToTrivial;
  1149. ppdev->pfnLineToClipped = vMmLineToClipped;
  1150. ppdev->pfnCopyTransparent = vMmCopyTransparent;
  1151. if (ppdev->flCaps & CAPS_MM_32BIT_TRANSFER)
  1152. ppdev->pfnImageTransfer = vMmImageTransferMm32;
  1153. else
  1154. ppdev->pfnImageTransfer = vMmImageTransferMm16;
  1155. // On some cards, it may be faster to use the old I/O based
  1156. // glyph routine, which uses the CPU to draw all the glyphs
  1157. // to a monochrome buffer, and then uses the video hardware
  1158. // to colour expand the result:
  1159. if (!(ppdev->flCaps & CAPS_MM_GLYPH_EXPAND))
  1160. ppdev->pfnTextOut = bIoTextOut;
  1161. if (ppdev->flCaps & CAPS_NEW_MMIO)
  1162. {
  1163. ppdev->pfnTextOut = bNwTextOut;
  1164. ppdev->pfnLineToTrivial = vNwLineToTrivial;
  1165. ppdev->pfnLineToClipped = vNwLineToClipped;
  1166. }
  1167. }
  1168. else
  1169. {
  1170. // Have to do IN/OUTs:
  1171. ppdev->pfnFillSolid = vIoFillSolid;
  1172. ppdev->pfnFillPat = vIoFillPatFast;
  1173. // bEnableBrushCache may override this value
  1174. ppdev->pfnXfer1bpp = vIoXfer1bpp;
  1175. ppdev->pfnXfer4bpp = vIoXfer4bpp;
  1176. ppdev->pfnXferNative = vIoXferNative;
  1177. ppdev->pfnCopyBlt = vIoCopyBlt;
  1178. ppdev->pfnFastPatRealize = vIoFastPatRealize;
  1179. ppdev->pfnTextOut = bIoTextOut;
  1180. ppdev->pfnLineToTrivial = vIoLineToTrivial;
  1181. ppdev->pfnLineToClipped = vIoLineToClipped;
  1182. ppdev->pfnCopyTransparent = vIoCopyTransparent;
  1183. if (ppdev->flCaps & CAPS_MM_TRANSFER)
  1184. ppdev->pfnImageTransfer = vIoImageTransferMm16;
  1185. else
  1186. ppdev->pfnImageTransfer = vIoImageTransferIo16;
  1187. }
  1188. #if DBG
  1189. {
  1190. ACQUIRE_CRTC_CRITICAL_SECTION(ppdev);
  1191. OUTP(pjIoBase, CRTC_INDEX, 0x30);
  1192. DISPDBG((0, "Chip: %lx Bank: %lx Width: %li Height: %li Stride: %li Flags: %08lx",
  1193. (ULONG) INP(pjIoBase, CRTC_DATA), ppdev->cjBank, ppdev->cxMemory, ppdev->cyMemory,
  1194. ppdev->lDelta, ppdev->flCaps));
  1195. RELEASE_CRTC_CRITICAL_SECTION(ppdev);
  1196. }
  1197. #endif
  1198. DISPDBG((5, "Passed bEnableHardware"));
  1199. return(TRUE);
  1200. ReturnFalse:
  1201. DISPDBG((0, "Failed bEnableHardware"));
  1202. return(FALSE);
  1203. }
  1204. /******************************Public*Routine******************************\
  1205. * VOID vDisableHardware
  1206. *
  1207. * Undoes anything done in bEnableHardware.
  1208. *
  1209. * Note: In an error case, we may call this before bEnableHardware is
  1210. * completely done.
  1211. *
  1212. \**************************************************************************/
  1213. VOID vDisableHardware(
  1214. PDEV* ppdev)
  1215. {
  1216. DWORD ReturnedDataLength;
  1217. VIDEO_MEMORY VideoMemory[2];
  1218. VideoMemory[0].RequestedVirtualAddress = ppdev->pjScreen;
  1219. if (EngDeviceIoControl(ppdev->hDriver,
  1220. IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
  1221. VideoMemory,
  1222. sizeof(VIDEO_MEMORY),
  1223. NULL,
  1224. 0,
  1225. &ReturnedDataLength))
  1226. {
  1227. DISPDBG((0, "vDisableHardware failed IOCTL_VIDEO_UNMAP_VIDEO"));
  1228. }
  1229. VideoMemory[0].RequestedVirtualAddress = ppdev->pjIoBase;
  1230. VideoMemory[1].RequestedVirtualAddress = ppdev->pjMmBase;
  1231. if (EngDeviceIoControl(ppdev->hDriver,
  1232. IOCTL_VIDEO_FREE_PUBLIC_ACCESS_RANGES,
  1233. VideoMemory,
  1234. sizeof(VideoMemory),
  1235. NULL,
  1236. 0,
  1237. &ReturnedDataLength))
  1238. {
  1239. DISPDBG((0, "vDisableHardware failed IOCTL_VIDEO_FREE_PUBLIC_ACCESS"));
  1240. }
  1241. EngDeleteSemaphore(ppdev->csCrtc);
  1242. }
  1243. /******************************Public*Routine******************************\
  1244. * BOOL bInitializeModeFields
  1245. *
  1246. * Initializes a bunch of fields in the pdev, devcaps (aka gdiinfo), and
  1247. * devinfo based on the requested mode.
  1248. *
  1249. \**************************************************************************/
  1250. BOOL bInitializeModeFields(
  1251. PDEV* ppdev,
  1252. GDIINFO* pgdi,
  1253. DEVINFO* pdi,
  1254. DEVMODEW* pdm)
  1255. {
  1256. ULONG cModes;
  1257. PVIDEO_MODE_INFORMATION pVideoBuffer;
  1258. PVIDEO_MODE_INFORMATION pVideoModeSelected;
  1259. PVIDEO_MODE_INFORMATION pVideoTemp;
  1260. BOOL bSelectDefault;
  1261. VIDEO_MODE_INFORMATION VideoModeInformation;
  1262. ULONG cbModeSize;
  1263. // Call the miniport to get mode information
  1264. cModes = getAvailableModes(ppdev->hDriver, &pVideoBuffer, &cbModeSize);
  1265. if (cModes == 0)
  1266. goto ReturnFalse;
  1267. // Now see if the requested mode has a match in that table.
  1268. pVideoModeSelected = NULL;
  1269. pVideoTemp = pVideoBuffer;
  1270. if ((pdm->dmPelsWidth == 0) &&
  1271. (pdm->dmPelsHeight == 0) &&
  1272. (pdm->dmBitsPerPel == 0) &&
  1273. (pdm->dmDisplayFrequency == 0))
  1274. {
  1275. DISPDBG((1, "Default mode requested"));
  1276. bSelectDefault = TRUE;
  1277. }
  1278. else
  1279. {
  1280. DISPDBG((1, "Requested mode..."));
  1281. DISPDBG((1, " Screen width -- %li", pdm->dmPelsWidth));
  1282. DISPDBG((1, " Screen height -- %li", pdm->dmPelsHeight));
  1283. DISPDBG((1, " Bits per pel -- %li", pdm->dmBitsPerPel));
  1284. DISPDBG((1, " Frequency -- %li", pdm->dmDisplayFrequency));
  1285. bSelectDefault = FALSE;
  1286. }
  1287. while (cModes--)
  1288. {
  1289. if (pVideoTemp->Length != 0)
  1290. {
  1291. DISPDBG((8, " Checking against miniport mode:"));
  1292. DISPDBG((8, " Screen width -- %li", pVideoTemp->VisScreenWidth));
  1293. DISPDBG((8, " Screen height -- %li", pVideoTemp->VisScreenHeight));
  1294. DISPDBG((8, " Bits per pel -- %li", pVideoTemp->BitsPerPlane *
  1295. pVideoTemp->NumberOfPlanes));
  1296. DISPDBG((8, " Frequency -- %li", pVideoTemp->Frequency));
  1297. if (bSelectDefault ||
  1298. ((pVideoTemp->VisScreenWidth == pdm->dmPelsWidth) &&
  1299. (pVideoTemp->VisScreenHeight == pdm->dmPelsHeight) &&
  1300. (pVideoTemp->BitsPerPlane *
  1301. pVideoTemp->NumberOfPlanes == pdm->dmBitsPerPel) &&
  1302. (pVideoTemp->Frequency == pdm->dmDisplayFrequency)))
  1303. {
  1304. pVideoModeSelected = pVideoTemp;
  1305. DISPDBG((1, "...Found a mode match!"));
  1306. break;
  1307. }
  1308. }
  1309. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  1310. (((PUCHAR)pVideoTemp) + cbModeSize);
  1311. }
  1312. // If no mode has been found, return an error
  1313. if (pVideoModeSelected == NULL)
  1314. {
  1315. DISPDBG((1, "...Couldn't find a mode match!"));
  1316. EngFreeMem(pVideoBuffer);
  1317. goto ReturnFalse;
  1318. }
  1319. // We have chosen the one we want. Save it in a stack buffer and
  1320. // get rid of allocated memory before we forget to free it.
  1321. VideoModeInformation = *pVideoModeSelected;
  1322. EngFreeMem(pVideoBuffer);
  1323. #if DEBUG_HEAP
  1324. VideoModeInformation.VisScreenWidth = 640;
  1325. VideoModeInformation.VisScreenHeight = 480;
  1326. pdm->dmPelsWidth = 640;
  1327. pdm->dmPelsHeight = 480;
  1328. #endif
  1329. // Set up screen information from the mini-port:
  1330. ppdev->ulMode = VideoModeInformation.ModeIndex;
  1331. ppdev->cxScreen = VideoModeInformation.VisScreenWidth;
  1332. ppdev->cyScreen = VideoModeInformation.VisScreenHeight;
  1333. ppdev->cBitsPerPel = VideoModeInformation.BitsPerPlane;
  1334. DISPDBG((1, "ScreenStride: %lx", VideoModeInformation.ScreenStride));
  1335. // We handle HOOK_SYNCHRONIZE separately at surface creation time:
  1336. ppdev->flHooks = (HOOK_BITBLT |
  1337. HOOK_TEXTOUT |
  1338. HOOK_FILLPATH |
  1339. HOOK_COPYBITS |
  1340. HOOK_STROKEPATH |
  1341. HOOK_LINETO |
  1342. HOOK_STRETCHBLT |
  1343. HOOK_TRANSPARENTBLT);
  1344. // Fill in the GDIINFO data structure with the default 8bpp values:
  1345. *pgdi = ggdiDefault;
  1346. // Now overwrite the defaults with the relevant information returned
  1347. // from the kernel driver:
  1348. pgdi->ulHorzSize = VideoModeInformation.XMillimeter;
  1349. pgdi->ulVertSize = VideoModeInformation.YMillimeter;
  1350. pgdi->ulHorzRes = VideoModeInformation.VisScreenWidth;
  1351. pgdi->ulVertRes = VideoModeInformation.VisScreenHeight;
  1352. pgdi->ulPanningHorzRes = VideoModeInformation.VisScreenWidth;
  1353. pgdi->ulPanningVertRes = VideoModeInformation.VisScreenHeight;
  1354. pgdi->cBitsPixel = VideoModeInformation.BitsPerPlane;
  1355. pgdi->cPlanes = VideoModeInformation.NumberOfPlanes;
  1356. pgdi->ulVRefresh = VideoModeInformation.Frequency;
  1357. pgdi->ulDACRed = VideoModeInformation.NumberRedBits;
  1358. pgdi->ulDACGreen = VideoModeInformation.NumberGreenBits;
  1359. pgdi->ulDACBlue = VideoModeInformation.NumberBlueBits;
  1360. pgdi->ulLogPixelsX = pdm->dmLogPixels;
  1361. pgdi->ulLogPixelsY = pdm->dmLogPixels;
  1362. // Fill in the devinfo structure with the default 8bpp values:
  1363. *pdi = gdevinfoDefault;
  1364. if (VideoModeInformation.BitsPerPlane == 8)
  1365. {
  1366. ppdev->cjPelSize = 1;
  1367. ppdev->iBitmapFormat = BMF_8BPP;
  1368. // Assuming palette is orthogonal - all colors are same size.
  1369. ppdev->cPaletteShift = 8 - pgdi->ulDACRed;
  1370. DISPDBG((3, "palette shift = %d\n", ppdev->cPaletteShift));
  1371. }
  1372. else if ((VideoModeInformation.BitsPerPlane == 16) ||
  1373. (VideoModeInformation.BitsPerPlane == 15))
  1374. {
  1375. ppdev->cjPelSize = 2;
  1376. ppdev->iBitmapFormat = BMF_16BPP;
  1377. ppdev->flRed = VideoModeInformation.RedMask;
  1378. ppdev->flGreen = VideoModeInformation.GreenMask;
  1379. ppdev->flBlue = VideoModeInformation.BlueMask;
  1380. pgdi->ulNumColors = (ULONG) -1;
  1381. pgdi->ulNumPalReg = 0;
  1382. pgdi->ulHTOutputFormat = HT_FORMAT_16BPP;
  1383. pdi->iDitherFormat = BMF_16BPP;
  1384. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1385. }
  1386. else if (VideoModeInformation.BitsPerPlane == 24)
  1387. {
  1388. ppdev->cjPelSize = 3;
  1389. ppdev->iBitmapFormat = BMF_24BPP;
  1390. ppdev->flRed = VideoModeInformation.RedMask;
  1391. ppdev->flGreen = VideoModeInformation.GreenMask;
  1392. ppdev->flBlue = VideoModeInformation.BlueMask;
  1393. pgdi->ulNumColors = (ULONG) -1;
  1394. pgdi->ulNumPalReg = 0;
  1395. pgdi->ulHTOutputFormat = HT_FORMAT_24BPP;
  1396. pdi->iDitherFormat = BMF_24BPP;
  1397. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1398. }
  1399. else
  1400. {
  1401. ASSERTDD(VideoModeInformation.BitsPerPlane == 32,
  1402. "This driver supports only 8, 16, 24 and 32bpp");
  1403. ppdev->cjPelSize = 4;
  1404. ppdev->iBitmapFormat = BMF_32BPP;
  1405. ppdev->flRed = VideoModeInformation.RedMask;
  1406. ppdev->flGreen = VideoModeInformation.GreenMask;
  1407. ppdev->flBlue = VideoModeInformation.BlueMask;
  1408. pgdi->ulNumColors = (ULONG) -1;
  1409. pgdi->ulNumPalReg = 0;
  1410. pgdi->ulHTOutputFormat = HT_FORMAT_32BPP;
  1411. pdi->iDitherFormat = BMF_32BPP;
  1412. pdi->flGraphicsCaps &= ~(GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
  1413. }
  1414. DISPDBG((5, "Passed bInitializeModeFields"));
  1415. return(TRUE);
  1416. ReturnFalse:
  1417. DISPDBG((0, "Failed bInitializeModeFields"));
  1418. return(FALSE);
  1419. }
  1420. /******************************Public*Routine******************************\
  1421. * DWORD getAvailableModes
  1422. *
  1423. * Calls the miniport to get the list of modes supported by the kernel driver,
  1424. * and returns the list of modes supported by the diplay driver among those
  1425. *
  1426. * returns the number of entries in the videomode buffer.
  1427. * 0 means no modes are supported by the miniport or that an error occured.
  1428. *
  1429. * NOTE: the buffer must be freed up by the caller.
  1430. *
  1431. \**************************************************************************/
  1432. DWORD getAvailableModes(
  1433. HANDLE hDriver,
  1434. PVIDEO_MODE_INFORMATION* modeInformation, // Must be freed by caller
  1435. DWORD* cbModeSize)
  1436. {
  1437. ULONG ulTemp;
  1438. VIDEO_NUM_MODES modes;
  1439. PVIDEO_MODE_INFORMATION pVideoTemp;
  1440. //
  1441. // Get the number of modes supported by the mini-port
  1442. //
  1443. if (EngDeviceIoControl(hDriver,
  1444. IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
  1445. NULL,
  1446. 0,
  1447. &modes,
  1448. sizeof(VIDEO_NUM_MODES),
  1449. &ulTemp))
  1450. {
  1451. DISPDBG((0, "getAvailableModes - Failed VIDEO_QUERY_NUM_AVAIL_MODES"));
  1452. return(0);
  1453. }
  1454. *cbModeSize = modes.ModeInformationLength;
  1455. //
  1456. // Allocate the buffer for the mini-port to write the modes in.
  1457. //
  1458. *modeInformation = EngAllocMem(FL_ZERO_MEMORY,
  1459. modes.NumModes * modes.ModeInformationLength,
  1460. ALLOC_TAG);
  1461. if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
  1462. {
  1463. DISPDBG((0, "getAvailableModes - Failed EngAllocMem"));
  1464. return 0;
  1465. }
  1466. //
  1467. // Ask the mini-port to fill in the available modes.
  1468. //
  1469. if (EngDeviceIoControl(hDriver,
  1470. IOCTL_VIDEO_QUERY_AVAIL_MODES,
  1471. NULL,
  1472. 0,
  1473. *modeInformation,
  1474. modes.NumModes * modes.ModeInformationLength,
  1475. &ulTemp))
  1476. {
  1477. DISPDBG((0, "getAvailableModes - Failed VIDEO_QUERY_AVAIL_MODES"));
  1478. EngFreeMem(*modeInformation);
  1479. *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
  1480. return(0);
  1481. }
  1482. //
  1483. // Now see which of these modes are supported by the display driver.
  1484. // As an internal mechanism, set the length to 0 for the modes we
  1485. // DO NOT support.
  1486. //
  1487. ulTemp = modes.NumModes;
  1488. pVideoTemp = *modeInformation;
  1489. //
  1490. // Mode is rejected if it is not one plane, or not graphics, or is not
  1491. // one of 8, 15, 16, 24 or 32 bits per pel.
  1492. //
  1493. while (ulTemp--)
  1494. {
  1495. if ((pVideoTemp->NumberOfPlanes != 1 ) ||
  1496. !(pVideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
  1497. ((pVideoTemp->BitsPerPlane != 8) &&
  1498. (pVideoTemp->BitsPerPlane != 15) &&
  1499. (pVideoTemp->BitsPerPlane != 16) &&
  1500. (pVideoTemp->BitsPerPlane != 24) &&
  1501. (pVideoTemp->BitsPerPlane != 32)))
  1502. {
  1503. DISPDBG((2, "Rejecting miniport mode:"));
  1504. DISPDBG((2, " Screen width -- %li", pVideoTemp->VisScreenWidth));
  1505. DISPDBG((2, " Screen height -- %li", pVideoTemp->VisScreenHeight));
  1506. DISPDBG((2, " Bits per pel -- %li", pVideoTemp->BitsPerPlane *
  1507. pVideoTemp->NumberOfPlanes));
  1508. DISPDBG((2, " Frequency -- %li", pVideoTemp->Frequency));
  1509. pVideoTemp->Length = 0;
  1510. }
  1511. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  1512. (((PUCHAR)pVideoTemp) + modes.ModeInformationLength);
  1513. }
  1514. return(modes.NumModes);
  1515. }