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

📄 win32_os.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
字号:
/**************************************************************************
 * Name         : win32_os.c
 * Author       : BCB
 * Created      : 13/08/2003
 *
 * Copyright    : 2003 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.
 *
 * Platform     : ANSI
 *
 * $Date: 2004/10/08 19:03:10 $ $Revision: 1.11 $
 * $Log: win32_os.c $
 **************************************************************************/
#define MODULE_ID MODID_WIN32OS

#include <stdlib.h>
#ifdef UNDER_CE
#include <wtypes.h>
#endif
#include <windows.h>
#include "tstring.h"
#include "ogles_types.h"
#include "services.h"
#include "osglue.h"
#include "debug.h"
#include "modid.h"

static FILE *fOutput;
static IMG_UINT32 ga_ui32TLSIndex[2] = {0xFFFFFFFF,0xFFFFFFFF};

/***********************************************************************************
 Function Name      : GLESServicesConnect
 Inputs             : -
 Outputs            : -
 Returns            : -
 Description        : Connects to PVR Services
************************************************************************************/

PVRSRV_ERROR GLESServicesConnect(IMG_HANDLE *phServices)
{
	return PVRSRVConnect(NULL, phServices);
}

/***********************************************************************************
 Function Name      : GLESMalloc
 Inputs             : -
 Outputs            : -
 Returns            : -
 Description        : Allocates some host memory.
************************************************************************************/

IMG_VOID * GLESMalloc(GLESContext *gc, IMG_UINT32 ui32Size)
{
	return malloc(ui32Size);
}

/***********************************************************************************
 Function Name      : GLESFree
 Inputs             : -
 Outputs            : -
 Returns            : -
 Description        : Frees some memory.
************************************************************************************/

IMG_VOID GLESFree(GLESContext *gc, IMG_VOID *pvAddress)
{
	free(pvAddress);
}

/***********************************************************************************
 Function Name      : GLESCalloc
 Inputs             : -
 Outputs            : -
 Returns            : -
 Description        : Allocates some host memory and clears to 0.
************************************************************************************/

IMG_VOID * GLESCalloc(GLESContext *gc, IMG_UINT32 ui32Size)
{
	return calloc(1, ui32Size);
}

/***********************************************************************************
 Function Name      : GLESRealloc
 Inputs             : -
 Outputs            : -
 Returns            : -
 Description        : Reallocates some host memory
************************************************************************************/

IMG_VOID * GLESRealloc(GLESContext *gc, IMG_VOID *pvAddress, IMG_UINT32 ui32Size)
{
	return realloc(pvAddress, ui32Size);
}


/***********************************************************************************
 Function Name      : ENV_GetTLSValue
 Inputs             : uTLS_ID - The ID of the TLS slot to return
 Outputs            : -
 Returns            : The value from thread local storage, as a void*
 Description        : Gets a value from thread local storage
************************************************************************************/
IMG_VOID* ENV_GetTLSValue(IMG_UINT uTLS_ID)
{
	if(ga_ui32TLSIndex[uTLS_ID] == (IMG_UINT32) -1)
	{
		ga_ui32TLSIndex[uTLS_ID] = TlsAlloc();
	}

	return(TlsGetValue(ga_ui32TLSIndex[uTLS_ID]));

}

/***********************************************************************************
 Function Name      : ENV_SetTLSValue
 Inputs             : uTLS_ID - The ID of the TLS slot to set, psA - the value to set
 Outputs            : -
 Returns            : IMG_TRUE, if successful
 Description        : Sets a value in thread local storage
************************************************************************************/
IMG_BOOL ENV_SetTLSValue(IMG_UINT uTLS_ID, IMG_VOID *pvA)
{
	if(ga_ui32TLSIndex[uTLS_ID] == (IMG_UINT32) -1)
	{
		ga_ui32TLSIndex[uTLS_ID] = TlsAlloc();
	}

	if(TlsSetValue(ga_ui32TLSIndex[uTLS_ID], pvA) != 0)
		return IMG_TRUE;
	
	return IMG_FALSE;
}

/***********************************************************************************
 Function Name      : GLESTimeNow
 Inputs             : gc
 Outputs            : -
 Returns            : Time
 Description        : Unsigned int value being the current 32bit clock tick with ref
					  to the CPU Speed.
************************************************************************************/

