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

📄 ddlcdcoverlay.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    }

    DDGPESurf* pSrcSurf = DDGPESurf::GetDDGPESurf(pd->lpDDSrcSurface);

    if (pSrcSurf != m_pVisibleOverlay)
    {
        pd->ddRVal = DD_OK;
        return DDHAL_DRIVER_HANDLED;
    }

    // Parameter validity check
    if(
        (pd->lXPos + m_pOverlaySurfaceOp->Width > m_pMode->width) ||
        (pd->lYPos + m_pOverlaySurfaceOp->Height > m_pMode->height)                 
        )
    {
        DEBUGMSG(GPE_ZONE_ERROR, (TEXT("MX27DDLcdc SetOverlayPosition: error pd->lXPos [%d], pd->lYPos[%d]\r\n"), pd->lXPos, pd->lYPos));
        DUMP_OVERLAY_OP();
        pd->ddRVal = DDERR_INVALIDPARAMS;
        return DDHAL_DRIVER_HANDLED;
    }

    SETUP_OVERLAY_POSITION(pd->lXPos, pd->lYPos);

    WaitForNotBusyOverlay();

    m_pLcdcReg->GWPR = \
            CSP_BITFVAL(LCDC_GWPR_GWXP, m_pOverlaySurfaceOp->XOffset) |
            CSP_BITFVAL(LCDC_GWPR_GWYP, m_pOverlaySurfaceOp->YOffset) ;
    
    pd->ddRVal = DD_OK;
    return DDHAL_DRIVER_HANDLED;
}


//------------------------------------------------------------------------------
//
// Function: SetVisibleSurfaceOverlay
//
// This function changes the overlay surface displayed by the LCDC.
//
// Parameters:
//      pSurf
//          [in] Surface to be set as the visible overlay.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
VOID MX27DDLcdc::SetVisibleSurfaceOverlay(DDGPESurf * pSurf)
{
    if(!m_pOverlaySurfaceOp->isGraphicWindowRunning)
    {
        return;
    }

    if(m_pOverlaySurfaceOp->isUpsideDown)
    {
        m_pOverlaySurfaceOp->nBufPhysicalAddr = m_nLAWPhysical + pSurf->OffsetInVideoMemory() + m_pOverlaySurfaceOp->LineStride * (m_pOverlaySurfaceOp->HeightHw - 1);
    }
    else
    {
        m_pOverlaySurfaceOp->nBufPhysicalAddr = m_nLAWPhysical + pSurf->OffsetInVideoMemory();
    }

    WaitForNotBusyOverlay();

    m_pLcdcReg->GWSAR = m_pOverlaySurfaceOp->nBufPhysicalAddr;

    return;
}


