blt.cpp

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C++ 代码 · 共 357 行

CPP
357
字号
/*++
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.
Copyright (c) 1995, 1996, 1997, 1998  Microsoft Corporation

Module Name:  

Abstract:  
   MGDI driver (for IGS2010)
  
Functions:


Notes: 


--*/

#include "precomp.h"

//
//  BltPrepare - pre Blt prepare
//  inputs:  pBltParms - Blt parameters
//  outputs: pBltParms - Blt parameters
//
SCODE IGS2010::BltPrepare(
    GPEBltParms *pBltParms )
{
    DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::BltPrepare rop4: 0x%04x\r\n"), pBltParms->rop4 ));
    DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("Dest Format: %d, Dest Rect: t:%d,l:%d,b:%d,r:%d Dest GPESurf 0x%08x\r\n"),
        (int)pBltParms->pDst->Format(),
        (pBltParms->prclDst != NULL) ? pBltParms->prclDst->top : 0,
        (pBltParms->prclDst != NULL) ? pBltParms->prclDst->left : 0,
        (pBltParms->prclDst != NULL) ? pBltParms->prclDst->bottom : 0,
        (pBltParms->prclDst != NULL) ? pBltParms->prclDst->right : 0,
        pBltParms->pDst ));
    if( pBltParms->prclSrc && pBltParms->pSrc ) {
        DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("Src format: %d, Src Rect: %d,%d,%d,%d Src GPESurf 0x%08x\r\n"),
            (int)pBltParms->pSrc->Format(),
            pBltParms->prclSrc->top,
            pBltParms->prclSrc->left,
            pBltParms->prclSrc->bottom,
            pBltParms->prclSrc->right,
            pBltParms->pSrc ));
    }

    DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("Blt preparation phase\r\n")));
    DEBUGWAIT(GPE_ZONE_BLT_LO)

    pBltParms->pBlt = EmulatedBlt; // catch all

    // Look for operations that can be accelerated in hardware
#ifdef ENABLE_ACCELERATION

    // Can only accelerate in S3 if destination is video memory
    if( !pBltParms->pDst->InVideoMemory() ) {
#ifdef ENABLE_EMULATION
        // If software emulations are enabled, go try those
        goto LCheckEmulation;
#else
        return S_OK;
#endif
    }

    switch( pBltParms->rop4 ) {
    case 0x0000:    // BLACKNESS
        DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - BLACKNESS\r\n")));
        SelectSolidColor( 0 );
        pBltParms->pBlt = (SCODE (GPE::*)(struct GPEBltParms *))AcceleratedFillRect;
        return S_OK;

    case 0xFFFF:    // WHITENESS
        DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - WHITENESS\r\n")));
        SelectSolidColor( 0x00ffffff );
        pBltParms->pBlt = (SCODE (GPE::*)(struct GPEBltParms *))AcceleratedFillRect;
        return S_OK;

    case 0xF0F0:    // PATCOPY
        if( pBltParms->solidColor == -1 ) {
            DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - PATCOPY - patterned brush\r\n")));
            DEBUGWAIT(GPE_ZONE_BLT_LO);
               // for the moment, we won't accelerate pattern fills
        } else {
            DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - PATCOPY - solid brush\r\n")));
            DEBUGWAIT(GPE_ZONE_BLT_LO)
            SelectSolidColor( pBltParms->solidColor );
            pBltParms->pBlt = (SCODE (GPE::*)(struct GPEBltParms *))AcceleratedFillRect;
            return S_OK;
        }
        break;

    case 0xCCCC:    // SRCCOPY
    if( !pBltParms->pSrc->InVideoMemory()   // can't accelerate if src not in video memory
        || pBltParms->pLookup               // can't accelerate color translations
        || pBltParms->pConvert )
        break;

        if( pBltParms->bltFlags & BLT_STRETCH ) {
            // Stretch Blt
            DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("Stretch Blt!\r\n")));
            break;
        }
        if( pBltParms->bltFlags & BLT_TRANSPARENT ) {
            // Transparent Blt
            DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("Transparent Blt!\r\n")));
            break;
        }
        pBltParms->pBlt = (SCODE (GPE::*)(struct GPEBltParms *))AcceleratedSrcCopyBlt;
        return S_OK;

    default:        // some random ROP4
            ;
    }
#endif // ENABLE_ACCELERATION

    // Look for specific operations to emulate in software
#ifdef ENABLE_EMULATION

#ifdef ENABLE_ACCELERATION
LCheckEmulation:;
#endif

    //
    // Bail on any parameter values that would make this
    // blt non-emulatable
    //

