⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpeaccel.cpp

📁 EP931X系列的WinCE显示器驱动源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//**********************************************************************
//                                                                      
// Filename: gpeaccel.cpp
//                                                                      
// Description: Accelerated video driver for the EP9312.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to 
// use this source code. For a copy of the EULA, please see the 
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2002, All Rights Reserved                       
//                                                                      
//**********************************************************************
                   
#include    "precomp.h"
#include    "..\common\palette.h" // for 8Bpp we use the natural palette

INSTANTIATE_PALETTE

//
// Set up the debug zones.
//
INSTANTIATE_GPE_ZONES(0x0003,"Accelerated DDI Driver","Palette","unused2")    // Start with errors and warnings
#define     GPE_ZONE_PALETTE    DEBUGZONE(14)


static  GPE *gGPE = (GPE*)NULL;

// This prototype avoids problems exporting from .lib
BOOL APIENTRY GPEEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA *data,
                              PENGCALLBACKS  engineCallbacks);



//****************************************************************************
// DrvEnableDriver
//****************************************************************************
//
BOOL APIENTRY DrvEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA *data,
                              PENGCALLBACKS  engineCallbacks)
{
    return GPEEnableDriver(engineVersion, cj, data, engineCallbacks);
}

//****************************************************************************
// GetGPE
//****************************************************************************
// Main entry point for a GPE-compliant driver
// 
//

GPE *GetGPE(void)
{
    if (!gGPE)
    {
        gGPE = new GPEAccel();
    }

    return gGPE;
}




//****************************************************************************
// GPEAccel::GPEAccel
//****************************************************************************
// GPEAccel Constructor
//
GPEAccel::GPEAccel (void)
{
    DWORD       oldMode;
    ULONG       fbSize;

    DEBUGMSG(GPE_ZONE_INIT,(TEXT("GPEAccel::GPEAccel\r\n")));
    RETAILMSG(1,(TEXT("Init Raster engine\r\n")));

    oldMode = SetKMode(TRUE);

    //
    // Read in the settings from the registry.
    //
    GetDisplayRegistrySettings(&m_Registry);

    //
    // Initialize the values that are being used.
    //
    m_VirtualFrameBuffer    = FRAMEBUF_VIRTUAL_MEMORY;
    m_pvFlatFrameBuffer     = FRAMEBUF_PHYSICAL_MEMORY;
    m_ulColorDepth          = m_Registry.ulColorDepth;
    m_nScreenWidth          = m_Registry.ulScreenWidth;
    m_nScreenHeight         = m_Registry.ulScreenHeight;


    //
    // If the flag Set Directly is used then take the Raster values directly
    // from the registry.
    //
    if(m_Registry.ulSetDirectly)
    {
        //
        // Use the values from the registry to setup the display.
        //       
        GenericDisplaySetup(&m_Registry, m_pvFlatFrameBuffer, &m_StartStop);
    }
    else
    {
        //
        // Use the generic CRT setup.
        //
        CRTVideoSetup
        (
            m_nScreenWidth,
            m_nScreenHeight,
            m_ulColorDepth,
            m_Registry.ulFrequency, 
            m_pvFlatFrameBuffer,
            &m_StartStop
        );
    }
    
    //
    // Program the proper color depth settings.
    //
    switch(m_ulColorDepth)
    {
        case  8:
        
            //
            // Set up the Color Look up table.   There are two LUT's in hardware.
            // the lookup table that is visible is not the one that is accessable.
            //
            SetPalette(_rgbIdentity, 0 , PALETTE_SIZE);
            
            //
            // Set up the Pixel mode.
            //
            *RASTER_PIXELMODE       = PIXELMODE_C_LUT | PIXELMODE_M_BLINKDISABLED |
                                      PIXELMODE_S_MODE1 | PIXELMODE_P_8BITS;
            m_ModeInfo.format       = gpe8Bpp;
            break;                                       
            
        case 16:
            *RASTER_PIXELMODE        = PIXELMODE_C_565 | PIXELMODE_M_BLINKDISABLED | PIXELMODE_S_MODE1 | 
                                       PIXELMODE_P_16BITS;
                                       
            //
            // Since we are not using a palette, setup red, green and blue masks.
            //                                       
            m_RedMaskSize           = 5;
            m_RedMaskPosition       = 11;
            m_GreenMaskSize         = 6;
            m_GreenMaskPosition     = 5;
            m_BlueMaskSize          = 5;
            m_BlueMaskPosition      = 0;
            m_ModeInfo.format       = gpe16Bpp;
            break;            
            
        case 24:
            *RASTER_PIXELMODE        = PIXELMODE_C_TRIPLE8 | PIXELMODE_M_BLINKDISABLED | PIXELMODE_S_MODE1 | 
                                       PIXELMODE_P_24BITS;
            //
            // Since we are not using a palette, setup red, green and blue masks.
            //                                       
            m_RedMaskSize           = 8;
            m_RedMaskPosition       = 16;
            m_GreenMaskSize         = 8;
            m_GreenMaskPosition     = 8;
            m_BlueMaskSize          = 8;
            m_BlueMaskPosition      = 0;
            m_ModeInfo.format       = gpe24Bpp;
            break;                                       

        case    32:
            //m_ModeInfo.format = gpe32Bpp;
            //break;

        default:
            DEBUGMSG(GPE_ZONE_ERROR,(TEXT("Invalid BPP value passed to driver - %d\r\n"), m_ModeInfo.Bpp));
            m_ModeInfo.format = gpeUndefined;
            break;
    }            
    m_pMode = &m_ModeInfo;    



    //
    //  Copy a few more variables.
    //
    m_cxPhysicalScreen  = m_nScreenWidth;
    m_cyPhysicalScreen  = m_nScreenHeight;
    m_cbScanLineLength  = m_cxPhysicalScreen * (m_ulColorDepth /8);


    //
    // set rest of ModeInfo values
    //
    m_ModeInfo.modeId       = 0;
    m_ModeInfo.width        = m_nScreenWidth;
    m_ModeInfo.height       = m_nScreenHeight;
    m_ModeInfo.Bpp          = m_ulColorDepth;
    m_ModeInfo.frequency    = m_Registry.ulFrequency;
    

    m_pPrimarySurface = new GPESurf
        (
            m_nScreenWidth, 
            m_nScreenHeight, 
            (void*)m_VirtualFrameBuffer, 
            m_cbScanLineLength, 
            m_ModeInfo.format
        );

    
    //
    // Clear the screen.
    //
    RETAILMSG(1,(TEXT("Clearing screen\r\n")));
    fbSize = m_cyPhysicalScreen * m_cbScanLineLength ;     
    memset ((void*)m_VirtualFrameBuffer, 0x0, fbSize);
    RETAILMSG(1,(TEXT("memset of video\r\n")));


    //
    // Setup the cursor stuff.
    //
    m_dwPhysCursorAddress   = (DWORD)m_pvFlatFrameBuffer + m_cbScanLineLength * m_cyPhysicalScreen;
    m_pCursor               = (unsigned char *)m_VirtualFrameBuffer + m_cbScanLineLength * m_cyPhysicalScreen;
    *RASTER_CURSOR_ADR_START = *RASTER_CURSOR_ADR_RESET = m_dwPhysCursorAddress;
    *RASTER_CURSORCOLOR1    = 0;
    *RASTER_CURSORCOLOR2    = 0xFFFFFF ;
    *RASTER_CURSORXYLOC     = 0;
    *RASTER_CURSOR_BLINK1   = 0;
    *RASTER_CURSOR_BLINK2   = 0;
    *RASTER_CURSOR_BLINK    = 0;

    m_bCursorEnabled        = FALSE;
    //m_bCursorInitialized    = FALSE;
    m_bCursorHasShape       = FALSE;
    memset(&m_CursorRect, sizeof(m_CursorRect), 0);
    memset(&m_CursorSize, sizeof(m_CursorSize), 0);
    memset(&m_CursorHotspot, sizeof(m_CursorHotspot),0);

    RETAILMSG(1,(TEXT("Returning from DDI init\r\n")));
}

