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.

626 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. #define DBG 1
  15. #include "driver.h"
  16. // The driver function table with all function index/address pairs
  17. static DRVFN gadrvfn[] =
  18. {
  19. { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
  20. { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
  21. { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
  22. { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
  23. { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
  24. { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
  25. #if 0
  26. // Windows 2000 Beta 3 has a bug in GDI that causes a crash
  27. // if a mirror driver supports device bitmaps. A fix will be
  28. // in Windows 2000 RC0.
  29. { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap },
  30. { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap },
  31. #endif
  32. { INDEX_DrvTextOut, (PFN) DrvTextOut },
  33. { INDEX_DrvBitBlt, (PFN) DrvBitBlt },
  34. { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
  35. { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
  36. };
  37. //
  38. // always hook these routines to ensure the mirrored driver
  39. // is called for our surfaces
  40. //
  41. #define flGlobalHooks HOOK_BITBLT|HOOK_TEXTOUT|HOOK_COPYBITS|HOOK_STROKEPATH
  42. // Define the functions you want to hook for 8/16/24/32 pel formats
  43. #define HOOKS_BMF8BPP 0
  44. #define HOOKS_BMF16BPP 0
  45. #define HOOKS_BMF24BPP 0
  46. #define HOOKS_BMF32BPP 0
  47. /******************************Public*Routine******************************\
  48. * DrvEnableDriver
  49. *
  50. * Enables the driver by retrieving the drivers function table and version.
  51. *
  52. \**************************************************************************/
  53. BOOL DrvEnableDriver(
  54. ULONG iEngineVersion,
  55. ULONG cj,
  56. PDRVENABLEDATA pded)
  57. {
  58. // Engine Version is passed down so future drivers can support previous
  59. // engine versions. A next generation driver can support both the old
  60. // and new engine conventions if told what version of engine it is
  61. // working with. For the first version the driver does nothing with it.
  62. iEngineVersion;
  63. DISPDBG((0,"DrvEnableDriver:\n"));
  64. // Fill in as much as we can.
  65. if (cj >= sizeof(DRVENABLEDATA))
  66. pded->pdrvfn = gadrvfn;
  67. if (cj >= (sizeof(ULONG) * 2))
  68. pded->c = sizeof(gadrvfn) / sizeof(DRVFN);
  69. // DDI version this driver was targeted for is passed back to engine.
  70. // Future graphic's engine may break calls down to old driver format.
  71. if (cj >= sizeof(ULONG))
  72. // DDI_DRIVER_VERSION is now out-dated. See winddi.h
  73. // DDI_DRIVER_VERSION_NT4 is equivalent to the old DDI_DRIVER_VERSION
  74. pded->iDriverVersion = DDI_DRIVER_VERSION_NT4;
  75. return(TRUE);
  76. }
  77. /******************************Public*Routine******************************\
  78. * DrvEnablePDEV
  79. *
  80. * DDI function, Enables the Physical Device.
  81. *
  82. * Return Value: device handle to pdev.
  83. *
  84. \**************************************************************************/
  85. DHPDEV DrvEnablePDEV(
  86. DEVMODEW *pDevmode, // Pointer to DEVMODE
  87. PWSTR pwszLogAddress, // Logical address
  88. ULONG cPatterns, // number of patterns
  89. HSURF *ahsurfPatterns, // return standard patterns
  90. ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
  91. ULONG *pGdiInfo, // Pointer to GdiInfo structure
  92. ULONG cjDevInfo, // Length of following PDEVINFO structure
  93. DEVINFO *pDevInfo, // physical device information structure
  94. HDEV hdev, // HDEV, used for callbacks
  95. PWSTR pwszDeviceName, // DeviceName - not used
  96. HANDLE hDriver) // Handle to base driver
  97. {
  98. GDIINFO GdiInfo;
  99. DEVINFO DevInfo;
  100. PPDEV ppdev = (PPDEV) NULL;
  101. DISPDBG((0,"DrvEnablePDEV:\n"));
  102. UNREFERENCED_PARAMETER(pwszLogAddress);
  103. UNREFERENCED_PARAMETER(pwszDeviceName);
  104. // Allocate a physical device structure.
  105. ppdev = (PPDEV) EngAllocMem(0, sizeof(PDEV), ALLOC_TAG);
  106. if (ppdev == (PPDEV) NULL)
  107. {
  108. RIP("DISP DrvEnablePDEV failed EngAllocMem\n");
  109. return((DHPDEV) 0);
  110. }
  111. memset(ppdev, 0, sizeof(PDEV));
  112. // Save the screen handle in the PDEV.
  113. ppdev->hDriver = hDriver;
  114. // Get the current screen mode information. Set up device caps and devinfo.
  115. if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
  116. {
  117. DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
  118. goto error_free;
  119. }
  120. // Copy the devinfo into the engine buffer.
  121. memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
  122. // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
  123. // pdev.
  124. memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
  125. //
  126. return((DHPDEV) ppdev);
  127. // Error case for failure.
  128. error_free:
  129. EngFreeMem(ppdev);
  130. return((DHPDEV) 0);
  131. }
  132. /******************************Public*Routine******************************\
  133. * DrvCompletePDEV
  134. *
  135. * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
  136. *
  137. \**************************************************************************/
  138. VOID DrvCompletePDEV(
  139. DHPDEV dhpdev,
  140. HDEV hdev)
  141. {
  142. ((PPDEV) dhpdev)->hdevEng = hdev;
  143. }
  144. /******************************Public*Routine******************************\
  145. * DrvDisablePDEV
  146. *
  147. * Release the resources allocated in DrvEnablePDEV. If a surface has been
  148. * enabled DrvDisableSurface will have already been called.
  149. *
  150. \**************************************************************************/
  151. VOID DrvDisablePDEV(
  152. DHPDEV dhpdev)
  153. {
  154. PPDEV ppdev = (PPDEV) dhpdev;
  155. EngDeletePalette(ppdev->hpalDefault);
  156. EngFreeMem(dhpdev);
  157. }
  158. /******************************Public*Routine******************************\
  159. * DrvEnableSurface
  160. *
  161. * Enable the surface for the device. Hook the calls this driver supports.
  162. *
  163. * Return: Handle to the surface if successful, 0 for failure.
  164. *
  165. \**************************************************************************/
  166. HSURF DrvEnableSurface(
  167. DHPDEV dhpdev)
  168. {
  169. PPDEV ppdev;
  170. HSURF hsurf;
  171. SIZEL sizl;
  172. ULONG ulBitmapType;
  173. FLONG flHooks;
  174. ULONG mirrorsize;
  175. MIRRSURF *mirrsurf;
  176. DHSURF dhsurf;
  177. // Create engine bitmap around frame buffer.
  178. DISPDBG((0,"DrvEnableSurface:\n"));
  179. ppdev = (PPDEV) dhpdev;
  180. ppdev->ptlOrg.x = 0;
  181. ppdev->ptlOrg.y = 0;
  182. sizl.cx = ppdev->cxScreen;
  183. sizl.cy = ppdev->cyScreen;
  184. if (ppdev->ulBitCount == 16)
  185. {
  186. ulBitmapType = BMF_16BPP;
  187. flHooks = HOOKS_BMF16BPP;
  188. }
  189. else if (ppdev->ulBitCount == 24)
  190. {
  191. ulBitmapType = BMF_24BPP;
  192. flHooks = HOOKS_BMF24BPP;
  193. }
  194. else
  195. {
  196. ulBitmapType = BMF_32BPP;
  197. flHooks = HOOKS_BMF32BPP;
  198. }
  199. flHooks |= flGlobalHooks;
  200. mirrorsize = (ULONG)(sizeof(MIRRSURF) +
  201. ppdev->lDeltaScreen * sizl.cy);
  202. mirrsurf = (MIRRSURF *) EngAllocMem(FL_ZERO_MEMORY,
  203. mirrorsize,
  204. 0x4D495252);
  205. if (!mirrsurf) {
  206. RIP("DISP DrvEnableSurface failed EngAllocMem\n");
  207. return(FALSE);
  208. }
  209. dhsurf = (DHSURF) mirrsurf;
  210. hsurf = EngCreateDeviceSurface(dhsurf,
  211. sizl,
  212. ulBitmapType);
  213. if (hsurf == (HSURF) 0)
  214. {
  215. RIP("DISP DrvEnableSurface failed EngCreateBitmap\n");
  216. return(FALSE);
  217. }
  218. if (!EngAssociateSurface(hsurf, ppdev->hdevEng, flHooks))
  219. {
  220. RIP("DISP DrvEnableSurface failed EngAssociateSurface\n");
  221. EngDeleteSurface(hsurf);
  222. return(FALSE);
  223. }
  224. ppdev->hsurfEng = (HSURF) hsurf;
  225. ppdev->pvTmpBuffer = (PVOID) dhsurf;
  226. mirrsurf->cx = ppdev->cxScreen;
  227. mirrsurf->cy = ppdev->cyScreen;
  228. mirrsurf->lDelta = ppdev->lDeltaScreen;
  229. mirrsurf->ulBitCount = ppdev->ulBitCount;
  230. mirrsurf->bIsScreen = TRUE;
  231. return(hsurf);
  232. }
  233. /******************************Public*Routine******************************\
  234. * DrvDisableSurface
  235. *
  236. * Free resources allocated by DrvEnableSurface. Release the surface.
  237. *
  238. \**************************************************************************/
  239. VOID DrvDisableSurface(
  240. DHPDEV dhpdev)
  241. {
  242. PPDEV ppdev = (PPDEV) dhpdev;
  243. DISPDBG((0,"DrvDisableSurface:\n"));
  244. EngDeleteSurface( ppdev->hsurfEng );
  245. // deallocate MIRRSURF structure.
  246. EngFreeMem( ppdev->pvTmpBuffer );
  247. }
  248. /******************************Public*Routine******************************\
  249. * DrvCopyBits
  250. *
  251. \**************************************************************************/
  252. BOOL DrvCopyBits(
  253. OUT SURFOBJ *psoDst,
  254. IN SURFOBJ *psoSrc,
  255. IN CLIPOBJ *pco,
  256. IN XLATEOBJ *pxlo,
  257. IN RECTL *prclDst,
  258. IN POINTL *pptlSrc
  259. )
  260. {
  261. INT cnt1 = 0, cnt2 = 0;
  262. DISPDBG((1,"Mirror Driver DrvCopyBits: \n"));
  263. if (psoSrc)
  264. {
  265. if (psoSrc->dhsurf)
  266. {
  267. MIRRSURF *mirrsurf = (MIRRSURF *)psoSrc->dhsurf;
  268. if (mirrsurf->bIsScreen)
  269. {
  270. DISPDBG((1, "From Mirror Screen "));
  271. }
  272. else
  273. {
  274. DISPDBG((1, "From Mirror DFB "));
  275. }
  276. cnt1 ++;
  277. }
  278. else
  279. {
  280. DISPDBG((1, "From DIB "));
  281. }
  282. }
  283. if (psoDst)
  284. {
  285. if (psoDst->dhsurf)
  286. {
  287. MIRRSURF *mirrsurf = (MIRRSURF *)psoDst->dhsurf;
  288. if (mirrsurf->bIsScreen)
  289. {
  290. DISPDBG((1, "to MirrorScreen "));
  291. }
  292. else
  293. {
  294. DISPDBG((1, "to Mirror DFB "));
  295. }
  296. cnt2 ++;
  297. }
  298. else
  299. {
  300. DISPDBG((1, "to DIB "));
  301. }
  302. }
  303. if (cnt1 && cnt2)
  304. {
  305. DISPDBG((1, " [Send Request Over Wire]\n"));
  306. }
  307. else if (cnt1)
  308. {
  309. DISPDBG((1, " [Read Cached Bits, Or Pull Bits]\n"));
  310. }
  311. else if (cnt2)
  312. {
  313. DISPDBG((1, " [Push Bits/Compress]\n"));
  314. }
  315. else
  316. {
  317. DISPDBG((1, " [What Are We Doing Here?]\n"));
  318. }
  319. return FALSE;
  320. }
  321. /******************************Public*Routine******************************\
  322. * DrvBitBlt
  323. *
  324. \**************************************************************************/
  325. BOOL DrvBitBlt(
  326. IN SURFOBJ *psoDst,
  327. IN SURFOBJ *psoSrc,
  328. IN SURFOBJ *psoMask,
  329. IN CLIPOBJ *pco,
  330. IN XLATEOBJ *pxlo,
  331. IN RECTL *prclDst,
  332. IN POINTL *pptlSrc,
  333. IN POINTL *pptlMask,
  334. IN BRUSHOBJ *pbo,
  335. IN POINTL *pptlBrush,
  336. IN ROP4 rop4
  337. )
  338. {
  339. INT cnt1 = 0, cnt2 = 0;
  340. DISPDBG((1,
  341. "Mirror Driver DrvBitBlt (Mask=%08x, rop=%08x:\n",
  342. psoMask,
  343. rop4));
  344. if (psoSrc)
  345. {
  346. if (psoSrc->dhsurf)
  347. {
  348. MIRRSURF *mirrsurf = (MIRRSURF *)psoSrc->dhsurf;
  349. if (mirrsurf->bIsScreen)
  350. {
  351. DISPDBG((1, "From Mirror Screen "));
  352. }
  353. else
  354. {
  355. DISPDBG((1, "From Mirror DFB "));
  356. }
  357. cnt1 ++;
  358. }
  359. else
  360. {
  361. DISPDBG((1, "From DIB "));
  362. }
  363. }
  364. if (psoDst)
  365. {
  366. if (psoDst->dhsurf)
  367. {
  368. MIRRSURF *mirrsurf = (MIRRSURF *)psoDst->dhsurf;
  369. if (mirrsurf->bIsScreen)
  370. {
  371. DISPDBG((1, "to MirrorScreen "));
  372. }
  373. else
  374. {
  375. DISPDBG((1, "to Mirror DFB "));
  376. }
  377. cnt2 ++;
  378. }
  379. else
  380. {
  381. DISPDBG((1, "to DIB "));
  382. }
  383. }
  384. if (cnt1 && cnt2)
  385. {
  386. DISPDBG((1, " [Send Request Over Wire]\n"));
  387. }
  388. else if (cnt1)
  389. {
  390. DISPDBG((1, " [Read Cached Bits, Or Pull Bits]\n"));
  391. }
  392. else if (cnt2)
  393. {
  394. DISPDBG((1, " [Push Bits/Compress]\n"));
  395. }
  396. else
  397. {
  398. DISPDBG((1, " [What Are We Doing Here?]\n"));
  399. }
  400. return FALSE;
  401. }
  402. BOOL DrvTextOut(
  403. IN SURFOBJ *psoDst,
  404. IN STROBJ *pstro,
  405. IN FONTOBJ *pfo,
  406. IN CLIPOBJ *pco,
  407. IN RECTL *prclExtra,
  408. IN RECTL *prclOpaque,
  409. IN BRUSHOBJ *pboFore,
  410. IN BRUSHOBJ *pboOpaque,
  411. IN POINTL *pptlOrg,
  412. IN MIX mix
  413. )
  414. {
  415. DISPDBG((1,
  416. "Mirror Driver DrvTextOut: pwstr=%08x\n",
  417. pstro ? pstro->pwszOrg : (WCHAR*)-1));
  418. return FALSE;
  419. }
  420. BOOL
  421. DrvStrokePath(SURFOBJ* pso,
  422. PATHOBJ* ppo,
  423. CLIPOBJ* pco,
  424. XFORMOBJ* pxo,
  425. BRUSHOBJ* pbo,
  426. POINTL* pptlBrush,
  427. LINEATTRS* pLineAttrs,
  428. MIX mix)
  429. {
  430. DISPDBG((1,
  431. "Mirror Driver DrvStrokePath:\n"));
  432. return FALSE;
  433. }
  434. #if 0
  435. HBITMAP DrvCreateDeviceBitmap(
  436. IN DHPDEV dhpdev,
  437. IN SIZEL sizl,
  438. IN ULONG iFormat
  439. )
  440. {
  441. HBITMAP hbm;
  442. MIRRSURF *mirrsurf;
  443. ULONG mirrorsize;
  444. DHSURF dhsurf;
  445. ULONG stride;
  446. HSURF hsurf;
  447. PPDEV ppdev = (PPDEV) dhpdev;
  448. DISPDBG((1,"CreateDeviceBitmap:\n"));
  449. if (iFormat == BMF_1BPP || iFormat == BMF_4BPP)
  450. {
  451. return NULL;
  452. };
  453. // DWORD align each stride
  454. stride = (sizl.cx*(iFormat/8)+3);
  455. stride -= stride % 4;
  456. mirrorsize = (int)(sizeof(MIRRSURF) + stride * sizl.cy);
  457. mirrsurf = (MIRRSURF *) EngAllocMem(FL_ZERO_MEMORY,
  458. mirrorsize,
  459. 0x4D495252);
  460. if (!mirrsurf) {
  461. RIP("DISP DrvEnableSurface failed EngAllocMem\n");
  462. return(FALSE);
  463. }
  464. dhsurf = (DHSURF) mirrsurf;
  465. hsurf = (HSURF) EngCreateDeviceBitmap(dhsurf,
  466. sizl,
  467. iFormat);
  468. if (hsurf == (HSURF) 0)
  469. {
  470. RIP("DISP DrvEnableSurface failed EngCreateBitmap\n");
  471. return(FALSE);
  472. }
  473. if (!EngAssociateSurface(hsurf,
  474. ppdev->hdevEng,
  475. flGlobalHooks))
  476. {
  477. RIP("DISP DrvEnableSurface failed EngAssociateSurface\n");
  478. EngDeleteSurface(hsurf);
  479. return(FALSE);
  480. }
  481. mirrsurf->cx = sizl.cx;
  482. mirrsurf->cy = sizl.cy;
  483. mirrsurf->lDelta = stride;
  484. mirrsurf->ulBitCount = iFormat;
  485. mirrsurf->bIsScreen = TRUE;
  486. return((HBITMAP)hsurf);
  487. }
  488. VOID DrvDeleteDeviceBitmap(
  489. IN DHSURF dhsurf
  490. )
  491. {
  492. MIRRSURF *mirrsurf;
  493. DISPDBG((1, "DeleteDeviceBitmap:\n"));
  494. mirrsurf = (MIRRSURF *) dhsurf;
  495. EngFreeMem((PVOID) mirrsurf);
  496. }
  497. #endif
  498. /******************************Public*Routine******************************\
  499. * DrvAssertMode
  500. *
  501. * Enable/Disable the given device.
  502. *
  503. \**************************************************************************/
  504. DrvAssertMode(DHPDEV dhpdev,
  505. BOOL bEnable)
  506. {
  507. PPDEV ppdev = (PPDEV) dhpdev;
  508. DISPDBG((0, "DrvAssertMode(%lx, %lx)", dhpdev, bEnable));
  509. return TRUE;
  510. }// DrvAssertMode()