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.

831 lines
27 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: enable.c
  3. *
  4. * The initialization guts of the Headless driver.
  5. *
  6. * The drawing guts of a portable Headless driver for Windows NT. The
  7. * implementation herein may possibly be the simplest method of bringing
  8. * up a driver whose surface is not directly writable by GDI. One might
  9. * use the phrase "quick and dirty" when describing it.
  10. *
  11. * We create a 4bpp bitmap that is the size of the screen, and simply
  12. * have GDI do all the drawing to it. We update the screen directly
  13. * from the bitmap, based on the bounds of the drawing (basically
  14. * employing "dirty rectangles").
  15. *
  16. * In total, the only hardware-specific code we had to write was the
  17. * initialization code, and a routine for doing aligned srccopy blts
  18. * from a DIB to the screen.
  19. *
  20. * Obvious Note: This approach is definitely not recommended for decent
  21. * driver performance.
  22. *
  23. * Copyright (c) 2000 Microsoft Corporation
  24. *
  25. \**************************************************************************/
  26. #include "precomp.h"
  27. /******************************Public*Structure****************************\
  28. * DFVFN gadrvfn[]
  29. *
  30. * Build the driver function table gadrvfn with function index/address
  31. * pairs. This table tells GDI which DDI calls we support, and their
  32. * location (GDI does an indirect call through this table to call us).
  33. *
  34. \**************************************************************************/
  35. static DRVFN gadrvfn[] = {
  36. { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
  37. { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
  38. { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
  39. { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
  40. { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
  41. { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
  42. { INDEX_DrvGetModes, (PFN) DrvGetModes }
  43. };
  44. ULONG gcdrvfn = sizeof(gadrvfn) / sizeof(DRVFN);
  45. /******************************Public*Structure****************************\
  46. * GDIINFO ggdiDefault
  47. *
  48. * This contains the default GDIINFO fields that are passed back to GDI
  49. * during DrvEnablePDEV.
  50. *
  51. * NOTE: This structure defaults to values for a 4bpp non-palette device.
  52. \**************************************************************************/
  53. GDIINFO ggdiDefault = {
  54. GDI_DRIVER_VERSION,
  55. DT_RASDISPLAY, // ulTechnology
  56. 0, // ulHorzSize
  57. 0, // ulVertSize
  58. 0, // ulHorzRes (filled in at initialization)
  59. 0, // ulVertRes (filled in at initialization)
  60. 4, // cBitsPixel
  61. 1, // cPlanes
  62. 16, // ulNumColors
  63. 0, // flRaster (DDI reserved field)
  64. 0, // ulLogPixelsX (filled in at initialization)
  65. 0, // ulLogPixelsY (filled in at initialization)
  66. TC_RA_ABLE, // flTextCaps
  67. 6, // ulDACRed
  68. 6, // ulDACGree
  69. 6, // ulDACBlue
  70. 0x0024, // ulAspectX (one-to-one aspect ratio)
  71. 0x0024, // ulAspectY
  72. 0x0033, // ulAspectXY
  73. 1, // xStyleStep
  74. 1, // yStyleSte;
  75. 3, // denStyleStep
  76. { 0, 0 }, // ptlPhysOffset
  77. { 0, 0 }, // szlPhysSize
  78. 0, // ulNumPalReg (win3.1 16 color drivers say 0 too)
  79. // These fields are for halftone initialization.
  80. { // ciDevice, ColorInfo
  81. { 6700, 3300, 0 }, // Red
  82. { 2100, 7100, 0 }, // Green
  83. { 1400, 800, 0 }, // Blue
  84. { 1750, 3950, 0 }, // Cyan
  85. { 4050, 2050, 0 }, // Magenta
  86. { 4400, 5200, 0 }, // Yellow
  87. { 3127, 3290, 0 }, // AlignmentWhite
  88. 20000, // RedGamma
  89. 20000, // GreenGamma
  90. 20000, // BlueGamma
  91. 0, 0, 0, 0, 0, 0
  92. },
  93. 0, // ulDevicePelsDPI (filled in at initialization)
  94. PRIMARY_ORDER_CBA, // ulPrimaryOrder
  95. HT_PATSIZE_4x4_M, // ulHTPatternSize
  96. HT_FORMAT_4BPP_IRGB, // ulHTOutputFormat
  97. HT_FLAG_ADDITIVE_PRIMS, // flHTFlags
  98. 0, // ulVRefresh
  99. 1, // ulBltAlignment (preferred window alignment
  100. // for fast-text routines)
  101. 0, // ulPanningHorzRes
  102. 0, // ulPanningVertRes
  103. };
  104. /******************************Public*Structure****************************\
  105. * DEVINFO gdevinfoDefault
  106. *
  107. * This contains the default DEVINFO fields that are passed back to GDI
  108. * during DrvEnablePDEV.
  109. *
  110. * NOTE: This structure defaults to values for a 4bpp non-palette device.
  111. \**************************************************************************/
  112. #define SYSTM_LOGFONT {16,7,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS, \
  113. CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, \
  114. VARIABLE_PITCH | FF_DONTCARE,L"System"}
  115. #define HELVE_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS, \
  116. CLIP_STROKE_PRECIS,PROOF_QUALITY, \
  117. VARIABLE_PITCH | FF_DONTCARE, L"MS Sans Serif"}
  118. #define COURI_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS, \
  119. CLIP_STROKE_PRECIS,PROOF_QUALITY, \
  120. FIXED_PITCH | FF_DONTCARE, L"Courier"}
  121. DEVINFO gdevinfoDefault =
  122. {
  123. (GCAPS_MONO_DITHER | GCAPS_COLOR_DITHER), // Graphics capabilities
  124. SYSTM_LOGFONT, // Default font description
  125. HELVE_LOGFONT, // ANSI variable font description
  126. COURI_LOGFONT, // ANSI fixed font description
  127. 0, // Count of device fonts
  128. BMF_4BPP, // preferred DIB format
  129. 8, // Width of color dither
  130. 8, // Height of color dither
  131. 0 // Default palette to use for this device
  132. };
  133. /******************************Public*Data*Struct*************************\
  134. * VGALOGPALETTE logPalVGA
  135. *
  136. * This is the palette for the VGA.
  137. *
  138. \**************************************************************************/
  139. typedef struct _VGALOGPALETTE
  140. {
  141. USHORT ident;
  142. USHORT NumEntries;
  143. PALETTEENTRY palPalEntry[16];
  144. } VGALOGPALETTE;
  145. const VGALOGPALETTE logPalVGA =
  146. {
  147. 0x500, // Driver version
  148. 16, // Number of entries
  149. {
  150. { 0, 0, 0, 0 }, // 0
  151. { 0x80,0, 0, 0 }, // 1
  152. { 0, 0x80,0, 0 }, // 2
  153. { 0x80,0x80,0, 0 }, // 3
  154. { 0, 0, 0x80,0 }, // 4
  155. { 0x80,0, 0x80,0 }, // 5
  156. { 0, 0x80,0x80,0 }, // 6
  157. { 0x80,0x80,0x80,0 }, // 7
  158. { 0xC0,0xC0,0xC0,0 }, // 8
  159. { 0xFF,0, 0, 0 }, // 9
  160. { 0, 0xFF,0, 0 }, // 10
  161. { 0xFF,0xFF,0, 0 }, // 11
  162. { 0, 0, 0xFF,0 }, // 12
  163. { 0xFF,0, 0xFF,0 }, // 13
  164. { 0, 0xFF,0xFF,0 }, // 14
  165. { 0xFF,0xFF,0xFF,0 } // 15
  166. }
  167. };
  168. /******************************Public*Routine******************************\
  169. * BOOL DrvEnableDriver
  170. *
  171. * Enables the driver by retrieving the drivers function table and version.
  172. *
  173. \**************************************************************************/
  174. BOOL DrvEnableDriver(
  175. ULONG iEngineVersion,
  176. ULONG cj,
  177. DRVENABLEDATA* pded)
  178. {
  179. // Engine Version is passed down so future drivers can support previous
  180. // engine versions. A next generation driver can support both the old
  181. // and new engine conventions if told what version of engine it is
  182. // working with. For the first version the driver does nothing with it.
  183. // Fill in as much as we can.
  184. if (cj >= sizeof(DRVENABLEDATA))
  185. pded->pdrvfn = gadrvfn;
  186. if (cj >= (sizeof(ULONG) * 2))
  187. pded->c = gcdrvfn;
  188. // DDI version this driver was targeted for is passed back to engine.
  189. // Future graphic's engine may break calls down to old driver format.
  190. if (cj >= sizeof(ULONG))
  191. pded->iDriverVersion = DDI_DRIVER_VERSION;
  192. return(TRUE);
  193. }
  194. /******************************Public*Routine******************************\
  195. * VOID DrvDisableDriver
  196. *
  197. * Tells the driver it is being disabled. Release any resources allocated in
  198. * DrvEnableDriver.
  199. *
  200. \**************************************************************************/
  201. VOID DrvDisableDriver(VOID)
  202. {
  203. return;
  204. }
  205. /******************************Public*Routine******************************\
  206. * DWORD getAvailableModes
  207. *
  208. * Calls the miniport to get the list of modes supported by the kernel driver,
  209. * and returns the list of modes supported by the diplay driver among those
  210. *
  211. * returns the number of entries in the videomode buffer.
  212. * 0 means no modes are supported by the miniport or that an error occured.
  213. *
  214. * NOTE: the buffer must be freed up by the caller.
  215. *
  216. \**************************************************************************/
  217. DWORD getAvailableModes(
  218. HANDLE hDriver,
  219. PVIDEO_MODE_INFORMATION* modeInformation,
  220. DWORD* cbModeSize)
  221. {
  222. ULONG ulTemp;
  223. VIDEO_NUM_MODES modes;
  224. DWORD status;
  225. //
  226. // Get the number of modes supported by the mini-port
  227. //
  228. if (status = EngDeviceIoControl(hDriver,
  229. IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
  230. NULL,
  231. 0,
  232. &modes,
  233. sizeof(VIDEO_NUM_MODES),
  234. &ulTemp))
  235. {
  236. DISPDBG((0, "getAvailableModes failed VIDEO_QUERY_NUM_AVAIL_MODES"));
  237. DISPDBG((0, "Win32 Status = %x", status));
  238. return(0);
  239. }
  240. *cbModeSize = modes.ModeInformationLength;
  241. //
  242. // Allocate the buffer for the mini-port to write the modes in.
  243. //
  244. *modeInformation = (PVIDEO_MODE_INFORMATION)
  245. EngAllocMem(FL_ZERO_MEMORY,
  246. modes.NumModes *
  247. modes.ModeInformationLength, ALLOC_TAG);
  248. if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
  249. {
  250. DISPDBG((0, "getAvailableModes failed EngAllocMem"));
  251. return(0);
  252. }
  253. //
  254. // Ask the mini-port to fill in the available modes.
  255. //
  256. if (status = EngDeviceIoControl(hDriver,
  257. IOCTL_VIDEO_QUERY_AVAIL_MODES,
  258. NULL,
  259. 0,
  260. *modeInformation,
  261. modes.NumModes * modes.ModeInformationLength,
  262. &ulTemp))
  263. {
  264. DISPDBG((0, "getAvailableModes failed VIDEO_QUERY_AVAIL_MODES"));
  265. DISPDBG((0, "Win32 Status = %x", status));
  266. EngFreeMem(*modeInformation);
  267. *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
  268. return(0);
  269. }
  270. return(modes.NumModes);
  271. }
  272. /******************************Public*Routine******************************\
  273. * BOOL bInitializeModeFields
  274. *
  275. * Initializes a bunch of fields in the pdev, devcaps (aka gdiinfo), and
  276. * devinfo based on the requested mode.
  277. *
  278. \**************************************************************************/
  279. BOOL bInitializeModeFields(
  280. PDEV* ppdev,
  281. GDIINFO* pgdi,
  282. DEVINFO* pdi,
  283. DEVMODEW* pdm)
  284. {
  285. ULONG cModes;
  286. PVIDEO_MODE_INFORMATION pVideoBuffer;
  287. PVIDEO_MODE_INFORMATION pVideoModeSelected;
  288. PVIDEO_MODE_INFORMATION pVideoTemp;
  289. BOOL bSelectDefault;
  290. VIDEO_MODE_INFORMATION VideoModeInformation;
  291. ULONG cbModeSize;
  292. // Call the miniport to get mode information
  293. cModes = getAvailableModes(ppdev->hDriver, &pVideoBuffer, &cbModeSize);
  294. if (cModes == 0)
  295. goto ReturnFalse;
  296. // Now see if the requested mode has a match in that table.
  297. pVideoModeSelected = NULL;
  298. pVideoTemp = pVideoBuffer;
  299. if ((pdm->dmPelsWidth == 0) &&
  300. (pdm->dmPelsHeight == 0) &&
  301. (pdm->dmBitsPerPel == 0) &&
  302. (pdm->dmDisplayFrequency == 0))
  303. {
  304. DISPDBG((1, "Default mode requested"));
  305. bSelectDefault = TRUE;
  306. }
  307. else
  308. {
  309. DISPDBG((1, "Requested mode..."));
  310. DISPDBG((1, " Screen width -- %li", pdm->dmPelsWidth));
  311. DISPDBG((1, " Screen height -- %li", pdm->dmPelsHeight));
  312. DISPDBG((1, " Bits per pel -- %li", pdm->dmBitsPerPel));
  313. DISPDBG((1, " Frequency -- %li", pdm->dmDisplayFrequency));
  314. bSelectDefault = FALSE;
  315. }
  316. while (cModes--)
  317. {
  318. if (pVideoTemp->Length != 0)
  319. {
  320. DISPDBG((2, " Checking against miniport mode:"));
  321. DISPDBG((2, " Screen width -- %li", pVideoTemp->VisScreenWidth));
  322. DISPDBG((2, " Screen height -- %li", pVideoTemp->VisScreenHeight));
  323. DISPDBG((2, " Bits per pel -- %li", pVideoTemp->BitsPerPlane *
  324. pVideoTemp->NumberOfPlanes));
  325. DISPDBG((2, " Frequency -- %li", pVideoTemp->Frequency));
  326. if (bSelectDefault ||
  327. ((pVideoTemp->VisScreenWidth == pdm->dmPelsWidth) &&
  328. (pVideoTemp->VisScreenHeight == pdm->dmPelsHeight) &&
  329. (pVideoTemp->BitsPerPlane *
  330. pVideoTemp->NumberOfPlanes == pdm->dmBitsPerPel) &&
  331. (pVideoTemp->Frequency == pdm->dmDisplayFrequency)))
  332. {
  333. pVideoModeSelected = pVideoTemp;
  334. DISPDBG((1, "...Found a mode match!"));
  335. break;
  336. }
  337. }
  338. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  339. (((PUCHAR)pVideoTemp) + cbModeSize);
  340. }
  341. // If no mode has been found, return an error
  342. if (pVideoModeSelected == NULL)
  343. {
  344. DISPDBG((1, "...Couldn't find a mode match!"));
  345. EngFreeMem(pVideoBuffer);
  346. goto ReturnFalse;
  347. }
  348. // We have chosen the one we want. Save it in a stack buffer and
  349. // get rid of allocated memory before we forget to free it.
  350. VideoModeInformation = *pVideoModeSelected;
  351. EngFreeMem(pVideoBuffer);
  352. // Set up screen information from the mini-port:
  353. ppdev->cxScreen = VideoModeInformation.VisScreenWidth;
  354. ppdev->cyScreen = VideoModeInformation.VisScreenHeight;
  355. // Fill in the GDIINFO data structure with the default 4bpp values:
  356. *pgdi = ggdiDefault;
  357. // Now overwrite the defaults with the relevant information returned
  358. // from the kernel driver:
  359. pgdi->ulHorzSize = VideoModeInformation.XMillimeter;
  360. pgdi->ulVertSize = VideoModeInformation.YMillimeter;
  361. pgdi->ulHorzRes = VideoModeInformation.VisScreenWidth;
  362. pgdi->ulVertRes = VideoModeInformation.VisScreenHeight;
  363. pgdi->ulPanningHorzRes = VideoModeInformation.VisScreenWidth;
  364. pgdi->ulPanningVertRes = VideoModeInformation.VisScreenHeight;
  365. pgdi->cBitsPixel = VideoModeInformation.BitsPerPlane;
  366. pgdi->cPlanes = VideoModeInformation.NumberOfPlanes;
  367. pgdi->ulVRefresh = VideoModeInformation.Frequency;
  368. pgdi->ulDACRed = VideoModeInformation.NumberRedBits;
  369. pgdi->ulDACGreen = VideoModeInformation.NumberGreenBits;
  370. pgdi->ulDACBlue = VideoModeInformation.NumberBlueBits;
  371. pgdi->ulLogPixelsX = pdm->dmLogPixels;
  372. pgdi->ulLogPixelsY = pdm->dmLogPixels;
  373. // Fill in the devinfo structure with the default 4bpp values:
  374. *pdi = gdevinfoDefault;
  375. return(TRUE);
  376. ReturnFalse:
  377. DISPDBG((0, "Failed bInitializeModeFields"));
  378. return(FALSE);
  379. }
  380. /******************************Public*Routine******************************\
  381. * BOOL bInitializePalette
  382. *
  383. * Initializes default palette for PDEV.
  384. *
  385. \**************************************************************************/
  386. BOOL bInitializePalette(
  387. PDEV* ppdev,
  388. DEVINFO* pdi)
  389. {
  390. HPALETTE hpal;
  391. hpal = EngCreatePalette(PAL_INDEXED, 16, (ULONG*) (logPalVGA.palPalEntry),
  392. 0, 0, 0);
  393. if (hpal == 0)
  394. goto ReturnFalse;
  395. ppdev->hpalDefault = hpal;
  396. pdi->hpalDefault = hpal;
  397. return(TRUE);
  398. ReturnFalse:
  399. DISPDBG((0, "Failed bInitializePalette"));
  400. return(FALSE);
  401. }
  402. /******************************Public*Routine******************************\
  403. * VOID vUninitializePalette
  404. *
  405. * Frees resources allocated by bInitializePalette.
  406. *
  407. * Note: In an error case, this may be called before bInitializePalette.
  408. *
  409. \**************************************************************************/
  410. VOID vUninitializePalette(PDEV* ppdev)
  411. {
  412. // Delete the default palette if we created one:
  413. if (ppdev->hpalDefault != 0)
  414. EngDeletePalette(ppdev->hpalDefault);
  415. }
  416. /******************************Public*Routine******************************\
  417. * DHPDEV DrvEnablePDEV
  418. *
  419. * Initializes a bunch of fields for GDI, based on the mode we've been asked
  420. * to do. This is the first thing called after DrvEnableDriver, when GDI
  421. * wants to get some information about us.
  422. *
  423. * (This function mostly returns back information; DrvEnableSurface is used
  424. * for initializing the hardware and driver components.)
  425. *
  426. \**************************************************************************/
  427. DHPDEV DrvEnablePDEV(
  428. DEVMODEW* pdm, // Contains data pertaining to requested mode
  429. PWSTR pwszLogAddr, // Logical address
  430. ULONG cPat, // Count of standard patterns
  431. HSURF* phsurfPatterns, // Buffer for standard patterns
  432. ULONG cjCaps, // Size of buffer for device caps 'pdevcaps'
  433. ULONG* pdevcaps, // Buffer for device caps, also known as 'gdiinfo'
  434. ULONG cjDevInfo, // Number of bytes in device info 'pdi'
  435. DEVINFO* pdi, // Device information
  436. HDEV hdev, // HDEV, used for callbacks
  437. PWSTR pwszDeviceName, // Device name
  438. HANDLE hDriver) // Kernel driver handle
  439. {
  440. PDEV* ppdev;
  441. // Future versions of NT had better supply 'devcaps' and 'devinfo'
  442. // structures that are the same size or larger than the current
  443. // structures:
  444. if ((cjCaps < sizeof(GDIINFO)) || (cjDevInfo < sizeof(DEVINFO)))
  445. {
  446. DISPDBG((0, "DrvEnablePDEV - Buffer size too small"));
  447. goto ReturnFailure0;
  448. }
  449. // Allocate a physical device structure. Note that we definitely
  450. // rely on the zero initialization:
  451. ppdev = (PDEV*) EngAllocMem(FL_ZERO_MEMORY, sizeof(PDEV), ALLOC_TAG);
  452. if (ppdev == NULL)
  453. {
  454. DISPDBG((0, "DrvEnablePDEV - Failed EngAllocMem"));
  455. goto ReturnFailure0;
  456. }
  457. ppdev->hDriver = hDriver;
  458. // Get the current screen mode information. Set up device caps and
  459. // devinfo:
  460. if (!bInitializeModeFields(ppdev, (GDIINFO*) pdevcaps, pdi, pdm))
  461. {
  462. DISPDBG((0, "DrvEnablePDEV - Failed bInitializeModeFields"));
  463. goto ReturnFailure1;
  464. }
  465. // Initialize palette information.
  466. if (!bInitializePalette(ppdev, pdi))
  467. {
  468. DISPDBG((0, "DrvEnablePDEV - Failed bInitializePalette"));
  469. goto ReturnFailure1;
  470. }
  471. return((DHPDEV) ppdev);
  472. ReturnFailure1:
  473. DrvDisablePDEV((DHPDEV) ppdev);
  474. ReturnFailure0:
  475. DISPDBG((0, "Failed DrvEnablePDEV"));
  476. return(0);
  477. }
  478. /******************************Public*Routine******************************\
  479. * DrvDisablePDEV
  480. *
  481. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  482. * enabled DrvDisableSurface will have already been called.
  483. *
  484. * Note: In an error, we may call this before DrvEnablePDEV is done.
  485. *
  486. \**************************************************************************/
  487. VOID DrvDisablePDEV(
  488. DHPDEV dhpdev)
  489. {
  490. PDEV* ppdev;
  491. ppdev = (PDEV*) dhpdev;
  492. vUninitializePalette(ppdev);
  493. EngFreeMem(ppdev);
  494. }
  495. /******************************Public*Routine******************************\
  496. * VOID DrvCompletePDEV
  497. *
  498. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  499. *
  500. \**************************************************************************/
  501. VOID DrvCompletePDEV(
  502. DHPDEV dhpdev,
  503. HDEV hdev)
  504. {
  505. ((PDEV*) dhpdev)->hdevEng = hdev;
  506. }
  507. /******************************Public*Routine******************************\
  508. * HSURF DrvEnableSurface
  509. *
  510. * Creates the drawing surface, initializes the hardware, and initializes
  511. * driver components. This function is called after DrvEnablePDEV, and
  512. * performs the final device initialization.
  513. *
  514. \**************************************************************************/
  515. HSURF DrvEnableSurface(
  516. DHPDEV dhpdev)
  517. {
  518. PDEV* ppdev;
  519. HSURF hsurfShadow;
  520. SIZEL sizl;
  521. DWORD status;
  522. ULONG ulTemp;
  523. ppdev = (PDEV*) dhpdev;
  524. // Create the 4bpp DIB on which we'll have GDI do all the drawing.
  525. // We'll merely occasionally blt portions to the screen to update.
  526. sizl.cx = ppdev->cxScreen;
  527. sizl.cy = ppdev->cyScreen;
  528. hsurfShadow = (HSURF) EngCreateBitmap(sizl, 0, BMF_4BPP, 0, NULL);
  529. if (hsurfShadow == 0)
  530. goto ReturnFailure;
  531. if (!EngAssociateSurface(hsurfShadow, ppdev->hdevEng, 0))
  532. {
  533. DISPDBG((0, "DrvEnableSurface - Failed second EngAssociateSurface"));
  534. goto ReturnFailure;
  535. }
  536. ppdev->pso = EngLockSurface(hsurfShadow);
  537. if (ppdev->pso == NULL)
  538. goto ReturnFailure;
  539. /////////////////////////////////////////////////////////////////////
  540. // Now enable all the subcomponents.
  541. //
  542. // Note that the order in which these 'Enable' functions are called
  543. // may be significant in low off-screen memory conditions, because
  544. // the off-screen heap manager may fail some of the later
  545. // allocations...
  546. DISPDBG((5, "Passed DrvEnableSurface"));
  547. return hsurfShadow;
  548. ReturnFailure:
  549. DrvDisableSurface((DHPDEV) ppdev);
  550. DISPDBG((0, "Failed DrvEnableSurface"));
  551. return(0);
  552. }
  553. /******************************Public*Routine******************************\
  554. * VOID DrvDisableSurface
  555. *
  556. * Free resources allocated by DrvEnableSurface. Release the surface.
  557. *
  558. * Note: In an error case, we may call this before DrvEnableSurface is
  559. * completely done.
  560. *
  561. \**************************************************************************/
  562. VOID DrvDisableSurface(
  563. DHPDEV dhpdev)
  564. {
  565. PDEV* ppdev;
  566. HSURF hsurf;
  567. DWORD status;
  568. ULONG ulTemp;
  569. ppdev = (PDEV*) dhpdev;
  570. // Note: In an error case, some of the following relies on the
  571. // fact that the PDEV is zero-initialized, so fields like
  572. // 'hsurfScreen' will be zero unless the surface has been
  573. // sucessfully initialized, and makes the assumption that
  574. // EngDeleteSurface can take '0' as a parameter.
  575. hsurf = ppdev->pso->hsurf;
  576. EngUnlockSurface(ppdev->pso);
  577. EngDeleteSurface(hsurf);
  578. }
  579. /******************************Public*Routine******************************\
  580. * VOID DrvAssertMode
  581. *
  582. * This asks the device to reset itself to the mode of the pdev passed in.
  583. *
  584. \**************************************************************************/
  585. BOOL DrvAssertMode(
  586. DHPDEV dhpdev,
  587. BOOL bEnable)
  588. {
  589. return TRUE;
  590. }
  591. /******************************Public*Routine******************************\
  592. * ULONG DrvGetModes
  593. *
  594. * Returns the list of available modes for the device.
  595. *
  596. \**************************************************************************/
  597. ULONG DrvGetModes(
  598. HANDLE hDriver,
  599. ULONG cjSize,
  600. DEVMODEW* pdm)
  601. {
  602. DWORD cModes;
  603. DWORD cbOutputSize;
  604. PVIDEO_MODE_INFORMATION pVideoModeInformation;
  605. PVIDEO_MODE_INFORMATION pVideoTemp;
  606. DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  607. DWORD cbModeSize;
  608. cModes = getAvailableModes(hDriver,
  609. (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
  610. &cbModeSize);
  611. if (cModes == 0)
  612. {
  613. DISPDBG((0, "DrvGetModes failed to get mode information"));
  614. return(0);
  615. }
  616. if (pdm == NULL)
  617. {
  618. cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  619. }
  620. else
  621. {
  622. //
  623. // Now copy the information for the supported modes back into the
  624. // output buffer
  625. //
  626. cbOutputSize = 0;
  627. pVideoTemp = pVideoModeInformation;
  628. do
  629. {
  630. if (pVideoTemp->Length != 0)
  631. {
  632. if (cOutputModes == 0)
  633. {
  634. break;
  635. }
  636. //
  637. // Zero the entire structure to start off with.
  638. //
  639. memset(pdm, 0, sizeof(DEVMODEW));
  640. //
  641. // Set the name of the device to the name of the DLL.
  642. //
  643. memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
  644. pdm->dmSpecVersion = DM_SPECVERSION;
  645. pdm->dmDriverVersion = DM_SPECVERSION;
  646. pdm->dmSize = sizeof(DEVMODEW);
  647. pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
  648. pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
  649. pVideoTemp->BitsPerPlane;
  650. pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
  651. pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
  652. pdm->dmDisplayFrequency = pVideoTemp->Frequency;
  653. pdm->dmDisplayFlags = 0;
  654. pdm->dmFields = DM_BITSPERPEL |
  655. DM_PELSWIDTH |
  656. DM_PELSHEIGHT |
  657. DM_DISPLAYFREQUENCY |
  658. DM_DISPLAYFLAGS ;
  659. //
  660. // Go to the next DEVMODE entry in the buffer.
  661. //
  662. cOutputModes--;
  663. pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW) +
  664. DRIVER_EXTRA_SIZE);
  665. cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  666. }
  667. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  668. (((PUCHAR)pVideoTemp) + cbModeSize);
  669. } while (--cModes);
  670. }
  671. EngFreeMem(pVideoModeInformation);
  672. return(cbOutputSize);
  673. }