//------------------------------------------------------------------------------
//
// Function: EnableOverlay
//
//  DESCRIPTION:   This function enable the graphic window of LCDC of 
//                 i.MX27 processor for overlay window.
//
// Parameters:
//      None.
//
// Returns:
//      DD_OK                successful
//      others               failed
//
//------------------------------------------------------------------------------
HRESULT MX27DDLcdc::EnableOverlay(VOID)
{
    UINT32  tempGWCR = CSP_BITFMASK(LCDC_GWCR_GWE);
    HRESULT result = DDERR_OUTOFCAPS;
    UINT32  RGBColorKey;


    if(m_pOverlaySurfaceOp->isGraphicWindowRunning)
    {
        WaitForNotBusyOverlay();
    }

    INSREG32BF(&m_pLcdcReg->GWSR, LCDC_GWSR_GWH, m_pOverlaySurfaceOp->HeightHw);
    INSREG32BF(&m_pLcdcReg->GWSR, LCDC_GWSR_GWW, LCDC_GW_SIZE_X(m_pOverlaySurfaceOp->WidthHw));

    INSREG32BF(&m_pLcdcReg->GWVPWR, LCDC_GWVPWR_GWVPW, LCDC_GW_SIZE_STRIDE(m_pOverlaySurfaceOp->LineStride));

    INSREG32BF(&m_pLcdcReg->GWPR, LCDC_GWPR_GWXP, m_pOverlaySurfaceOp->XOffset);
    INSREG32BF(&m_pLcdcReg->GWPR, LCDC_GWPR_GWYP, m_pOverlaySurfaceOp->YOffset);
    
    CSP_BITFINS(tempGWCR, LCDC_GWCR_GWAV, LCDC_GW_TRANSPARENCY(m_pOverlaySurfaceOp->Transparency));

    if(m_pOverlaySurfaceOp->ColorKeyMask != 0xFFFFFFFF)
    {
        // Convert Microsoft color key mask into the one of the IPU
        // for graphic window.
        // Microsoft    : r bit 0~4; g bit 5~10; b bit 11~15        565
        // GW           : r bit 12~17; g bit 6~11, b bit 0~5        666

        switch (m_pMode->Bpp)
        {
            case 16:
                RGBColorKey =
                    ((((m_pOverlaySurfaceOp->ColorKeyMask & 0x0000FF) >> 3) << 12) | 
                    (((m_pOverlaySurfaceOp->ColorKeyMask & 0x00FF00) >> (8+2)) << 6) | 
                    ((m_pOverlaySurfaceOp->ColorKeyMask & 0xFF0000) >> (16+3))); 
                break;
            default:
                RGBColorKey = 0;
                break;
        }
        tempGWCR |= ((RGBColorKey) | CSP_BITFMASK(LCDC_GWCR_GWCKE));
    }
        
    if(m_pOverlaySurfaceOp->isUpsideDown)
    {
        m_pLcdcReg->GWSAR = (UINT32)m_pOverlaySurfaceOp->nBufPhysicalAddr + m_pOverlaySurfaceOp->LineStride * (m_pOverlaySurfaceOp->HeightHw - 1);
        CSP_BITFINS(tempGWCR, LCDC_GWCR_GW_RVS, 1);
    }
    else
    {
        m_pLcdcReg->GWSAR = (UINT32)m_pOverlaySurfaceOp->nBufPhysicalAddr;
    }

	if(m_nMask != 0) // for flicker
    {
	    m_pOverlaySurfaceOp->isGraphicWindowRunning = TRUE;
        m_pLcdcReg->GWCR = tempGWCR;
    }
    else
    {
        //DWORD dwTransferred;
        BOOL initState;

        m_nMask = 1;
        m_pOverlaySurfaceOp->isGraphicWindowRunning = TRUE;

        // Disable LCDC hw clocks
        initState = DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_LCDC, DDK_CLOCK_GATE_MODE_DISABLE);
        if(!initState)
        {
            DEBUGMSG(GPE_ZONE_ERROR, (TEXT("MX27DDLcdc SetModeHardware: can not shutdown LCDC clock, error[%d]!\r\n"), GetLastError()));        
            goto _done;
        }
    
        m_pLcdcReg->GWCR = tempGWCR;
        
        // Re-enable LCDC hw clocks
        initState = DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_LCDC, DDK_CLOCK_GATE_MODE_ENABLE);
        if(initState != TRUE)
        {
            DEBUGMSG(GPE_ZONE_ERROR, (TEXT("MX27DDLcdc EnableOverlay: LCDC hw clock enable failed!\r\n")));
            goto _done;
        }
    }
    
    result = DD_OK;

_done:

    DEBUGMSG(HAL_ZONE_INIT, (TEXT("MX27DDLcdc EnableOverlay: result 0x%08x\r\n"), result));
    
    return result;
}


//------------------------------------------------------------------------------
//
// Function: DisableOverlay
//
//  DESCRIPTION:   This function disable the graphic window of LCDC of 
//                 i.MX27 processor for overlay window.
//
// Parameters:
//      None.
//
// Returns:
//      DD_OK                successful
//      DDERR_EXCEPTION      failed (for WinCE/PMC)
//      DDERR_GENERIC        failed (for Windows Mobile/PocketPC)
//
//------------------------------------------------------------------------------
HRESULT MX27DDLcdc::DisableOverlay(VOID)
{
    if(m_pOverlaySurfaceOp->isGraphicWindowRunning)
    {
	    // we should set the alpha to 0, and reduce 
	    // the GW size first, then set GWE to 0
	    INSREG32BF(&m_pLcdcReg->GWCR, LCDC_GWCR_GWAV, 0);
	    // INSREG32BF(&m_pLcdcReg->GWSR, LCDC_GWSR_GWH, 16);
	    // INSREG32BF(&m_pLcdcReg->GWSR, LCDC_GWSR_GWW, 16);
        Sleep(10);
		INSREG32BF(&m_pLcdcReg->GWCR, LCDC_GWCR_GWE, 0);
		//ClearGraphicWindowRegs(m_pLcdcReg);
        memset(m_pOverlaySurfaceOp, 0x00, sizeof(overlaySurf_t));
    }
    
    return DD_OK;
}


