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

📄 halsurf.cpp

📁 Freescale ARM11系列CPU MX31的WINCE 5.0下的BSP
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
//  Copyright (C) 2004-2005, MOTOROLA, INC. All Rights Reserved
//  THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
//  BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
//  MOTOROLA, INC.
//------------------------------------------------------------------------------
//
//  Copyright (C) 2005-2006, Freescale Semiconductor, Inc. All Rights Reserved.
//  THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
//  AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------
//
//  File:  halcaps.cpp
//
//  DirectDrawSurface callback functions.
//
//------------------------------------------------------------------------------


#include "precomp.h"


//------------------------------------------------------------------------------
// External Functions


//------------------------------------------------------------------------------
// External Variables


//------------------------------------------------------------------------------
// Defines


//------------------------------------------------------------------------------
// Types


//------------------------------------------------------------------------------
// Global Variables


//------------------------------------------------------------------------------
// Local Variables


//------------------------------------------------------------------------------
// Local Functions


// retrieve pFormat and pPixelFormat based on pDDPF
SCODE DetectPixelFormat(DDPIXELFORMAT *pDDPF,
                        EGPEFormat *pFormat,
                        EDDGPEPixelFormat *pPixelFormat)
{
    if( pDDPF->dwFlags & DDPF_RGB )
    {
        if( !(pDDPF->dwFlags & DDPF_ALPHAPIXELS) )
        {
            pDDPF->dwRGBAlphaBitMask = 0;
        }

        if( pDDPF->dwRGBBitCount == 16 )
        {
            if( pDDPF->dwRGBAlphaBitMask == 0x0000 &&
                pDDPF->dwRBitMask == 0xF800 )
            {
                DEBUGMSG(1, (TEXT("565 surface detected\r\n") ));
                *pPixelFormat = ddgpePixelFormat_565;
            }
            else {
                DEBUGMSG(1, (TEXT("DetectFormat: Unsupported 16-bit format\r\n") ));
                return DDERR_UNSUPPORTEDFORMAT;
            }
        }
        else
        {
            DEBUGMSG(1, (TEXT("DetectFormat: Unsupported bit-depth (%d)\r\n"), pDDPF->dwRGBBitCount));
            return DDERR_UNSUPPORTEDFORMAT;
        }
    }
#ifndef PLAT_WPC
#ifndef PLAT_SMARTPHONE
    else if( pDDPF->dwFlags & DDPF_ZBUFFER )
    {
        return DDERR_UNSUPPORTEDFORMAT;
    }
#endif // PLAT_SMARTPHONE
#endif // PLAT_WPC
    else if( pDDPF->dwFlags & DDPF_FOURCC )
    {
        if( pDDPF->dwFourCC == FOURCC_YV12) {
            DEBUGMSG(1, (TEXT("DetectFormat: YV12 surface detected\r\n") ));
            return DDERR_UNSUPPORTEDFORMAT;
            *pPixelFormat = (EDDGPEPixelFormat) ddgpePixelFormat_YV12;
        }
        else if( pDDPF->dwFourCC == FOURCC_UYVY422 ) {
            DEBUGMSG(1, (TEXT("DetectFormat: UYVY422 surface detected\r\n") ));
            *pPixelFormat = ddgpePixelFormat_UYVY422;
        }
        else {
            DEBUGMSG(1, (TEXT("DetectFormat: Unsupported FOURCC %08x\r\n"), pDDPF->dwFourCC ));
            return DDERR_UNSUPPORTEDFORMAT;
        }
    }
    else
    {
        DEBUGMSG(1, (TEXT("DetectFormat: Unsupported Non-RGB, Non-FOURCC surface.\r\n")));
        return DDERR_UNSUPPORTEDFORMAT;
    }

    if (*pPixelFormat == ddgpePixelFormat_YV12)
    {
        *pFormat = gpe8Bpp;
    }
    else
    {
        *pFormat = EDDGPEPixelFormatToEGPEFormat[*pPixelFormat];
    }

    DEBUGMSG(1, (TEXT("Detected surface pixelFormat, format = %d, %d\r\n"),
        *pPixelFormat, *pFormat));

    return DD_OK;
}


