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