Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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