////////////////////////////////////////////////////////////////////////////////
///////////////////////////// DDHAL_DDCALLBACKS ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
//
// Function: HalCreateSurface
//
// This callback function creates a DirectDrawSurface object
// for this DirectDraw object.
//
// Parameters:
//      lpcsd
//          [in, out] Pointer to a DDHAL_CREATESURFACEDATA structure
//          that contains the information necessary to create the
//          DirectDrawSurface object.
//
// Returns:
//      Returns one of the following values:
//          DDHAL_DRIVER_HANDLED
//          DDHAL_DRIVER_NOTHANDLED
//
//------------------------------------------------------------------------------
DWORD WINAPI HalCreateSurface( LPDDHAL_CREATESURFACEDATA pd )
{
    DEBUGENTER( HalCreateSurface );
    /*
    typedef struct _DDHAL_CREATESURFACEDATA
    {
        LPDDRAWI_DIRECTDRAW_GBL     lpDD;           // driver struct
        LPDDSURFACEDESC             lpDDSurfaceDesc;// description of surface being created
        LPDDRAWI_DDRAWSURFACE_LCL   FAR *lplpSList; // list of created surface objects
        DWORD                       dwSCnt;         // number of surfaces in SList
        HRESULT                     ddRVal;         // return value
        LPDDHAL_CREATESURFACE       CreateSurface;  // PRIVATE: ptr to callback
    } DDHAL_CREATESURFACEDATA;
    */

    DWORD result = DDHAL_DRIVER_HANDLED;
    // Implementation
    EGPEFormat format;
    EDDGPEPixelFormat pixelFormat;
    EDDGPEPixelFormat primaryPixelFormat;
    DWORD dwFlags = pd->lpDDSurfaceDesc->dwFlags;
    DWORD dwCaps = pd->lpDDSurfaceDesc->ddsCaps.dwCaps;
    BOOL bIsYV12Surface = FALSE;
    DWORD i;

#if defined(PLAT_WPC) || defined(PLAT_SMARTPHONE)
    DDIPU_SDC *pGPE = (DDIPU_SDC *)GetDDGPE();
#else
    DDIPU_SDC *pGPE = (DDIPU_SDC *)g_pGPE;
#endif // PLAT_WPC || PLAT_SMARTPHONE

    // get the pixel format for the primary surface
    GPEMode modeInfo;
    SCODE sc = pGPE->GetModeInfo(&modeInfo, 0);
    if (FAILED(sc))
    {
        DEBUGMSG(1, (TEXT("Error: can't get mode info\r\n")));
        pd->ddRVal = DDERR_GENERIC;
        return DDHAL_DRIVER_HANDLED;
    }

    GPEModeEx modeInfoEx;
    sc = pGPE->GetModeInfoEx(&modeInfoEx, 0);
    if (FAILED(sc))
    {
        primaryPixelFormat = EGPEFormatToEDDGPEPixelFormat[modeInfo.format];
    }
    else
    {
        primaryPixelFormat = modeInfoEx.ePixelFormat;
    }

    // get the pixel format for the surface to be created
    if (dwFlags & DDSD_PIXELFORMAT)
    {
        pd->ddRVal = DetectPixelFormat(
            &pd->lpDDSurfaceDesc->ddpfPixelFormat,
            &format,
            &pixelFormat);
        if (FAILED(pd->ddRVal))
        {
            DEBUGMSG(1, (TEXT("HalCreateSurface: unsupported format\r\n")));
            return DDHAL_DRIVER_HANDLED;
        }
    }
    else
    {
        pixelFormat = primaryPixelFormat;
    }

    if ((!(dwCaps & DDSCAPS_OVERLAY)) &&
        (dwCaps & DDSCAPS_VIDEOMEMORY) &&
        (pixelFormat != primaryPixelFormat))
    {
        DEBUGMSG(1, (TEXT("HalCreateSurface: non-overlay video memory surface must have same format as primary surface\r\n")));
        pd->ddRVal = DDERR_UNSUPPORTEDFORMAT;
        return DDHAL_DRIVER_HANDLED;
    }

    // Implementation
    if(pd->lpDDSurfaceDesc->ddsCaps.dwCaps & (DDSCAPS_FLIP | DDSCAPS_OVERLAY))
    {
        DWORD *dwCapsList = (DWORD *)malloc(sizeof(DWORD) * pd->dwSCnt);
        DWORD iSurf = 0;

        if(NULL == dwCapsList)
        {
            DEBUGMSG(GPE_ZONE_ERROR, (TEXT("HalCreateSurface: NO LOCAL HEAP MEMORY!!!\r\n")));
            pd->ddRVal = DDERR_OUTOFMEMORY;
            return DDHAL_DRIVER_HANDLED;
        }

        // Force all flip or overlay to be in video memory
        for(iSurf = 0; iSurf < pd->dwSCnt; iSurf++)
        {
            dwCapsList[iSurf] = pd->lplpSList[iSurf]->ddsCaps.dwCaps;
            pd->lplpSList[iSurf]->ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
        }

        // we know from CanCreateSurface that this is an overlay of a supported format, so
        // just go ahead and fill in the surface ptrs
        if( pd->lpDDSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_FOURCC ) // if fourcc field is valid
        {
            // DDGPECreateSurface will does not support YV12 surfaces,
            // so we must allocate it ourselves.
            if( pd->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC == FOURCC_YV12 ) // if it's a YV12 overlay
            {
                bIsYV12Surface = TRUE;

                for( i = 0; i < pd->dwSCnt; i++ ) // for each surface in the list
                {
                    // allocate a new YV12 surface
                    DDIPU_SDCSurf *newSurf;

                    if (FAILED(sc = ((DDIPU_SDC *)GetGPE())->AllocSurface((DDGPESurf **) &newSurf,
                        pd->lpDDSurfaceDesc->dwWidth, pd->lpDDSurfaceDesc->dwHeight,
                        gpe16Bpp, (EDDGPEPixelFormat) ddgpePixelFormat_YV12, GPE_REQUIRE_VIDEO_MEMORY)))
                    {
                        DEBUGMSG(GPE_ZONE_ERROR, (TEXT("%s: Can't allocate YV12 surface.\r\n"), __WFUNCTION__));
                        return S_FALSE;
                    }

#ifndef PLAT_WPC
#ifndef PLAT_SMARTPHONE
                    // fill in the required fields in the DDRAWI_DIRECTDRAW_GBL struct
                    pd->lplpSList[i]->lpGbl->fpVidMem = (FLATPTR) newSurf->Buffer();
                    pd->lplpSList[i]->lpGbl->lPitch = newSurf->Stride();
                    pd->lplpSList[i]->lpGbl->dwReserved1 = (ULONG_PTR)newSurf;
#endif // ifndef PLAT_SMARTPHONE
#endif // ifndef PLAT_WPC

                    pd->ddRVal = DD_OK;

                    DEBUGMSG( GPE_ZONE_CREATE, (TEXT("HalSurf.cpp::CreateSurface() - YV12 Overlay Surface requested.\r\n")));
                }
            }
        }

        if (!bIsYV12Surface)
        {
            result = DDGPECreateSurface(pd);
        }

        // Restore back the DDSCAPS parameters
        for(iSurf = 0; iSurf < pd->dwSCnt; iSurf++)
        {
            pd->lplpSList[iSurf]->ddsCaps.dwCaps = dwCapsList[iSurf];
        }

        free(dwCapsList);

        return result;
    }

    result = DDGPECreateSurface(pd);

    DEBUGMSG(GPE_ZONE_CREATE, (TEXT("HalCreateSurface: surface create %s\r\n"), (pd->ddRVal == DD_OK) ? L"successful" : L"failed"));

    return result;
}



//------------------------------------------------------------------------------
//
// Function: HalCanCreateSurface
//
// This function indicates whether a surface can be created.
//
// Parameters:
//      lpccsd
//          [in, out] Pointer to a DDHAL_CANCREATESURFACEDATA structure
//          that contains the information required for the driver to
//          determine whether a surface can be created.
//
// Returns:
//      Returns one of the following values:
//          DDHAL_DRIVER_HANDLED
//          DDHAL_DRIVER_NOTHANDLED
//
//------------------------------------------------------------------------------
DWORD WINAPI HalCanCreateSurface( LPDDHAL_CANCREATESURFACEDATA pd )
{
    DEBUGENTER( HalCanCreateSurface );
    /*
    typedef struct _DDHAL_CANCREATESURFACEDATA
    {

⌨️ 快捷键说明

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