//------------------------------------------------------------------------------
//
// These three function is for furture expansion (alpha blending and 
// more efficient invert overlay)
//
//------------------------------------------------------------------------------
#if 0
//------------------------------------------------------------------------------
//
//  FUNCTION:      InverOverlay
//
//  DESCRIPTION:   This function is to invert the Graphic Window to the 
//                 opposite of the current one.
//
//  PARAMETERS:     
//
//  RETURNS:        
//                 DD_OK             successful
//                 others            failed
//
//------------------------------------------------------------------------------
HRESULT MX27DDLcdc::InverOverlay(VOID)
{
    if(m_pOverlaySurfaceOp->isUpsideDown)
    {
        INSREG32BF(&m_pLcdcReg->GWCR, LCDC_GWCR_GW_RVS, 0);
        INSREG32BF(&m_pLcdcReg->GWSAR, LCDC_GWSAR_GWSA, \
                (UINT32)m_pOverlaySurfaceOp->nBufPhysicalAddr);
        m_pOverlaySurfaceOp->isUpsideDown = FALSE;
    }
    else
    {
        INSREG32BF(&m_pLcdcReg->GWCR, LCDC_GWCR_GW_RVS, 1);
        INSREG32BF(&m_pLcdcReg->GWSAR, LCDC_GWSAR_GWSA, \
                (UINT32)m_pOverlaySurfaceOp->nBufPhysicalAddr + m_pOverlaySurfaceOp->LineStride * (m_pOverlaySurfaceOp->HeightHw - 1));
        m_pOverlaySurfaceOp->isUpsideDown = TRUE;
    }

    return DD_OK;
}


//------------------------------------------------------------------------------
//
//  FUNCTION:     GetOverlayAlphaValue
//
//  DESCRIPTION:  This function is to get current transparency of the 
//                graphic window.
//
//  PARAMETERS:     
//
//  RETURNS:        
//                DD_OK             successful
//                others            failed
//
//------------------------------------------------------------------------------
HRESULT MX27DDLcdc::GetOverlayAlphaValue(VOID)
{
    m_pOverlaySurfaceOp->Transparency = \
        LCDC_GW_TRANSPARENCY(EXTREG32BF(&m_pLcdcReg->GWCR, LCDC_GWCR_GWAV));

    return DD_OK;
}


//------------------------------------------------------------------------------
//
//  FUNCTION:     SetOverlayAlphaValue
//
//  DESCRIPTION:  This function is to set current transparency of the 
//                graphic window.
//
//  PARAMETERS:     
//
//  RETURNS:        
//                DD_OK             successful
//                others            failed
//
//------------------------------------------------------------------------------
HRESULT MX27DDLcdc::SetOverlayAlphaValue(VOID)
{
    if((m_pOverlaySurfaceOp->Transparency >= 0) &&
        (m_pOverlaySurfaceOp->Transparency <= 0xFF))
    {
        INSREG32BF(&m_pLcdcReg->GWCR, LCDC_GWCR_GWAV, \
            LCDC_GW_TRANSPARENCY(m_pOverlaySurfaceOp->Transparency));

        return DD_OK;
    }
    else
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return DDERR_INVALIDPARAMS;
    }
}
#endif //0  


//------------------------------------------------------------------------------
//
//  FUNCTION:     WaitForNotBusyOverlay
//
//  DESCRIPTION:  This function is to wait until the graphic window of 
//                the LCDC of i.MX27 processor available to update.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
VOID MX27DDLcdc::WaitForNotBusyOverlay(VOID)
{
    // TODO: We can't use the interrupt for graphic window because it
    //       will mess up the syncronyzation of the main frame buffer.

    return;
}

//------------------------------------------------------------------------------
//
// Function: IsOverlaySurfEqual
//
// This function compares overlay surfaces to determine if they are equal.
// update.
//
// Parameters:
//      pSurf1
//          [in] Overlay surface descriptor 1.
//
//      pSurf2
//          [in] Overlay surface descriptor 2.
//
// Returns:
//      TRUE if pSurf1 and pSurf2 are equal.
//      FALSE if not.
//
//------------------------------------------------------------------------------
BOOL IsOverlaySurfEqual(pOverlaySurf_t pSurf1, pOverlaySurf_t pSurf2)
{
    if ((pSurf1->nBufPhysicalAddr == pSurf2->nBufPhysicalAddr) &&
        (pSurf1->Width == pSurf2->Width) &&
        (pSurf1->Height == pSurf2->Height) &&
        (pSurf1->WidthHw == pSurf2->WidthHw) &&
        (pSurf1->HeightHw == pSurf2->HeightHw) &&
        (pSurf1->LineStride == pSurf2->LineStride) &&
        (pSurf1->XOffset == pSurf2->XOffset) &&
        (pSurf1->YOffset == pSurf2->YOffset) &&
        (pSurf1->Transparency == pSurf2->Transparency) &&
        (pSurf1->isUpsideDown == pSurf2->isUpsideDown) &&
        (pSurf1->ColorKeyMask == pSurf2->ColorKeyMask))
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}

⌨️ 快捷键说明

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