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.

636 lines
19 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_DrvGetModes, (PFN) DrvGetModes },
  30. { INDEX_DrvBitBlt, (PFN) DrvBitBlt },
  31. { INDEX_DrvTextOut, (PFN) DrvTextOut },
  32. { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
  33. { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
  34. { INDEX_DrvFillPath, (PFN) DrvFillPath },
  35. { INDEX_DrvPaint, (PFN) DrvPaint }
  36. };
  37. /* from VGA
  38. static DRVFN gadrvfn[] = {
  39. { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
  40. { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
  41. { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
  42. { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
  43. { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
  44. { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush },
  45. { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap },
  46. { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap },
  47. { INDEX_DrvBitBlt, (PFN) DrvBitBlt },
  48. { INDEX_DrvTextOut, (PFN) DrvTextOut },
  49. { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape },
  50. { INDEX_DrvMovePointer, (PFN) DrvMovePointer },
  51. { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
  52. { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
  53. { INDEX_DrvDitherColor, (PFN) DrvDitherColor },
  54. { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
  55. { INDEX_DrvSaveScreenBits, (PFN) DrvSaveScreenBits },
  56. { INDEX_DrvGetModes, (PFN) DrvGetModes },
  57. { INDEX_DrvFillPath, (PFN) DrvFillPath },
  58. { INDEX_DrvPaint, (PFN) DrvPaint }
  59. };*/
  60. /******************************Public*Routine******************************\
  61. * DrvEnableDriver
  62. *
  63. * Enables the driver by retrieving the drivers function table and version.
  64. *
  65. \**************************************************************************/
  66. BOOL DrvEnableDriver(
  67. ULONG iEngineVersion,
  68. ULONG cj,
  69. PDRVENABLEDATA pded)
  70. {
  71. // Engine Version is passed down so future drivers can support previous
  72. // engine versions. A next generation driver can support both the old
  73. // and new engine conventions if told what version of engine it is
  74. // working with. For the first version the driver does nothing with it.
  75. iEngineVersion;
  76. // Fill in as much as we can.
  77. if (cj >= sizeof(DRVENABLEDATA))
  78. pded->pdrvfn = gadrvfn;
  79. if (cj >= (sizeof(ULONG) * 2))
  80. pded->c = sizeof(gadrvfn) / sizeof(DRVFN);
  81. // DDI version this driver was targeted for is passed back to engine.
  82. // Future graphic's engine may break calls down to old driver format.
  83. if (cj >= sizeof(ULONG))
  84. pded->iDriverVersion = DDI_DRIVER_VERSION_NT5_01;
  85. return(TRUE);
  86. }
  87. /******************************Public*Routine******************************\
  88. * DrvEnablePDEV
  89. *
  90. * DDI function, Enables the Physical Device.
  91. *
  92. * Return Value: device handle to pdev.
  93. *
  94. \**************************************************************************/
  95. DHPDEV DrvEnablePDEV(
  96. DEVMODEW *pDevmode, // Pointer to DEVMODE
  97. PWSTR pwszLogAddress, // Logical address
  98. ULONG cPatterns, // number of patterns
  99. HSURF *ahsurfPatterns, // return standard patterns
  100. ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
  101. ULONG *pGdiInfo, // Pointer to GdiInfo structure
  102. ULONG cjDevInfo, // Length of following PDEVINFO structure
  103. DEVINFO *pDevInfo, // physical device information structure
  104. HDEV hdev, // HDEV, used for callbacks
  105. PWSTR pwszDeviceName, // DeviceName - not used
  106. HANDLE hDriver) // Handle to base driver
  107. {
  108. GDIINFO GdiInfo;
  109. DEVINFO DevInfo;
  110. PPDEV ppdev = (PPDEV) NULL;
  111. UNREFERENCED_PARAMETER(pwszLogAddress);
  112. UNREFERENCED_PARAMETER(pwszDeviceName);
  113. // Allocate a physical device structure.
  114. ppdev = (PPDEV) EngAllocMem(0, sizeof(PDEV), ALLOC_TAG);
  115. if (ppdev == (PPDEV) NULL)
  116. {
  117. RIP("DISP DrvEnablePDEV failed EngAllocMem\n");
  118. return((DHPDEV) 0);
  119. }
  120. memset(ppdev, 0, sizeof(PDEV));
  121. // Save the screen handle in the PDEV.
  122. ppdev->hDriver = hDriver;
  123. // Get the current screen mode information. Set up device caps and devinfo.
  124. if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
  125. {
  126. DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
  127. goto error_free;
  128. }
  129. // Initialize the cursor information.
  130. if (!bInitPointer(ppdev, &DevInfo))
  131. {
  132. // Not a fatal error...
  133. DISPDBG((0, "DrvEnablePDEV failed bInitPointer\n"));
  134. }
  135. // Initialize palette information.
  136. if (!bInitPaletteInfo(ppdev, &DevInfo))
  137. {
  138. RIP("DrvEnablePDEV failed bInitPalette\n");
  139. goto error_free;
  140. }
  141. // Copy the devinfo into the engine buffer.
  142. memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
  143. // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
  144. // pdev.
  145. memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
  146. return((DHPDEV) ppdev);
  147. // Error case for failure.
  148. error_free:
  149. EngFreeMem(ppdev);
  150. return((DHPDEV) 0);
  151. }
  152. /******************************Public*Routine******************************\
  153. * DrvCompletePDEV
  154. *
  155. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  156. *
  157. \**************************************************************************/
  158. VOID DrvCompletePDEV(
  159. DHPDEV dhpdev,
  160. HDEV hdev)
  161. {
  162. ((PPDEV) dhpdev)->hdevEng = hdev;
  163. }
  164. /******************************Public*Routine******************************\
  165. * DrvDisablePDEV
  166. *
  167. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  168. * enabled DrvDisableSurface will have already been called.
  169. *
  170. \**************************************************************************/
  171. VOID DrvDisablePDEV(
  172. DHPDEV dhpdev)
  173. {
  174. vDisablePalette((PPDEV) dhpdev);
  175. EngFreeMem(dhpdev);
  176. }
  177. /******************************Public*Routine******************************\
  178. * VOID DrvOffset
  179. *
  180. * DescriptionText
  181. *
  182. \**************************************************************************/
  183. BOOL DrvOffset(
  184. SURFOBJ* pso,
  185. LONG x,
  186. LONG y,
  187. FLONG flReserved)
  188. {
  189. PDEV* ppdev = (PDEV*) pso->dhpdev;
  190. // Add back last offset that we subtracted. I could combine the next
  191. // two statements, but I thought this was more clear. It's not
  192. // performance critical anyway.
  193. ppdev->pjScreen += ((ppdev->ptlOrg.y * ppdev->lDeltaScreen) +
  194. (ppdev->ptlOrg.x * ((ppdev->ulBitCount+1) >> 3)));
  195. // Subtract out new offset
  196. ppdev->pjScreen -= ((y * ppdev->lDeltaScreen) +
  197. (x * ((ppdev->ulBitCount+1) >> 3)));
  198. ppdev->ptlOrg.x = x;
  199. ppdev->ptlOrg.y = y;
  200. return(TRUE);
  201. }
  202. /******************************Public*Routine******************************\
  203. * DrvEnableSurface
  204. *
  205. * Enable the surface for the device. Hook the calls this driver supports.
  206. *
  207. * Return: Handle to the surface if successful, 0 for failure.
  208. *
  209. \**************************************************************************/
  210. HSURF DrvEnableSurface(
  211. DHPDEV dhpdev)
  212. {
  213. PPDEV ppdev;
  214. HSURF hsurf;
  215. PDEVSURF pdsurf;
  216. DHSURF dhsurf;
  217. // Create engine bitmap around frame buffer.
  218. ppdev = (PPDEV) dhpdev;
  219. ppdev->ptlOrg.x = 0;
  220. ppdev->ptlOrg.y = 0;
  221. if (!bInitSURF(ppdev, TRUE))
  222. {
  223. DISPDBG((0, "DISP DrvEnableSurface failed bInitSURF\n"));
  224. return((HSURF) 0);
  225. }
  226. dhsurf = (DHSURF) EngAllocMem(0, sizeof(DEVSURF), ALLOC_TAG);
  227. if (dhsurf == (DHSURF) 0)
  228. {
  229. return((HSURF) 0);
  230. }
  231. // from VGA - begin
  232. pdsurf = (PDEVSURF) dhsurf;
  233. pdsurf->flSurf = 0;
  234. pdsurf->iFormat = 0;
  235. pdsurf->jReserved1 = 0;
  236. pdsurf->jReserved2 = 0;
  237. pdsurf->ppdev = ppdev;
  238. pdsurf->sizlSurf.cx = ppdev->sizlSurf.cx;
  239. pdsurf->sizlSurf.cy = ppdev->sizlSurf.cy;
  240. pdsurf->lNextPlane = 0;
  241. // from VGA - end
  242. hsurf = (HSURF)EngCreateDeviceSurface(dhsurf, ppdev->sizlSurf, BMF_8BPP);
  243. if (hsurf == (HSURF) 0)
  244. {
  245. DISPDBG((0,"DISP DrvEnableSurface failed EngCreateBitmap\n"));
  246. EngFreeMem(dhsurf);
  247. return((HSURF) 0);
  248. }
  249. if (!EngAssociateSurface(hsurf, ppdev->hdevEng,
  250. HOOK_BITBLT | HOOK_TEXTOUT | HOOK_STROKEPATH |
  251. HOOK_COPYBITS | HOOK_PAINT | HOOK_FILLPATH
  252. ))
  253. {
  254. DISPDBG((0, "DISP DrvEnableSurface failed EngAssociateSurface\n"));
  255. EngDeleteSurface(hsurf);
  256. EngFreeMem(dhsurf);
  257. return((HSURF) 0);
  258. }
  259. ppdev->hsurfEng = hsurf;
  260. ppdev->pdsurf = pdsurf;
  261. return(hsurf);
  262. }
  263. /******************************Public*Routine******************************\
  264. * DrvDisableSurface
  265. *
  266. * Free resources allocated by DrvEnableSurface. Release the surface.
  267. *
  268. \**************************************************************************/
  269. VOID DrvDisableSurface(
  270. DHPDEV dhpdev)
  271. {
  272. EngDeleteSurface(((PPDEV) dhpdev)->hsurfEng);
  273. vDisableSURF((PPDEV) dhpdev);
  274. ((PPDEV) dhpdev)->hsurfEng = (HSURF) 0;
  275. if (((PPDEV) dhpdev)->pPointerAttributes != NULL) {
  276. EngFreeMem(((PPDEV) dhpdev)->pPointerAttributes);
  277. ((PPDEV) dhpdev)->pPointerAttributes = NULL;
  278. }
  279. }
  280. /******************************Public*Routine******************************\
  281. * DrvAssertMode
  282. *
  283. * This asks the device to reset itself to the mode of the pdev passed in.
  284. *
  285. \**************************************************************************/
  286. BOOL DrvAssertMode(
  287. DHPDEV dhpdev,
  288. BOOL bEnable)
  289. {
  290. PPDEV ppdev = (PPDEV) dhpdev;
  291. ULONG ulReturn;
  292. if (bEnable)
  293. {
  294. //
  295. // The screen must be reenabled, reinitialize the device to clean state.
  296. //
  297. return (bInitSURF(ppdev, FALSE));
  298. }
  299. else
  300. {
  301. //
  302. // We must give up the display.
  303. // Call the kernel driver to reset the device to a known state.
  304. //
  305. /*
  306. if (EngDeviceIoControl(ppdev->hDriver,
  307. IOCTL_VIDEO_RESET_DEVICE,
  308. NULL,
  309. 0,
  310. NULL,
  311. 0,
  312. &ulReturn))
  313. {
  314. RIP("DISP DrvAssertMode failed IOCTL");
  315. return FALSE;
  316. }
  317. else
  318. */
  319. {
  320. return TRUE;
  321. }
  322. }
  323. }
  324. /******************************Public*Routine******************************\
  325. * DrvGetModes
  326. *
  327. * Returns the list of available modes for the device.
  328. *
  329. \**************************************************************************/
  330. ULONG DrvGetModes(
  331. HANDLE hDriver,
  332. ULONG cjSize,
  333. DEVMODEW *pdm)
  334. {
  335. DWORD cModes;
  336. DWORD cbOutputSize;
  337. PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp;
  338. DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  339. DWORD cbModeSize;
  340. DISPDBG((3, "DrvGetModes\n"));
  341. cModes = getAvailableModes(hDriver,
  342. (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
  343. &cbModeSize);
  344. if (cModes == 0)
  345. {
  346. DISPDBG((0, "DrvGetModes failed to get mode information"));
  347. return 0;
  348. }
  349. if (pdm == NULL)
  350. {
  351. cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  352. }
  353. else
  354. {
  355. //
  356. // Now copy the information for the supported modes back into the output
  357. // buffer
  358. //
  359. cbOutputSize = 0;
  360. pVideoTemp = pVideoModeInformation;
  361. do
  362. {
  363. if (pVideoTemp->Length != 0)
  364. {
  365. if (cOutputModes == 0)
  366. {
  367. break;
  368. }
  369. //
  370. // Zero the entire structure to start off with.
  371. //
  372. memset(pdm, 0, sizeof(DEVMODEW));
  373. //
  374. // Set the name of the device to the name of the DLL.
  375. //
  376. memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
  377. pdm->dmSpecVersion = DM_SPECVERSION;
  378. pdm->dmDriverVersion = DM_SPECVERSION;
  379. pdm->dmSize = sizeof(DEVMODEW);
  380. pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
  381. pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
  382. pVideoTemp->BitsPerPlane;
  383. pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
  384. pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
  385. pdm->dmDisplayFrequency = pVideoTemp->Frequency;
  386. pdm->dmDisplayFlags = 0;
  387. pdm->dmFields = DM_BITSPERPEL |
  388. DM_PELSWIDTH |
  389. DM_PELSHEIGHT |
  390. DM_DISPLAYFREQUENCY |
  391. DM_DISPLAYFLAGS ;
  392. //
  393. // Go to the next DEVMODE entry in the buffer.
  394. //
  395. cOutputModes--;
  396. pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW)
  397. + DRIVER_EXTRA_SIZE);
  398. cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
  399. }
  400. pVideoTemp = (PVIDEO_MODE_INFORMATION)
  401. (((PUCHAR)pVideoTemp) + cbModeSize);
  402. } while (--cModes);
  403. }
  404. EngFreeMem(pVideoModeInformation);
  405. return cbOutputSize;
  406. }
  407. ////////////////////////////////////////////////////////////////////////////
  408. // Hooked functions that drop everything because our surface is NULL
  409. ////////////////////////////////////////////////////////////////////////////
  410. /******************************Public*Routine******************************\
  411. * VOID DrvBitBlt(pso,pso,pso,pco,pxlo,prcl,pptl,pptl,pdbrush,pptl,rop4)
  412. *
  413. * Bitblt.
  414. *
  415. \**************************************************************************/
  416. BOOL DrvBitBlt
  417. (
  418. SURFOBJ *psoTrg, // Target surface
  419. SURFOBJ *psoSrc, // Source surface
  420. SURFOBJ *psoMask, // Mask
  421. CLIPOBJ *pco, // Clip through this
  422. XLATEOBJ *pxlo, // Color translation
  423. RECTL *prclTrg, // Target offset and extent
  424. POINTL *pptlSrc, // Source offset
  425. POINTL *pptlMask, // Mask offset
  426. BRUSHOBJ *pbo, // Pointer to brush object
  427. POINTL *pptlBrush, // Brush offset
  428. ROP4 rop4 // Raster operation
  429. )
  430. {
  431. return(TRUE);
  432. }
  433. /******************************Public*Routine******************************\
  434. * BOOL DrvTextOut(pso,pstro,pfo,pco,prclExtra,prcOpaque,
  435. * pvFore,pvBack,pptOrg,r2Fore,r2Back)
  436. *
  437. \**************************************************************************/
  438. BOOL DrvTextOut(
  439. SURFOBJ *pso,
  440. STROBJ *pstro,
  441. FONTOBJ *pfo,
  442. CLIPOBJ *pco,
  443. PRECTL prclExtra,
  444. PRECTL prclOpaque,
  445. BRUSHOBJ *pboFore,
  446. BRUSHOBJ *pboOpaque,
  447. PPOINTL pptlOrg,
  448. MIX mix)
  449. {
  450. return(TRUE);
  451. }
  452. /******************************Public*Routine******************************\
  453. * BOOL DrvStrokePath(pso, ppo, pco, pxo, pbo, pptlBrushOrg, pla, mix)
  454. *
  455. * Strokes the path.
  456. *
  457. \**************************************************************************/
  458. BOOL DrvStrokePath(
  459. SURFOBJ* pso,
  460. PATHOBJ* ppo,
  461. CLIPOBJ* pco,
  462. XFORMOBJ* pxo,
  463. BRUSHOBJ* pbo,
  464. POINTL* pptlBrushOrg,
  465. LINEATTRS* pla,
  466. MIX mix)
  467. {
  468. return(TRUE);
  469. }
  470. /******************************Public*Routine******************************\
  471. * BOOL DrvCopyBits(psoTrg,psoSrc,pco,pxlo,prclTrg,pptlSrc)
  472. *
  473. * Copy the bits.
  474. *
  475. \**************************************************************************/
  476. BOOL DrvCopyBits
  477. (
  478. SURFOBJ *psoTrg,
  479. SURFOBJ *psoSrc,
  480. CLIPOBJ *pco,
  481. XLATEOBJ *pxlo,
  482. PRECTL prclTrg,
  483. PPOINTL pptlSrc
  484. )
  485. {
  486. return(TRUE);
  487. }
  488. /******************************Public*Routine******************************\
  489. * DrvFillPath
  490. *
  491. * Fill the specified path with the specified brush and ROP.
  492. *
  493. \**************************************************************************/
  494. BOOL DrvFillPath
  495. (
  496. SURFOBJ *pso,
  497. PATHOBJ *ppo,
  498. CLIPOBJ *pco,
  499. BRUSHOBJ *pbo,
  500. POINTL *pptlBrush,
  501. MIX mix,
  502. FLONG flOptions
  503. )
  504. {
  505. return(TRUE);
  506. }
  507. /******************************Public*Routine******************************\
  508. * DrvPaint
  509. *
  510. * Paint the clipping region with the specified brush
  511. *
  512. \**************************************************************************/
  513. BOOL DrvPaint
  514. (
  515. SURFOBJ *pso,
  516. CLIPOBJ *pco,
  517. BRUSHOBJ *pbo,
  518. POINTL *pptlBrush,
  519. MIX mix
  520. )
  521. {
  522. return(TRUE);
  523. }