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

📄 surf.cpp

📁 WinCE5.0BSP for Renesas SH7770
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
//  Copyright(C) Renesas Technology Corp. 1998-2005. All rights reserved.
//  Portions Copyright (c) 1997 Microsoft Corporation.
//
//  NCG Display Driver for ITS-DS7
//
//  FILE      : surf.cpp
//  CREATED   : 2003.08.28
//  MODIFIED  : 2005.11.10
//  AUTHOR    : Renesas Technology Corp.
//  HARDWARE  : RENESAS ITS-DS7
//  HISTORY   : 
//              2003.08.28
//              - Created prototype code.
//                (based on Q2SD Display Driver for PFM-DS6C Ver.3.1.0)
//              2003.09.02
//              - Modified flip.
//              2003.11.18
//              - Corrected pixel format.
//              - Removed unused code.
//              2004.03.01
//              - Removed unused code.
//              2004.09.02
//              - Removed unused code.
//              2005.11.10
//              - Modified DetectPixelFormat to support RGB1555 format.
//

#include "precomp.h"

// surface list
extern NCGSurf* g_pNCGSurfList;

SCODE NCG::AllocSurface(
    GPESurf **ppSurf,
    int width,
    int height,
    EGPEFormat format,
    int surfaceFlags )
{
    EDDGPEPixelFormat pixelFormat;
    GPEModeEx modeInfoEx;

    if (format == gpeDeviceCompatible) {
        GetModeInfoEx(&modeInfoEx, GetModeId());
        format = modeInfoEx.modeInfo.format;
        pixelFormat = modeInfoEx.ePixelFormat;
    }
    else pixelFormat = EGPEFormatToEDDGPEPixelFormat[format];

#ifdef PREFER_SYSTEM_MEMORY
    /* When GPE surface flags is set to GPE_PREFER_VIDEO_MEMORY,  */
    /* surface memory is allocated in system memory.              */
    /* In order to avoid a exception on BitBlt from system memory,*/
    /* it is used only when width and height are larger than 32   */
    /* pixel.                                                     */
    if ((surfaceFlags & GPE_PREFER_VIDEO_MEMORY) && (width > 32) && (height > 32))
        surfaceFlags &= ~GPE_PREFER_VIDEO_MEMORY;
#endif

    return AllocSurface((NCGSurf**)ppSurf, width, height, 
                        format, pixelFormat, surfaceFlags);
}


SCODE NCG::AllocSurface(
    DDGPESurf **ppSurf,
    int width,
    int height,
    EGPEFormat format,
    EDDGPEPixelFormat pixelFormat,
    int surfaceFlags )
{
    return AllocSurface((NCGSurf**)ppSurf, width, height,
                        format, pixelFormat, surfaceFlags);
}