#ifdef FB16BPP
    if ( EGPEFormatToBpp[pBltParms->pDst->Format()] != 16       ||
        (pBltParms->bltFlags & (BLT_TRANSPARENT | BLT_STRETCH)) ||
         pBltParms->pLookup                                     ||  
         pBltParms->pConvert) {
#else  //FB16BPP
    if ( EGPEFormatToBpp[pBltParms->pDst->Format()] != 8        ||
        (pBltParms->bltFlags & (BLT_TRANSPARENT | BLT_STRETCH)) ||
         pBltParms->pLookup                                     ||  
         pBltParms->pConvert) {
#endif  //FB16BPP
        return S_OK;
    }

#define FUNCNAME(basename) \
    ((SCODE (GPE::*)(struct GPEBltParms *))Emulator::Emulated##basename)

    switch( pBltParms->rop4 ) {
#ifndef FB16BPP
    case 0x0000:    // BLACKNESS
        DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - BLACKNESS\r\n")));
        pBltParms->solidColor = 0;
        pBltParms->pBlt = FUNCNAME(BltFill08);
        return S_OK;

    case 0xFFFF:    // WHITENESS
        DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - WHITENESS\r\n")));
        pBltParms->solidColor = 0x00ffffff;
        pBltParms->pBlt = FUNCNAME(BltFill08);
        return S_OK;

    case 0xF0F0:    // PATCOPY
        if( pBltParms->solidColor != -1 ) {
            DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - PATCOPY - solid brush\r\n")));
            pBltParms->pBlt = FUNCNAME(BltFill08);
            return S_OK;
        }
        break;

    case 0x5A5A:    // PATINVERT
        if( pBltParms->solidColor != -1 ) {
            DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - PATINVERT - solid brush\r\n")));
            pBltParms->pBlt = FUNCNAME(BltPatInvert08);
            return S_OK;
        }
        break;

    case 0x5555:    // DSTINVERT
        DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - DSTINVERT\r\n")));
        pBltParms->pBlt = FUNCNAME(BltDstInvert08);
        return S_OK;

    case 0xCCCC:    // SRCCOPY
        DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - SRCCOPY\r\n")));
        pBltParms->pBlt = FUNCNAME(BltSrcCopy0808);
        return S_OK;

    case 0x8888:    // SRCAND
        DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - SRCAND\r\n")));
        pBltParms->pBlt = FUNCNAME(BltSrcAnd0808);
        return S_OK;

    case 0xEEEE:    // SRCPAINT
        DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - SRCPAINT\r\n")));
        pBltParms->pBlt = FUNCNAME(BltSrcPaint0808);
        return S_OK;

    case 0x6666:    // SRCINVERT
        DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - SRCINVERT\r\n")));
        pBltParms->pBlt = FUNCNAME(BltSrcInvert0808);
        return S_OK;
#endif  //!FB16BPP

    case 0xAAF0:    // Special PATCOPY rop for text output -- fill where mask is 1.
#ifndef FB16BPP
        // Not a pattern brush?
        if( pBltParms->solidColor != -1 ) {
            DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - 0xAAF0\r\n")));
            pBltParms->pBlt = FUNCNAME(BltText08);
            return S_OK;
        }
#else //!FB16BPP
        // Not a pattern brush?
        if( pBltParms->solidColor != -1 ) {
            if (pBltParms->pMask->Format() == gpe1Bpp) {
                DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - 0xAAF0\r\n")));
                pBltParms->pBlt = (SCODE (GPE::*)(struct GPEBltParms *))Emulator::EmulatedBltText16;
                return S_OK;
            } else  {
                // Anti-aliased text
                DEBUGMSG(GPE_ZONE_BLT_LO,(TEXT("IGS2010::Blt - 0xAAF0 alpha\r\n")));
                pBltParms->pBlt = (SCODE (GPE::*)(struct GPEBltParms *))Emulator::EmulatedBltAlphaText16;
                return S_OK;
            }
        }
#endif  //!FB16BPP
        break;

    default:
            ;
    }

#endif // ENABLE_EMULATION

    return S_OK;
}

//
//  BltComplete - post Blt
//  inputs:  pBltParms - Blt parameters
//  outputs: pBltParms - Blt parameters
//
SCODE IGS2010::BltComplete( GPEBltParms *pBltParms )
{
    return S_OK;
}


#ifdef ENABLE_ACCELERATION
//
//  AcceleratedFillRect - Fill rectangle Blt
//  inputs:  pBltParms - Blt parameters
//  outputs: none
//
SCODE IGS2010::AcceleratedFillRect( GPEBltParms *pBltParms )
{
    DEBUGMSG(GPE_ZONE_BLT_HI,(TEXT("AcceleratedFillRect\r\n")));

    int x1 = pBltParms->prclDst->left   + ((IGS2010Surf *)(pBltParms->pDst))->Left();
    int y1 = pBltParms->prclDst->top    + ((IGS2010Surf *)(pBltParms->pDst))->Top();
    int x2 = pBltParms->prclDst->right  + ((IGS2010Surf *)(pBltParms->pDst))->Left();
    int y2 = pBltParms->prclDst->bottom + ((IGS2010Surf *)(pBltParms->pDst))->Top();
    int width;
    int height;

    unsigned short direction;

        // set the direction
    if( (x2 > x1) && (y2 > y1)) {
        direction = Right_Down;
        width = x2 - x1;
        height = y2 - y1;
    } else if (x2 > x1) {
        direction = Right_Up;
        width = x2 - x1;
        height = y1 - y2;
    } else if (y2 > y1) {
        direction = Left_Down;
        width = x1 - x2;
        height = y2 - y1;
    } else {
        direction = Left_Up;
        width = x2 - x1;
        height = y2 - y1;
    }


    // Draw rectangle
    WaitForNotBusy();
    reg_Cop_control = 0;
    reg_Op_Dimension_1 = width-1;
    reg_Dst_Start_Ptr  = (DWORD)y1*(640) + x1;
    reg_Op_Dimension_2 = height - 1;

    ULONG op  = Fore_Src_color;
    op |= PxBlt;
    op |= Pattern_Foreground | direction;
    reg_Px_OpL = (USHORT)(op & 0xFFFF);   /*this can be byte, 2 bytes or 4 bytes access,*/
    reg_Px_OpH = (USHORT)((op >> 16) & 0xFFFF);   /*but, hi byte must be the last to access.*/

    return S_OK;
}

//
//  AcceleratedSrcCopyBlt - source copy Blt
//  inputs:  pBltParms - Blt parameters
//  outputs: none
//
SCODE IGS2010::AcceleratedSrcCopyBlt( GPEBltParms *pBltParms )
{
    DEBUGMSG(GPE_ZONE_BLT_HI,(TEXT("AcceleratedSrcCopyBlt\r\n")));

    int srcX = pBltParms->prclSrc->left   + ((IGS2010Surf *)(pBltParms->pSrc))->Left(); // left of source rect
    int srcY = pBltParms->prclSrc->top    + ((IGS2010Surf *)(pBltParms->pSrc))->Top();  // top of source rect
    int dstX = pBltParms->prclDst->left   + ((IGS2010Surf *)(pBltParms->pDst))->Left(); // left of dest rect
    int dstY = pBltParms->prclDst->top    + ((IGS2010Surf *)(pBltParms->pDst))->Top();  // top of dest rect
    int width = pBltParms->prclDst->right  - pBltParms->prclDst->left;
    int height = pBltParms->prclDst->bottom - pBltParms->prclDst->top;
    unsigned short direction = Right_Down;

    if( !pBltParms->xPositive ) {
        srcX += ( width - 1 );
        dstX += ( width - 1 );
        if(pBltParms->yPositive) {
            direction = Left_Down;
        } else {
            direction = Left_Up;
        }
    }
    if( !pBltParms->yPositive ) {
        srcY += ( height - 1 );
        dstY += ( height - 1 );
        if(pBltParms->xPositive) {
            direction = Right_Up;
        } else {
            direction = Left_Up;
        }
    }
    WaitForNotBusy();
    reg_Cop_control = 0;
    reg_Op_Dimension_1 = width-1;
    reg_Dst_Start_Ptr  = (DWORD)dstY*(640) + dstX;
    reg_Src_Start_Ptr  = (DWORD)srcY*(640) + srcX;

    reg_Op_Dimension_2 = height - 1;

    ULONG op  = Fore_Src_PxMap;
    op |= PxBlt;
    op |= Pattern_Foreground | direction;
    reg_Px_OpL = (USHORT)(op & 0xFFFF);   /*this can be byte, 2 bytes or 4 bytes access,*/
    reg_Px_OpH = (USHORT)((op >> 16) & 0xFFFF);   /*but, hi byte must be the last to access.*/

    return S_OK;
}

#endif // ENABLE_ACCELERATION

⌨️ 快捷键说明

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