📄 mbxmain.cpp
字号:
/***************************************************************************
* Name : mbxmain.cpp
* Title : MBX WinCE driver GPE class
* 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 GPE class.
*
* Platform : WinCE
*
* Modifications:-
* $Log: mbxmain.cpp $
*
* --- Revision Logs Removed ---
*
* --- Revision Logs Removed ---
*
* --- Revision Logs Removed ---
*
* --- Revision Logs Removed ---
*
* --- Revision Logs Removed ---
*
* --- Revision Logs Removed ---
*
* --- Revision Logs Removed ---
*
****************************************************************************/
#include "precomp.h"
#ifdef SUPPORT_CLEARTYPE
#include <ctblt.h>
#endif // SUPPORT_CLEARTYPE
#include <aablt.h>
// profiling
#include "dispperf.h"
// mbx power management
#include "power.h"
/*
* global variables ----------------------------------------------------------
*/
INSTANTIATE_PVR_ZONES(PVR_MESSAGE_MASK,"MBX Driver"); // Start with errors and warnings
MBX *g_pclGPE = (MBX *)NULL;
// Calls debugger if hardware locks up
#define ENABLE_TIMEOUT 0 // Set to 1 to enable, 0 to disable
#if ENABLE_TIMEOUT
DWORD dwTimeout=100;
#endif
/*
* function prototypes -------------------------------------------------------
*/
// This prototype avoids problems exporting from .lib
BOOL APIENTRY GPEEnableDriver(ULONG ulEngineVersion, ULONG ulCj, DRVENABLEDATA *psData,
PENGCALLBACKS psEngineCallbacks);
// GWES will invoke this routine once prior to making any other calls into the driver.
// This routine needs to save its instance path information and return TRUE. If it
// returns FALSE, GWES will abort the display initialization.
BOOL APIENTRY
DisplayInit(LPCTSTR pszInstance, ULONG ulNumMonitors)
{
//////////DPFINFO((L"MBX: display instance '%s', num monitors %d\r",
//// pszInstance != NULL ? pszInstance : L"<NULL>", ulNumMonitors));
// Initialize our dynamic system memory access.
return (InitializeSystemMem());
}
#ifdef DRV_VERIFIABLE
/*****************************************************************************
FunctionName : InitDrvVerification
Inputs : pDrvVerify points to callers buffer to be filled by file contents
Outputs :
Returns :
Globals used :
Description : Enables the driver to be verified by the test system by loading overrides
*****************************************************************************/
static BOOL InitDrvVerification(PDRV_VERIFY pDrvVerify)
{
HANDLE hFile;
BOOL bOK;
ULONG ulBytesread;
/* Open file */
hFile = CreateFile (DRV_VERIFY_FILENAME, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
// Normally this file will not exist and so the settings would be read from the registry.
if (hFile != INVALID_HANDLE_VALUE)
{
DPFINFO((L"--- Driver Verification file opened"));
bOK = ReadFile(hFile, pDrvVerify, sizeof(DRV_VERIFY), &ulBytesread, NULL);
// Close the file here before doing anything else */
CloseHandle(hFile);
// Open it and read the ATS data which should have survived a reboot
if ( !bOK || (ulBytesread != sizeof(DRV_VERIFY)) )
{
DPFINFO((L"Failed to read %d bytes from file",sizeof(DRV_VERIFY)));
}
else if (pDrvVerify->ui32StructSize != sizeof(DRV_VERIFY))
{
DPFINFO((L"DRV_VERIFY Structure size mismatch"));
}
else
{
return TRUE; // pDrvVerify has been initialised.
}
}
// Error, so NULL out the structure.
memset(pDrvVerify,0,sizeof(DRV_VERIFY));
return FALSE;
}
#endif//#ifdef DRV_VERIFIABLE
BOOL APIENTRY DrvEnableDriver(ULONG ulEngineVersion, ULONG ulCj, DRVENABLEDATA *psData,
PENGCALLBACKS psEngineCallbacks)
{
BOOL bRtn;
pfnGetAAMaskBits = NULL;
if (!InitializeSystemMem())
{
return (FALSE); // failure
}
bRtn = GPEEnableDriver(ulEngineVersion, ulCj, psData, psEngineCallbacks);
pfnMSDrvGradientFill = psData->DrvGradientFill;
psData->DrvGradientFill = &MBXDrvGradientFill;
#ifdef ENABLE_2D_PROFILE
memset(gProfile, 0, sizeof(gProfile));
#endif
return(bRtn);
}
typedef struct _DDHALINFO_ *LPDDHALINFO;
EXTERN_C BOOL PVRHALInit ( LPDDHALINFO psHALInfo, BOOL bReset, ULONG ulModeIndex );
EXTERN_C BOOL HALInit ( LPDDHALINFO psHALInfo, BOOL bReset, ULONG ulModeIndex )
{
#ifdef INCLUDE_DXHAL
return PVRHALInit ( psHALInfo, bReset, ulModeIndex );
#else
return FALSE;
#endif
}
#ifdef D3DM_REMOTE_HOOK
typedef struct _D3DM_INITIALIZE_DATA_ *LPD3DM_INITIALIZE_DATA;
EXTERN_C DWORD PVRD3DM_Initialize(LPD3DM_INITIALIZE_DATA *pid);
EXTERN_C DWORD D3DM_Initialize(LPD3DM_INITIALIZE_DATA *pid)
{
return PVRD3DM_Initialize(pid);
}
#endif // D3DM_REMOTE_HOOK
void RegisterDDHALAPI(void)
{
; // DDHAL wrapper not required for new-style DDI/DDHAL
}
//
// Main entry point for a GPE-compliant driver
//
GPE *GetGPE(void)
{
if (!g_pclGPE)
{
g_pclGPE = new MBX();
}
return g_pclGPE;
}
MBX::MBX (void)
{
DPFX(PVR_ZONE_INIT,(L"MBX::MBX"));
g_pclGPE = this;
#ifdef DEBUG
#if PUNTALL
m_bPunt=TRUE;
#else
m_bPunt=FALSE;
#endif//PUNTALL
#endif//#ifdef DEBUG
#ifdef ROTATE_ENABLE
m_iRotate = GetRotateModeFromReg();
m_bDisableDynScrnRotation = FALSE;
#endif//ROTATE_ENABLE
#ifdef DRV_VERIFIABLE
if (InitDrvVerification(&m_sDrvVerify))
{
#ifdef ROTATE_ENABLE
LONG lPhysAngle = LogicalToPhysRotDegrees(m_sDrvVerify.ui32Rotation);
m_iRotate = DegreesToRotEnum(lPhysAngle);
#endif//ROTATE_ENABLE
}
#endif//DRV_VERIFIABLE
#ifdef LOCAL_MEMORY_SELF_REFRESH
InitializeCriticalSection(&m_LocalMemoryCS);
#endif
InitializeHardware();
m_eHWBltState = BLT_Idle;
m_sPaletteInfo.prgbqSrcPalette = NULL;
m_sPaletteInfo.prgbqPatPalette = NULL;
#ifdef SUPPORT_POWER_STATE
m_ePowerState = VideoPowerOn;
m_sDevData.psDevInfoUM->ePowerState = PVRSRV_POWER_STATE_D0;
#endif
//////////DPFINFO ((L"Setting default MBX resolution of 320 x 240 x 16"));
DWORD oldMode = SetKMode(TRUE);
m_nScreenWidth = 320; // virtual size
m_nScreenHeight = 240;
m_ulColorDepth = 16;
m_ulScanLineLength = 640;
m_lVisibleX = 0; // top left co-ordinates
m_lVisibleY = 0;
m_ulPhysicalScreenX = 320; // physical size
m_ulPhysicalScreenY = 240;
m_sModeInfo.modeId = 0;
m_sModeInfo.width = m_nScreenWidth;
m_sModeInfo.height = m_nScreenHeight;
m_sModeInfo.Bpp = m_ulColorDepth;
m_sModeInfo.frequency = 60;
m_sModeInfo.format = gpe16Bpp;
m_ui32SecondaryRotationAngle=0;
m_bForceSecondaryExtFullscreen = FALSE;
m_eSecondarySurfaceState = eSurfFree;
m_bDualScreenIfaceLocked = FALSE;
m_bForceSyncWithHost = FALSE; /* Run the test kit with no forced syncs. */
m_bSlavePortAquired = FALSE;
m_ulBufferIdx = 0;
#if defined ROTATE_ENABLE && (_WINCEOSVER < 500)
m_pvMostRecentAllocSurfaceAddr = 0;
m_psMostRecentMBXSurf = 0;
#endif
SetKMode(oldMode);
m_pMode = &m_sModeInfo;
#ifdef USE_SW_CURSOR
m_bCursorVisible = FALSE;
m_bCursorDisabled = TRUE;
m_bCursorForcedOff = FALSE;
memset (&m_sCursorRect, 0x0, sizeof(m_sCursorRect));
#endif
#ifndef DEBUG
/* exception handler counters */
m_ulEmulatedBltExceptions = 0;
m_ulEmulatedBltRotateExceptions = 0;
#endif
m_bPrimaryLocked = FALSE;
m_bHardwareUsed = FALSE;
PVRSRVCreateCommandQueue(&m_sDevData, 1024, &m_pQueueInfo);
#ifdef SUPPORT_CLEARTYPE
HKEY hKey;
ULONG ulValue;
ULONG ulGamma = DEFAULT_CT_GAMMA;
if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE,szGamma,0, NULL,0,0,0, &hKey, &ulValue))
{
if (ulValue == REG_OPENED_EXISTING_KEY)
{
ULONG ulType = REG_DWORD;
ULONG ulSize = sizeof(ULONG);
if (ERROR_SUCCESS == RegQueryValueEx(hKey,szGammaValue,0,&ulType,(BYTE *)&ulValue,&ulSize))
{
ulGamma = ulValue;
}
}
else if (ulValue == REG_CREATED_NEW_KEY )
{
RegSetValueEx(hKey,szGammaValue,0,REG_DWORD,(BYTE *)&ulGamma,sizeof(ULONG));
}
RegCloseKey(hKey);
}
SetClearTypeBltGamma(ulGamma);
#endif // SUPPORT_CLEARTYPE
#ifdef SUPPORT_M24VA
m_hM24VAOwner = 0; /* Default state h/w not ownered */
#endif
// Notify the system that we are a power-manageable device
AdvertisePowerInterface(g_hmodDisplayDll);
//Start process monitoring thread
ResManStartThread();
}
MBX::~MBX()
{
ResManStopThread();
PVRSRVDestroyCommandQueue(&m_sDevData, m_pQueueInfo);
DeInitializeHardware();
/* free up the heap table */
DestroySystemMemHeap();
}
void MBX::GetDisplayModeMasks (PULONG pulRedMask, PULONG pulGreenMask, PULONG pulBlueMask, PULONG pulAlphaMask)
{
*pulRedMask = m_ulPixelTableFormats[0];
*pulGreenMask = m_ulPixelTableFormats[1];
*pulBlueMask = m_ulPixelTableFormats[2];
*pulAlphaMask = m_ulPixelTableFormats[3];
}
/*****************************************************************************
FunctionName : GetDisplayInfo (MBX)
Inputs : PPVR_DISPLAYINFO psDisplayInfo
Outputs : none
Returns : TRUE
Globals used : none
Description : Fills in supplied structure with display information.
*****************************************************************************/
BOOL MBX::GetDisplayInfo(PPVR_DISPLAYINFO psDisplayInfo)
{
psDisplayInfo->pvFBLinBaseAddr = PrimarySurface()->Buffer();
psDisplayInfo->ulDisplayWidth = m_nScreenWidth;
psDisplayInfo->ulDisplayHeight = m_nScreenHeight;
psDisplayInfo->ulDisplayPitch = m_ulScanLineLength;
psDisplayInfo->ulMonitorFrequency = m_sModeInfo.frequency;
psDisplayInfo->ulBpp = m_ulColorDepth;
psDisplayInfo->ulRedBitMask = m_ulPixelTableFormats[0];
psDisplayInfo->ulGreenBitMask = m_ulPixelTableFormats[1];
psDisplayInfo->ulBlueBitMask = m_ulPixelTableFormats[2];
psDisplayInfo->ulAlphaBitMask = m_ulPixelTableFormats[3];
return (TRUE);
}
BOOL GetDisplayInfo(PPVR_DISPLAYINFO psDisplayInfo)
{
((MBX *)GetGPE())->GetDisplayInfo(psDisplayInfo);
return (TRUE);
}
void MBX::WaitForNotBusy(void)
{
DPFX (PVR_ZONE_BLT, (L"MBX::WaitForNotBusy"));
SyncWithHost();
return;
}
void MBX::SyncWithHost(void)
{
DWORD dwCounter=0;
#if !defined TIMED2DGATING && !defined NO_2D_CLOCKCONTROL
BOOL bSysEnabled = FALSE;
#endif
if (!m_bMBXBltActioned)
{
// Nothing to wait for.
return;
}
#ifdef ENABLE_2D_PROFILE
profile_wait_sync_start(m_sActiveNode);
#endif//ENABLE_2D_PROFILE
if (m_bSlavePortAquired == FALSE)
{
PVRSRVAcquireSlavePort(m_sDevData.psDevInfoKM, PVRSRV_SLAVEPORT_2D, IMG_TRUE);
}
IMG_UINT32 ui32Value = *m_sCallbacks.sBltComplete.pulLinAddr;
DPFX (PVR_ZONE_BLT, (L"MBX::SyncWithHost"));
#if !defined NO_2D_CLOCKCONTROL
#if defined TIMED2DGATING
m_sDevData.psDevInfoKM->sDeviceSpecific.s3D.ui32OpsCount++;
if (SysCoreQuery(DEV_CGCORE_MBX_2D) == IMG_FALSE)
{
SysCoreEnable(m_sDevData.psDevInfoKM, DEV_CGCORE_MBX_2D, IMG_TRUE);
}
#else
if (SysCoreQuery(DEV_CGCORE_MBX_2D) == IMG_FALSE)
{
SysCoreEnable(m_sDevData.psDevInfoKM, DEV_CGCORE_MBX_2D, IMG_TRUE);
bSysEnabled = TRUE;
}
#endif
#endif /* NO_2D_CLOCKCONTROL */
SurfaceUpdateBlit (m_sCallbacks.sBltComplete.ulPhysAddr, ++ui32Value );
#if ENABLE_TIMEOUT
while (ui32Value != *(volatile IMG_UINT32 *)m_sCallbacks.sBltComplete.pulLinAddr)
{
Sleep(10);
dwCounter++;
if (dwCounter>dwTimeout)
{
DebugBreak();
}
}
#else
while (ui32Value != *(volatile IMG_UINT32 *)m_sCallbacks.sBltComplete.pulLinAddr)
{
if ( (dwCounter > 500) && (dwCounter < 520) )
{
Sleep(0); // Reduce the polling bandwidth
}
else if (dwCounter >= 520)
{
/*
If we haven't done the blit after so many tries we must yield this high priority
thread to allow recovery
*/
Sleep(2);
}
dwCounter++;
}
#endif
m_bMBXBltActioned = FALSE;
/* while we know that MBX is NOT processing any blits
* we can reset the stripe buffer signature thus
* preventing the Signature from wrapping */
*m_sCallbacks.sStripeComplete.pulLinAddr = 0;
m_ulStrideBufSig = 0;
#if !defined TIMED2DGATING && !defined NO_2D_CLOCKCONTROL
if (bSysEnabled)
{
SysCoreDisable(m_sDevData.psDevInfoKM, DEV_CGCORE_MBX_2D, IMG_FALSE);
}
#endif
if (m_bSlavePortAquired == FALSE)
{
PVRSRVReleaseSlavePort( m_sDevData.psDevInfoKM, PVRSRV_SLAVEPORT_2D);
}
#ifdef ENABLE_2D_PROFILE
profile_wait_sync_end(m_sActiveNode);
#endif//ENABLE_2D_PROFILE
}
int MBX::IsBusy(void)
{
DPFX (PVR_ZONE_BLT, (L"MBX::IsBusy"));
return 0;
}
void MBX::GetPhysicalVideoMemory(PULONG pulPhysicalMemoryBase, PULONG pulVideoMemorySize)
{
DPFX (PVR_ZONE_INIT, (L"MBX::GetPhysicalVideoMemory"));
*pulPhysicalMemoryBase = (ULONG)m_pbyFBPhysBase;
*pulVideoMemorySize = m_ulScanLineLength * m_ulPhysicalScreenY;
}
SCODE MBX::SetPalette(const PALETTEENTRY *psSource, USHORT usFirstEntry, USHORT usNumEntries)
{
DPFX (PVR_ZONE_INIT, (L"MBX::SetPalette"));
if (usFirstEntry < 0 || usFirstEntry + usNumEntries > 256 || psSource == NULL)
{
return (E_INVALIDARG);
}
m_clDisplay.PDP_Palette((PPDP_PALETTE)psSource, usFirstEntry, usNumEntries, FALSE);
return (S_OK);
}
ULONG MBX::GetGraphicsCaps()
{
if (m_pMode)
{
#ifdef SUPPORT_CLEARTYPE
if (m_pMode->Bpp >= 8) // if in 16bpp mode, return GCAPS_GRAY16 to denote that we support anti-aliased fonts
{
return (GCAPS_CLEARTYPE | GCAPS_GRAY16);
}
#else
if (m_pMode->Bpp == 16)
{
return (GCAPS_GRAY16);
}
#endif // SUPPORT_CLEARTYPE
}
return (0);
}
#ifdef LOCAL_MEMORY_SELF_REFRESH
extern "C"
void LockLocalMemoryFunction(void)
{
EnterCriticalSection(&(g_pclGPE->m_LocalMemoryCS));
}
extern "C"
void UnLockLocalMemoryFunction(void)
{
LeaveCriticalSection(&(g_pclGPE->m_LocalMemoryCS));
}
#endif
/********************************** end of file ******************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -