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.

537 lines
15 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 "driver.h"
  15. // The driver function table with all function index/address pairs
  16. static DRVFN gadrvfn[] =
  17. {
  18. { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
  19. { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
  20. { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
  21. { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
  22. { INDEX_DrvOffset, (PFN) DrvOffset },
  23. { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
  24. { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
  25. { INDEX_DrvSetPalette, (PFN) DrvSetPalette },
  26. { INDEX_DrvMovePointer, (PFN) DrvMovePointer },
  27. { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape },
  28. { INDEX_DrvDitherColor, (PFN) DrvDitherColor },
  29. { INDEX_DrvSynchronize, (PFN) DrvSynchronize },
  30. { INDEX_DrvGetModes, (PFN) DrvGetModes },
  31. { INDEX_DrvDisableDriver, (PFN) DrvDisableDriver }
  32. };
  33. // Define the functions you want to hook for 8/16/24/32 pel formats
  34. #define HOOKS_BMF8BPP 0
  35. #define HOOKS_BMF16BPP 0
  36. #define HOOKS_BMF24BPP 0
  37. #define HOOKS_BMF32BPP 0
  38. /******************************Public*Routine******************************\
  39. * DrvEnableDriver
  40. *
  41. * Enables the driver by retrieving the drivers function table and version.
  42. *
  43. \**************************************************************************/
  44. BOOL DrvEnableDriver(
  45. ULONG iEngineVersion,
  46. ULONG cj,
  47. PDRVENABLEDATA pded)
  48. {
  49. // Engine Version is passed down so future drivers can support previous
  50. // engine versions. A next generation driver can support both the old
  51. // and new engine conventions if told what version of engine it is
  52. // working with. For the first version the driver does nothing with it.
  53. iEngineVersion;
  54. // Fill in as much as we can.
  55. if (cj >= sizeof(DRVENABLEDATA))
  56. pded->pdrvfn = gadrvfn;
  57. if (cj >= (sizeof(ULONG) * 2))
  58. pded->c = sizeof(gadrvfn) / sizeof(DRVFN);
  59. // DDI version this driver was targeted for is passed back to engine.
  60. // Future graphic's engine may break calls down to old driver format.
  61. if (cj >= sizeof(ULONG))
  62. pded->iDriverVersion = DDI_DRIVER_VERSION_NT4;
  63. return(TRUE);
  64. }
  65. /******************************Public*Routine******************************\
  66. * DrvDisableDriver
  67. *
  68. * Tells the driver it is being disabled. Release any resources allocated in
  69. * DrvEnableDriver.
  70. *
  71. \**************************************************************************/
  72. VOID DrvDisableDriver(VOID)
  73. {
  74. return;
  75. }
  76. /******************************Public*Routine******************************\
  77. * DrvEnablePDEV
  78. *
  79. * DDI function, Enables the Physical Device.
  80. *
  81. * Return Value: device handle to pdev.
  82. *
  83. \**************************************************************************/
  84. DHPDEV DrvEnablePDEV(
  85. DEVMODEW *pDevmode, // Pointer to DEVMODE
  86. PWSTR pwszLogAddress, // Logical address
  87. ULONG cPatterns, // number of patterns
  88. HSURF *ahsurfPatterns, // return standard patterns
  89. ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
  90. ULONG *pGdiInfo, // Pointer to GdiInfo structure
  91. ULONG cjDevInfo, // Length of following PDEVINFO structure
  92. DEVINFO *pDevInfo, // physical device information structure
  93. HDEV hdev, // HDEV, used for callbacks
  94. PWSTR pwszDeviceName, // DeviceName - not used
  95. HANDLE hDriver) // Handle to base driver
  96. {
  97. GDIINFO GdiInfo;
  98. DEVINFO DevInfo;
  99. PPDEV ppdev = (PPDEV) NULL;
  100. UNREFERENCED_PARAMETER(pwszLogAddress);
  101. UNREFERENCED_PARAMETER(pwszDeviceName);
  102. // Allocate a physical device structure.
  103. ppdev = (PPDEV) EngAllocMem(0, sizeof(PDEV), ALLOC_TAG);
  104. if (ppdev == (PPDEV) NULL)
  105. {
  106. DISPDBG((0, "DISP DrvEnablePDEV failed EngAllocMem\n"));
  107. return((DHPDEV) 0);
  108. }
  109. memset(ppdev, 0, sizeof(PDEV));
  110. // Save the screen handle in the PDEV.
  111. ppdev->hDriver = hDriver;
  112. // Get the current screen mode information. Set up device caps and devinfo.
  113. if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
  114. {
  115. DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
  116. goto error_free;
  117. }
  118. // Initialize the cursor information.
  119. if (!bInitPointer(ppdev, &DevInfo))
  120. {
  121. // Not a fatal error...
  122. DISPDBG((0, "DrvEnablePDEV failed bInitPointer\n"));
  123. }
  124. // Initialize palette information.
  125. if (!bInitPaletteInfo(ppdev, &DevInfo))
  126. {
  127. DISPDBG((0, "DrvEnablePDEV failed bInitPalette\n"));
  128. goto error_free;
  129. }
  130. // Copy the devinfo into the engine buffer.
  131. memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
  132. // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
  133. // pdev.
  134. memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
  135. return((DHPDEV) ppdev);
  136. // Error case for failure.
  137. error_free:
  138. EngFreeMem(ppdev);
  139. return((DHPDEV) 0);
  140. }
  141. /******************************Public*Routine******************************\
  142. * DrvCompletePDEV
  143. *
  144. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  145. *
  146. \**************************************************************************/
  147. VOID DrvCompletePDEV(
  148. DHPDEV dhpdev,
  149. HDEV hdev)
  150. {
  151. ((PPDEV) dhpdev)->hdevEng = hdev;
  152. }
  153. /******************************Public*Routine******************************\
  154. * DrvDisablePDEV
  155. *
  156. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  157. * enabled DrvDisableSurface will have already been called.
  158. *
  159. \**************************************************************************/
  160. VOID DrvDisablePDEV(
  161. DHPDEV dhpdev)
  162. {
  163. vDisablePalette((PPDEV) dhpdev);
  164. EngFreeMem(dhpdev);
  165. }
  166. /******************************Public*Routine******************************\
  167. * VOID DrvOffset
  168. *
  169. * DescriptionText
  170. *
  171. \**************************************************************************/
  172. BOOL DrvOffset(
  173. SURFOBJ* pso,
  174. LONG x,
  175. LONG y,
  176. FLONG flReserved)
  177. {
  178. PDEV* ppdev = (PDEV*) pso->dhpdev;
  179. // Add back last offset that we subtracted. I could combine the next
  180. // two statements, but I thought this was more clear. It's not
  181. // performance critical anyway.
  182. ppdev->pjScreen += ((ppdev->ptlOrg.y * ppdev->lDeltaScreen) +
  183. (ppdev->ptlOrg.x * ((ppdev->ulBitCount+1) >> 3)));
  184. // Subtract out new offset
  185. ppdev->pjScreen -= ((y * ppdev->lDeltaScreen) +
  186. (x * ((ppdev->ulBitCount+1) >> 3)));
  187. ppdev->ptlOrg.x = x;
  188. ppdev->ptlOrg.y = y;
  189. return(TRUE);
  190. }
  191. /******************************Public*Routine******************************\
  192. * DrvEnableSurface
  193. *
  194. * Enable the surface for the device. Hook the calls this driver supports.
  195. *
  196. * Return: Handle to the surface if successful, 0 for failure.
  197. *
  198. \**************************************************************************/
  199. HSURF DrvEnableSurface(
  200. DHPDEV dhpdev)
  201. {
  202. PPDEV ppdev;
  203. HSURF hsurf;
  204. SIZEL sizl;
  205. ULONG ulBitmapType;
  206. FLONG flHooks;
  207. // Create engine bitmap around frame buffer.
  208. ppdev = (PPDEV) dhpdev;
  209. ppdev->ptlOrg.x = 0;
  210. ppdev->ptlOrg.y = 0;
  211. if (!bInitSURF(ppdev, TRUE))
  212. {
  213. DISPDBG((0, "DISP DrvEnableSurface failed bInitSURF\n"));
  214. return(FALSE);
  215. }
  216. sizl.cx = ppdev->cxScreen;
  217. sizl.cy = ppdev->cyScreen;
  218. if (ppdev->ulBitCount == 8)
  219. {
  220. if (!bInit256ColorPalette(ppdev)) {
  221. DISPDBG((0, "DISP DrvEnableSurface failed to init the 8bpp palette\n"));
  222. return(FALSE);
  223. }
  224. ulBitmapType = BMF_8BPP;
  225. flHooks = HOOKS_BMF8BPP;
  226. }
  227. else if (ppdev->ulBitCount == 16)
  228. {
  229. ulBitmapType = BMF_16BPP;
  230. flHooks = HOOKS_BMF16BPP;
  231. }
  232. else if (ppdev->ulBitCount == 24)
  233. {
  234. ulBitmapType = BMF_24BPP;
  235. flHooks = HOOKS_BMF24BPP;
  236. }
  237. else
  238. {
  239. ulBitmapType = BMF_32BPP;
  240. flHooks = HOOKS_BMF32BPP;
  241. }
  242. ppdev->flHooks = flHooks;
  243. hsurf = (HSURF)EngCreateDeviceSurface((DHSURF)ppdev,
  244. sizl,
  245. ulBitmapType);
  246. if (hsurf == (HSURF) 0)
  247. {
  248. DISPDBG((0, "DISP DrvEnableSurface failed EngCreateDeviceSurface\n"));
  249. return(FALSE);
  250. }
  251. if ( !EngModifySurface(hsurf,
  252. ppdev->hdevEng,
  253. ppdev->flHooks | HOOK_SYNCHRONIZE,
  254. MS_NOTSYSTEMMEMORY,
  255. (DHSURF)ppdev,
  256. ppdev->pjScreen,
  257. ppdev->lDeltaScreen,
  258. NULL))
  259. {
  260. DISPDBG((0, "DISP DrvEnableSurface failed EngModifySurface\n"));
  261. return(FALSE);
  262. }
  263. ppdev->hsurfEng = hsurf;
  264. return(hsurf);
  265. }
  266. /******************************Public*Routine******************************\
  267. * DrvDisableSurface
  268. *
  269. * Free resources allocated by DrvEnableSurface. Release the surface.
  270. *
  271. \**************************************************************************/
  272. VOID DrvDisableSurface(
  273. DHPDEV dhpdev)
  274. {
  275. EngDeleteSurface(((PPDEV) dhpdev)->hsurfEng);
  276. vDisableSURF((PPDEV) dhpdev);
  277. ((PPDEV) dhpdev)->hsurfEng = (HSURF) 0;
  278. }
  279. /******************************Public*Routine******************************\
  280. * DrvAssertMode
  281. *
  282. * This asks the device to reset itself to the mode of the pdev passed in.
  283. *
  284. \**************************************************************************/
  285. BOOL DrvAssertMode(
  286. DHPDEV dhpdev,
  287. BOOL bEnable)
  288. {
  289. PPDEV ppdev = (PPDEV) dhpdev;
  290. ULONG ulReturn;
  291. PBYTE pjScreen;
  292. if (bEnable)
  293. {
  294. //
  295. // The screen must be reenabled, reinitialize the device to clean state.
  296. //
  297. pjScreen = ppdev->pjScreen;
  298. if (!bInitSURF(ppdev, FALSE))
  299. {
  300. DISPDBG((0, "DISP DrvAssertMode failed bInitSURF\n"));
  301. return (FALSE);
  302. }
  303. if (pjScreen != ppdev->pjScreen) {
  304. if ( !EngModifySurface(ppdev->hsurfEng,
  305. ppdev->hdevEng,
  306. ppdev->flHooks | HOOK_SYNCHRONIZE,
  307. MS_NOTSYSTEMMEMORY,
  308. (DHSURF)ppdev,
  309. ppdev->pjScreen,
  310. ppdev->lDeltaScreen,
  311. NULL))
  312. {
  313. DISPDBG((0, "DISP DrvAssertMode failed EngModifySurface\n"));
  314. return (FALSE);
  315. }
  316. }
  317. return (TRUE);
  318. }
  319. else
  320. {
  321. //
  322. // We must give up the display.
  323. // Call the kernel driver to reset the device to a known state.
  324. //
  325. if (EngDeviceIoControl(ppdev->hDriver,
  326. IOCTL_VIDEO_RESET_DEVICE,
  327. NULL,
  328. 0,
  329. NULL,
  330. 0,
  331. &ulReturn))
  332. {
  333. DISPDBG((0, "DISP DrvAssertMode failed IOCTL\n"));
  334. return FALSE;
  335. }
  336. else
  337. {
  338. return TRUE;
  339. }
  340. }
  341. }
  342. /******************************Public*Routine******************************\
  343. * DrvGetModes
  344. *
  345. * Returns the list of available modes for the device.
  346. *
  347. \**************************************************************************/
  348. ULONG DrvGetModes(
  349. HANDLE hDriver,
  350. ULONG cjSize,
  351. DEVMODEW *pdm)
  352. {
  353. DWORD cModes;
  354. DWORD cbOutputSize;
  355. PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp;
  356. DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  357. DWORD cbModeSize;
  358. DISPDBG((3, "DrvGetModes\n"));
  359. cModes = getAvailableModes(hDriver,
  360. (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
  361. &cbModeSize);
  362. if (cModes == 0)
  363. {
  364. DISPDBG((0, "DrvGetModes failed to get mode information"));
  365. return 0;
  366. }
  367. if (pdm == NULL)
  368. {
  369. cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  370. }
  371. else
  372. {
  373. //
  374. // Now copy the information for the supported modes back into the output
  375. // buffer
  376. //
  377. cbOutputSize = 0;
  378. pVideoTemp = pVideoModeInformation;
  379. do
  380. {
  381. if (pVideoTemp->Length != 0)
  382. {
  383. if (cOutputModes == 0)
  384. {
  385. break;
  386. }
  387. //
  388. // Zero the entire structure to start off with.
  389. //
  390. memset(pdm, 0, sizeof(DEVMODEW));
  391. //
  392. // Set the name of the device to the name of the DLL.
  393. //
  394. memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
  395. pdm->dmSpecVersion = DM_SPECVERSION;
  396. pdm->dmDriverVersion = DM_SPECVERSION;
  397. pdm->dmSize = sizeof(DEVMODEW);
  398. pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
  399. pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
  400. pVideoTemp->BitsPerPlane;
  401. pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
  402. pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
  403. pdm->dmDisplayFrequency = pVideoTemp->Frequency;
  404. pdm->dmDisplayFlags = 0;
  405. pdm->dmFields = DM_BITSPERPEL |
  406. DM_PELSWIDTH |
  407. DM_PELSHEIGHT |
  408. DM_DISPLAYFREQUENCY |
  409. DM_DISPLAYFLAGS ;
  410. //
  411. // Go to the next DEVMODE entry in the buffer.
  412. //
  413. cOutputModes--;
  414. pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW)
  415. + DRIVER_EXTRA_SIZE);
  416. cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  417. }
  418. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  419. (((PUCHAR)pVideoTemp) + cbModeSize);
  420. } while (--cModes);
  421. }
  422. EngFreeMem(pVideoModeInformation);
  423. return cbOutputSize;
  424. }
  425. VOID DrvSynchronize(
  426. IN DHPDEV dhpdev,
  427. IN RECTL *prcl)
  428. {
  429. }