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

📄 surf.cpp

📁 三星ARM9系列CPU S3C2440A的WINCE 5.0下的BSP
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
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.

Module Name:    surface allocation/manipulation/free routines

Abstract:

Functions:


Notes:


--*/

#include "precomp.h"

SCODE
S3C2440DISP::AllocSurface(
    GPESurf    ** ppSurf,
    int           width,
    int           height,
    EGPEFormat    format,
    int           surfaceFlags
    )
{
    DEBUGMSG (GPE_ZONE_INIT, (L"AllocSurface without pixelFormat\n"));

    if ((surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY) || (format == m_pMode->format) && (surfaceFlags & GPE_PREFER_VIDEO_MEMORY))
    {
        if (!(format == m_pMode->format))
        {
            RETAILMSG (1, (L"AllocSurface - Invalid format value\n"));
            return E_INVALIDARG;
        }

        // Attempt to allocate from video memory
        Node2D *pNode = m_p2DVideoMemory->Alloc(width, height);
        if (pNode)
        {
            ULONG offset = (m_cbScanLineLength * pNode->Top()) + ((pNode->Left() * EGPEFormatToBpp[format]) / 8);
            *ppSurf = new S3C2440DISPSurf(width, height, offset, (PVOID)(m_VirtualFrameBuffer + offset), m_cbScanLineLength, format, pNode);
            if (!(*ppSurf))
            {
                pNode->Free();
                RETAILMSG (1, (L"AllocSurface - Out of Memory 1\n"));
                return E_OUTOFMEMORY;
            }
            return S_OK;
        }

        if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
        {
            *ppSurf = (GPESurf *)NULL;
            RETAILMSG (1, (L"AllocSurface - Out of Memory 2\n"));
            return E_OUTOFMEMORY;
        }
    }

    if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
    {
        *ppSurf = (GPESurf *)NULL;
        RETAILMSG (1, (L"AllocSurface - Out of Memory 3\n"));
        return    E_OUTOFMEMORY;
    }

    // Allocate from system memory
    RETAILMSG(0, (TEXT("Creating a GPESurf in system memory. EGPEFormat = %d\r\n"), (int) format));
    *ppSurf = new GPESurf(width, height, format);
    if (*ppSurf != NULL)
    {
        // check we allocated bits succesfully
        if (((*ppSurf)->Buffer()) == NULL)
        {
            delete *ppSurf;
        }
        else
        {
            return    S_OK;
        }
    }

    RETAILMSG (1, (L"AllocSurface - Out of Memory 4\n"));
    return E_OUTOFMEMORY;
}


SCODE 
S3C2440DISP::AllocSurface(
    DDGPESurf         ** ppSurf,
    int                  width,
    int                  height,
    EGPEFormat           format,
    EDDGPEPixelFormat    pixelFormat,
    int                  surfaceFlags
    )
{
    if ((surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY) || (format == m_pMode->format) && (surfaceFlags & GPE_PREFER_VIDEO_MEMORY))
    {
        if (!(format == m_pMode->format))
        {
            RETAILMSG (1, (L"AllocSurface - Invalid format value\n"));
            return E_INVALIDARG;
        }

        // Attempt to allocate from video memory
        Node2D *pNode = m_p2DVideoMemory->Alloc(width, height);
        if (pNode)
        {
            ULONG offset = (m_cbScanLineLength * pNode->Top()) + ((pNode->Left() * EGPEFormatToBpp[format]) / 8);
            *ppSurf = new S3C2440DISPSurf(width, height, offset, (PVOID)(m_VirtualFrameBuffer + offset), m_cbScanLineLength, format, pixelFormat, pNode);
            if (!(*ppSurf))
            {
                pNode->Free();
                RETAILMSG (1, (L"AllocSurface - Out of Memory 1\n"));
                return E_OUTOFMEMORY;
            }

            return S_OK;
        }

        if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
        {
            *ppSurf = (DDGPESurf *)NULL;
            RETAILMSG (1, (L"AllocSurface - Out of Memory 2\n"));
            return E_OUTOFMEMORY;
        }
    }

    if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
    {
        *ppSurf = (DDGPESurf *)NULL;
        RETAILMSG (1, (L"AllocSurface - Out of Memory 3\n"));
        return E_OUTOFMEMORY;
    }

    // Allocate from system memory
    RETAILMSG(0, (TEXT("Creating a GPESurf in system memory. EGPEFormat = %d\r\n"), (int) format));
    {
        DWORD bpp  = EGPEFormatToBpp[format];
        DWORD stride = ((bpp * width + 31) >> 5) << 2;
        DWORD nSurfaceBytes = stride * height;

        *ppSurf = new DDGPESurf(width, height, stride, format, pixelFormat);
    }

    if (*ppSurf != NULL)
    {
        // check we allocated bits succesfully
        if (((*ppSurf)->Buffer()) == NULL)
        {
            delete *ppSurf;
        }
        else
        {
            return    S_OK;
        }
    }

    RETAILMSG (1, (L"AllocSurface - Out of Memory 4\n"));
    return E_OUTOFMEMORY;
}


void
S3C2440DISP::SetVisibleSurface(
    GPESurf * pTempSurf,
    BOOL      bWaitForVBlank
    )
{
    S3C2440DISPSurf *pSurf = (S3C2440DISPSurf *) pTempSurf;
}

S3C2440DISPSurf::S3C2440DISPSurf(
    int          width,
    int          height,
    ULONG        offset,
    void       * pBits,
    int          stride,
    EGPEFormat   format,
    Node2D     * pNode
    ) : DDGPESurf (width, height, pBits, stride, format)
{
    m_pNode2D              = pNode;
    m_fInVideoMemory       = FALSE;
    m_nOffsetInVideoMemory = offset;
}

S3C2440DISPSurf::S3C2440DISPSurf(
    int                 width,
    int                 height,
    ULONG               offset,
    void              * pBits,
    int                 stride,
    EGPEFormat          format,
    EDDGPEPixelFormat   pixelFormat,
    Node2D            * pNode
    ) : DDGPESurf (width, height, pBits, stride, format, pixelFormat)
{
    m_pNode2D              = pNode;
    m_fInVideoMemory       = FALSE;
    m_nOffsetInVideoMemory = offset;
}

S3C2440DISPSurf::~S3C2440DISPSurf()
{
    m_pNode2D->Free();
}

⌨️ 快捷键说明

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