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

📄 gpeaccel.cpp

📁 EP9315 BSP for WinCE 源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                                  ( 0xF << LINEPATTRN_CNT_SHIFT);

    *GRAPHICS_TRANSPATTRN       = 0;

    *GRAPHICS_BACKGROUND        = lineParameters->solidColor;

    *GRAPHICS_BLOCKMASK         = lineParameters->solidColor;


    //
    // I don't think that this is ever necessary.
    //
    //if (sLine->BackgroundEn)
    //{
    //    Control |= BLOCKCTRL_BACKGROUNDG;
    //}

    *GRAPHICS_BLOCKCTRL = ulControl |= BLOCKCTRL_BG | BLOCKCTRL_LINE | (BytesPerPixel  << (BLOCKCTRL_PIXEL_SHIFT + 1));
    *GRAPHICS_BLOCKCTRL = ulControl | BLOCKCTRL_ENABLE;

    
    return S_OK;
}

//****************************************************************************
// GPEAccel::Line
//****************************************************************************
// 
// 
SCODE GPEAccel::Line
(   
    GPELineParms    *lineParameters, 
    EGPEPhase       phase
)
{
    EGPEFormat  Format;
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPEAccel::Line\r\n")));

    //
    // Don't start another GDI operation until the last has finished.
    //
    Format = lineParameters->pDst->Format();
    
    if (phase == gpeSingle || phase == gpePrepare )
    {
        if (( lineParameters->pDst->InVideoMemory())                            && 
            ( (lineParameters->style & 0xFFFF) == (lineParameters->style>>16))  && 
            ( lineParameters->mix == 0x0d0d )                                   &&
            Format != gpe1Bpp                                                   &&
            Format != gpe4Bpp )
        {
            lineParameters->pLine = (SCODE (GPE::*)(struct GPELineParms *)) AcceleratedLine;
        }
        else
        {
            WaitForNotBusy();
            lineParameters->pLine = EmulatedLine;
        }
    }

    return S_OK;
}

//****************************************************************************
// GPEAccel::BltPrepare
//****************************************************************************
// 

SCODE   GPEAccel::BltPrepare(GPEBltParms *pBltParms)
{
    // RECTL   rectl;
    DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPEAccel::BltPrepare\r\n")));
    BOOL    bTryAccelSoft = TRUE;
    EGPEFormat  Format;
    // Format = blitParameters->prclDst->Format();

    //
    // default to base EmulatedBlt routine
    //
    pBltParms->pBlt = EmulatedBlt;
    Format = pBltParms->pDst->Format();

    //
    // Don't start another GDI operation until the last has finished.
    //

    //
    // Can only hardware accel if Destination is in video memory and
    // if the graphics is not performing another operation.
    //
    if (pBltParms->pDst->InVideoMemory() && Format != gpe1Bpp && Format != gpe4Bpp )
    {
        switch (pBltParms->rop4)
        {
            case    0x0000: // BLACKNESS
                pBltParms->solidColor   = 0x0;
                pBltParms->pBlt         = (SCODE (GPE::*) (struct GPEBltParms *)) AcceleratedFillRect;
                bTryAccelSoft           = FALSE;
                break;

            case    0xFFFF: // WHITENESS
                pBltParms->solidColor   = 0xffffff;
                pBltParms->pBlt         = (SCODE (GPE::*) (struct GPEBltParms *)) AcceleratedFillRect;
                bTryAccelSoft           = FALSE;
                break;

            case    0xF0F0: // PATCOPY
            if(pBltParms->solidColor != -1)
            {
                pBltParms->pBlt         = (SCODE (GPE::*) (struct GPEBltParms *)) AcceleratedFillRect;
                bTryAccelSoft           = FALSE;
            }
            break;

            case    0x5A5A: // PATINVERT
            //if(pBltParms->solidColor != -1)
            //{
            //    pBltParms->pBlt = (SCODE (GPE::*) (struct GPEBltParms *)) AcceleratedSrcCopyBlt;
            //    bTryAccelSoft           = FALSE;
            //}
            break;
            case    0x6666: // SRCINVERT
            case    0x8888: // SRCAND
            case    0xEEEE: // SRCPAINT
            case    0xCCCC: // SRCCOPY
                if(    ( !pBltParms->pSrc->InVideoMemory() ) ||                  // Only Accelerate For Source In Memory
                       ( pBltParms->pLookup  )              ||                  // Emulate if color conversion required
                       ( pBltParms->pConvert )              ||                  // Emulate if color conversion required
                       ( pBltParms->bltFlags & BLT_STRETCH ) ||                  // Emulate if Stretching required
                       ( pBltParms->bltFlags & BLT_TRANSPARENT ) )              // Emulate if transparent
                {
                    break;
                }
                pBltParms->pBlt = (SCODE (GPE::*) (struct GPEBltParms *)) AcceleratedSrcCopyBlt;
                bTryAccelSoft           = FALSE;
                break;
            case    0x3333: // NOTSRCCOPY
                if(    ( !pBltParms->pSrc->InVideoMemory() ) ||                  // Only Accelerate For Source In Memory
                       ( pBltParms->pLookup  )              ||                  // Emulate if color conversion required
                       ( pBltParms->pConvert )              ||                  // Emulate if color conversion required
                       ( pBltParms->bltFlags & BLT_STRETCH ) ||                  // Emulate if Stretching required
                       ( pBltParms->bltFlags & BLT_TRANSPARENT ) )              // Emulate if transparent
                {
                    break;
                }
            
                pBltParms->pBlt = (SCODE (GPE::*) (struct GPEBltParms *)) AcceleratedSrcCopyBlt;
                bTryAccelSoft           = FALSE;
                break;

            break;
            case    0x1111: // NOTSRCERASE
                break;
            default:
                break;
        }
        
    }

    //
    // If we don't use the Hardware ROP, try to find a software blit if one is 
    // available.
    //
    if(bTryAccelSoft)
    {
        //
        // see if there are any optimized software blits available
        //
        WaitForNotBusy();
        EmulatedBltSelect02(pBltParms);
        EmulatedBltSelect08(pBltParms);
        EmulatedBltSelect16(pBltParms);
    }

    return S_OK;
}


