Annotation of ntddk/src/perf/vgacode/enable.c, revision 1.1.1.1

1.1       root        1: /******************************Module*Header*******************************\
                      2: * Module Name: enable.c
                      3: *
                      4: * Functions to enable and disable the driver
                      5: *
                      6: * Copyright (c) 1992 Microsoft Corporation
                      7: \**************************************************************************/
                      8: 
                      9: 
                     10: #include "driver.h"
                     11: #include "winperf.h"        // for Performance API strucuture definitions  (PERFCTR)
                     12: 
                     13: PPERF_COUNTER_BLOCK     pCounterBlock;  // data structure for counter values (PERFCTR)
                     14: 
                     15: FLONG   gflDrv = 0;
                     16: #ifdef  FIREWALLS
                     17: LONG    cPDEV = 0;                  // PDEV counter for checking Engine
                     18: #endif
                     19: 
                     20: extern GDIINFO gaulCap;             // in gdiinfo.c
                     21: extern LOGPALETTE logPalVGA;        // in gdiinfo.c
                     22: extern BYTE gaajPat[19][32];        // in gdiinfo.c
                     23: extern DEVINFO devinfoVGA;          // in gdiinfo.c
                     24: extern LPBYTE pPtrSave;
                     25: 
                     26: BOOL SetUpBanking(PDEVSURF, PPDEV);
                     27: BOOL bInitPointer(PPDEV);
                     28: 
                     29: extern ajConvertBuffer[1];            // Arbitrary sized array!
                     30: 
                     31: static  DRVFN   gadrvfn[] = {
                     32:     {   INDEX_DrvEnablePDEV,            (PFN) DrvEnablePDEV             },
                     33:     {   INDEX_DrvCompletePDEV,          (PFN) DrvCompletePDEV           },
                     34:     {   INDEX_DrvDisablePDEV,           (PFN) DrvDisablePDEV            },
                     35:     {   INDEX_DrvEnableSurface,         (PFN) DrvEnableSurface          },
                     36:     {   INDEX_DrvDisableSurface,        (PFN) DrvDisableSurface         },
                     37:     {   INDEX_DrvRealizeBrush,          (PFN) DrvRealizeBrush           },
                     38:     {   INDEX_DrvBitBlt,                (PFN) DrvBitBlt                 },
                     39:     {   INDEX_DrvTextOut,               (PFN) DrvTextOut                },
                     40:     {   INDEX_DrvSetPointerShape,       (PFN) DrvSetPointerShape        },
                     41:     {   INDEX_DrvMovePointer,           (PFN) DrvMovePointer            },
                     42:     {   INDEX_DrvStrokePath,            (PFN) DrvStrokePath             },
                     43:     {   INDEX_DrvCopyBits,              (PFN) DrvCopyBits               },
                     44:     {   INDEX_DrvDitherColor,           (PFN) DrvDitherColor            },
                     45:     {   INDEX_DrvAssertMode,            (PFN) DrvAssertMode             },
                     46:     {   INDEX_DrvSaveScreenBits,        (PFN) DrvSaveScreenBits         },
                     47:     {   INDEX_DrvGetModes,              (PFN) DrvGetModes               },
                     48:     {   INDEX_DrvFillPath,              (PFN) DrvFillPath               },
                     49:     {   INDEX_DrvPaint,                 (PFN) DrvPaint                  }
                     50: };
                     51: 
                     52: /******************************Public*Routine******************************\
                     53: * BOOL bInitProc(HMODULE hmod)
                     54: *
                     55: * DLL initialization procedure.  Save the module handle and exit.
                     56: *
                     57: *   This routine creates a named mapped memory section that is used
                     58: *   to communicate the driver's performance data to the extensible counter
                     59: *   DLL. This method will only work with "user" mode driver DLL's. 
                     60: *   Kernel or privileged drivers need to provide an IOCTL interface that
                     61: *   will communicate the performance data to the extensible counter DLL.
                     62: *
                     63: \**************************************************************************/
                     64: 
                     65: BOOL bInitProc(HMODULE hmod, ULONG Reason, LPVOID Reserved)
                     66: {
                     67:     HANDLE hMappedObject;
                     68:     TCHAR  szMappedObjectName[] = TEXT("VGA_COUNTER_BLOCK");
                     69: 
                     70:     if (Reason == DLL_PROCESS_ATTACH)
                     71:     {
                     72:         //
                     73:         //  create named section for the performance data
                     74:         //
                     75:         hMappedObject = CreateFileMapping((HANDLE)0xFFFFFFFF,
                     76:                      NULL,
                     77:                      PAGE_READWRITE,
                     78:                      0,
                     79:                      4096,
                     80:                      szMappedObjectName);
                     81:         if (hMappedObject == NULL)
                     82:         {
                     83:             // Should put out an EventLog error message here
                     84:             DISPDBG((0, "VGA: Could not Create Mapped Object for Counters %x",
                     85:                          GetLastError()));
                     86:                 pCounterBlock = NULL;
                     87:             }
                     88:         else
                     89:         {
                     90:                 // Mapped object created okay
                     91:             // 
                     92:             // map the section and assign the counter block pointer
                     93:             // to this section of memory
                     94:             //
                     95:             pCounterBlock = (PPERF_COUNTER_BLOCK)
                     96:                      MapViewOfFile(hMappedObject,
                     97:                      FILE_MAP_ALL_ACCESS,
                     98:                      0,
                     99:                      0,
                    100:                      0);
                    101:             if (pCounterBlock == NULL)
                    102:             {
                    103:                 // Failed to Map View of file
                    104:                 DISPDBG((0, "VGA: Failed to Map View of File %x",
                    105:                         GetLastError()));
                    106:             }
                    107:         }
                    108:     }
                    109: 
                    110:     return(TRUE);
                    111: 
                    112:     Reserved=Reserved;
                    113: }
                    114: 
                    115: 
                    116: 
                    117: /******************************Public*Routine******************************\
                    118: * BOOL bEnableDriver(iEngineVersion, cb, pded)
                    119: *
                    120: * Enables the driver by filling the function table.  This call is made by
                    121: * the Engine to fill its driver function table in the LDEV (Logical DEVice).
                    122: * This call should only be made once per driver but we can handle being
                    123: * called multiple times.
                    124: *
                    125: \**************************************************************************/
                    126: 
                    127: BOOL DrvEnableDriver
                    128: (
                    129:     ULONG           iEngineVersion,
                    130:     ULONG           cb,
                    131:     PDRVENABLEDATA  pded
                    132: )
                    133: {
                    134:     DISPDBG((2, "VGA: enabling Driver\n"));
                    135: 
                    136:     cb /= sizeof(ULONG);
                    137: 
                    138:     switch(cb)
                    139:     {
                    140:     case 3:
                    141:         pded->pdrvfn = gadrvfn;
                    142:     case 2:
                    143:         pded->c = sizeof(gadrvfn) / sizeof(DRVFN);
                    144:     case 1:
                    145:         pded->iDriverVersion = DDI_DRIVER_VERSION;
                    146:     }
                    147: 
                    148:     return(TRUE);
                    149: }
                    150: 
                    151: /******************************Public*Routine******************************\
                    152: * VOID vDisableDriver
                    153: *
                    154: * Unload the driver and any data in may have created.
                    155: *
                    156: \**************************************************************************/
                    157: 
                    158: VOID DrvDisableDriver()
                    159: {
                    160:     DISPDBG((2, "VGA: disabling Driver\n"));
                    161: }
                    162: 
                    163: /******************************Public*Routine******************************\
                    164: * BOOL bLoadResources()
                    165: *
                    166: * Load the resources used by the PDEV
                    167: *
                    168: \**************************************************************************/
                    169: 
                    170: BOOL bLoadResources(PPDEV ppdev)
                    171: {
                    172: // Load the font resources
                    173: 
                    174:     return(TRUE);
                    175: 
                    176:     UNREFERENCED_PARAMETER(ppdev);
                    177: }
                    178: 
                    179: /******************************Public*Routine******************************\
                    180: * bInitDefaultPatterns
                    181: *
                    182: * Creates the default monochrome patterns to be used on it's surface.
                    183: *
                    184: \**************************************************************************/
                    185: 
                    186: BOOL bInitDefaultPatterns(PPDEV ppdev)
                    187: {
                    188:     SIZEL           sizl;
                    189:     INT             iLoop;
                    190:     PULONG          pulInit;
                    191: 
                    192:     sizl.cx = 8;
                    193:     sizl.cy = 8;
                    194: 
                    195:     DISPDBG((2, "VGA: initializing defailt patterns\n"));
                    196: 
                    197:     for (iLoop = 0; iLoop < HS_DDI_MAX; iLoop++)
                    198:     {
                    199:         pulInit = (PULONG) (&gaajPat[iLoop][0]);
                    200:         ppdev->ahbmPat[iLoop] = EngCreateBitmap(sizl, sizl.cx / 8, BMF_1BPP,
                    201:                                                 BMF_TOPDOWN, pulInit);
                    202: 
                    203:         if (ppdev->ahbmPat[iLoop] == (HBITMAP)0)
                    204:         {
                    205:         // Release any bitmaps we have created.
                    206: 
                    207:             while(iLoop--)
                    208:                 EngDeleteSurface((HSURF) ppdev->ahbmPat[iLoop]);
                    209: 
                    210:             return(FALSE);
                    211:         }
                    212:     }
                    213: 
                    214:     return(TRUE);
                    215: }
                    216: 
                    217: /******************************Public*Routine******************************\
                    218: * DHPDEV DrvEnablePDEV
                    219: *
                    220: * Enable the Physical DEVice
                    221: *
                    222: * Warnings:
                    223: *   The PDEV isn't complete until bCompletePDEV is called.
                    224: *
                    225: \**************************************************************************/
                    226: 
                    227: DHPDEV DrvEnablePDEV
                    228: (
                    229:     DEVMODEW *pdrivw,
                    230:     PWSTR     pwszLogAddress,
                    231:     ULONG     cPatterns,
                    232:     PHSURF    ahsurfPatterns,
                    233:     ULONG     cjGdiInfo,
                    234:     ULONG    *pdevcaps,
                    235:     ULONG     cb,
                    236:     PDEVINFO  pdevinfo,
                    237:     PWSTR     pwszDataFile,
                    238:     PWSTR     pwszDeviceName,
                    239:     HANDLE    hDriver          // Handle to base driver
                    240: )
                    241: {
                    242:     FLONG   fl = 0;
                    243:     DHPDEV  dhpdev = (DHPDEV) 0;
                    244:     PPDEV   ppdev;
                    245:     SYSTEM_INFO SystemInfo;
                    246: 
                    247:     DISPDBG((2, "VGA: enabling PDEV\n"));
                    248: 
                    249: // Define flag to keep track of allocation
                    250: 
                    251: #define PDEV_ALLOCED    0x01
                    252: 
                    253: #ifdef DRV_ONE_PDEV
                    254:     if (gflDrv & DRV_ENABLED_PDEV)
                    255:     {
                    256:         // SAVE_ERROR_CODE(DDI_PDEV_ALREADY_ENABLED);
                    257:         goto error;
                    258:     }
                    259: #endif
                    260: 
                    261:     dhpdev = (DHPDEV) LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, sizeof(PDEV));
                    262:     if (dhpdev == (DHPDEV) 0)
                    263:         goto error;
                    264: 
                    265:     fl |= PDEV_ALLOCED;
                    266: 
                    267:     ppdev = (PPDEV) dhpdev;
                    268: 
                    269:     // Identifier, for debugging purposes
                    270:     ppdev->ident = PDEV_IDENT;
                    271: 
                    272:     // Determine whether this is a 386 or a better processor
                    273:     GetSystemInfo(&SystemInfo);
                    274:     if (SystemInfo.dwProcessorType == PROCESSOR_INTEL_386) {
                    275:         ppdev->ulIs386 = 1;
                    276:     } else {
                    277:         ppdev->ulIs386 = 0;
                    278:     }
                    279: 
                    280:     // Cache the device driver handle away for later use.
                    281: 
                    282:     ppdev->hDriver = hDriver;
                    283: 
                    284:     // Initialize the cursor stuff.  We can violate the atomic rule here
                    285:     // since nobody can talk to the driver yet.
                    286: 
                    287:     ppdev->xyCursor.x = 320;            // Non-atomic
                    288:     ppdev->xyCursor.y = 240;            // Non-atomic
                    289: 
                    290:     ppdev->ptlExtent.x = 0;
                    291:     ppdev->ptlExtent.y = 0;
                    292:     ppdev->cExtent = 0;
                    293: 
                    294:     ppdev->flCursor = CURSOR_DOWN;
                    295: 
                    296:     //
                    297:     // Get the current screen mode information.  Set up device caps and devinfo.
                    298:     //
                    299: 
                    300:     if (!bInitPDEV(ppdev, pdrivw, &gaulCap, &devinfoVGA))
                    301:     {
                    302:         DISPDBG((1, "DISP VGA DrvEnablePDEV failed bInitPDEV\n"));
                    303:         goto error;
                    304:     }
                    305: 
                    306:     if (!bLoadResources(ppdev))
                    307:         goto error;
                    308: 
                    309:     if (!bInitDefaultPatterns(ppdev))
                    310:         goto error;
                    311: 
                    312: #ifdef DRV_ONE_PDEV
                    313:     gflDrv |= DRV_ENABLED_PDEV;             // So we're not called twice
                    314: #endif
                    315: 
                    316:     cPatterns=min(cPatterns, HS_DDI_MAX);
                    317: 
                    318:     memcpy((PVOID)ahsurfPatterns, ppdev->ahbmPat, cPatterns*sizeof(HBITMAP));
                    319: 
                    320:     cjGdiInfo=min(cjGdiInfo, sizeof(GDIINFO));
                    321: 
                    322:     memcpy(pdevcaps, &gaulCap, cjGdiInfo);
                    323: 
                    324:      // Now let's pass back the devinfo
                    325: 
                    326:     devinfoVGA.hpalDefault = EngCreatePalette(PAL_INDEXED, 16,
                    327:                                               (PULONG) (logPalVGA.palPalEntry),
                    328:                                               0, 0, 0);
                    329: 
                    330:     // *pdevinfo  = devinfoVGA;
                    331:     memcpy((PVOID) pdevinfo, (PVOID) &devinfoVGA, (ULONG) sizeof(DEVINFO));
                    332: 
                    333:     // Try to preallocate a saved screen bits buffer. If we fail, set the flag
                    334:     // to indicate the buffer is in use, so that we'll never attempt to use it.
                    335:     // If we succeed, mark the buffer as free.
                    336: 
                    337:     if ((ppdev->pjPreallocSSBBuffer = (PUCHAR)
                    338:               LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, PREALLOC_SSB_SIZE))
                    339:               != NULL) {
                    340:         ppdev->flPreallocSSBBufferInUse = FALSE;
                    341:         ppdev->ulPreallocSSBSize = PREALLOC_SSB_SIZE;
                    342:     } else {
                    343:         ppdev->flPreallocSSBBufferInUse = TRUE;
                    344:     }
                    345: 
                    346:     // Fill in the DIB4->VGA conversion tables. Allow 256 extra bytes so that
                    347:     // we can always safely align the tables to a 256-byte boundary, for
                    348:     // look-up reasons. There are four tables, each 256 bytes long
                    349: 
                    350:     ppdev->pucDIB4ToVGAConvBuffer =
                    351:             (UCHAR *) LocalAlloc((LMEM_FIXED | LMEM_ZEROINIT),
                    352:             ((256*4+256)*sizeof(UCHAR)));
                    353: 
                    354:     if (ppdev->pucDIB4ToVGAConvBuffer == NULL) {
                    355:         goto error;
                    356:     }
                    357: 
                    358:     // Round the table start up to the nearest 256 byte boundary, because the
                    359:     // tables must start on 256-byte boundaries for look-up reasons
                    360: 
                    361:     ppdev->pucDIB4ToVGAConvTables =
                    362:             (UCHAR *) ((ULONG) (ppdev->pucDIB4ToVGAConvBuffer + 0xFF) & ~0xFF);
                    363: 
                    364:     vSetDIB4ToVGATables(ppdev->pucDIB4ToVGAConvTables);
                    365: 
                    366:     return(dhpdev);
                    367: 
                    368: error:
                    369:     if (fl & PDEV_ALLOCED)
                    370:         LocalFree(dhpdev);
                    371: 
                    372:     return((DHPDEV) 0);
                    373: 
                    374:     UNREFERENCED_PARAMETER(cb);
                    375:     UNREFERENCED_PARAMETER(pwszLogAddress);
                    376:     UNREFERENCED_PARAMETER(pwszDataFile);
                    377:     UNREFERENCED_PARAMETER(pwszDeviceName);
                    378: }
                    379: 
                    380: /******************************Public*Routine******************************\
                    381: * BOOL bCompletePDEV(dhpdev, hpdev)
                    382: *
                    383: * Complete the initialization of the PDEV
                    384: *
                    385: \**************************************************************************/
                    386: 
                    387: VOID DrvCompletePDEV(
                    388:     DHPDEV dhpdev,
                    389:     HDEV  hdev)
                    390: {
                    391:     PPDEV   ppdev;
                    392: 
                    393:     ppdev = (PPDEV) dhpdev;
                    394: 
                    395:     ppdev->hdevEng = hdev;
                    396: }
                    397: 
                    398: /******************************Public*Routine******************************\
                    399: * VOID vFreeResources(ppdev)
                    400: *
                    401: * Free the resources used by the PDEV
                    402: *
                    403: * Effects:
                    404: *
                    405: * Warnings:
                    406: *
                    407: \**************************************************************************/
                    408: 
                    409: VOID vFreeResources(PPDEV ppdev)
                    410: {
                    411: 
                    412:     UNREFERENCED_PARAMETER(ppdev);
                    413: }
                    414: 
                    415: /******************************Public*Routine******************************\
                    416: * VOID vKillPatterns(ppdev)
                    417: *
                    418: * Clear the standard patterns
                    419: *
                    420: \**************************************************************************/
                    421: 
                    422: VOID vKillPatterns(PPDEV ppdev)
                    423: {
                    424:     INT     ii;
                    425: 
                    426:     for (ii = 0; ii < HS_DDI_MAX; ii++)
                    427:         EngDeleteSurface((HSURF) ppdev->ahbmPat[ii]);
                    428: }
                    429: 
                    430: /******************************Public*Routine******************************\
                    431: * VOID DrvDisablePDEV(dhpdev)
                    432: *
                    433: * Shutdown this physical device.
                    434: *
                    435: * Warnings:
                    436: *   If a surface is still active for this PDEV it will be freed.
                    437: *
                    438: 
                    439: \**************************************************************************/
                    440: 
                    441: VOID DrvDisablePDEV(DHPDEV dhpdev)
                    442: {
                    443:     PPDEV   ppdev;
                    444: 
                    445:     ppdev = (PPDEV) dhpdev;
                    446: 
                    447:     DISPDBG((2, "VGA:disabling PDEV\n"));
                    448: 
                    449: //    ASSERT(ppdev != (PPDEV) NULL, "PDEV error");
                    450: 
                    451: // Is there a deliquent surface still in the PDEV?
                    452: 
                    453:     if (ppdev->hsurfEng != (HSURF) 0)
                    454:         DrvDisableSurface(dhpdev);
                    455: 
                    456: // Check if the Engine has called us to many times.
                    457: 
                    458: //    ASSERT(--cPDEV >= 0, "PDEV - too many disables");
                    459: 
                    460: // Free the resources and bitmaps associated with this PDEV
                    461: 
                    462:     vFreeResources(ppdev);
                    463:     vKillPatterns(ppdev);
                    464: 
                    465: // Free the preallocated saved screen bits buffer, if there is one.
                    466: 
                    467:     if (ppdev->pjPreallocSSBBuffer != NULL) {
                    468:         LocalFree(ppdev->pjPreallocSSBBuffer);
                    469:     }
                    470: 
                    471: // Free the conversion table buffer
                    472: 
                    473:     if (ppdev->pucDIB4ToVGAConvBuffer != NULL) {
                    474:         LocalFree(ppdev->pucDIB4ToVGAConvBuffer);
                    475:     }
                    476: 
                    477: // Delete the PDEV
                    478: 
                    479:     LocalFree(dhpdev);
                    480: 
                    481:     DISPDBG((2, "VGA: disabled PDEV\n"));
                    482: 
                    483: #ifdef  DRV_ONE_PDEV
                    484:     gflDrv &= ~DRV_ENABLED_PDEV;
                    485: #endif
                    486: }
                    487: 
                    488: /******************************Public*Routine******************************\
                    489: * HSURF DrvEnableSurface(dhpdev)
                    490: *
                    491: * Enable the surface for the device.  This will actually intialize the
                    492: * screen on the VGA.
                    493: *
                    494: * Warnings:
                    495: *   This routine should only be called ONCE per PDEV.
                    496: *
                    497: \**************************************************************************/
                    498: 
                    499: HSURF DrvEnableSurface(DHPDEV dhpdev)
                    500: {
                    501:     PPDEV    ppdev;
                    502:     PDEVSURF pdsurf;
                    503:     DHSURF   dhsurf;
                    504:     HSURF    hsurf;
                    505: 
                    506:     DISPDBG((2, "VGA:enabling Surface\n"));
                    507: 
                    508:     ppdev = (PPDEV) dhpdev;
                    509: 
                    510:     //
                    511:     // Initialize the VGA device into the selected mode which will also map
                    512:     // the video frame buffer
                    513:     //
                    514: 
                    515:     if (!bInitVGA(ppdev, TRUE))
                    516:     {
                    517:         goto error_done;
                    518:     }
                    519: 
                    520:     dhsurf = (DHSURF) LocalAlloc(LMEM_FIXED, (SIZE_T) sizeof(DEVSURF));
                    521: 
                    522:     if (dhsurf == (DHSURF) 0)
                    523:         goto error_done;
                    524: 
                    525:     pdsurf = (PDEVSURF) dhsurf;
                    526: 
                    527:     pdsurf->ident           = DEVSURF_IDENT;
                    528:     pdsurf->flSurf          = 0;
                    529:     pdsurf->iFormat         = BMF_PHYSDEVICE;
                    530:     pdsurf->jReserved1      = 0;
                    531:     pdsurf->jReserved2      = 0;
                    532:     pdsurf->ppdev           = ppdev;
                    533:     pdsurf->sizlSurf.cx     = ppdev->sizlSurf.cx;
                    534:     pdsurf->sizlSurf.cy     = ppdev->sizlSurf.cy;
                    535:     pdsurf->lNextPlane      = 0;
                    536:     pdsurf->pvScan0         = ppdev->pjScreen;
                    537:     pdsurf->pvBitmapStart   = ppdev->pjScreen;
                    538:     pdsurf->pvStart         = ppdev->pjScreen;
                    539:     pdsurf->pvConv          = &ajConvertBuffer[0];
                    540: 
                    541:     if (!bInitPointer(ppdev)) {
                    542:         DISPDBG((0, "VGA DrvEnablePDEV failed bInitPointer\n"));
                    543:         goto error_clean;
                    544:     }
                    545: 
                    546:     if (!SetUpBanking(pdsurf, ppdev)) {
                    547:         DISPDBG((0, "VGA DrvEnablePDEV failed SetUpBanking\n"));
                    548:         goto error_clean;
                    549:     }
                    550: 
                    551:     // Initialize pointer information.
                    552: 
                    553:     if ((hsurf = EngCreateSurface(dhsurf, ppdev->sizlSurf)) == (HSURF) 0)
                    554:     {
                    555:         DISPDBG((0, "VGA DrvEnablePDEV failed EngCreateSurface\n"));
                    556:         goto error_clean;
                    557:     }
                    558: 
                    559:     if (EngAssociateSurface(hsurf, ppdev->hdevEng,
                    560:                         HOOK_BITBLT | HOOK_TEXTOUT | HOOK_STROKEPATH |
                    561:                         HOOK_COPYBITS | HOOK_PAINT | HOOK_FILLPATH))
                    562:     {
                    563:         ppdev->hsurfEng = hsurf;
                    564:         ppdev->pdsurf = pdsurf;
                    565: 
                    566:         // Set up an empty saved screen block list
                    567:         pdsurf->ssbList = NULL;
                    568:         // Initialize the offscreen adapter memory heap to currently all
                    569:         // available
                    570:         // Beginning of heap starts right after the displayed bitmap ends
                    571:         pdsurf->pjAdapterHeapStart = ((PBYTE)pdsurf->pvBitmapStart) +
                    572:              (pdsurf->lNextScan * pdsurf->sizlSurf.cy);
                    573: 
                    574:         // End of heap is the start of either the pointer work area or the
                    575:         // hardware pointer reserved memory area, whichever comes first
                    576:         pdsurf->pjAdapterHeapEnd = pPtrSave;
                    577:         if (ppdev->pPointerAttributes != NULL)
                    578:         {
                    579:             // There's a hardware pointer, so check what display memory it
                    580:             //  uses, if any
                    581:             if (ppdev->PointerCapabilities.HWPtrBitmapStart != -1)
                    582:             {
                    583:                 // The hardware pointer does use display memory
                    584:                 if (( ((PBYTE)pdsurf->pvBitmapStart) +
                    585:                         ppdev->PointerCapabilities.HWPtrBitmapStart) <
                    586:                         pdsurf->pjAdapterHeapEnd)
                    587:                 {
                    588:                     // The hardware pointer marks the end of the heap
                    589:                     pdsurf->pjAdapterHeapEnd = ((PBYTE)pdsurf->pvBitmapStart) +
                    590:                         ppdev->PointerCapabilities.HWPtrBitmapStart;
                    591:                 }
                    592:             }
                    593:         }
                    594: 
                    595:         // The current top of the heap is the end of the heap, because the heap
                    596:         // is empty
                    597:         pdsurf->pjAdapterHeapTop = pdsurf->pjAdapterHeapEnd;
                    598: 
                    599:         DISPDBG((2, "VGA: enabled surface\n"));
                    600: 
                    601:         return(hsurf);
                    602: 
                    603:     }
                    604: 
                    605:     DISPDBG((0, "VGA DrvEnablePDEV failed EngDeleteSurface\n"));
                    606:     EngDeleteSurface(hsurf);
                    607: 
                    608: error_clean:
                    609:     // We created the surface, so delete it
                    610:     LocalFree(dhsurf);
                    611: 
                    612: error_done:
                    613:     return((HSURF) 0);
                    614: }
                    615: 
                    616: 
                    617: /******************************Public*Routine******************************\
                    618: * DrvDisableSurface
                    619: *
                    620: * Free resources associated with this surface.
                    621: *
                    622: \**************************************************************************/
                    623: 
                    624: VOID DrvDisableSurface(DHPDEV dhpdev)
                    625: {
                    626:     PPDEV   ppdev = (PPDEV) dhpdev;
                    627:     PDEVSURF pdsurf = ppdev->pdsurf;
                    628:     PSAVED_SCREEN_BITS pSSB, pSSBNext;
                    629: 
                    630:     DISPDBG((2, "VGA:disabling surface\n"));
                    631: 
                    632:     // Free up banking-related stuff.
                    633:     LocalFree(pdsurf->pBankSelectInfo);
                    634: 
                    635:     if (pdsurf->pbiBankInfo != NULL) {
                    636:         LocalFree(pdsurf->pbiBankInfo);
                    637:     }
                    638: 
                    639:     if (pdsurf->pbiBankInfo2RW != NULL) {
                    640:         LocalFree(pdsurf->pbiBankInfo2RW);
                    641:     }
                    642: 
                    643:     if (pdsurf->pvBankBufferPlane0 != NULL) {
                    644:         LocalFree(pdsurf->pvBankBufferPlane0);
                    645:     }
                    646: 
                    647:     if (ppdev->pPointerAttributes != NULL) {
                    648:         LocalFree(ppdev->pPointerAttributes);
                    649:     }
                    650: 
                    651:     // Free any pending saved screen bit blocks.
                    652:     pSSB = pdsurf->ssbList;
                    653:     while (pSSB != (PSAVED_SCREEN_BITS) NULL) {
                    654:         // Point to the next saved screen bits block
                    655:         pSSBNext = (PSAVED_SCREEN_BITS) pSSB->pvNextSSB;
                    656:         // Free the current block
                    657:         LocalFree(pSSB);
                    658:         pSSB = pSSBNext;
                    659:     }
                    660: 
                    661:     EngDeleteSurface((HSURF) ppdev->hsurfEng);
                    662: 
                    663:     LocalFree(pdsurf);  // free the surface
                    664: 
                    665:     DISPDBG((2, "VGA:disabled surface\n"));
                    666: 
                    667: }
                    668: 
                    669: /******************************Public*Routine******************************\
                    670: * DrvAssertMode
                    671: *
                    672: * Ping the device back into its last known mode
                    673: *
                    674: \**************************************************************************/
                    675: 
                    676: VOID DrvAssertMode(DHPDEV dhpdev, BOOL Enable)
                    677: {
                    678:     PPDEV   ppdev = (PPDEV) dhpdev;
                    679:     ULONG   returnedDataLength;
                    680: 
                    681:     DISPDBG((2, "VGA: DrvAssertMode\n"));
                    682: 
                    683:     if (Enable) {
                    684: 
                    685:         //
                    686:         // The screen must be reenabled since we had gone to full screen.
                    687:         // Re-initialize the device.
                    688:         // !!! BUGBUG what happens if this fails ??
                    689:         //
                    690: 
                    691:         bInitVGA(ppdev, FALSE);
                    692: 
                    693:         vForceBank0(ppdev);
                    694: 
                    695:     } else {
                    696: 
                    697:         //
                    698:         // We must give up the display.
                    699:         // Call the kernel driver to reset the device to a known state.
                    700:         //
                    701: 
                    702:         if (!DeviceIoControl(ppdev->hDriver,
                    703:                              IOCTL_VIDEO_RESET_DEVICE,
                    704:                              NULL,
                    705:                              0,
                    706:                              NULL,
                    707:                              0,
                    708:                              &returnedDataLength,
                    709:                              NULL)) {
                    710: 
                    711:             RIP("VGA.DLL: Reset Device Failed");
                    712: 
                    713:         }
                    714:     }
                    715: 
                    716:     return;
                    717: }
                    718: 
                    719: /******************************Public*Routine******************************\
                    720: * DrvGetModes
                    721: *
                    722: * Returns the list of available modes for the device.
                    723: *
                    724: \**************************************************************************/
                    725: 
                    726: ULONG DrvGetModes(
                    727: HANDLE hDriver,
                    728: ULONG cjSize,
                    729: DEVMODEW *pdm)
                    730: 
                    731: {
                    732: 
                    733:     DWORD cModes;
                    734:     DWORD cbOutputSize;
                    735:     PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp;
                    736:     DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
                    737:     DWORD cbModeSize;
                    738: 
                    739:     DISPDBG((2, "Vga.dll:DrvGetModes\n"));
                    740: 
                    741:     cModes = getAvailableModes(hDriver,
                    742:                                (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
                    743:                                &cbModeSize);
                    744: 
                    745:     if (cModes == 0)
                    746:     {
                    747:         DISPDBG((0, "VGA DISP DrvGetModes failed to get mode information"));
                    748:         return 0;
                    749:     }
                    750: 
                    751:     if (pdm == NULL)
                    752:     {
                    753:         cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
                    754:     }
                    755:     else
                    756:     {
                    757:         //
                    758:         // Now copy the information for the supported modes back into the output
                    759:         // buffer
                    760:         //
                    761: 
                    762:         cbOutputSize = 0;
                    763: 
                    764:         pVideoTemp = pVideoModeInformation;
                    765: 
                    766:         do
                    767:         {
                    768:             if (pVideoTemp->Length != 0)
                    769:             {
                    770:                 if (cOutputModes == 0)
                    771:                 {
                    772:                     break;
                    773:                 }
                    774: 
                    775:                 //
                    776:                 // Zero the entire structure to start off with.
                    777:                 //
                    778: 
                    779:                 memset(pdm, 0, sizeof(DEVMODEW));
                    780: 
                    781:                 //
                    782:                 // Set the name of the device to the name of the DLL.
                    783:                 //
                    784: 
                    785:                 memcpy(&(pdm->dmDeviceName), L"vga", sizeof(L"vga"));
                    786: 
                    787:                 pdm->dmSpecVersion = DM_SPECVERSION;
                    788:                 pdm->dmDriverVersion = DM_SPECVERSION;
                    789: 
                    790:                 //
                    791:                 // We currently do not support Extra information in the driver
                    792:                 //
                    793: 
                    794:                 pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
                    795: 
                    796:                 pdm->dmSize = sizeof(DEVMODEW);
                    797:                 pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
                    798:                                     pVideoTemp->BitsPerPlane;
                    799:                 pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
                    800:                 pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
                    801:                 pdm->dmDisplayFrequency = pVideoTemp->Frequency;
                    802: 
                    803:                 if (pVideoTemp->AttributeFlags & VIDEO_MODE_INTERLACED)
                    804:                 {
                    805:                     pdm->dmDisplayFlags |= DM_INTERLACED;
                    806:                 }
                    807: 
                    808:                 //
                    809:                 // Go to the next DEVMODE entry in the buffer.
                    810:                 //
                    811: 
                    812:                 cOutputModes--;
                    813: 
                    814:                 pdm = (LPDEVMODEW) ( ((ULONG)pdm) + sizeof(DEVMODEW) +
                    815:                                                    DRIVER_EXTRA_SIZE);
                    816: 
                    817:                 cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
                    818: 
                    819:             }
                    820: 
                    821:             pVideoTemp = (PVIDEO_MODE_INFORMATION)
                    822:                 (((PUCHAR)pVideoTemp) + cbModeSize);
                    823: 
                    824:         } while (--cModes);
                    825:     }
                    826: 
                    827:     LocalFree(pVideoModeInformation);
                    828: 
                    829:     return cbOutputSize;
                    830: 
                    831: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.