SCODE NCG::AllocSurface(
    NCGSurf **ppSurf,
    int width,
    int height,
    EGPEFormat format,
    EDDGPEPixelFormat pixelFormat,
    int surfaceFlags )
{
	SurfaceHeap	*pHeap;
	int			nSurfaceBytes;
	int			nBpp = EGPEFormatToBpp[format];
	int			stride;
	int			nAlign, nAlignedWidth;
//	int			nWidth, nHeight;

    DEBUGMSG(GPE_ZONE_ENTER, (TEXT("NCG::AllocSurface\r\n")));

    DEBUGMSG(GPE_ZONE_CREATE,
//    RETAILMSG(1,
        (TEXT("AllocSurface: %dx%d, %dbpp, format = %d, pixelformat = 0x%x, surfaceFlags = %d\r\n"),
        width, height, nBpp, format, pixelFormat, surfaceFlags));

    /* GPE requires dword aligned source width, so 1bpp linear    */
    /* surface must be aligned with 32 pixel.                     */
    if (nBpp == 1)
        nAlign = 32;
    else
        nAlign = 8;
    nAlignedWidth = ((width + nAlign - 1) & (- nAlign));
    nSurfaceBytes = (nBpp * (nAlignedWidth * height)) / 8;
    stride = nAlignedWidth * nBpp / 8;  // default stride

    /* When video memory is required or prefered, try to allocate */
    /* surface image buffer from video memory.                    */
    if ((surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY) ||
        (surfaceFlags & GPE_PREFER_VIDEO_MEMORY)) {

        pHeap = m_pVideoMemoryHeap->Alloc(nSurfaceBytes);

        if (pHeap) {
            ULONG offset = pHeap->Address();
            *ppSurf = new NCGSurf(width, height, offset, 
                                      (void *)(m_pLAW + offset), stride, 
                                      format, pixelFormat, pHeap);
            if (!(*ppSurf)) {
                pHeap->Free();
                return E_OUTOFMEMORY;
            }

            DEBUGMSG(GPE_ZONE_CREATE,
                (TEXT("AllocSurface: ")
                TEXT("Created in video RAM.\r\n")));

            goto CreatedSurface;
        }

        if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY) {
            *ppSurf = (NCGSurf*)NULL;
            DEBUGMSG(GPE_ZONE_ERROR | GPE_ZONE_CREATE,
                (TEXT("AllocSurface: ")
                TEXT("Failed to allocate video RAM.\r\n")));
            return E_OUTOFMEMORY;
        }
    }

    /*  GPE requires 32 pixel or more as source width in system memory. */
    if (width < 32)
        width = 32;

    *ppSurf = new NCGSurf(width, height, stride, format, pixelFormat);
    if (*ppSurf) {
        // check we allocated bits succesfully
        if ((*ppSurf)->Buffer()) {
            DEBUGMSG(GPE_ZONE_CREATE,
                (TEXT("AllocSurface: ")
                TEXT("Created in system RAM.\r\n")));
           goto CreatedSurface;
        }
        delete *ppSurf;
    }

    DEBUGMSG(GPE_ZONE_ERROR | GPE_ZONE_CREATE,
        (TEXT("AllocSurface: ")
        TEXT("Failed to create surface.\r\n")));
    return E_OUTOFMEMORY;

CreatedSurface:
//    DEBUGMSG(1,(TEXT("AllocSurface: *ppSurf = 0x%08x\r\n"), *ppSurf));

    return S_OK;
}


NCGSurf::NCGSurf(
    int width,
    int height,
    unsigned long offset,
    void *pBits,
    int stride,
    EGPEFormat format,
    SurfaceHeap *pHeap )
    : DDGPESurf( width, height, pBits, stride, format )
{
    DEBUGMSG(1, (TEXT("NCGSurf::NCGSurf(%d, %d, 0x%08x, 0x%08x, %d, %d, 0x%08x)\r\n"),
        width, height, offset, pBits, stride, format, pHeap));

    m_pHeap = pHeap;
    m_fInVideoMemory = TRUE;
    m_nOffsetInVideoMemory = offset;
    m_nSrcCount = 0;
    m_nDstCount = 0;

    NCGSurf* pSurf = g_pNCGSurfList;
    if (pSurf == NULL) {
        g_pNCGSurfList = this;
    }
    while (pSurf != NULL) {
        if (pSurf->m_pSurfList == NULL) {
            pSurf->m_pSurfList = this;
            break;
        }
        pSurf = pSurf->m_pSurfList;
    }
    m_pSurfList = NULL;
    m_dwSurfaceID = 0;
    m_dwLayerID = 0;
} 


NCGSurf::NCGSurf(
    int width,
    int height,
    unsigned long offset,
    void *pBits,
    int stride,
    EGPEFormat format,
    EDDGPEPixelFormat pixelFormat,
    SurfaceHeap *pHeap )
    : DDGPESurf( width, height, pBits, stride, format, pixelFormat )
{
    DEBUGMSG(1, (TEXT("NCGSurf::NCGSurf(%d, %d, 0x%08x, 0x%08x, %d, %d, 0x%08x)\r\n"),
        width, height, offset, pBits, stride, format, pHeap));

    m_pHeap = pHeap;
    m_fInVideoMemory = TRUE;
    m_nOffsetInVideoMemory = offset;
    m_nSrcCount = 0;
    m_nDstCount = 0;

    NCGSurf* pSurf = g_pNCGSurfList;
    if (pSurf == NULL) {
        g_pNCGSurfList = this;
    }
    while (pSurf != NULL) {
        if (pSurf->m_pSurfList == NULL) {
            pSurf->m_pSurfList = this;
            break;
        }
        pSurf = pSurf->m_pSurfList;
    }
    m_pSurfList = NULL;
    m_dwSurfaceID = 0;
    m_dwLayerID = 0;
} 