//****************************************************************************
// GPEAccel::BltComplete
//****************************************************************************
// 
SCODE   GPEAccel::BltComplete(GPEBltParms *blitParameters)
{
    return S_OK;
}

//****************************************************************************
// GPEAccel::InVBlank
//****************************************************************************
// We don't have to worry about blanking.
//
INT    GPEAccel::InVBlank(void)
{
    static  BOOL    value = FALSE;
    DEBUGMSG (GPE_ZONE_LINE, (TEXT("GPEAccel::InVBlank\r\n")));
    value = !value;
    return value;
}

//****************************************************************************
// PrintPalette
//****************************************************************************
// Debug routine to print out the current palette
// 
//
void PrintPalette()
{
    #ifdef DEBUG
    ULONG   ulEntry;
    DEBUGMSG (GPE_ZONE_LINE, (L"GPEAccel: Current Palette, "));
    
    //
    // If the print Palette zone is enabled print out the palette whenever
    // we open the palette.
    //
    if(GPE_ZONE_PALETTE)
    {
        for(ulEntry = 0; ulEntry < 256 ; ulEntry+=4)
        {
            RETAILMSG
            (
            1, 
                (
                    L"Entry 0x%03x:  0x%08x  0x%08x  0x%08x  0x%08x\n",
                    ulEntry,
                    RASTER_COLOR_LUT[ulEntry],
                    RASTER_COLOR_LUT[ulEntry + 1],
                    RASTER_COLOR_LUT[ulEntry + 2],
                    RASTER_COLOR_LUT[ulEntry + 3]
                )
            );
        }
    }        
    #endif //DEBUG
}

//****************************************************************************
// Converts a 24 bit RGB color into grey scale
//****************************************************************************
// Converts 24 bit color to an 8 bit grey scale image.
// 
// 
//
inline unsigned char ConvertToGreyScale(const PALETTEENTRY *p)
{
    unsigned int ret;
    
    if(p->peRed > p->peGreen && p->peRed > p->peBlue)
    {
        ret = (p->peRed + p->peRed + p->peGreen + p->peBlue)>>2;
    }
    else if(p->peGreen > p->peRed && p->peGreen > p->peBlue)
    {
        ret = (p->peRed + p->peGreen + p->peGreen + p->peBlue)>>2;
    }
    else    
    {
        ret = (p->peRed + p->peGreen + p->peBlue + p->peBlue)>>2;
    }
    
    // sum = (p->peRed * p->peRed +  p->peGreen * p->peGreen + p->peBlue *  p->peBlue)/3;
    // ret = (unsigned char)sqrt((float)sum);
    return ret;
}

//****************************************************************************
// GPEAccel::SetPalette
//****************************************************************************
// 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.
// 
//
SCODE  GPEAccel::SetPalette
(
    const PALETTEENTRY  *source, 
    USHORT              firstEntry, 
    USHORT              numEntries
)
{
    ULONG   ulEntry;
    ULONG   ulCount;
    unsigned char    red, green, blue;
    DEBUGMSG (GPE_ZONE_LINE, (TEXT("GPEAccel::SetPalette\r\n")));

    if (firstEntry < 0 || firstEntry + numEntries > 256 || source == NULL)
    {
        DEBUGMSG (GPE_ZONE_LINE,(TEXT("SetPalette invalid arguments\r\n")));
        return  E_INVALIDARG;
    }

    //
    // Copy into our palette.
    //
    memcpy((void *)&m_Palette[firstEntry], source, sizeof(PALETTEENTRY) * numEntries);
    

    //
    // I would do a memory copy but the red and blue
    // palette entries are reversed.
    //
    for(ulEntry = firstEntry ; ulEntry < numEntries; ulEntry++)
    {
        if(m_Registry.ulScreenType == SCREEN_TYPE_GREYSCALE_STN)
        {
            red = green = blue = ConvertToGreyScale(source + ulEntry);
        }
        else
        {
            //
            // Get the values for Red, Green and Blue.
            //
            red     = source[ulEntry].peRed ;
            green   = source[ulEntry].peGreen;
            blue    = source[ulEntry].peBlue;
        }
        //
        // Program up the Color lookup table.
        //
        RASTER_COLOR_LUT[ulEntry] = ((ULONG)red<< 16) + ((ULONG)green << 8) + (ULONG)blue;
    }
    
    //
    // Switch to the other LUT and program the same values.
    //                                       
    *RASTER_LUTCONT          ^= LUTCONT_SWTCH;
    
    //
    // Wait until a palette switch occurs at the end of the frame.
    //
    for(ulCount = 0 ;; ulCount++)
    {
        //
        // Put a small delay to wait for the change.
        //
        Sleep(1);
        
        //
        // Has the switch occured.
        //
        if(((*RASTER_LUTCONT & LUTCONT_SSTAT) && (*RASTER_LUTCONT &LUTCONT_SWTCH)) ||
          (!(*RASTER_LUTCONT & LUTCONT_SSTAT) && !(*RASTER_LUTCONT & LUTCONT_SWTCH)))
        {
            break;
        }
        
        if(ulCount > 100)
        {
            DEBUGMSG (GPE_ZONE_LINE, (TEXT("ERROR: Palette switch never occured.\n")));
        }
    }

    //
    // I would do a memory copy but the red and blue palette entries are reversed.
    //
    for(ulEntry = firstEntry ; ulEntry < numEntries; ulEntry++)
    {

        if(m_Registry.ulScreenType == SCREEN_TYPE_GREYSCALE_STN)
        {
            red = green = blue = ConvertToGreyScale(source + ulEntry);
        }
        else
        {
            //
            // Get the values for Red, Green and Blue.
            //
            red     = source[ulEntry].peRed ;
            green   = source[ulEntry].peGreen;
            blue    = source[ulEntry].peBlue;
        }
        //
        // Program up the Color lookup table.
        //
        RASTER_COLOR_LUT[ulEntry] = ((ULONG)red<< 16) + ((ULONG)green << 8) + (ULONG)blue;
    }
    
    //
    // Print out the palette to the debugger if the debug zone is enabled.
    //
    PrintPalette();


    return  S_OK;
}




//****************************************************************************
// GPEAccel::GetGraphicsCaps
//****************************************************************************
// 
// 
ULONG   GPEAccel::GetGraphicsCaps()
{
    DEBUGMSG (GPE_ZONE_LINE, (TEXT("GPEAccel::GetGraphicsCaps\r\n")));
    if (m_pMode)
    {
        //
        // if in 16bpp mode, return GCAPS_GRAY16 to denote that we support 
        // anti-aliased fonts
        if (m_pMode->Bpp == 16)     
        {
            return  GCAPS_GRAY16;
        }
    }
    return  0;
}

//****************************************************************************
// RegisterDDHALAPI
//****************************************************************************
// no DDHAL support
// 
#ifndef DD_ENABLE
void  RegisterDDHALAPI(void)
{
    return; 
}
#endif

ULONG gBitMasks[] = { 0x0001,0x0002,0x0000 };


//****************************************************************************
// DrvGetMasks
//****************************************************************************
//
//
ULONG *APIENTRY DrvGetMasks(DHPDEV dhpdev)
{
    return gBitMasks;
}


//****************************************************************************
// GPEAccel::AcceleratedFillRect
//****************************************************************************
//  Use the accelerated block fill.
// 
//
SCODE  GPEAccel::AcceleratedFillRect (GPEBltParms *pBltParms)
{
    ULONG   ulPhyStart;
    ULONG   ulPhyEnd;
    ULONG   ulBlockControl;

    RECTL    *prclDst   = pBltParms->prclDst;
    GPESurf  *pDst      = pBltParms->pDst;

    int     left    = prclDst->left;
    int     top     = prclDst->top ;
    int     right   = prclDst->right ;
    int     bottom  = prclDst->bottom ;
    int     stride  = pDst->Stride();
    int     BytesPerPixel = EGPEFormatToBpp[pDst->Format()] >> 3;
    ULONG   ulRightByteCount;
    ULONG   ulLeftByteCount;
    // ULONG   ulBlockDestWidth

    //ulPhySize  = width * height * BytesPerPixel;


    DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPEAccel::AcceleratedFillRect\r\n")));


    //
    // Check for negative x or y direction and correct values accordingly

⌨️ 快捷键说明

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