sa2video.cpp

来自「该BSP是基于PXA270+WINCE的BSP」· C++ 代码 · 共 2,007 行 · 第 1/5 页

CPP
2,007
字号
            PowerState = VideoPowerOn;
            break;
    }

    return(PowerState);
}

// This routine maps video power states to PM power states.
// Not currently used.
CEDEVICE_POWER_STATE 
SA2Video::VideoToPmPowerState(ULONG PowerState)
{
    CEDEVICE_POWER_STATE Dx;

    switch( PowerState ) 
    {
        case VideoPowerOn:
            Dx = D0;
            break;

        case VideoPowerStandBy:
            Dx = D2;
            break;

        case VideoPowerSuspend:
            Dx = D3;
            break;

        case VideoPowerOff:
            Dx = D4;
            break;

        default:
            Dx = D0;
            break;
    }

    return Dx;
}

void SA2Video::SetPmPowerState(CEDEVICE_POWER_STATE PowerState)
{
    DEBUGMSG(ZONE_PM, (TEXT("SA2Video::SetPmPowerState: (D%d)\r\n"), PowerState));
    switch ( PowerState )
    {
        case D0:
        case D1:
            if (bSuspended)
            {
                DEBUGMSG(ZONE_PM, (TEXT("SA2Video::SetPmPowerState: TurnOn Display %d\r\n"), PowerState));
                DispDrvrPowerHandler(FALSE);
                bSuspended = FALSE;
            }
            break;

        case D2:
        case D3:
        case D4:
            if (!bSuspended)
            {
                DEBUGMSG(ZONE_PM, (TEXT("SA2Video::SetPmPowerState: TurnOff Display %d\r\n"), PowerState));
                DispDrvrPowerHandler(TRUE);
                bSuspended = TRUE;
            }
            break;
    }

    m_PmPowerState = PowerState;
}

CEDEVICE_POWER_STATE
SA2Video::GetPmPowerState(void)
{
    return(m_PmPowerState);
}

ULONG 
SA2Video::GetVideoPowerState(void)
{
    return( PmToVideoPowerState(m_PmPowerState) );
}

// this routine converts a string into a GUID and returns TRUE if the
// conversion was successful.
BOOL 
SA2Video::ConvertStringToGuid (LPCTSTR pszGuid, GUID *pGuid)
{
    UINT Data4[8];
    int  Count;
    BOOL fOk = FALSE;
    TCHAR *pszGuidFormat = _T("{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}");

    DEBUGCHK(pGuid != NULL && pszGuid != NULL);
    __try
    {
        if (_stscanf(pszGuid, pszGuidFormat, &pGuid->Data1, 
            &pGuid->Data2, &pGuid->Data3, &Data4[0], &Data4[1], &Data4[2], &Data4[3], 
            &Data4[4], &Data4[5], &Data4[6], &Data4[7]) == 11)
        {
            for(Count = 0; Count < (sizeof(Data4) / sizeof(Data4[0])); Count++)
            {
                        pGuid->Data4[Count] = (UCHAR) Data4[Count];
            }
        }
        fOk = TRUE;
    }
    __except(EXCEPTION_EXECUTE_HANDLER)
    {
    }

    return fOk;
}


// This routine notifies the OS that we support the Power Manager IOCTLs (through
// ExtEscape(), which calls DrvEscape()).
BOOL
SA2Video::AdvertisePowerInterface()
{
    BOOL fOk = FALSE;
    DWORD dwStatus;
    GUID gClass;

    // PM assumes device is in power state D0 when it registers.
    m_PmPowerState    = D0;

    // assume we are advertising the default class
    ConvertStringToGuid(PMCLASS_DISPLAY, &gClass);
    DEBUGMSG(ZONE_PM,(TEXT("SA2Video::AdvertisePowerInterface: (%s)\r\n"), PMCLASS_DISPLAY));
    DEBUGMSG(ZONE_PM,(TEXT("SA2Video::AdvertisePowerInterface: 0x%x-0x%x-0x%x 0x%x-0x%x-0x%x-0x%x-0x%x-0x%x-0x%x-0x%x\r\n"), 
                             gClass.Data1, gClass.Data2, gClass.Data3,
                             gClass.Data4[0], gClass.Data4[1], gClass.Data4[2], gClass.Data4[3],
                             gClass.Data4[4], gClass.Data4[5], gClass.Data4[6], gClass.Data4[7]));

    // Build the display device name for DevicePowerNotify().
    wcscpy(m_DisplayDeviceName, PMCLASS_DISPLAY);
    wcscat(m_DisplayDeviceName, _T("\\"));
    wcscat(m_DisplayDeviceName, _T("pxa27x_lcd"));
    DEBUGMSG(ZONE_PM,(TEXT("SA2Video::AdvertisePowerInterface: m_DisplayDeviceName=%s\r\n"),m_DisplayDeviceName));

    // now advertise the interface
    fOk = AdvertiseInterface(&gClass, L"pxa27x_lcd", TRUE);
   
    if(fOk)
    {
        // Request initial power management state.
        dwStatus = DevicePowerNotify(m_DisplayDeviceName, m_PmPowerState, POWER_NAME);
        DEBUGMSG(ZONE_PM,(TEXT("SA2Video::AdvertisePowerInterface: dwStatus=0x%x\r\n"), dwStatus));
    }

    return fOk;
}

ULONG
SA2Video::DrvEscape(
    SURFOBJ * pso,
    ULONG     iEsc,
    ULONG     cjIn,
    PVOID     pvIn,
    ULONG     cjOut,
    PVOID pvOut
    )
{
    int RetVal = 0; // default return value: "not supported"
    DWORD EscapeFunction;
    GXDeviceInfo *pgxoi;
    CEDEVICE_POWER_STATE NewDx;
    VIDEO_POWER_MANAGEMENT *pvpm;
    BOOL  bErr = TRUE;

    switch (iEsc)
    {
        case GETPOWERMANAGEMENT :

            if (!pvOut || (cjOut < sizeof(VIDEO_POWER_MANAGEMENT)))
            {
                SetLastError(ERROR_INVALID_PARAMETER);
                return -1;
            }

            pvpm = (VIDEO_POWER_MANAGEMENT*)pvOut;
            pvpm->Length = sizeof(VIDEO_POWER_MANAGEMENT);
            pvpm->DPMSVersion = 0;
            pvpm->PowerState  = GetVideoPowerState();
            RetVal = 1;

            DEBUGMSG(ZONE_PM, (TEXT("SA2Video::GETPOWERMANAGEMENT: VidPowerState=0x%x\r\n"),pvpm->PowerState));

            break;

        case SETPOWERMANAGEMENT :
        {    
            pvpm = (VIDEO_POWER_MANAGEMENT *)pvIn;

            if (!pvpm || (cjIn < sizeof(VIDEO_POWER_MANAGEMENT)))
            {
                SetLastError(ERROR_INVALID_PARAMETER);
                return -1;
            }

            if (pvpm->Length < sizeof(VIDEO_POWER_MANAGEMENT))
            {
                SetLastError(ERROR_INVALID_PARAMETER);
                return -1;
            }

            if (DevicePowerNotify(m_DisplayDeviceName, VideoToPmPowerState(pvpm->PowerState), POWER_NAME) )
            {
               DEBUGMSG(ZONE_PM, (TEXT("SA2Video::SetPowerManagement:DevicePowerNotify-success VPwrstate=%d (D%d)\r\n"),pvpm->PowerState, VideoToPmPowerState(pvpm->PowerState)));
            }
            else
            {
               RETAILMSG(1, (TEXT("SA2Video::SetPowerManagement:DevicePowerNotify failed\r\n")));
            }

            RetVal = 1;
            break;
        }
        case IOCTL_POWER_CAPABILITIES:
            if ( pvOut != NULL && cjOut == sizeof(POWER_CAPABILITIES) ) 
            {
                DEBUGMSG(ZONE_PM, (TEXT("SA2Video::SA2VIDEO:IOCTL_POWER_CAPABILITIES\r\n")));
                PPOWER_CAPABILITIES PowerCaps = (PPOWER_CAPABILITIES) pvOut;
                
                memcpy(PowerCaps, &DisplayDrvPowerCaps, sizeof(DisplayDrvPowerCaps));
                RetVal = 1;
            }
            else
            {
                SetLastError(MMSYSERR_INVALPARAM);
                RetVal = -1;
            }
            break;
     
        case IOCTL_POWER_QUERY:
            DEBUGMSG(ZONE_PM, (TEXT("SA2VIDEO::IOCTL_POWER_QUERY\r\n")));
            if ( pvOut != NULL && cjOut == sizeof(CEDEVICE_POWER_STATE) )
            {
                // Return a good status on any valid query since 
                // we are always ready to change power states.
                NewDx = *(PCEDEVICE_POWER_STATE) pvOut;

                if ( ! VALID_DX(NewDx) ) 
                {
                    DEBUGMSG(ZONE_PM, (TEXT("SA2VIDEO::IOCTL_POWER_QUERY-(D%d) success\r\n"),NewDx));
                    RetVal = 1;
                    bErr = FALSE;
                }
            }

            if (bErr)
            {
                RETAILMSG(1, (TEXT("SA2VIDEO::IOCTL_POWER_QUERY-(D%d) failed\r\n"),NewDx));
                SetLastError(MMSYSERR_INVALPARAM);
                RetVal = -1;
            }
            break;
     
        case IOCTL_POWER_SET:
            if ( pvOut != NULL && cjOut == sizeof(CEDEVICE_POWER_STATE) )
            {
                NewDx = *(PCEDEVICE_POWER_STATE)pvOut;

                if ( VALID_DX(NewDx) )
                {
                    DEBUGMSG(ZONE_PM, (TEXT("SA2VIDEO::IOCTL_POWER_SET-(D%d) success\r\n"), NewDx));
                    SetPmPowerState(NewDx);
                    RetVal = 1;
                    bErr = FALSE;
                }
            }

            if (bErr)
            {
                RETAILMSG(1, (TEXT("SA2VIDEO::IOCTL_POWER_SET-(D%d) failed\r\n"), NewDx));
                SetLastError(MMSYSERR_INVALPARAM);
                RetVal = -1;
            }
            break;
     
        case IOCTL_POWER_GET:
            DEBUGMSG(ZONE_PM, (TEXT("SA2VIDEO::IOCTL_POWER_GET\r\n")));
            if(pvOut != NULL && cjOut == sizeof(CEDEVICE_POWER_STATE))
            {
                *(PCEDEVICE_POWER_STATE) pvOut = GetPmPowerState();
                RetVal = 1;
            }
            break;

        case QUERYESCSUPPORT:
            EscapeFunction = *(DWORD *)pvIn;
            if ((EscapeFunction == GETVFRAMEPHYSICAL)        ||
                (EscapeFunction == GETVFRAMELEN)             ||
                (EscapeFunction == GETPALETTERAMPHYSICAL)    ||
                (EscapeFunction == VERTICALBLANKINTERRUPT)   ||
                (EscapeFunction == SCROLL)                   ||
                (EscapeFunction == OVERLAY2_ENABLE)          ||
                (EscapeFunction == OVERLAY2_DISABLE)         ||
                (EscapeFunction == OVERLAY1_ENABLE)          ||
                (EscapeFunction == OVERLAY1_DISABLE)         ||
                (EscapeFunction == GET_OVERLAY1_ADDRESS)     ||
                (EscapeFunction == GET_OVERLAY2_ADDRESS)     ||
                (EscapeFunction == SETPOWERMANAGEMENT)       ||
                (EscapeFunction == GETPOWERMANAGEMENT)       ||
                (EscapeFunction == IOCTL_POWER_CAPABILITIES) ||
                (EscapeFunction == IOCTL_POWER_QUERY) ||
                (EscapeFunction == IOCTL_POWER_SET) ||
                (EscapeFunction == IOCTL_POWER_GET) ||
                (EscapeFunction == GETGXINFO))
            {
                RetVal = 1;
            }
            else if ((!g_fDisableRotation) &&
                ((EscapeFunction == DRVESC_GETSCREENROTATION) ||
                (EscapeFunction == DRVESC_SETSCREENROTATION)))
            {
                RetVal = 1;
            }
            break;

        // Provide the mapped virtual address of the frame buffer ram
        // for direct frame buffer manipulation.
        case GETVFRAMEPHYSICAL: 
            if (cjIn < NUM_FRAME_BUFFERS)
            {
                // This works as long as the frame buffers are in a contiguous region.
                *(DWORD *)pvOut = (ULONG)FRAME_BUFFER_0_BASE_VIRTUAL + cjIn * (DispDrvr_cdwStride * DispDrvr_cyScreen);
                RetVal = 1;
            } else
            {
                *(DWORD *)pvOut = NULL;
            }
            break;

        // Provide the length of the frame buffer in bytes
        case GETVFRAMELEN:
            *(DWORD *)pvOut = (ULONG)DispDrvr_cdwStride * DispDrvr_cyScreen;
            RetVal = 1;
            break;

        // Provide the mapped virtual address of the palette ram
        // for direct palette buffer manipulation.
        case GETPALETTERAMPHYSICAL:
            *(DWORD *)pvOut = (ULONG)PALETTE_BUFFER_BASE_VIRTUAL;
            RetVal = 1;
            break;

        case VERTICALBLANKINTERRUPT:
            RetVal = 1;
            break;

        case SCROLL:
            ScrollBuffer(cjIn);
            break;

        case OVERLAY2_ENABLE:
            Overlay2_Enable((P_XLLP_OVERLAY_T)pvIn);
            RetVal = 1;            
            break;

        case OVERLAY2_DISABLE:
            Overlay2_Disable((P_XLLP_OVERLAY_T)pvIn);

            RetVal = 1;            
            break;

        case GET_OVERLAY1_ADDRESS:
            RetVal = 1;            
            break;

        case GET_OVERLAY2_ADDRESS:

            RetVal = 1;
            // Check the DMA length to see if everything will fit into SRAM.
            // If it does, then locate the descriptors and the frame buffers there.
            // Otherwise, locate it in external memory.
            Overlay2_DMA_Length((P_XLLP_OVERLAY_T)pvIn);

                
            XllpLCD._OVERLAY2_Y_CHANNEL_BASE_PHYSICAL = OVERLAY2_PHYSICAL_BASE_ADDRESS;
            XllpLCD._OVERLAY2_Cb_CHANNEL_BASE_PHYSICAL = OVERLAY2_PHYSICAL_BASE_ADDRESS + ((P_XLLP_OVERLAY_T)pvIn)->ch2_size;
            XllpLCD._OVERLAY2_Cr_CHANNEL_BASE_PHYSICAL = OVERLAY2_PHYSICAL_BASE_ADDRESS + ((P_XLLP_OVERLAY_T)pvIn)->ch2_size + ((P_XLLP_OVERLAY_T)pvIn)->ch3_size;
            XllpLCD._DMA_CHANNEL_2_Y_FRAME_DESCRIPTOR_BASE_PHYSICAL = DMA_CHANNEL_2_Y_FRAME_DESCRIPTOR_BASE_PHYSICAL;
            XllpLCD._DMA_CHANNEL_3_Cb_FRAME_DESCRIPTOR_BASE_PHYSICAL = DMA_CHANNEL_3_Cb_FRAME_DESCRIPTOR_BASE_PHYSICAL;
            XllpLCD._DMA_CHANNEL_4_Cr_FRAME_DESCRIPTOR_BASE_PHYSICAL = DMA_CHANNEL_4_Cr_FRAME_DESCRIPTOR_BASE_PHYSICAL;

            if (frameDescriptorCh2_YCbCr_Y)
                VirtualFree((PVOID)frameDescriptorCh2_YCbCr_Y,0,MEM_RELEASE);

            frameDescriptorCh2_YCbCr_Y = (volatile LCD_FRAME_DESCRIPTOR *)VirtualAllocCopy(sizeof(LCD_FRAME_DESCRIPTOR), "DispDrvrInitialize : lcdFrameDescriptor", (PVOID)(DMA_CHANNEL_2_Y_FRAME_DESCRIPTOR_BASE_VIRTUAL));
            if (!frameDescriptorCh2_YCbCr_Y)
            {
                RetVal = 0;    
                break;
            }

            if (frameDescriptorCh3_YCbCr_Cb)
                VirtualFree((PVOID)frameDescriptorCh3_YCbCr_Cb,0,MEM_RELEASE);

            frameDescriptorCh3_YCbCr_Cb = (volatile LCD_FRAME_DESCRIPTOR *)VirtualAllocCopy(sizeof(LCD_FRAME_DESCRIPTOR), "DispDrvrInitialize : lcdFrameDescriptor", (PVOID)(DMA_CHANNEL_3_Cb_FRAME_DESCRIPTOR_BASE_VIRTUAL));
            if (!frameDescriptorCh3_YCbCr_Cb)
            {

⌨️ 快捷键说明

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