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

📄 surf.cpp

📁 SMDK2416_BSP
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// 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"

#define DBGLCD	0
#define DBGLCD1	0

static UINT nCount = 0;

UINT32 saved_x;
UINT32 saved_y;
UINT32 saved_width;
UINT32 saved_height;

//  This method is used to allocate DirectDraw enabled surfaces
SCODE	S3C2450DISP::AllocSurface(DDGPESurf **ppSurf, int width, int height, 
					EGPEFormat format, EDDGPEPixelFormat pixelFormat, int surfaceFlags)
{
	SCODE sc = S_OK;
	DWORD pa;
#if 1
	DWORD 	bpp  	= EGPEFormatToBpp[format];
	LONG 	align 	= m_nSurfaceBitsAlign / 8;
    	DWORD 	alignedWidth = ((width + align - 1) & (- align));
    	DWORD 	nSurfaceSize = (bpp * (alignedWidth * height)) / 8;
#endif
	ULONG stride = (width * EGPEFormatToBpp[format] + 7) >> 3;
	ULONG size = stride * height;//MulDiv(stride, height, 1);

	if(width == 0)
		RETAILMSG(1, (TEXT("WidthSave = %d, HeightSave = %d"), m_nScreenWidthSave, m_nScreenHeightSave));

	RETAILMSG(DBGLCD, (TEXT("AllocSurface DirectDraw, surfaceFlags = %d, f = %d, m_pMode->format = %d , pF = %d\r\n"), surfaceFlags, format, m_pMode->format , pixelFormat));
	RETAILMSG(DBGLCD, (TEXT("align = %d, alignedwidth = %d, surfacesize = %d, height = %d, width = %d stride = %d\r\n"), align, alignedWidth, nSurfaceSize, height, width, stride));


	// Is video memory required/prefered?
	//apart from the primary and directdraw surfaces, all others are 
	//allocated in system memory
	if (/*(surfaceFlags & GPE_BACK_BUFFER) ||*/
        	(surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY) || 
        	((surfaceFlags & GPE_PREFER_VIDEO_MEMORY) && (format == m_pMode->format)))
	{		
		if (size == -1) 
		{
	    		return E_OUTOFMEMORY;
		}
		/*if(surfaceFlags & GPE_BACK_BUFFER)
			RETAILMSG(DBGLCD, (TEXT("BB -------------- In BackBuffer alloc -----\r\n")));*/

		// Attempt to allocate from internal SRAM
		SurfaceHeap *pHeap = m_pVideoMemoryHeap->Alloc(size);

		if (pHeap != NULL) 
		{
			RETAILMSG(DBGLCD, (TEXT("pHeap->Address() = 0x%x, pHeap = 0x%x, remains = 0x%x, size = 0x%x\r\n"), pHeap->Address(), pHeap, m_pVideoMemoryHeap->Available(), m_pVideoMemoryHeap->Size()));		
			// We get memory in SRAM, build surface there			
			pa  = pHeap->Address() - (DWORD)m_VirtualFrameBuffer/* + IMAGE_FRAMEBUFFER_DMA_BASE*/;
			
			RETAILMSG(DBGLCD, (TEXT("---------------------> pa = 0x%x\r\n"), pa));
			if ((*ppSurf = new S3C2450Surf(width, height, pa, (VOID*)pHeap->Address(),
				stride, format, pixelFormat, pHeap)) == NULL)
			{
			    	// When allocation failed, we are out of memory...
			    	RETAILMSG(DBGLCD, (TEXT("--------------------> Failed allocating memory for S3C2450Surf --------------------------\r\n")));
			    	pHeap->Free();
			    	return E_OUTOFMEMORY;
			}

			// We are done
			RETAILMSG(DBGLCD, (TEXT("--------------------> Succeeded allocating memory for S3C2450Surf --------------------------\r\n")));
			return S_OK;
		}
		RETAILMSG(DBGLCD, (TEXT("Surface Heap size is not enough to allocation requested surface\r\n")));				
		if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
		{
		    	*ppSurf = (DDGPESurf *)NULL;
		    	return E_OUTOFMEMORY;
		}
	}

	if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
	{
	    	*ppSurf = (DDGPESurf *)NULL;
	    	return  E_OUTOFMEMORY;
	}

	RETAILMSG(DBGLCD, (TEXT("* Allocating surface in system memory DD*\r\n")));
    	*ppSurf = new DDGPESurf(width, height, stride, format, pixelFormat);
#if 0	//{		
	if (*ppSurf == NULL || (*ppSurf)->Buffer() == NULL) 
	{
	    	RETAILMSG(DBGLCD, (L"ERROR: S3C2450Surf::AllocSurface: Failed allocate surface (width: %d, height: %d, format %d)\r\n", width, height, format));
	    	delete *ppSurf;
	    	*ppSurf = NULL;
	    	sc = E_OUTOFMEMORY;
	    	goto cleanUp;
	}
#else
	if (*ppSurf != NULL)
    	{
		// check we allocated bits succesfully
		if ( (*ppSurf)->Buffer() == NULL)
		{
		    	delete *ppSurf;
		    	ppSurf = NULL;
		}
		else
		{
			// We are done
			RETAILMSG(DBGLCD, (L"S3C2450Surf::AllocSurface: Surface in memory (width: %d, height: %d, format %d, 0x%08x)\r\n",
	    			width, height, format, (*ppSurf)->Buffer()));
		    	return  S_OK;
		}
	}
#endif	//}

		return E_OUTOFMEMORY;

}