//****************************************************************************
// GPEAccel::SetMode
//****************************************************************************
// Sets the Graphics mode and the palette.
//
SCODE   GPEAccel::SetMode (INT modeId, HPALETTE *palette)
{
    DEBUGMSG(GPE_ZONE_INIT,(TEXT("GPEAccel::SetMode\r\n")));

    if (modeId != 0)
    {
        DEBUGMSG(GPE_ZONE_ERROR,(TEXT("GPEAccel::SetMode Want mode %d, only have mode 0\r\n"),modeId));
        return  E_INVALIDARG;
    }

    if (palette)
    {
        switch (m_ulColorDepth)
        {
            case    8:
                *palette = EngCreatePalette (PAL_INDEXED,
                             PALETTE_SIZE,
                             (ULONG*)_rgbIdentity,
                             0,
                             0,
                             0);
                break;

            case    16:
            case    24:
            case    32:
                *palette = EngCreatePalette (PAL_BITFIELDS,
                                             0,
                                             NULL,
                                             ((1 << m_RedMaskSize) - 1) << m_RedMaskPosition,
                                             ((1 << m_GreenMaskSize) - 1) << m_GreenMaskPosition,
                                             ((1 << m_BlueMaskSize) - 1) << m_BlueMaskPosition);
                break;
        }
    }

    return S_OK;
}

//****************************************************************************
// GPEAccel::GetModeInfo
//****************************************************************************
//
//
SCODE GPEAccel::GetModeInfo(GPEMode *mode, INT modeNumber)
{
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPEAccel::GetModeInfo\r\n")));

    if (modeNumber != 0)
    {
        return E_INVALIDARG;
    }

    *mode = m_ModeInfo;

    return S_OK;
}

//****************************************************************************
// GPEAccel::NumModes
//****************************************************************************
// Only one graphics mode currently supported.
// 
//
int  GPEAccel::NumModes()
{
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPEAccel::NumModes\r\n")));
    return  1;
}