IMG_UINT32 GLESTimeNow(GLESContext *gc)
{
	static IMG_UINT32 ui32Time;

#if defined (MSVC_IA32) || (defined( UNDER_CE ) && defined( _X86_ ))
	__asm
		{
			push	eax
			push	edx

			_emit 0Fh
			_emit 31h	

			shrd	eax, edx, 4

			mov		ui32Time, eax
			pop		edx
			pop		eax
		}
#else

	static IMG_BOOL bFirstTime = IMG_TRUE;
	LARGE_INTEGER sTime;
	if (bFirstTime)
	{
		DPF ((DBG_WARNING, "GLESTimeNow: using QueryPerformanceCounter"));
		bFirstTime = IMG_FALSE;
	}
	QueryPerformanceCounter(&sTime);
	return sTime.LowPart;

#endif

	return ui32Time;
}


/***********************************************************************************
 Function Name      : GLESGetCPUFreq
 Inputs             : gc
 Outputs            : -
 Returns            : Float value being the CPU frequency.
 Description        : Gets the CPU frequency
************************************************************************************/

IMG_FLOAT GLESGetCPUFreq(GLESContext *gc)
{
	LARGE_INTEGER sAccFreq;
	IMG_FLOAT fTPS;

#if defined (MSVC_IA32) || (defined( UNDER_CE ) && defined( _X86_ ))
	static IMG_UINT32 ui32Time1, ui32Time2;
	IMG_UINT32 ui32AccTime;
	LARGE_INTEGER sAccClock1, sAccClock2;

	QueryPerformanceCounter( &sAccClock1);
	ui32Time1 = GLESTimeNow(gc);
	GLESSleep(1000);
	ui32Time2 = GLESTimeNow(gc);
	QueryPerformanceCounter( &sAccClock2);
	
	QueryPerformanceFrequency( &sAccFreq );
	
	ui32Time1 = (ui32Time2 - ui32Time1);
	ui32AccTime = ( sAccClock2.LowPart - sAccClock1.LowPart);
	fTPS = (IMG_FLOAT)ui32Time1 / ((IMG_FLOAT)ui32AccTime/(IMG_FLOAT)(sAccFreq.LowPart));
	if ( ui32Time1 != 0 ) 
		return fTPS;
	else
		return 1.0f;
#else
	QueryPerformanceFrequency( &sAccFreq );
	fTPS = (IMG_FLOAT)sAccFreq.LowPart;
	return fTPS;
#endif
}

/***********************************************************************************
 Function Name      : GLESSleep
 Inputs             : ui32MilliSeconds
 Outputs            : -
 Returns            : -
 Description        : Relinquish the time slice for a specified amount of time
************************************************************************************/

IMG_VOID GLESSleep(IMG_UINT32 ui32MilliSeconds)
{
	Sleep(ui32MilliSeconds);
}

/***********************************************************************************
 Function Name      : GLESInitProfileOutput
 Inputs             : gc
 Outputs            : -
 Returns            : -
 Description        : Inits the profile output file
************************************************************************************/
IMG_VOID GLESInitProfileOutput(GLESContext *gc)
{
	WCHAR szCaller[256];
	WCHAR szTemp[256];

	if (GetModuleFileName (NULL, szCaller, sizeof (szCaller)))
	{
		WCHAR *pExe = wcsrchr(szCaller, '\\');
		WCHAR *pExtension;

		if (pExe)
		{
			pExe++;
		}
		else
		{
			pExe = szCaller;
		}

		pExtension = wcsrchr(pExe, '.');
		if(pExtension)
			pExtension[0] = 0;

		wcscat(pExe, TEXT("_profile.txt"));
		wcscpy(szTemp, TEXT("release\\"));
		wcscat(szTemp, pExe);

		fOutput = _wfopen(szTemp,TEXT("w"));
	}
	else
	{
		/* Default filename if we can't get the app name */
		fOutput = _wfopen(TEXT("release\\profile.txt"),TEXT("w"));
	}
	
}

/***********************************************************************************
 Function Name      : GLESDeInitProfileOutput
 Inputs             : gc
 Outputs            : -
 Returns            : -
 Description        : Ends the profile output file by closing it
************************************************************************************/
IMG_VOID GLESDeInitProfileOutput(GLESContext *gc)
{
	fclose(fOutput);
}

/***********************************************************************************
 Function Name      : GLESProfileOutput
 Inputs             : gc, psString
 Outputs            : -
 Returns            : -
 Description        : Prints the string to the profile file and to the console
************************************************************************************/
IMG_VOID GLESProfileOutput(GLESContext *gc, IMG_CHAR *psString)
{
	fprintf(fOutput, "%s", psString);
#ifndef UNICODE
	OutputDebugString(psString);
#else
	{
		TCHAR szUnicodeBuffer[256];
		ASCIITOTSTR( szUnicodeBuffer, psString, 256 );
		OutputDebugString(szUnicodeBuffer);
	}
#endif
}

⌨️ 快捷键说明

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