/*
SCODE S3C2450DISP::AllocSurface(DDGPESurf **ppSurf, int width, int height, EGPEFormat format, EDDGPEPixelFormat pixelFormat, int surfaceFlags)
{
	RETAILMSG(DBGLCD, (TEXT("AllocSurface DirectDraw, surfaceFlags = %d, f = %d, m_pMode->format = %d , pF = %d\r\n"), surfaceFlags, format, m_pMode->format , pixelFormat));
	RETAILMSG(DBGLCD, (TEXT("height = %d, width = %d\r\n"), height, width));

    if ((surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY) || (format == m_pMode->format) && (surfaceFlags & GPE_PREFER_VIDEO_MEMORY))
    {
        // Attempt to allocate from video memory

        WORD bytepp = (EGPEFormatToBpp[format]/8);
        ulong stride = ((width+7)&~0x7)*bytepp;        
        ulong heapsize = MulDiv (stride, height, 1);
        if (heapsize == -1)
        {
            return E_OUTOFMEMORY;       // overflow
        }

        SurfaceHeap *pHeap = m_pVideoMemoryHeap->Alloc(heapsize);
        if (pHeap)
        {
            *ppSurf = new S3C2450Surf ( width, height,
                                    (DWORD)pHeap->Address() - (DWORD)m_VirtualFrameBuffer,
                                    (void*)pHeap->Address(),
                                    stride,
                                    format,
                                    pixelFormat,
                                    pHeap);

            if (!(*ppSurf))
            {
                pHeap->Free();
                return E_OUTOFMEMORY;
            }
            return S_OK;
        }

        if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
        {
            *ppSurf = (DDGPESurf *)NULL;
            return E_OUTOFMEMORY;
        }
    }

    if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
    {
        *ppSurf = (DDGPESurf *)NULL;

        return  E_OUTOFMEMORY;
    }

    // Allocate from system memory
    RETAILMSG(1, (TEXT("Creating a GPESurf in system memory DDDD. 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;
        }
    }

    return E_OUTOFMEMORY;
}
*/

//  This method is called for all normal surface allocations from ddgpe and gpe
SCODE S3C2450DISP::AllocSurface(GPESurf **ppSurf, INT width, INT height, EGPEFormat format, INT surfaceFlags)
{
	SCODE sc = S_OK;
	
	ULONG stride = (width * EGPEFormatToBpp[format] + 7) >> 3;
#if USE_PACSURF	
	/// Only Support 16bpp, 24bpp, 32bpp
	if(  ( (format == gpe16Bpp || format == gpeDeviceCompatible)
#if G2D_BLT_OPTIMIZE	
	         && (width*height*2 > PAC_ALLOCATION_BOUNDARY) 
#endif
	         )
	||
	      ( (format == gpe24Bpp || format == gpe32Bpp)
#if G2D_BLT_OPTIMIZE	      
	      	&& (width*height*4 > PAC_ALLOCATION_BOUNDARY )
#endif	      	
	      	)
	      	) 
	{
		/// try to allocate physically linear address
			*ppSurf = new PACSurf(width, height, format);
		
		if (*ppSurf == NULL)
		{
			RETAILMSG(1,(_T("\n[DISPDRV:ERR] AllocSurface() : PACSurface allocate Failed -> Try to allocate Normal GPE Surface")));
		}
		else if ((*ppSurf)->Buffer() == NULL)
		{
			delete *ppSurf;
			*ppSurf = NULL;

			RETAILMSG(1,(_T("\n[DISPDRV:ERR] AllocSurface() : PACSurface Buffer is NULL -> Try to allocate Normal GPE Surface")));
		}

⌨️ 快捷键说明

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