surf.cpp

来自「S3C24A0的完整BSP包,对开发此芯片的开发者很有用.」· C++ 代码 · 共 209 行

CPP
209
字号
//
// 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
S3C24A0DISP::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 S3C24A0Surf(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;
}


#ifdef	DD_ENABLE
SCODE 
S3C24A0DISP::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 S3C24A0Surf(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];
		LONG align = 8; // quadword aligned
		DWORD alignedWidth = ((width + align - 1) & (- align));
		DWORD nSurfaceBytes = (bpp * (alignedWidth * height)) / 8;
		DWORD stride = ((alignedWidth * bpp) / 8);

		*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;
}
#endif	// DD_ENABLE

#ifdef	DD_ENABLE
void
S3C24A0DISP::SetVisibleSurface( GPESurf *pTempSurf, BOOL bWaitForVBlank)
{
    S3C24A0Surf *pSurf = (S3C24A0Surf *) pTempSurf;

//	if(bWaitForVBlank)
//	{
//		WAIT_FOR_VBLANK;
//	}

//	// set CRT memory offset without changing CRT pitch
//	_memwD_reg(CRTC_OFF_PITCH, (_memrD_reg(CRTC_OFF_PITCH) & 0xffc00000) | ((pSurf->Stride() * pSurf->Top()) >> 3));
}
#endif	// DD_ENABLE

S3C24A0Surf::S3C24A0Surf(int width, int height, ULONG offset, PVOID pBits, int stride, EGPEFormat format, Node2D *pNode)
#ifdef	DD_ENABLE
	: DDGPESurf (width, height, pBits, stride, format)
#else	// DD_ENABLE
	: GPESurf(width, height, pBits, stride, format)
#endif	// DD_ENABLE
{
	m_pNode2D = pNode;
	m_fInVideoMemory = FALSE;
	m_nOffsetInVideoMemory = offset;
}

#ifdef	DD_ENABLE
S3C24A0Surf::S3C24A0Surf(int width, int height, ULONG offset, PVOID 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;
}
#endif

S3C24A0Surf::~S3C24A0Surf(void)
{
	m_pNode2D->Free();
}

⌨️ 快捷键说明

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