NCGSurf::NCGSurf(
    int width,
    int height,
    int stride,
    EGPEFormat format,
    EDDGPEPixelFormat pixelFormat )
    : DDGPESurf( width, height, stride, format, pixelFormat )
{
    DEBUGMSG(1, (TEXT("NCGSurf::NCGSurf(%d, %d, %d, %d)\r\n"),
        width, height, stride, format));

    m_pHeap = NULL;
    m_fInVideoMemory = FALSE;
    m_nOffsetInVideoMemory = 0;
    m_nSrcCount = 0;
    m_nDstCount = 0;

    NCGSurf* pSurf = g_pNCGSurfList;
    if (pSurf == NULL) {
        g_pNCGSurfList = this;
    }
    while (pSurf != NULL) {
        if (pSurf->m_pSurfList == NULL) {
            pSurf->m_pSurfList = this;
            break;
        }
        pSurf = pSurf->m_pSurfList;
    }
    m_pSurfList = NULL;
    m_dwSurfaceID = 0;
    m_dwLayerID = 0;
} 


NCGSurf::~NCGSurf()
{
//    DEBUGMSG(1, (TEXT("NCG::~NCG()\r\n")));

    if (m_pHeap) {
        m_pHeap->Free();
    }

    NCGSurf* pCurrSurf = g_pNCGSurfList;
    NCGSurf* pPrevSurf = pCurrSurf;
    while (pCurrSurf != NULL) {
        if (pCurrSurf == this) {
            pPrevSurf->m_pSurfList = pCurrSurf->m_pSurfList;
            break;
        }
        pPrevSurf = pCurrSurf;
        pCurrSurf = pCurrSurf->m_pSurfList;
    }
}


SCODE NCG::DetectPixelFormat(
    DWORD dwCaps,
    DDPIXELFORMAT *pddpf,
    EGPEFormat *pFormat,
    EDDGPEPixelFormat *pPixelFormat )
{
    if (pddpf->dwFlags & DDPF_FOURCC) {
		RETAILMSG(1,
            (TEXT("DetectPixelFormat: Unsupported FourCC 0x%08x.\r\n"), pddpf->dwFourCC));
		return E_INVALIDARG;
    }
    else if (pddpf->dwFlags & DDPF_RGB) {
        if (pddpf->dwRGBBitCount == 1) {
            DEBUGMSG(GPE_ZONE_CREATE,
                (TEXT("DetectPixelFormat: RGB 1bpp.\r\n")));
            *pPixelFormat = ddgpePixelFormat_1bpp;
            *pFormat = gpe1Bpp;
        }
        else if (pddpf->dwRGBBitCount == 8) {
            DEBUGMSG(GPE_ZONE_CREATE,
                (TEXT("DetectPixelFormat: RGB 8bpp.\r\n")));
            *pPixelFormat = ddgpePixelFormat_8bpp;
            *pFormat = gpe8Bpp;
        }
        else if (pddpf->dwRGBBitCount == 16) {
            DEBUGMSG(GPE_ZONE_CREATE,
                (TEXT("DetectPixelFormat: RGB 16bpp.\r\n")));
			if (pddpf->dwFlags & DDPF_ALPHAPIXELS)
	            *pPixelFormat = ddgpePixelFormat_5551;
			else
	            *pPixelFormat = ddgpePixelFormat_565;

            *pFormat = gpe16Bpp;
        }
        else {
            RETAILMSG(1,
                (TEXT("DetectPixelFormat: Unsupported RGB %dbpp.\r\n"), pddpf->dwRGBBitCount));
            return E_INVALIDARG;
        }
    }
    else {
        RETAILMSG(1,
            (TEXT("DetectPixelFormat: Unknown format.\r\n")));
        return E_INVALIDARG;
    }

    return S_OK;
}


void NCG::SetVisibleSurface( GPESurf *pSurf )
{
    DWORD   dwOffset = pSurf->OffsetInVideoMemory();
	int		nPlane = 0;

	DEBUGMSG(1, (TEXT("SetVisibleSurface : 0x%08x\r\n"), NCG_FBBASE + dwOffset));
	m_pDUPnRegs[0][DU_PnDSA0R] = NCG_FBBASE + dwOffset;
	m_pDUPnRegs[0][DU_PnDSA1R] = NCG_FBBASE + dwOffset;

⌨️ 快捷键说明

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