//****************************************************************************
// GPEAccel::SetPointerShape
//****************************************************************************
// Set the pointer shape.
// 
SCODE   GPEAccel::SetPointerShape
(
    GPESurf     *pMask, 
    GPESurf     *pColorSurf, 
    INT         xHot, 
    INT         yHot, 
    INT         cX, 
    INT         cY
)
{
    char    bAnd;
    char    bXor;
    int     row;
    int     col;
    // int     bitMask;
    int     i;
    UCHAR   *andPtr;        // input pointer
    UCHAR   *xorPtr;        // input pointer
    ULONG   ulCursorSize = 0;
    USHORT  usMask;
    ULONG   ulXYLOC;
    BOOL    bSizeChanged= FALSE;

    
    if(!pMask)
    {
        if(m_bCursorHasShape)
        {
            m_bCursorHasShape   = FALSE;
            *RASTER_CURSORXYLOC = 0;
        }
    }

    //
    // Check to see if the size changed.
    //
    if(cX != m_CursorSize.x && cY != m_CursorSize.y)
    {
        bSizeChanged = TRUE;
    }

    //
    // If the Size has changed then 
    //
    switch(cX)
    {
        case 16:
            ulCursorSize = CURSORSIZE_CWID_16PIXELS | CURSORSIZE_CSTEP_16PIXELS;
            break;
        case 32:
            ulCursorSize = CURSORSIZE_CWID_32PIXELS | CURSORSIZE_CSTEP_32PIXELS;
            break;
        case 48:
            ulCursorSize = CURSORSIZE_CWID_48PIXELS | CURSORSIZE_CSTEP_48PIXELS;
            break;
        case 64:
            ulCursorSize = CURSORSIZE_CWID_64PIXELS | CURSORSIZE_CSTEP_64PIXELS;
            break;
        default:
            //
            // Return that it is not ok.
            //
            DEBUGMSG (GPE_ZONE_ERROR, (TEXT("GPEAccel::SetPointerShape Invalid Cursor Width, cX = 0%08x\r\n"), cX));
            return  S_FALSE;
    }

    //
    // Store size and hotspot for new cursor
    //
    m_CursorSize.x      = cX;
    m_CursorSize.y      = cY;
    m_CursorHotspot.x   = xHot;
    m_CursorHotspot.y   = yHot;

    //
    // Disable the cursor if the size has changed.
    //
    if(m_bCursorEnabled && bSizeChanged)
    {
        *RASTER_CURSORXYLOC &= ~CURSORXYLOC_CEN;

        //
        // Program in the cursor size register.
        //
        *RASTER_CURSORSIZE =  ulCursorSize |  ((cY - 1)<<CURSORSIZE_CLINS_SHIFT);
    }


    //
    // store OR and AND mask for new cursor
    //
    for (row = 0; row < cY; row++)
    {
        andPtr = (UCHAR*)pMask->Buffer();
        xorPtr = (UCHAR*)pMask->Buffer() + (cY * pMask->Stride());
        for (col = 0; col < cX / 8; col++)
        {
            bAnd = ~andPtr[row * pMask->Stride() + col];
            bXor = xorPtr[row * pMask->Stride() + col];
            usMask = 0;
            for ( i = 0; i < 4;  i++)
            {
                usMask |=  (bAnd & (0x80>>i))?  0x80>>(i * 2): 0 ;
                usMask |=  (bXor & (0x80>>i))?  0x40>>(i * 2): 0;
                usMask |=  (bAnd & (0x8>>i) )?  0x8000>>(i * 2 ): 0 ;
                usMask |=  (bXor & (0x8>>i) )?  0x4000>>(i * 2): 0;
            }
            ((PUSHORT)m_pCursor)[col + ((row * cX)>>3)] = usMask;
        }
    }

    //
    // Cursor has been initialized.
    //
    m_bCursorHasShape = TRUE;

    //
    // Enable the cursor and display the new cursor.
    //
    if(m_bCursorEnabled)
    {
        //
        // Compute new cursor rect
        //
        m_CursorRect.left   = m_xPosition - m_CursorHotspot.x;
        m_CursorRect.right  = m_CursorRect.left + m_CursorSize.x;
        m_CursorRect.top    = m_yPosition - m_CursorHotspot.y;
        m_CursorRect.bottom = m_CursorRect.top + m_CursorSize.y;

        ulXYLOC = CURSORXYLOC_XMASK & ((m_StartStop.ulHActiveStart - m_CursorRect.left)<<CURSORXYLOC_XSHIFT);
        ulXYLOC |= CURSORXYLOC_YMASK & ((m_StartStop.ulVActiveStart - m_CursorRect.top)<<CURSORXYLOC_YSHIFT);
        ulXYLOC |= m_bCursorEnabled? CURSORXYLOC_CEN: 0;

        //
        // Write the New XY Cursor value.
        //
        *RASTER_CURSORXYLOC = ulXYLOC;
    }

    //
    // Renable the cursor if the size has changed.
    //
    if(m_bCursorEnabled && bSizeChanged)
    {
        *RASTER_CURSORXYLOC |= CURSORXYLOC_CEN;
    }


    return  S_OK;
}

//****************************************************************************
// GPEAccel::MovePointer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -