📄 surf.cpp
字号:
/***************************************************************************
* Name : surf.cpp
* Title : MBX WinCE driver
* Author(s) : Imagination Technologies
* Created : 2nd January 2003
*
* Copyright : 2003 by Imagination Technologies. All rights reserved.
* : No part of this software, either material or conceptual
* : may be copied or distributed, transmitted, transcribed,
* : stored in a retrieval system or translated into any
* : human or computer language in any form by any means,
* : electronic, mechanical, manual or other-wise, or
* : disclosed to third parties without the express written
* : permission of Imagination Technologies Limited, Unit 8,
* : HomePark Industrial Estate, King's Langley, Hertfordshire,
* : WD4 8LZ, U.K.
*
* Description : MBX WinCE driver.
*
* Platform : WinCE
*
* Modifications:-
* $Log: surf.cpp $
*
****************************************************************************/
#include "precomp.h"
SCODE
MBX::AllocSurface(GPESurf **ppclSurf, INT nWidth, INT nHeight, EGPEFormat eFormat, INT nSurfaceFlags)
{
BOOL bSecondarySurface=FALSE;
*ppclSurf = NULL;
#if defined ROTATE_ENABLE && (_WINCEOSVER < 500)
m_pvMostRecentAllocSurfaceAddr = 0;
m_psMostRecentMBXSurf = 0;
#endif
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryEnable(m_sDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
if ( nSurfaceFlags & (GPE_REQUIRE_VIDEO_MEMORY|GPE_PREFER_VIDEO_MEMORY) )
{
ULONG ulBpp = EGPEFormatToBpp[eFormat];
ULONG ulStride = ((nWidth * ulBpp) + 7) >> 3; /* Round up to next byte boundry */
ULONG ulSize = ulStride * nHeight;
ULONG ulFBOptions;
ULONG ulAlign = MBX1_TSPPL2_TEXADDRALIGNSIZE;
/* Secret secondary surface */
if ( (m_eSecondarySurfaceState == eSurfRequested)
&& (m_wSecondSurfWidth == (WORD)nWidth)
&& (m_wSecondSurfHeight == (WORD)nHeight) )
{
/* this is the secret secondary surface */
bSecondarySurface=TRUE;
ulAlign = 1024*4; /* set the alignment to 4k */
nSurfaceFlags |= GPE_REQUIRE_VIDEO_MEMORY;
}
if ((nSurfaceFlags & GPE_REQUIRE_VIDEO_MEMORY))
{
ulFBOptions = m_ulReqFBStrategy;
}
else
{
ulFBOptions = m_ulPrefFBStrategy;
}
/* Attempt to allocate from video memory */
MemNode *pclNode = new MemNode (ulSize,
&m_sDevData,
ulAlign,
ulFBOptions);
/* Did the alloc succeed ? */
if (pclNode && pclNode->m_psDevMemHandle)
{
/* New surface with no rotation */
*ppclSurf = new MBXSurf(nWidth, nHeight, ulStride, eFormat, pclNode, 0);
if (bSecondarySurface)
{
m_pclSecondarySurface = (MBXSurf*)*ppclSurf;
m_eSecondarySurfaceState = eSurfAllocated;
m_wSecondSurfStride = (IMG_UINT16) ulStride;
m_psSecondaryMemInfo = pclNode->m_psDevMemHandle;
m_wSecondSurfBPP = EGPEFormatToBpp[eFormat];
}
}
if (*ppclSurf)
{
/* Success */
m_cl2DMemNodes.AddToDevMemList(pclNode);
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryDisable(m_sDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
return (S_OK);
}
else if (nSurfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
{
/* Failure, the caller wanted video memory so we can't try system memory */
RETAILMSG (1, (L"AllocSurface - Out of Memory 3"));
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryDisable(m_sDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
return (E_OUTOFMEMORY);
}
/* else fall through and try system memory .... */
}
/* Allocate from system memory */
RETAILMSG(0, (L"Creating a GPESurf in system memory. EGPEFormat = %d", (int) eFormat));
*ppclSurf = new GPESurf(nWidth, nHeight, eFormat);
if (*ppclSurf)
{
/* check we allocated bits succesfully */
if ((*ppclSurf)->Buffer())
{
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryDisable(m_sDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
return (S_OK);
}
else
{
delete *ppclSurf;
}
}
RETAILMSG (1, (L"AllocSurface - Out of Memory 4"));
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryDisable(m_sDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
return (E_OUTOFMEMORY);
}
MBXSurf::MBXSurf(INT nWidth, INT nHeight, INT nStride, EGPEFormat eFormat, MemNode *pclNode, LONG lRotate)
#if defined (ROTATE_ENABLE)
: GPESurfRotate(nWidth, nHeight, pclNode->m_psDevMemHandle->pvLinAddr, nStride, eFormat)
#else
: GPESurf(nWidth, nHeight, pclNode->m_psDevMemHandle->pvLinAddr, nStride, eFormat)
#endif
{
m_pclMemNode = pclNode;
m_fInVideoMemory = TRUE;
m_bIsRotated = FALSE;
m_lRotationAngle = 0;
#if defined (ROTATE_ENABLE)
SetRotation (nWidth, nHeight, DMDO_0);
#endif
m_pclMemNode->m_pclSurf = this;
}
MBXSurf::MBXSurf(int nWidth, int nHeight, void *pvBits, int nStride, EGPEFormat eFormat)
#if defined (ROTATE_ENABLE)
: GPESurfRotate(nWidth, nHeight, pvBits, nStride, eFormat)
#else
: GPESurf(nWidth, nHeight, pvBits, nStride, eFormat)
#endif
{
m_pclMemNode = NULL;
m_fInVideoMemory = TRUE;
m_bIsRotated = FALSE;
m_lRotationAngle = 0;
}
MBXSurf::~MBXSurf(void)
{
if (m_pclMemNode)
{
MBX *pclGpeDriver = (MBX*)GetGPE();
if ((pclGpeDriver->m_psSecondaryMemInfo) &&
((DWORD)pclGpeDriver->m_psSecondaryMemInfo->pvLinAddr == (DWORD)m_pclMemNode->m_psDevMemHandle->pvLinAddr))
{
if(pclGpeDriver->m_eSecondarySurfaceState == eSurfAllocated)
{
// fine just let the delete go though ok
pclGpeDriver->m_eSecondarySurfaceState = eSurfFree;
}
else
{
// we should tell the driver to restort to a sensible state!
pclGpeDriver->m_eSecondarySurfaceState = eSurfFree;
}
}
/*
* Before we delete this node, wait for any outstanding accelerated blits to complete
* Sometimes, large blits are still running when this function is called
* See PRM 584
*/
pclGpeDriver->SyncWithHost();
delete m_pclMemNode;
}
}
/* The OS calls this to see if our surface is rotated : */
BOOL MBXSurf::IsRotate()
{
return m_bIsRotated;
}
/********************************** end of file ******************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -