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

📄 utils.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
<module>
* Name         : Utils.c
* Title        : Utility functions
* Author(s)    : Imagination Technologies
* Created      : 2 March 2004
*
* Copyright    : 2004 by Imagination Technologies Limited.
*                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  : Utility function implementations
*
* Platform     : Windows CE
*
</module>
********************************************************************************/

#include "context.h"

/*----------------------------------------------------------------------------
<function>
	FUNCTION:   GetFBStats

	PURPOSE:    Gets total and available framebuffer memory

	PARAMETERS:	
	RETURNS:	void
</function>
------------------------------------------------------------------------------*/
IMG_VOID GetFBStats(IMG_UINT32 *pui32Total, IMG_UINT32 *pui32Available)
{
	DWORD						dwIndex			= 0;
	DWORD						dwNumDevices	= 0;
	IMG_HANDLE					hServicesHandle;
	PVRSRV_DEVICE_IDENTIFIER    asDevId[PVRSRV_MAX_DEVICES];
	PVRSRV_DEV_DATA				sDevData;

	ZeroMemory(&sDevData, sizeof(sDevData));

	/* Connect to Services */
	D3DMServicesConnect(&hServicesHandle);

	/* Enumerate PVRSRV devices	*/
	PVRSRVEnumerateDevices(hServicesHandle, &dwNumDevices, asDevId);

	/* Obtain Display device data object */
	for(dwIndex = 0; dwIndex < dwNumDevices; dwIndex++)
	{
		/* Get class of current device */
		PVRSRV_DEVICE_CLASS eDevClass = asDevId[dwIndex].eDeviceClass;

		if(eDevClass == PVRSRV_DEVICE_CLASS_3D)
		{
			/* Acquire device data for the Display device*/
			if(PVRSRVAcquireDeviceData(hServicesHandle, 
									   dwIndex,
									   &sDevData,
									   PVRSRV_DEVICE_TYPE_UNKNOWN) != PVRSRV_OK)
			{
				D3DM_DPF((DPF_ERROR, "D3DMGetFBStats:Failed to acquire device data!"));
				goto Error_Exit;
			}
		}
	}

	if(PVRSRVGetFBStats(&sDevData, pui32Total, pui32Available) != PVRSRV_OK)
	{
		D3DM_DPF((DPF_ERROR, "D3DMGetFBStats:Failed to get FB stats - setting to 0"));
		*pui32Total = *pui32Available = 0;
	}

	D3DM_DPF((DPF_MESSAGE, "D3DMGetFBStats:Total Bytes = %u - Available bytes = %u", *pui32Total, *pui32Available));

Error_Exit:

	/* clean up and exit */
	if(sDevData.psDevInfoKM != NULL)
		PVRSRVReleaseDeviceData(&sDevData);
	
	/* Disconnect from Services */
	D3DMServicesDisconnect(hServicesHandle);
}
/*----------------------------------------------------------------------------
<function>
	FUNCTION:   GetMBXVersionInfo

	PURPOSE:    Reads MBX revision register

	PARAMETERS:	
	RETURNS:	void
</function>
------------------------------------------------------------------------------*/
IMG_UINT32 GetMBXVersionInfo()
{
	DWORD						dwResult		= -1;
	DWORD						dwIndex			= 0;
	DWORD						dwNumDevices	= 0;
	IMG_HANDLE					hServicesHandle;
	PVRSRV_DEVICE_IDENTIFIER    asDevId[PVRSRV_MAX_DEVICES];
	PVRSRV_DEV_DATA				sDevData;

	ZeroMemory(&sDevData, sizeof(sDevData));

	/* Connect to Services */
	D3DMServicesConnect(&hServicesHandle);

	/* Enumerate PVRSRV devices	*/
	PVRSRVEnumerateDevices(hServicesHandle, &dwNumDevices, asDevId);

	/* Obtain Display device data object */
	for(dwIndex = 0; dwIndex < dwNumDevices; dwIndex++)
	{
		/* Get class of current device */
		PVRSRV_DEVICE_CLASS eDevClass = asDevId[dwIndex].eDeviceClass;

		if(eDevClass == PVRSRV_DEVICE_CLASS_3D)
		{
			/* Acquire device data for the Display device*/
			if(PVRSRVAcquireDeviceData(hServicesHandle, 
									   dwIndex,
									   &sDevData,
									   PVRSRV_DEVICE_TYPE_UNKNOWN) != PVRSRV_OK)
			{
				D3DM_DPF((DPF_ERROR, "GetMBXVersionInfo:Failed to acquire device data!"));
				goto Error_Exit;
			}
		}
	}

	dwResult = ReadHWReg(sDevData.psDevInfoKM->sDevLocation.pvRegsBaseKM, MBX1_GLOBREG_REVISION);

Error_Exit:

	/* clean up and exit */
	if(sDevData.psDevInfoKM != NULL)
		PVRSRVReleaseDeviceData(&sDevData);
	
	/* Disconnect from Services */
	D3DMServicesDisconnect(hServicesHandle);

	return dwResult;
}
/*----------------------------------------------------------------------------
<function>
    
 DESCRIPTION: 	Returns the Current rotation angle of the Window system 			 
 PARAMETERS	: 	
 RETURNS	: 	0,90,270,180
</function>
------------------------------------------------------------------------------*/
IMG_UINT32 GetRotationAngle()
{
	IMG_UINT32 ui32Angle=0;
	HDC hDC;

	hDC = GetDC(NULL);

	ExtEscape(hDC, DRVESC_GET_PHYS_ROTATION, 0, NULL, sizeof(PDWORD), (LPSTR)&ui32Angle);

	ReleaseDC(NULL, hDC);

	switch(ui32Angle)
	{
	case DMDO_0:
	default:
		break;
	case DMDO_90:
		ui32Angle=90;
		break;
	case DMDO_180:
		ui32Angle=180;
		break;
	case DMDO_270:
		ui32Angle=270;
		break;
	}

	return ui32Angle;
}
/*----------------------------------------------------------------------------
<function>
	FUNCTION:   RotateRects
    
 DESCRIPTION: 	Rotates a number of rectangles to current display rotation 			 
 PARAMETERS	: 	
 RETURNS	: 	flag array of fullscreen rects
</function>
------------------------------------------------------------------------------*/
IMG_UINT32 RotateRects(LPD3DM_CONTEXT	psContext, 
					   LPD3DMRECT		psNewRects, 
					   LPD3DMRECT		psRects, 
					   DWORD			dwNumRects,
					   DWORD			dwTargetWidth,
					   DWORD			dwTargetHeight)
{
	IMG_UINT32	i, ui32Fullscreen = 0;
	LPD3DMRECT psRect, psNewRect;
	BOOL		bFullScreen;
	

	for(i=0; i<dwNumRects; i++)
	{
		bFullScreen = FALSE;
		psRect		= &psRects[i];
		psNewRect	= &psNewRects[i];

		switch(psContext->dwRotationAngle)
		{
			case 0:
			{
				/* Is it fullscreen? */
				if((psRect->x1 == 0) && (psRect->x2 >= (int) (dwTargetWidth  - 1)) &&
				   (psRect->y1 == 0) &&	(psRect->y2 >= (int) (dwTargetHeight - 1)))
				{
					bFullScreen = TRUE;
				}
				*psNewRect = *psRect;				
				break;
			}
			case 90:
			{
				/* Is it fullscreen? */
				if((psRect->x1 == 0) && (psRect->x2 >= (int) (dwTargetWidth  - 1)) &&
				   (psRect->y1 == 0) &&	(psRect->y2 >= (int) (dwTargetHeight - 1)))
				{
					bFullScreen = TRUE;
					psNewRect->x2	= psRect->y2;
					psNewRect->y2	= psRect->x2;
					psNewRect->x1	= 0;
					psNewRect->y1	= 0;
				}
				else
				{
					LONG	lUnrotatedWidth, lUnrotatedHeight;

					lUnrotatedWidth		 = psRect->x2 - psRect->x1;
					lUnrotatedHeight	 = psRect->y2 - psRect->y1;
					psNewRect->x1		 = psRect->y1;
					psNewRect->y1		 = dwTargetHeight - psRect->x1 - lUnrotatedWidth;
					psNewRect->x2		 = psNewRect->x1 + lUnrotatedHeight;
					psNewRect->y2		 = psNewRect->y1 + lUnrotatedWidth;
				}					
				break;
			}
			case 180:
			{
				/* Is it fullscreen? */
				if((psRect->x1 == 0) && (psRect->x2 >= (int) (dwTargetWidth  - 1)) &&
				   (psRect->y1 == 0) &&	(psRect->y2 >= (int) (dwTargetHeight - 1)))
				{
					bFullScreen = TRUE;
					*psNewRect = *psRect;	
				}
				else
				{
					psNewRect->x1	 = dwTargetWidth  - psRect->x2;
					psNewRect->y1	 = dwTargetHeight - psRect->y2;
					psNewRect->x2	 = dwTargetWidth  - psRect->x1;
					psNewRect->y2	 = dwTargetHeight - psRect->y1;
				}
				break;			
			}
			case 270:
			{
				/* Is it fullscreen? */
				if((psRect->x1 == 0) && (psRect->x2 >= (int) (dwTargetWidth  - 1)) &&
				   (psRect->y1 == 0) &&	(psRect->y2 >= (int) (dwTargetHeight - 1)))
				{
					bFullScreen = TRUE;
					psNewRect->x2	= psRect->y2;
					psNewRect->y2	= psRect->x2;
					psNewRect->x1	= 0;
					psNewRect->y1	= 0;
				}
				else
				{
					LONG	lUnrotatedWidth, lUnrotatedHeight;

					lUnrotatedWidth  = psRect->x2 - psRect->x1;
					lUnrotatedHeight = psRect->y2 - psRect->y1;
					psNewRect->x1	 = dwTargetWidth - psRect->y1 - lUnrotatedHeight;
					psNewRect->y1	 = psRect->x1;
					psNewRect->x2	 = psNewRect->x1 + lUnrotatedHeight;
					psNewRect->y2	 = psNewRect->y1 + lUnrotatedWidth;
				}
				break;
			}
		}

		if(bFullScreen)
		{
			ui32Fullscreen |= 0x1 << i;
		}
	}	
	return ui32Fullscreen;
}
/*----------------------------------------------------------------------------
<function>
	FUNCTION:   RotateViewportRect
    
 DESCRIPTION: 	Rotates viewport rectangle 			 
 PARAMETERS	: 	
 RETURNS	: fullscreen flag
</function>
------------------------------------------------------------------------------*/
IMG_BOOL RotateViewportRect(LPD3DM_CONTEXT	psContext, 
							LPD3DMRECT		psNewRect, 
							LPD3DMRECT		psRect, 
							DWORD			dwTargetWidth,
							DWORD			dwTargetHeight)
{
	BOOL	bFullScreen = IMG_FALSE;

	dwTargetWidth  -= 1;
	dwTargetHeight -= 1;

	switch(psContext->dwRotationAngle)
	{
		case 0:
		{
			/* Is it fullscreen? */
			if((psRect->x1 == 0) && (psRect->x2 >= (int) dwTargetWidth) &&
			   (psRect->y1 == 0) &&	(psRect->y2 >= (int) dwTargetHeight))
			{
				bFullScreen = TRUE;
			}
			*psNewRect = *psRect;				
			break;
		}
		case 90:
		{
			/* Is it fullscreen? */
			if((psRect->x1 == 0) && (psRect->x2 >= (int) dwTargetHeight ) &&
			   (psRect->y1 == 0) &&	(psRect->y2 >= (int) dwTargetWidth))
			{
				bFullScreen = TRUE;
				psNewRect->x2	= psRect->y2;
				psNewRect->y2	= psRect->x2;
				psNewRect->x1	= 0;
				psNewRect->y1	= 0;
			}
			else
			{
				LONG	lUnrotatedWidth, lUnrotatedHeight;

				lUnrotatedWidth		 = psRect->x2 - psRect->x1;
				lUnrotatedHeight	 = psRect->y2 - psRect->y1;
				psNewRect->x1		 = psRect->y1;
				psNewRect->y1		 = dwTargetHeight - psRect->x1 - lUnrotatedWidth;
				psNewRect->x2		 = psNewRect->x1 + lUnrotatedHeight;
				psNewRect->y2		 = psNewRect->y1 + lUnrotatedWidth;
			}					
			break;
		}
		case 180:
		{
			/* Is it fullscreen? */
			if((psRect->x1 == 0) && (psRect->x2 >= (int) dwTargetWidth) &&
			   (psRect->y1 == 0) &&	(psRect->y2 >= (int) dwTargetHeight))
			{
				bFullScreen = TRUE;
				*psNewRect = *psRect;	
			}
			else
			{
				psNewRect->x1	 = dwTargetWidth  - psRect->x2;
				psNewRect->y1	 = dwTargetHeight - psRect->y2;
				psNewRect->x2	 = dwTargetWidth  - psRect->x1;
				psNewRect->y2	 = dwTargetHeight - psRect->y1;
			}
			break;			
		}
		case 270:
		{
			/* Is it fullscreen? */
			if((psRect->x1 == 0) && (psRect->x2 >= (int) dwTargetHeight ) &&
			   (psRect->y1 == 0) &&	(psRect->y2 >= (int) dwTargetWidth))
			{
				bFullScreen = TRUE;
				psNewRect->x2	= psRect->y2;
				psNewRect->y2	= psRect->x2;
				psNewRect->x1	= 0;
				psNewRect->y1	= 0;
			}
			else
			{
				LONG	lUnrotatedWidth, lUnrotatedHeight;

				lUnrotatedWidth  = psRect->x2 - psRect->x1;
				lUnrotatedHeight = psRect->y2 - psRect->y1;
				psNewRect->x1	 = dwTargetWidth - psRect->y1 - lUnrotatedHeight;
				psNewRect->y1	 = psRect->x1;
				psNewRect->x2	 = psNewRect->x1 + lUnrotatedHeight;
				psNewRect->y2	 = psNewRect->y1 + lUnrotatedWidth;
			}
			break;
		}
	}

	return bFullScreen;
}
/*----------------------------------------------------------------------------
<function>
	FUNCTION:   GetRotatedVertex
    
 DESCRIPTION: 	Rotates a vertex x and y vals to current display rotation 			 
 PARAMETERS	: 	
 RETURNS	: 	flag array of fullscreen rects
</function>
------------------------------------------------------------------------------*/
IMG_VOID GetRotatedVertex(LPD3DM_CONTEXT	psContext, 
						  NTV_TYPE			ntvXin,
						  NTV_TYPE			ntvYin,
						  NTV_TYPE			*pntvXout,
						  NTV_TYPE			*pntvYout,
						  DWORD				dwTargetWidth,
						  DWORD				dwTargetHeight,
						  DWORD				dwRotation)
{
	NTV_TYPE ntvWidth, ntvHeight;
	NTV_TYPE ntvX = ntvXin;
	NTV_TYPE ntvY = ntvYin;

	ntvWidth  = LONG_AS_NTV(dwTargetWidth - 1);
	ntvHeight = LONG_AS_NTV(dwTargetHeight - 1);

	switch(dwRotation)
	{
		case 0:
		{
			*pntvXout = ntvXin;
			*pntvYout = ntvYin;
			break;
		}
		case 90:
		{
			*pntvXout = ntvY;
			*pntvYout = Sub(ntvHeight, ntvX);
			break;	
		}
		case 180:
		{
			*pntvXout = Sub(ntvWidth,  ntvX);
			*pntvYout = Sub(ntvHeight, ntvY);

			break;			
		}
		case 270:
		{
			*pntvXout	 = Sub(ntvWidth, ntvY);
			*pntvYout	 = ntvX;
			break;
		}
	}
}
/*----------------------------------------------------------------------------
<function>
	FUNCTION:   GetCurrentModeDetails

	PURPOSE:    Gets the details of the current Display mode from the supported
				mode list

	PARAMETERS:	
	RETURNS:	void
</function>
------------------------------------------------------------------------------*/
VOID GetCurrentModeDetails()
{
	DWORD						dwResult		= -1;
	DWORD						dwIndex			= 0;
	DWORD						dwNumDevices	= 0;
	IMG_HANDLE					hServicesHandle;
	PVRSRV_DEVICE_IDENTIFIER    asDevId[PVRSRV_MAX_DEVICES];
	PVRSRV_DEV_DATA				sDisplayDevData;
	PVRSRV_PRIMARY_SURF_INFO	sPrimSurfData;
	PVR_DEVFORMAT				*psDevFormat	= NULL;

	ZeroMemory(&sDisplayDevData, sizeof(sDisplayDevData));

	/* Connect to Services */
	D3DMServicesConnect(&hServicesHandle);

⌨️ 快捷键说明

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