Annotation of ntddk/src/video/displays/jz484/screen.c, revision 1.1.1.1

1.1       root        1: /******************************Module*Header*******************************\
                      2: * Module Name: screen.c
                      3: *
                      4: * Initializes the GDIINFO and DEVINFO structures for DrvEnablePDEV.
                      5: *
                      6: * Copyright (C) 1991-1993  Microsoft Corporation.  All rights reserved.
                      7: \**************************************************************************/
                      8: 
                      9: #include "driver.h"
                     10: #include "jzvxl484.h"
                     11: 
                     12: //
                     13: // Define forward referenced prototypes.
                     14: //
                     15: 
                     16: 
                     17: BOOL
                     18: DrvpSetGammaColorPalette(
                     19:     IN PPDEV   ppdev,
                     20:     IN WORD    NumberOfEntries,
                     21:     IN LDECI4  GammaRed,
                     22:     IN LDECI4  GammaGreen,
                     23:     IN LDECI4  GammaBlue
                     24:     );
                     25: 
                     26: VIDEO_JAGUAR_INFO JaguarInfo;
                     27: 
                     28: extern PJAGUAR_FIFO FifoRegs;
                     29: extern PJAGUAR_REGISTERS Jaguar;
                     30: 
                     31: #define SYSTM_LOGFONT {16,7,0,0,700,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH | FF_DONTCARE,L"System"}
                     32: #define HELVE_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_STROKE_PRECIS,PROOF_QUALITY,VARIABLE_PITCH | FF_DONTCARE,L"MS Sans Serif"}
                     33: #define COURI_LOGFONT {12,9,0,0,400,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_STROKE_PRECIS,PROOF_QUALITY,FIXED_PITCH | FF_DONTCARE,L"Courier"}
                     34: 
                     35: //
                     36: // This is the basic devinfo for a default driver.  This is used as a base and customized based
                     37: // on information passed back from the miniport driver.
                     38: //
                     39: 
                     40: const DEVINFO gDevInfoFrameBuffer = {
                     41:     (GCAPS_OPAQUERECT | GCAPS_MONO_DITHER), // Graphics capabilities
                     42:     SYSTM_LOGFONT,    // Default font description
                     43:     HELVE_LOGFONT,    // ANSI variable font description
                     44:     COURI_LOGFONT,    // ANSI fixed font description
                     45:     0,                // Count of device fonts
                     46:     0,                // Preferred DIB format
                     47:     8,                // Width of color dither
                     48:     8,                // Height of color dither
                     49:     0                 // Default palette to use for this device
                     50: };
                     51: 
                     52: /******************************Public*Routine******************************\
                     53: * bInitSURF
                     54: *
                     55: * Enables the surface. Maps the frame buffer into memory.
                     56: *
                     57: \**************************************************************************/
                     58: 
                     59: BOOL bInitSURF(PPDEV ppdev, BOOL bFirst)
                     60: {
                     61:     DWORD returnedDataLength;
                     62:     VIDEO_MEMORY videoMemory;
                     63:     VIDEO_MEMORY_INFORMATION videoMemoryInformation;
                     64:     RECTL  Rectl;
                     65:     ULONG Index;
                     66:     ULONG MaxHeight,MaxWidth;
                     67:     //
                     68:     // Set the current mode into the hardware.
                     69:     //
                     70: 
                     71:     if (!DeviceIoControl(ppdev->hDriver,
                     72:             IOCTL_VIDEO_SET_CURRENT_MODE,
                     73:             &(ppdev->ulMode),
                     74:             sizeof(ULONG),
                     75:             NULL,
                     76:             0,
                     77:             &returnedDataLength,
                     78:             NULL))
                     79:     {
                     80:         DISPDBG((0, "DISP bInitSURF failed IOCTL_SET_MODE\n"));
                     81:         return(FALSE);
                     82:     }
                     83: 
                     84:     //
                     85:     // If this is the first time we enable the surface we need to map in the
                     86:     // memory also.
                     87:     //
                     88: 
                     89:     if (bFirst)
                     90:     {
                     91:         videoMemory.RequestedVirtualAddress = NULL;
                     92: 
                     93:         if (!DeviceIoControl(ppdev->hDriver,
                     94:                 IOCTL_VIDEO_MAP_VIDEO_MEMORY,
                     95:                 &videoMemory,
                     96:                 sizeof(VIDEO_MEMORY),
                     97:                 &videoMemoryInformation,
                     98:                 sizeof(VIDEO_MEMORY_INFORMATION),
                     99:                 &returnedDataLength,
                    100:                 NULL))
                    101:         {
                    102:             DISPDBG((0, "DISP bInitSURF failed IOCTL_VIDEO_MAP\n"));
                    103:             return(FALSE);
                    104:         }
                    105: 
                    106:         ppdev->pjScreen = (PBYTE)(videoMemoryInformation.FrameBufferBase);
                    107: 
                    108: 
                    109:         //
                    110:         //  Call the video miniport driver to get virtual address of JAGUAR registers
                    111:         //
                    112: 
                    113:         if (!DeviceIoControl(ppdev->hDriver,
                    114:                              IOCTL_VIDEO_QUERY_JAGUAR,
                    115:                              NULL,
                    116:                              0,
                    117:                              &JaguarInfo,
                    118:                              sizeof(VIDEO_JAGUAR_INFO),
                    119:                              &returnedDataLength,NULL)) {
                    120: 
                    121:             DISPDBG((0, " Get Jaguar information failed\n"));
                    122:             return(FALSE);
                    123: 
                    124:         }
                    125: 
                    126:         //
                    127:         // Initialize variables.
                    128:         //
                    129: 
                    130:         Jaguar   = (PJAGUAR_REGISTERS)JaguarInfo.VideoControlVirtualBase;
                    131:         FifoRegs = (PJAGUAR_FIFO)JaguarInfo.FifoVirtualBase;
                    132: 
                    133:         Vxl.ScreenBase = (ULONG) videoMemoryInformation.FrameBufferBase;
                    134:         Vxl.MemorySize = JaguarInfo.VideoMemoryLength;
                    135:         Vxl.FontCacheBase = (PULONG) (Vxl.ScreenBase + Vxl.FontCacheOffset);
                    136: 
                    137:         //
                    138:         // Determine how much off-screen memory is available for a font cache
                    139:         //
                    140: 
                    141:         while (Vxl.CacheSize*GlyphEntrySize > (Vxl.MemorySize - Vxl.FontCacheOffset)) {
                    142:             Vxl.CacheSize >>= 1;
                    143:             Vxl.CacheIndexMask >>= 1;
                    144:         }
                    145: 
                    146:         //
                    147:         // Allocate and initialize the font cache structure
                    148:         //
                    149: 
                    150:         Vxl.CacheTag = (PFONTCACHEINFO) LocalAlloc(LMEM_FIXED,sizeof(FONTCACHEINFO)*Vxl.CacheSize);
                    151: 
                    152:         if (Vxl.CacheTag == (PFONTCACHEINFO) NULL) {
                    153:             DISPDBG((0, "Cache Tag allocation error\n"));
                    154:             return(FALSE);
                    155:         }
                    156: 
                    157:         //
                    158:         // Initialize the tags to invalid.
                    159:         //
                    160: 
                    161:         for (Index = 0; Index < Vxl.CacheSize; Index++) {
                    162:             Vxl.CacheTag[Index].FontId = FreeTag;
                    163:             Vxl.CacheTag[Index].GlyphHandle = FreeTag;
                    164:         }
                    165: 
                    166:         //
                    167:         // It's a hardware pointer; set up pointer attributes.
                    168:         //
                    169:         // Allocate space for two DIBs (data/mask) for the pointer.
                    170:         //
                    171: 
                    172:         MaxHeight = ppdev->PointerCapabilities.MaxHeight;
                    173:         MaxWidth = (ppdev->PointerCapabilities.MaxWidth + 7) / 8;
                    174: 
                    175:         ppdev->cjPointerAttributes =
                    176:                 sizeof(VIDEO_POINTER_ATTRIBUTES) +
                    177:                 ((sizeof(UCHAR) * MaxWidth * MaxHeight) * 2);
                    178: 
                    179:         ppdev->pPointerAttributes = (PVIDEO_POINTER_ATTRIBUTES)
                    180:                 LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT,
                    181:                 ppdev->cjPointerAttributes);
                    182: 
                    183:         if (ppdev->pPointerAttributes == NULL) {
                    184:             DISPDBG((0, "VXL bInitPointer LocalAlloc failed\n"));
                    185:             return(FALSE);
                    186:         }
                    187: 
                    188:         ppdev->pPointerAttributes->WidthInBytes = MaxWidth;
                    189:         ppdev->pPointerAttributes->Width = ppdev->PointerCapabilities.MaxWidth;
                    190:         ppdev->pPointerAttributes->Height = MaxHeight;
                    191:         ppdev->pPointerAttributes->Column = 0;
                    192:         ppdev->pPointerAttributes->Row = 0;
                    193:         ppdev->pPointerAttributes->Enable = 0;
                    194:     }
                    195: 
                    196:     //
                    197:     // Send a command to the fifo to clear the screen.
                    198:     //
                    199:     Rectl.top = Rectl.left = 0;
                    200:     Rectl.right = Vxl.ScreenX;
                    201:     Rectl.bottom = Vxl.ScreenY;
                    202:     DrvpFillRectangle(&Rectl,0);
                    203: 
                    204:     return(TRUE);
                    205: }
                    206: 
                    207: /******************************Public*Routine******************************\
                    208: * vDisableSURF
                    209: *
                    210: * Disable the surface. Un-Maps the frame in memory.
                    211: *
                    212: \**************************************************************************/
                    213: 
                    214: VOID vDisableSURF(PPDEV ppdev)
                    215: {
                    216:     DWORD returnedDataLength;
                    217:     VIDEO_MEMORY videoMemory;
                    218: 
                    219:     videoMemory.RequestedVirtualAddress = (PVOID) ppdev->pjScreen;
                    220: 
                    221:     if (!DeviceIoControl(ppdev->hDriver,
                    222:             IOCTL_VIDEO_UNMAP_VIDEO_MEMORY,
                    223:             &videoMemory,
                    224:             sizeof(VIDEO_MEMORY),
                    225:             NULL,
                    226:             0,
                    227:             &returnedDataLength,
                    228:             NULL))
                    229:     {
                    230:         DISPDBG((0, "DISP vDisableSURF failed IOCTL_VIDEO_UNMAP\n"));
                    231:     }
                    232: }
                    233: 
                    234: 
                    235: /******************************Public*Routine******************************\
                    236: * bInitPDEV
                    237: *
                    238: * Determine the mode we should be in based on the DEVMODE passed in.
                    239: * Query mini-port to get information needed to fill in the DevInfo and the
                    240: * GdiInfo .
                    241: *
                    242: * BUGBUG Copy this routine from the other display drivers !!! HACK
                    243: *
                    244: \**************************************************************************/
                    245: 
                    246: BOOL
                    247: bInitPDEV(
                    248:     PPDEV ppdev,
                    249:     PDEVMODEW pDevMode,
                    250:     GDIINFO *pGdiInfo,
                    251:     DEVINFO *pDevInfo
                    252: )
                    253: 
                    254: {
                    255:     ULONG                    cModes, ulTemp;
                    256:     PVIDEO_MODE_INFORMATION  pVideoBuffer, pVideoTemp, pVideoModeInformation;
                    257:     PVIDEO_MODE_INFORMATION  pVideoModeDefault , pVideoModeSelected;
                    258:     VIDEO_MODE_INFORMATION   VideoModeInformation;
                    259:     VIDEO_COLOR_CAPABILITIES colorCapabilities;
                    260:     PDEVMODEW                DevMode = (PDEVMODEW) pDevMode;
                    261:     ULONG cbModeSize;
                    262: 
                    263:     //
                    264:     //  Get the enumeration of available modes from the miniport
                    265:     //
                    266: 
                    267:     cModes = getAvailableModes(ppdev->hDriver, &pVideoBuffer, &cbModeSize);
                    268: 
                    269:     if (cModes == 0)
                    270:     {
                    271:         return(FALSE);
                    272:     }
                    273: 
                    274:     //
                    275:     // Now see if the mini-port has a match for the mode we are requesting.
                    276:     // If not default to the first mode provided by the mini-port.
                    277:     //
                    278: 
                    279:     pVideoModeDefault = NULL;
                    280:     pVideoModeSelected = NULL;
                    281:     pVideoModeInformation = pVideoTemp = pVideoBuffer;
                    282: 
                    283:     //
                    284:     // search the mode table for a matching mode. If no match is found then
                    285:     // use the last entry as the default.
                    286:     //
                    287: 
                    288:     while (cModes--) {
                    289:         if (pVideoTemp->Length != 0) {
                    290:             pVideoModeDefault = pVideoTemp;
                    291: 
                    292:             if ((pVideoTemp->VisScreenWidth == pDevMode->dmPelsWidth) &&
                    293:                 (pVideoTemp->VisScreenHeight == pDevMode->dmPelsHeight) &&
                    294:                 (pVideoTemp->BitsPerPlane == pDevMode->dmBitsPerPel) &&
                    295:                 (pVideoTemp->Frequency ==  pDevMode->dmDisplayFrequency)) {
                    296: 
                    297:                 pVideoModeSelected = pVideoTemp;
                    298:                 break;
                    299:             }
                    300:         }
                    301: 
                    302:         pVideoTemp = (PVIDEO_MODE_INFORMATION)
                    303:             (((PUCHAR)pVideoTemp) + cbModeSize);
                    304:     }
                    305: 
                    306:     if (pVideoModeSelected == NULL)
                    307:     {
                    308:         if (pVideoModeDefault == NULL)
                    309:         {
                    310:             DISPDBG((0, "DISP bInitPDEV no supported mode available"));
                    311:             LocalFree(pVideoBuffer);
                    312: 
                    313:             return(FALSE);
                    314:         }
                    315:         pVideoModeSelected = pVideoModeDefault;
                    316:     }
                    317: 
                    318: 
                    319:     //
                    320:     // Set up screen information
                    321:     //
                    322: 
                    323:     VideoModeInformation = *pVideoModeSelected;
                    324: 
                    325:     //
                    326:     //  Fill in gdi structures
                    327:     //
                    328: 
                    329:     ppdev->ulMode       = VideoModeInformation.ModeIndex;
                    330:     ppdev->cxScreen     = VideoModeInformation.VisScreenWidth;
                    331:     ppdev->cyScreen     = VideoModeInformation.VisScreenHeight;
                    332:     ppdev->ulBitCount   = VideoModeInformation.BitsPerPlane;
                    333:     ppdev->lDeltaScreen = VideoModeInformation.ScreenStride;
                    334: 
                    335:     ppdev->flRed        = VideoModeInformation.RedMask;
                    336:     ppdev->flGreen      = VideoModeInformation.GreenMask;
                    337:     ppdev->flBlue       = VideoModeInformation.BlueMask;
                    338: 
                    339:     //
                    340:     // Fill in the GDIINFO data structure with the information returned from the
                    341:     // kernel driver.
                    342:     //
                    343: 
                    344:     pGdiInfo->ulVersion    = 0x1000;        // Our driver is version 1.000
                    345:     pGdiInfo->ulTechnology = DT_RASDISPLAY;
                    346:     pGdiInfo->ulHorzSize   = VideoModeInformation.XMillimeter;
                    347:     pGdiInfo->ulVertSize   = VideoModeInformation.YMillimeter;
                    348: 
                    349:     pGdiInfo->ulHorzRes    = ppdev->cxScreen;
                    350:     pGdiInfo->ulVertRes    = ppdev->cyScreen;
                    351:     pGdiInfo->cBitsPixel   = ppdev->ulBitCount;
                    352:     pGdiInfo->cPlanes      = 1;
                    353: 
                    354:     //
                    355:     // Fill in the VXL specific data structure.
                    356:     //
                    357: 
                    358:     Vxl.ScreenY = VideoModeInformation.VisScreenHeight;
                    359:     Vxl.ScreenX = VideoModeInformation.VisScreenWidth;
                    360:     Vxl.JaguarScreenX = VideoModeInformation.ScreenStride;
                    361: 
                    362:     // !!!
                    363:     // The following is a trick:
                    364:     // For 8 Bpp, we want 0, 16Bpp we want 1 and 24/32 Bpp 2.
                    365:     // (Vxl.JaguarScreenX / Vxl.ScreenX) has values of 1, 2 and 4
                    366:     // respectively for the three possibilities.
                    367:     // So shifting by 1 will give us a good result.
                    368:     //
                    369: 
                    370:     Vxl.ColorModeShift = (Vxl.JaguarScreenX / Vxl.ScreenX) >> 1;
                    371: 
                    372:     //
                    373:     // Init Font Cache variables
                    374:     //
                    375: 
                    376:     Vxl.FontCacheOffset = (Vxl.ScreenX*Vxl.ScreenY) << Vxl.ColorModeShift;
                    377:     Vxl.CacheIndexMask = MAX_FONT_CACHE_SIZE-1;
                    378:     Vxl.CacheSize = MAX_FONT_CACHE_SIZE;
                    379: 
                    380:     pGdiInfo->flRaster = 0;     // DDI reserves flRaster
                    381: 
                    382:     pGdiInfo->ulLogPixelsX = 96;
                    383:     pGdiInfo->ulLogPixelsY = 96;
                    384: 
                    385:     pGdiInfo->flTextCaps = TC_RA_ABLE;
                    386: 
                    387:     pGdiInfo->ulDACRed   = pVideoModeSelected->NumberRedBits;
                    388:     pGdiInfo->ulDACGreen = pVideoModeSelected->NumberGreenBits;
                    389:     pGdiInfo->ulDACBlue  = pVideoModeSelected->NumberBlueBits;
                    390: 
                    391:     pGdiInfo->ulAspectX    = 0x24;    // One-to-one aspect ratio
                    392:     pGdiInfo->ulAspectY    = 0x24;
                    393:     pGdiInfo->ulAspectXY   = 0x33;
                    394: 
                    395:     pGdiInfo->xStyleStep   = 1;       // A style unit is 3 pels
                    396:     pGdiInfo->yStyleStep   = 1;
                    397:     pGdiInfo->denStyleStep = 3;
                    398: 
                    399:     pGdiInfo->ptlPhysOffset.x = 0;
                    400:     pGdiInfo->ptlPhysOffset.y = 0;
                    401:     pGdiInfo->szlPhysSize.cx  = 0;
                    402:     pGdiInfo->szlPhysSize.cy  = 0;
                    403: 
                    404:     //
                    405:     // RGB and CMY color info.
                    406:     //
                    407: 
                    408:     pGdiInfo->ciDevice.Red.x = 6700;
                    409:     pGdiInfo->ciDevice.Red.y = 3300;
                    410:     pGdiInfo->ciDevice.Red.Y = 0;
                    411:     pGdiInfo->ciDevice.Green.x = 2100;
                    412:     pGdiInfo->ciDevice.Green.y = 7100;
                    413:     pGdiInfo->ciDevice.Green.Y = 0;
                    414:     pGdiInfo->ciDevice.Blue.x = 1400;
                    415:     pGdiInfo->ciDevice.Blue.y = 800;
                    416:     pGdiInfo->ciDevice.Blue.Y = 0;
                    417:     pGdiInfo->ciDevice.Cyan.x = 1750;
                    418:     pGdiInfo->ciDevice.Cyan.y = 3950;
                    419:     pGdiInfo->ciDevice.Cyan.Y = 0;
                    420:     pGdiInfo->ciDevice.Magenta.x = 4050;
                    421:     pGdiInfo->ciDevice.Magenta.y = 2050;
                    422:     pGdiInfo->ciDevice.Magenta.Y = 0;
                    423:     pGdiInfo->ciDevice.Yellow.x = 4400;
                    424:     pGdiInfo->ciDevice.Yellow.y = 5200;
                    425:     pGdiInfo->ciDevice.Yellow.Y = 0;
                    426:     pGdiInfo->ciDevice.AlignmentWhite.x = 3127;
                    427:     pGdiInfo->ciDevice.AlignmentWhite.y = 3290;
                    428:     pGdiInfo->ciDevice.AlignmentWhite.Y = 0;
                    429: 
                    430:     //
                    431:     // Color Gamma adjustment values.
                    432:     //
                    433: 
                    434:     pGdiInfo->ciDevice.RedGamma = 20000;
                    435:     pGdiInfo->ciDevice.GreenGamma = 20000;
                    436:     pGdiInfo->ciDevice.BlueGamma = 20000;
                    437: 
                    438:     //
                    439:     // No dye correction for raster displays.
                    440:     //
                    441: 
                    442:     pGdiInfo->ciDevice.MagentaInCyanDye =
                    443:     pGdiInfo->ciDevice.YellowInCyanDye =
                    444:     pGdiInfo->ciDevice.CyanInMagentaDye =
                    445:     pGdiInfo->ciDevice.YellowInMagentaDye =
                    446:     pGdiInfo->ciDevice.CyanInYellowDye =
                    447:     pGdiInfo->ciDevice.MagentaInYellowDye = 0;
                    448: 
                    449:     pGdiInfo->ulDevicePelsDPI = (pGdiInfo->ulHorzRes * 254) / 3300;
                    450:     pGdiInfo->ulPrimaryOrder = PRIMARY_ORDER_CBA;
                    451:     pGdiInfo->ulHTPatternSize = HT_PATSIZE_4x4_M;
                    452:     pGdiInfo->ulHTOutputFormat = HT_FORMAT_8BPP;
                    453:     pGdiInfo->flHTFlags = HT_FLAG_ADDITIVE_PRIMS;
                    454: 
                    455:     *(pDevInfo) = gDevInfoFrameBuffer;
                    456: 
                    457:     //
                    458:     // Initialize the color mode dependent fields.
                    459:     // Set the gamma corrected palette for 16/32 bits per pixel
                    460:     //
                    461: 
                    462:     switch (ppdev->ulBitCount)
                    463:     {
                    464: 
                    465:     case 8:
                    466: 
                    467:         //
                    468:         // It is Palette Managed.
                    469:         //
                    470:         pDevInfo->flGraphicsCaps |= (GCAPS_PALMANAGED | GCAPS_COLOR_DITHER);
                    471:         pGdiInfo->ulNumColors = 20;
                    472:        pGdiInfo->ulNumPalReg   = 256;
                    473:         pDevInfo->iDitherFormat = BMF_8BPP;
                    474:         break;
                    475: 
                    476:     case 16:
                    477: 
                    478:         pGdiInfo->ulNumColors = 2048;
                    479:        pGdiInfo->ulNumPalReg = 0;
                    480: 
                    481:         pDevInfo->iDitherFormat = BMF_16BPP;
                    482:         pGdiInfo->ulHTPatternSize = HT_PATSIZE_2x2_M;
                    483:         pGdiInfo->ulHTOutputFormat = HT_FORMAT_16BPP;
                    484: 
                    485:         //
                    486:         //  16 bpp mode is really  5 red,5 green and 5 blue
                    487:         //
                    488: 
                    489:         DrvpSetGammaColorPalette(ppdev,
                    490:                                 32,
                    491:                                 pGdiInfo->ciDevice.RedGamma,
                    492:                                 pGdiInfo->ciDevice.GreenGamma,
                    493:                                 pGdiInfo->ciDevice.BlueGamma
                    494:                                );
                    495:         break;
                    496: 
                    497:     case 24:
                    498:     case 32:
                    499: 
                    500:         pGdiInfo->ulNumColors = 2048;
                    501:        pGdiInfo->ulNumPalReg = 0;
                    502: 
                    503:         //
                    504:         // Reset the bit count to 32 since we are really in 32 bits wide
                    505:         //
                    506: 
                    507:         pGdiInfo->cBitsPixel = ppdev->ulBitCount = 32;
                    508: 
                    509:         pDevInfo->iDitherFormat = BMF_32BPP;
                    510: 
                    511:         DrvpSetGammaColorPalette(ppdev,
                    512:                                 256,
                    513:                                 pGdiInfo->ciDevice.RedGamma,
                    514:                                 pGdiInfo->ciDevice.GreenGamma,
                    515:                                 pGdiInfo->ciDevice.BlueGamma
                    516:                                );
                    517: 
                    518:         break;
                    519: 
                    520:     default:
                    521: 
                    522:         break;
                    523:     }
                    524: 
                    525:     //
                    526:     // Free video buffer from get mode info
                    527:     //
                    528: 
                    529:     LocalFree(pVideoBuffer);
                    530: 
                    531:     return(TRUE);
                    532: }
                    533: 
                    534: 
                    535: /******************************Public*Routine******************************\
                    536: * getAvailableModes
                    537: *
                    538: * Calls the miniport to get the list of modes supported by the kernel driver,
                    539: * and returns the list of modes supported by the diplay driver among those
                    540: *
                    541: * returns the number of entries in the videomode buffer.
                    542: * 0 means no modes are supported by the miniport or that an error occured.
                    543: *
                    544: * NOTE: the buffer must be freed up by the caller.
                    545: *
                    546: \**************************************************************************/
                    547: 
                    548: DWORD getAvailableModes(
                    549: HANDLE hDriver,
                    550: PVIDEO_MODE_INFORMATION *modeInformation,
                    551: DWORD *cbModeSize)
                    552: {
                    553:     ULONG ulTemp;
                    554:     VIDEO_NUM_MODES modes;
                    555:     PVIDEO_MODE_INFORMATION pVideoTemp;
                    556: 
                    557:     //
                    558:     // Get the number of modes supported by the mini-port
                    559:     //
                    560: 
                    561:     if (!DeviceIoControl(hDriver,
                    562:             IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES,
                    563:             NULL,
                    564:             0,
                    565:             &modes,
                    566:             sizeof(VIDEO_NUM_MODES),
                    567:             &ulTemp,
                    568:             NULL))
                    569:     {
                    570:         DISPDBG((0, "jzvxl484.dll getAvailableModes failed VIDEO_QUERY_NUM_AVAIL_MODES\n"));
                    571:         return(0);
                    572:     }
                    573: 
                    574:     *cbModeSize = modes.ModeInformationLength;
                    575: 
                    576:     //
                    577:     // Allocate the buffer for the mini-port to write the modes in.
                    578:     //
                    579: 
                    580:     *modeInformation = (PVIDEO_MODE_INFORMATION)
                    581:                         LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT,
                    582:                                    modes.NumModes *
                    583:                                    modes.ModeInformationLength);
                    584: 
                    585:     if (*modeInformation == (PVIDEO_MODE_INFORMATION) NULL)
                    586:     {
                    587:         DISPDBG((0, "jzvxl484.dll getAvailableModes failed LocalAlloc\n"));
                    588: 
                    589:         return 0;
                    590:     }
                    591: 
                    592:     //
                    593:     // Ask the mini-port to fill in the available modes.
                    594:     //
                    595: 
                    596:     if (!DeviceIoControl(hDriver,
                    597:             IOCTL_VIDEO_QUERY_AVAIL_MODES,
                    598:             NULL,
                    599:             0,
                    600:             *modeInformation,
                    601:             modes.NumModes * modes.ModeInformationLength,
                    602:             &ulTemp,
                    603:             NULL))
                    604:     {
                    605: 
                    606:         DISPDBG((0, "jzvxl484.dll getAvailableModes failed VIDEO_QUERY_AVAIL_MODES\n"));
                    607: 
                    608:         LocalFree(*modeInformation);
                    609:         *modeInformation = (PVIDEO_MODE_INFORMATION) NULL;
                    610: 
                    611:         return(0);
                    612:     }
                    613: 
                    614:     //
                    615:     // Now see which of these modes are supported by the display driver.
                    616:     // As an internal mechanism, set the length to 0 for the modes we
                    617:     // DO NOT support.
                    618:     //
                    619: 
                    620:     ulTemp = modes.NumModes;
                    621:     pVideoTemp = *modeInformation;
                    622: 
                    623:     //
                    624:     // Mode is rejected if it is not one plane, or not graphics, or is not
                    625:     // one of 8, 16, 24 or 32 bits per pel.
                    626:     //
                    627: 
                    628:     while (ulTemp--)
                    629:     {
                    630:         if ((pVideoTemp->NumberOfPlanes != 1 ) ||
                    631:             !(pVideoTemp->AttributeFlags & VIDEO_MODE_GRAPHICS) ||
                    632:             ((pVideoTemp->BitsPerPlane != 8) &&
                    633:              (pVideoTemp->BitsPerPlane != 16) &&
                    634:              (pVideoTemp->BitsPerPlane != 24) &&
                    635:              (pVideoTemp->BitsPerPlane != 32)))
                    636:         {
                    637:             pVideoTemp->Length = 0;
                    638:         }
                    639: 
                    640:         pVideoTemp = (PVIDEO_MODE_INFORMATION)
                    641:             (((PUCHAR)pVideoTemp) + modes.ModeInformationLength);
                    642:     }
                    643: 
                    644:     return modes.NumModes;
                    645: 
                    646: }
                    647: 
                    648: 
                    649: BOOL
                    650: DrvpSetGammaColorPalette(
                    651:     IN PPDEV   ppdev,
                    652:     IN WORD    NumberOfEntries,
                    653:     IN LDECI4  GammaRed,
                    654:     IN LDECI4  GammaGreen,
                    655:     IN LDECI4  GammaBlue
                    656:     )
                    657: /*++
                    658: 
                    659: Routine Description:
                    660: 
                    661:     This function will set the device palette to a gamma correctec palette for
                    662:     16 or 24 bit per pixel operation
                    663: 
                    664: Arguments:
                    665: 
                    666:     ppdev           -   device mode structure
                    667:     NumberOfEntries -   Bits per pixel: the number of color map entries needed
                    668:     GammaRed        -   Gamma value for red gun from devmode structure
                    669:     GammaGreen      -   Gamma value for green gun from devmode structure
                    670:     GammaBlue       -   Gamma value for blue gun from devmode structure
                    671: 
                    672: Return Value:
                    673: 
                    674:     A value of TRUE is returned if the gamma corrected palette is set
                    675:     A value of FALSE is returned if there is an error attempting to set the palette.
                    676: 
                    677: --*/
                    678: 
                    679: 
                    680: {
                    681:     ULONG           Index,ByteIndex;
                    682:     LONG            GammaReturn;
                    683:     PVIDEO_CLUT     pVideoClut;
                    684:     ULONG           ClutSize;
                    685:     DWORD           DNumberOfEntries;
                    686:     PBYTE           pGammaTable;
                    687: 
                    688:     //
                    689:     //  Allocate the gamma table used for return data from HT_
                    690:     //
                    691: 
                    692:     pGammaTable = (PBYTE)LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT,sizeof(BYTE) * 3 * NumberOfEntries);
                    693: 
                    694:     if (pGammaTable == NULL) {
                    695:         DISPDBG((0, "DrvpSetGammaColorPalette() failed LocalAlloc\n"));
                    696:         return(FALSE);
                    697:     }
                    698: 
                    699:     //
                    700:     //  Gamma values come in UDECI4 format as described in ht.h. This format is a
                    701:     //  fractional integer format with four decimal places ie: 00020000 = 2.0000
                    702:     //
                    703: 
                    704:     GammaReturn = HT_ComputeRGBGammaTable(NumberOfEntries,
                    705:                                           0,
                    706:                                           GammaRed,
                    707:                                           GammaGreen,
                    708:                                           GammaBlue,
                    709:                                           pGammaTable);
                    710: 
                    711:     if (GammaReturn != NumberOfEntries) {
                    712:         DISPDBG((0, "DrvpSetGammaColorPalette() failed HT_ComputeGammaTable\n"));
                    713:         return(FALSE);
                    714:     }
                    715: 
                    716:     //
                    717:     //  Allocate the PalatteEntry to call IOCTL
                    718:     //
                    719: 
                    720:     pVideoClut = (PVIDEO_CLUT)LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT,MAX_CLUT_SIZE);
                    721: 
                    722:     if (pVideoClut == NULL) {
                    723:         DISPDBG((0, "DrvpSetGammaColorPalette() failed LocalAlloc\n"));
                    724:         return(FALSE);
                    725:     }
                    726: 
                    727:     //
                    728:     //  Translate into paletteentry data
                    729:     //  Print the results
                    730:     //
                    731: 
                    732:     ByteIndex = 0;
                    733: 
                    734:     for (Index = 0;Index < NumberOfEntries;Index++ ) {
                    735:         pVideoClut->LookupTable[Index].RgbArray.Red   = pGammaTable[ByteIndex++];
                    736:         pVideoClut->LookupTable[Index].RgbArray.Green = pGammaTable[ByteIndex++];
                    737:         pVideoClut->LookupTable[Index].RgbArray.Blue  = pGammaTable[ByteIndex++];
                    738: 
                    739:     }
                    740: 
                    741:     //
                    742:     //  Set the other ScreenClut values
                    743:     //
                    744: 
                    745:     pVideoClut->NumEntries = NumberOfEntries;
                    746:     pVideoClut->FirstEntry = 0;
                    747: 
                    748:     //
                    749:     //  Set this palette through the IOCTL
                    750:     //
                    751: 
                    752:     if (!DeviceIoControl(ppdev->hDriver,
                    753:                       IOCTL_VIDEO_SET_COLOR_REGISTERS,
                    754:                       pVideoClut,
                    755:                       MAX_CLUT_SIZE,
                    756:                       NULL,
                    757:                       0,
                    758:                      &DNumberOfEntries,
                    759:                      NULL))
                    760:     {
                    761:         DISPDBG((0, "jzvxl484 DrvSetPalette failed DeviceIoControl\n"));
                    762:         return(FALSE);
                    763:     }
                    764: 
                    765:     //
                    766:     // free memory buffers
                    767:     //
                    768: 
                    769:     LocalFree(pVideoClut);
                    770:     LocalFree(pGammaTable);
                    771: 
                    772:     return(TRUE);
                    773: }

unix.superglobalmegacorp.com

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