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

📄 gpeaccel.cpp

📁 EP9315 BSP for WinCE 源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//**********************************************************************
//                                                                      
// 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
#ifdef  DD_ENABLE
extern "C" void FlushDCache(void);
#endif
//
// 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);


void EightBitTestPattern(void);
void  FourBitTestPattern(void);

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

#ifndef DD_ENABLE
void APIENTRY HALInit()
{
    DEBUGMSG( 0,(TEXT("HALInit: Stub, Shouldn't have come in hereX\n")));
    RETAILMSG( 0,(TEXT("HALInit: Stub, Shouldn't have come in hereX\n")));
}
#endif

//****************************************************************************
// 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;
    SurfaceHeapV* pNode;
    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.
    //
#ifdef  DD_ENABLE
    m_VirtualFrameBuffer    = FRAMEBUF_MEMORY_OFFSET | SDRAM_VIRTUAL_MEMORY;
#else
    m_VirtualFrameBuffer    = FRAMEBUF_VIRTUAL_MEMORY;
#endif
    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
        );
    }
    
    //
    // Save off the video attributes register.
    //
    m_ulVideoAttrib = *RASTER_VIDEOATTRIBS | VIDEOATTRIBS_SDSEL_CS3;

    //
    // Program the proper color depth settings.
    //
    switch(m_ulColorDepth)
    {
        case  4:
            //
            // 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 the Screen format to 4Bpp.
            //
            m_ModeInfo.format       = gpe4Bpp;


            if(m_Registry.ulScreenType == SCREEN_TYPE_18BITS_1BPC)
            {
                //
                // Set up the Pixel mode for 18 bit output, 1 pixel per vid clock
                // using color lut.
                //
                *RASTER_PIXELMODE       = PIXELMODE_C_LUT | PIXELMODE_M_BLINKDISABLED |
                                          PIXELMODE_S_MODE1 | PIXELMODE_P_4BITS;
            }
            else if(m_Registry.ulScreenType == SCREEN_TYPE_COLOR_STN)
            {
                //
                // Set up the pixel mode for 8 bit output using 2 2/3 pixel per vid clock.
                // 
                // In our system Red and blue need to be swapped so set TRBSW.
                //
                *RASTER_PIXELMODE       = PIXELMODE_TRBSW| PIXELMODE_C_GREYSCALE | 
                                          PIXELMODE_M_BLINKDISABLED |
                                          PIXELMODE_S_223PPC | PIXELMODE_P_4BITS;
                //
                // The grey scale luts are filled in GenericDisplaySetup.
                //
            }
            else if(m_Registry.ulScreenType == SCREEN_TYPE_GREYSCALE_STN)
            {
                //
                // Set up the pixel mode for 8 bit per pixel palletized using 4 pixel per vid clock.
                //
                *RASTER_PIXELMODE       = PIXELMODE_C_GREYSCALE | 
                                          PIXELMODE_M_BLINKDISABLED |
                                          PIXELMODE_S_4PPC | PIXELMODE_P_4BITS;
            }
            break;

        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);

            m_ModeInfo.format       = gpe8Bpp;
            if(m_Registry.ulScreenType == SCREEN_TYPE_18BITS_1BPC)
            {
                //
                // Set up the Pixel mode for 18 bit output, 1 pixel per vid clock
                // using color lut.
                //
                *RASTER_PIXELMODE       = PIXELMODE_C_LUT | PIXELMODE_M_BLINKDISABLED |
                                          PIXELMODE_S_MODE1 | PIXELMODE_P_8BITS;
            }
            else if(m_Registry.ulScreenType == SCREEN_TYPE_COLOR_STN)
            {
                //
                // Set up the pixel mode for 8 bit output using 2 2/3 pixel per vid clock.
                // 
                // In our system Red and blue need to be swapped so set TRBSW.
                //
                *RASTER_PIXELMODE       = PIXELMODE_TRBSW| PIXELMODE_C_GREYSCALE | 
                                          PIXELMODE_M_BLINKDISABLED |
                                          PIXELMODE_S_223PPC | PIXELMODE_P_8BITS;
                //
                // The grey scale luts are filled in GenericDisplaySetup.
                //
            }
            else if(m_Registry.ulScreenType == SCREEN_TYPE_GREYSCALE_STN)
            {
                //
                // Set up the pixel mode for 8 bit per pixel palletized using 4 pixel per vid clock.
                //
                *RASTER_PIXELMODE       = PIXELMODE_C_GREYSCALE | 
                                          PIXELMODE_M_BLINKDISABLED |
                                          PIXELMODE_S_4PPC | PIXELMODE_P_8BITS;
            }
            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;

    
    //
    // Clear the screen.
    //
    RETAILMSG(1,(TEXT("Clearing screen\r\n")));
    memset ((void*)m_VirtualFrameBuffer, 0x0, FRAMEBUF_MEMORY_SIZE);
    DEBUGMSG (GPE_ZONE_LINE,(TEXT("memset of video\r\n")));

    //
    // Make half the screen white.
    //
    // memset((void *)(m_VirtualFrameBuffer + 320 * 120), 0xFF, 320 * 120);
    // EightBitTestPattern();
    // FourBitTestPattern();
    // while(1);
   
    m_pPrimarySurface = new GPE93xxSurf
        (
            m_nScreenWidth, 
            m_nScreenHeight, 
            (void*)FRAMEBUF_VIRTUAL_MEMORY, 
            m_cbScanLineLength, 
            m_ModeInfo.format,
            FRAMEBUF_PHYSICAL_MEMORY
        );

    //
    // Allocate Video Memory for BitBlt
    //
    m_VideoMemSize = FRAMEBUF_MEMORY_SIZE - m_cyPhysicalScreen * m_cbScanLineLength ;
    
    m_VideoMemVirAddr = m_VirtualFrameBuffer + m_cyPhysicalScreen * m_cbScanLineLength;
    m_VideoMemPhyAddr = m_pvFlatFrameBuffer  + m_cyPhysicalScreen * m_cbScanLineLength;

    DEBUGMSG (GPE_ZONE_LINE,(TEXT("FramBUffer Size %x VideoMemory Size %x\r\n"),m_cyPhysicalScreen * m_cbScanLineLength,m_VideoMemSize));

    //
    // Initialize Video Memory SurfaceHeap
    //
    m_VideoMemPhyOffet = m_VideoMemPhyAddr - m_VideoMemVirAddr;
    m_pSurfHeap = new SurfaceHeapV(m_VideoMemSize, m_VideoMemVirAddr);
    if( m_pSurfHeap != NULL )
    {
        DEBUGMSG (GPE_ZONE_LINE, (TEXT("Initializing Video Memory SurfaceHeap succeeded\r\n")));
    }
    else
    {
        DEBUGMSG (GPE_ZONE_LINE, (TEXT("Initializing Video Memory SurfaceHeap failed\r\n")));
        return;
    }
    

    //
    // Allocate Memory For hardware cursor.
    //
    pNode = m_pSurfHeap->Alloc(1024);
    if( pNode == NULL )
    {
        DEBUGMSG (GPE_ZONE_LINE, (TEXT("Unable Allocate cursor memory.\r\n")));
        return;
    }

    //
    // Setup the cursor stuff.
    //
    
    m_dwPhysCursorAddress   = pNode->Address() + m_VideoMemPhyOffet;
    m_pCursor               = (unsigned char*)pNode->Address();
    *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);


    SetKMode(oldMode);

    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_LINE,(TEXT("GPEAccel::SetMode\r\n")));

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

    if (palette)
    {
        switch (m_ulColorDepth)
        {
            case    4:
            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_LINE, (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_LINE, (TEXT("GPEAccel::NumModes\r\n")));
    return  1;
}


//****************************************************************************
// GPEAccel::SetPointerShape
//****************************************************************************
// Set the pointer shape.

⌨️ 快捷键说明

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