|
|
1.1 ! root 1: /******************************Module*Header*******************************\ ! 2: * Module Name: enable.c ! 3: * ! 4: * This module contains the functions that enable and disable the ! 5: * driver, the pdev, and the surface. ! 6: * ! 7: * Copyright (c) 1992 Microsoft Corporation ! 8: \**************************************************************************/ ! 9: ! 10: #include "driver.h" ! 11: ! 12: // ! 13: // Build the driver function table gadrvfn with function index/address pairs ! 14: // ! 15: ! 16: DRVFN gadrvfn[] = { ! 17: { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV }, ! 18: { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV }, ! 19: { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV }, ! 20: { INDEX_DrvAssertMode, (PFN) DrvAssertMode }, ! 21: { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface }, ! 22: { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface }, ! 23: { INDEX_DrvMovePointer, (PFN) DrvMovePointer }, ! 24: { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape }, ! 25: { INDEX_DrvDitherColor, (PFN) DrvDitherColor }, ! 26: { INDEX_DrvSetPalette, (PFN) DrvSetPalette }, ! 27: { INDEX_DrvCopyBits, (PFN) DrvCopyBits }, ! 28: { INDEX_DrvBitBlt, (PFN) DrvBitBlt }, ! 29: { INDEX_DrvTextOut, (PFN) DrvTextOut }, ! 30: { INDEX_DrvStrokePath, (PFN) DrvStrokePath }, ! 31: { INDEX_DrvPaint, (PFN) DrvPaint }, ! 32: { INDEX_DrvGetModes, (PFN) DrvGetModes, } ! 33: }; ! 34: ! 35: DWORD gDevInfoSize = sizeof(gadrvfn) / sizeof(DRVFN); ! 36: ! 37: /******************************Public*Routine******************************\ ! 38: * DrvEnableDriver ! 39: * ! 40: * Enables the driver by retrieving the drivers function table and version. ! 41: * ! 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: ! 54: iEngineVersion; ! 55: ! 56: // Fill in as much as we can. ! 57: ! 58: if (cj >= sizeof(DRVENABLEDATA)) ! 59: pded->pdrvfn = gadrvfn; ! 60: ! 61: if (cj >= (sizeof(ULONG) * 2)) ! 62: pded->c = sizeof(gadrvfn) / sizeof(DRVFN); ! 63: ! 64: // DDI version this driver was targeted for is passed back to engine. ! 65: // Future graphic's engine may break calls down to old driver format. ! 66: ! 67: if (cj >= sizeof(ULONG)) ! 68: pded->iDriverVersion = DDI_DRIVER_VERSION; ! 69: ! 70: return(TRUE); ! 71: } ! 72: ! 73: /******************************Public*Routine******************************\ ! 74: * DrvDisableDriver ! 75: * ! 76: * Tells the driver it is being disabled. Release any resources allocated in ! 77: * DrvEnableDriver. ! 78: * ! 79: \**************************************************************************/ ! 80: ! 81: VOID DrvDisableDriver(VOID) ! 82: { ! 83: return; ! 84: } ! 85: ! 86: /******************************Public*Routine******************************\ ! 87: * DrvEnablePDEV ! 88: * ! 89: * DDI function, Enables the Physical Device. ! 90: * ! 91: * Return Value: device handle to pdev. ! 92: * ! 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: PWSTR pwszDataFile, // DataFile - not used ! 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: ! 112: UNREFERENCED_PARAMETER(pwszLogAddress); ! 113: UNREFERENCED_PARAMETER(pwszDataFile); ! 114: UNREFERENCED_PARAMETER(pwszDeviceName); ! 115: ! 116: // Allocate a physical device structure. ! 117: ! 118: ppdev = (PPDEV) LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, sizeof(PDEV)); ! 119: ! 120: if (ppdev == (PPDEV) NULL) ! 121: { ! 122: DISPDBG((0, "DISP DrvEnablePDEV failed LocalAlloc\n")); ! 123: return ((DHPDEV) 0); ! 124: } ! 125: ! 126: // Save the screen handle in the PDEV. ! 127: ! 128: ppdev->hDriver = hDriver; ! 129: ! 130: // Get the current screen mode information. Set up device caps and devinfo. ! 131: ! 132: if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo)) ! 133: { ! 134: DISPDBG((0, "DISP DrvEnablePDEV failed bGetScreenInfo\n")); ! 135: goto error_free; ! 136: } ! 137: ! 138: // Initialize palette information. ! 139: ! 140: if (!bInitPaletteInfo(ppdev, &DevInfo)) ! 141: { ! 142: DISPDBG((0, "DISP DrvEnableSurface failed bInitPalette\n")); ! 143: goto error_free; ! 144: } ! 145: ! 146: // Initialize device standard patterns. ! 147: ! 148: if (!bInitPatterns(ppdev, min(cPatterns, HS_DDI_MAX))) ! 149: { ! 150: DISPDBG((0, "DISP DrvEnablePDEV failed bInitPatterns\n")); ! 151: vDisablePatterns(ppdev); ! 152: vDisablePalette(ppdev); ! 153: goto error_free; ! 154: } ! 155: ! 156: // Copy the devinfo into the engine buffer. ! 157: ! 158: memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo)); ! 159: ! 160: // Set the ahsurfPatterns array to handles each of the standard ! 161: // patterns that were just created. ! 162: ! 163: memcpy((PVOID)ahsurfPatterns, ppdev->ahbmPat, ppdev->cPatterns*sizeof(HBITMAP)); ! 164: ! 165: // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this ! 166: // pdev. ! 167: ! 168: memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO))); ! 169: ! 170: return((DHPDEV) ppdev); ! 171: ! 172: // Error case for failure. ! 173: error_free: ! 174: LocalFree(ppdev); ! 175: DISPDBG((0, "DISP DrvEnablePDEV failed\n")); ! 176: return((DHPDEV) 0); ! 177: } ! 178: ! 179: /******************************Public*Routine******************************\ ! 180: * DrvCompletePDEV ! 181: * ! 182: * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV. ! 183: * ! 184: \**************************************************************************/ ! 185: ! 186: VOID DrvCompletePDEV( ! 187: DHPDEV dhpdev, ! 188: HDEV hdev) ! 189: { ! 190: ((PPDEV) dhpdev)->hdevEng = hdev; ! 191: } ! 192: ! 193: /******************************Public*Routine******************************\ ! 194: * DrvDisablePDEV ! 195: * ! 196: * Release the resources allocated in DrvEnablePDEV. If a surface has been ! 197: * enabled DrvDisableSurface will have already been called. ! 198: * ! 199: \**************************************************************************/ ! 200: ! 201: VOID DrvDisablePDEV( ! 202: DHPDEV dhpdev) ! 203: { ! 204: vDisablePalette((PPDEV) dhpdev); ! 205: vDisablePatterns((PPDEV) dhpdev); ! 206: LocalFree(dhpdev); ! 207: } ! 208: ! 209: /******************************Public*Routine******************************\ ! 210: * DrvEnableSurface ! 211: * ! 212: * Enable the surface for the device. Hook the calls this driver supports. ! 213: * ! 214: * Return: Handle to the surface if successful, 0 for failure. ! 215: * ! 216: \**************************************************************************/ ! 217: ! 218: HSURF DrvEnableSurface( ! 219: DHPDEV dhpdev) ! 220: { ! 221: PPDEV ppdev; ! 222: HSURF hsurf, ! 223: hSurfBm ; ! 224: SIZEL sizl; ! 225: ULONG ulBitmapType; ! 226: FLONG flHooks; ! 227: SURFOBJ *pSurfObj ; ! 228: ! 229: // Create engine bitmap around frame buffer. ! 230: ! 231: ppdev = (PPDEV) dhpdev; ! 232: ! 233: if (!bInitSURF(ppdev, TRUE)) ! 234: { ! 235: DISPDBG((0, "DISP DrvEnableSurface failed bInitSURF\n")); ! 236: return(FALSE); ! 237: } ! 238: ! 239: if (ppdev->ulBitCount == 8) { ! 240: if (!bInit256ColorPalette(ppdev)) { ! 241: DISPDBG((0, "DISP DrvEnableSurface failed to init the 8bpp palette\n")); ! 242: return(FALSE); ! 243: } ! 244: } ! 245: ! 246: sizl.cx = ppdev->cxScreen; ! 247: sizl.cy = ppdev->cyScreen; ! 248: ! 249: if (ppdev->ulBitCount == 8) ! 250: { ! 251: ulBitmapType = BMF_8BPP; ! 252: flHooks = HOOKS_BMF8BPP; ! 253: } ! 254: else if (ppdev->ulBitCount == 16) ! 255: { ! 256: ulBitmapType = BMF_16BPP; ! 257: flHooks = HOOKS_BMF16BPP; ! 258: } ! 259: else ! 260: { ! 261: RIP("XGA.DLL: DrvEnableSurface wrong big count"); ! 262: } ! 263: ! 264: hSurfBm = (HSURF) EngCreateBitmap(sizl, ! 265: (ULONG)ppdev->lDeltaScreen, ! 266: ulBitmapType, ! 267: (ppdev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0, ! 268: (PVOID) (ppdev->pjScreen)); ! 269: ! 270: if (hSurfBm == (HSURF) 0) ! 271: { ! 272: DISPDBG((0, "DISP!DrvEnableSurface failed EngCreateBitmap\n")); ! 273: return(FALSE); ! 274: } ! 275: ! 276: if (!EngAssociateSurface(hSurfBm, ppdev->hdevEng, 0)) ! 277: { ! 278: DISPDBG((0, "DISP DrvEnableSurface failed to Associate Engine Bitmap\n")); ! 279: EngDeleteSurface(hSurfBm); ! 280: return(FALSE); ! 281: } ! 282: ! 283: // BUGBUG check return code ! 284: ! 285: pSurfObj = EngLockSurface(hSurfBm) ; ! 286: ! 287: // BUGBUG check return code ! 288: ! 289: hsurf = EngCreateSurface((DHSURF) pSurfObj, sizl) ; ! 290: ! 291: if (!EngAssociateSurface(hsurf, ppdev->hdevEng, flHooks)) ! 292: { ! 293: DISPDBG((0, "DISP DrvEnableSurface failed to Associate Device Surface\n")); ! 294: EngUnlockSurface(pSurfObj); ! 295: EngDeleteSurface(hSurfBm); ! 296: EngDeleteSurface(hsurf); ! 297: return(FALSE); ! 298: } ! 299: ! 300: ppdev->hSurfEng = hsurf; ! 301: ppdev->hSurfBm = hSurfBm; ! 302: ppdev->pSurfObj = pSurfObj ; ! 303: ! 304: return(hsurf); ! 305: } ! 306: ! 307: /******************************Public*Routine******************************\ ! 308: * DrvDisableSurface ! 309: * ! 310: * Free resources allocated by DrvEnableSurface. Release the surface. ! 311: * ! 312: \**************************************************************************/ ! 313: ! 314: VOID DrvDisableSurface( ! 315: DHPDEV dhpdev) ! 316: { ! 317: EngUnlockSurface(((PPDEV) dhpdev)->pSurfObj); ! 318: EngDeleteSurface(((PPDEV) dhpdev)->hSurfBm); ! 319: EngDeleteSurface(((PPDEV) dhpdev)->hSurfEng); ! 320: vDisableSURF((PPDEV) dhpdev); ! 321: ((PPDEV) dhpdev)->hSurfEng = (HSURF) 0; ! 322: } ! 323: ! 324: /******************************Public*Routine******************************\ ! 325: * DrvAssertMode ! 326: * ! 327: * This asks the device to reset itself to the mode of the pdev passed in. ! 328: * ! 329: \**************************************************************************/ ! 330: ! 331: VOID DrvAssertMode( ! 332: DHPDEV dhpdev, ! 333: BOOL bEnable) ! 334: { ! 335: PPDEV ppdev = (PPDEV) dhpdev; ! 336: ULONG ulReturn; ! 337: BOOL b; ! 338: PCACHEDFONT pcf, ! 339: pcfLast; ! 340: ! 341: ! 342: if (bEnable) ! 343: { ! 344: // The screen must be reenabled, reinitialize the device to clean state. ! 345: ! 346: bInitSURF(ppdev, FALSE); ! 347: } ! 348: else ! 349: { ! 350: // We must give up the display. ! 351: // free the caches. ! 352: ! 353: // Traverse the CachedFonts list. ! 354: // Free all the system memory used for each font. ! 355: ! 356: for (pcf = ppdev->pCachedFontsRoot; pcf != NULL; pcf = pcf->pcfNext) ! 357: { ! 358: LocalFree(pcf->pCachedGlyphs); ! 359: } ! 360: ! 361: // Now free all the memory for the font nodes. ! 362: ! 363: for (pcf = ppdev->pCachedFontsRoot; pcf != NULL; ) ! 364: { ! 365: pcfLast = pcf; ! 366: pcf = pcf->pcfNext; ! 367: LocalFree(pcfLast); ! 368: } ! 369: ! 370: ppdev->pCachedFontsRoot = NULL; ! 371: ! 372: // Now Free all the memory used to maintain the XGA heap. ! 373: ! 374: b = bCpMmDestroyHeap(ppdev); ! 375: if (b == FALSE) ! 376: { ! 377: DISPDBG((1, "XGA.DLL!bBlowCache - bCpMmDestroyHeap failed\n")); ! 378: } ! 379: ! 380: // Now ReInitialize the XGA Heap. ! 381: ! 382: b = bCpMmInitHeap(ppdev); ! 383: if (b == FALSE) ! 384: { ! 385: DISPDBG((1, "XGA.DLL!bBlowCache - bCpMmInitHeap failed\n")); ! 386: } ! 387: ! 388: ! 389: // Call the kernel driver to reset the device to a known state. ! 390: ! 391: if (!DeviceIoControl(ppdev->hDriver, ! 392: IOCTL_VIDEO_RESET_DEVICE, ! 393: NULL, ! 394: 0, ! 395: NULL, ! 396: 0, ! 397: &ulReturn, ! 398: NULL)) ! 399: { ! 400: DISPDBG((1, "DISP DrvAssertMode failed IOCTL")); ! 401: } ! 402: } ! 403: ! 404: return; ! 405: } ! 406: ! 407: ! 408: /******************************Public*Routine******************************\ ! 409: * DrvGetModes ! 410: * ! 411: * Returns the list of available modes for the device. ! 412: * ! 413: \**************************************************************************/ ! 414: ! 415: ULONG DrvGetModes( ! 416: HANDLE hDriver, ! 417: ULONG cjSize, ! 418: DEVMODEW *pdm) ! 419: ! 420: { ! 421: ! 422: DWORD cModes; ! 423: DWORD cbOutputSize; ! 424: PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp; ! 425: DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE); ! 426: DWORD cbModeSize; ! 427: ! 428: DISPDBG((3, "Xga.dll:DrvGetModes\n")); ! 429: ! 430: cModes = getAvailableModes(hDriver, ! 431: (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation, ! 432: &cbModeSize); ! 433: ! 434: if (cModes == 0) ! 435: { ! 436: DISPDBG((0, "Xga.dll DrvGetModes failed to get mode information")); ! 437: return 0; ! 438: } ! 439: ! 440: if (pdm == NULL) ! 441: { ! 442: cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE); ! 443: } ! 444: else ! 445: { ! 446: // ! 447: // Now copy the information for the supported modes back into the output ! 448: // buffer ! 449: // ! 450: ! 451: cbOutputSize = 0; ! 452: ! 453: pVideoTemp = pVideoModeInformation; ! 454: ! 455: do ! 456: { ! 457: if (pVideoTemp->Length != 0) ! 458: { ! 459: if (cOutputModes == 0) ! 460: { ! 461: break; ! 462: } ! 463: ! 464: // ! 465: // Zero the entire structure to start off with. ! 466: // ! 467: ! 468: memset(pdm, 0, sizeof(DEVMODEW)); ! 469: ! 470: // ! 471: // Set the name of the device to the name of the DLL. ! 472: // ! 473: ! 474: memcpy(&(pdm->dmDeviceName), L"xga", sizeof(L"xga")); ! 475: ! 476: pdm->dmSpecVersion = DM_SPECVERSION; ! 477: pdm->dmDriverVersion = DM_SPECVERSION; ! 478: ! 479: // ! 480: // We currently do not support Extra information in the driver ! 481: // ! 482: ! 483: pdm->dmDriverExtra = DRIVER_EXTRA_SIZE; ! 484: ! 485: pdm->dmSize = sizeof(DEVMODEW); ! 486: pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes * ! 487: pVideoTemp->BitsPerPlane; ! 488: pdm->dmPelsWidth = pVideoTemp->VisScreenWidth; ! 489: pdm->dmPelsHeight = pVideoTemp->VisScreenHeight; ! 490: pdm->dmDisplayFrequency = pVideoTemp->Frequency; ! 491: ! 492: if (pVideoTemp->AttributeFlags & VIDEO_MODE_INTERLACED) ! 493: { ! 494: pdm->dmDisplayFlags |= DM_INTERLACED; ! 495: } ! 496: ! 497: // ! 498: // Go to the next DEVMODE entry in the buffer. ! 499: // ! 500: ! 501: cOutputModes--; ! 502: ! 503: pdm = (LPDEVMODEW) ( ((ULONG)pdm) + sizeof(DEVMODEW) + ! 504: DRIVER_EXTRA_SIZE); ! 505: ! 506: cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE); ! 507: ! 508: } ! 509: ! 510: pVideoTemp = (PVIDEO_MODE_INFORMATION) ! 511: (((PUCHAR)pVideoTemp) + cbModeSize); ! 512: ! 513: } while (--cModes); ! 514: } ! 515: ! 516: LocalFree(pVideoModeInformation); ! 517: ! 518: return cbOutputSize; ! 519: ! 520: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.