📄 power.cpp
字号:
/***************************************************************************
* Name : power.cpp
* Title : MBX WinCE driver Power Management
* Author(s) : Imagination Technologies
* Created : 19th June 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 Power Management.
*
* Platform : WinCE
*
* Modifications:-
* $Log: power.cpp $
*
* --- Revision Logs Removed ---
*
* --- Revision Logs Removed ---
*
* --- Revision Logs Removed ---
*
* --- Revision Logs Removed ---
*
****************************************************************************/
#include "precomp.h"
#include "power.h"
#include "pmstatemap.h"
// this routine converts a string into a GUID and returns TRUE if the
// conversion was successful.
static BOOL ConvertStringToGuid (LPCTSTR pszGuid, GUID *pGuid)
{
UINT Data4[8];
int Count;
BOOL fOk = FALSE;
TCHAR *pszGuidFormat = _T("{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}");
DEBUGCHK(pGuid != NULL && pszGuid != NULL);
__try
{
if (_stscanf(pszGuid, pszGuidFormat, &pGuid->Data1,
&pGuid->Data2, &pGuid->Data3, &Data4[0], &Data4[1], &Data4[2], &Data4[3],
&Data4[4], &Data4[5], &Data4[6], &Data4[7]) == 11)
{
for(Count = 0; Count < (sizeof(Data4) / sizeof(Data4[0])); Count++)
{
pGuid->Data4[Count] = (UCHAR) Data4[Count];
}
}
fOk = TRUE;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
return fOk;
}
// This routine notifies the OS that we support the Power Manager IOCTLs (through
// ExtEscape(), which calls DrvEscape()).
BOOL AdvertisePowerInterface(HMODULE hInst)
{
BOOL fOk = FALSE;
HKEY hk;
DWORD dwStatus;
TCHAR szTemp[MAX_PATH];
GUID gClass;
// assume we are advertising the default class
fOk = ConvertStringToGuid(PMCLASS_DISPLAY, &gClass);
DEBUGCHK(fOk);
// check for an override in the registry
dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\GDI\\Drivers"), 0, 0, &hk);
if(dwStatus == ERROR_SUCCESS)
{
DWORD dwType, dwSize;
dwSize = sizeof(szTemp);
dwStatus = RegQueryValueEx(hk, _T("DisplayPowerClass"), NULL, &dwType, (LPBYTE) szTemp, &dwSize);
if(dwStatus == ERROR_SUCCESS && dwType == REG_SZ)
{
// got a guid string, convert it to a guid
GUID gTemp;
fOk = ConvertStringToGuid(szTemp, &gTemp);
DEBUGCHK(fOk);
if(fOk)
{
gClass = gTemp;
}
}
// release the registry key
RegCloseKey(hk);
}
// figure out what device name to advertise
if(fOk)
{
fOk = GetModuleFileName(hInst, szTemp, sizeof(szTemp) / sizeof(szTemp[0]));
DEBUGCHK(fOk);
}
// now advertise the interface
if(fOk)
{
fOk = AdvertiseInterface(&gClass, szTemp, TRUE);
DEBUGCHK(fOk);
}
return fOk;
}
/*****************************************************************************
*
* Called as a results of selecting 'SUSPEND' from the Windows Menu or from
* a screensaver which blanks the screen.
*
* This functions is just to turn off the display/DAC and is not directly
* related to power management although it is called when entering or leaving
* a PVR_STATE_D3 state.
*
* Beware debugging this function. dpfx() causes an 0x0E exception and
* breakpoints a 0x03 exception. Both halt the target.
*
* This function is not used in Windows CE .NET 4.2 and later
*
*****************************************************************************/
#ifdef SUPPORT_POWER_STATE
void MBX::PowerHandler(BOOL bOff)
{
/****** note - don't set breakpoints in this functions or calls to dpf() */
/* still true for pocket PC especially when in D3/4 state */
/*
* 15th Feb 2004
* power manage RESET uses this function and dies in HostGetCurrentProcessID
* latest PPC doc states that this function is not used, so out it goes
*/
// if (m_ePowerState != PVRSRV_POWER_STATE_D3)
// {
// DEBUGMSG(1,(TEXT("MBX::PowerHandler %hs:\r\n"), (bOff) ? "Off" : "On"));
// m_clDisplay.PDP_ScreenPowerOff(bOff);
// }
}
static VIDEO_POWER_STATE PmToVideoPowerState( CEDEVICE_POWER_STATE Dx )
{
// PmToVideoPowerState
// this routine maps between power manager power states and video ioctl power states
// Local variables.
VIDEO_POWER_STATE vps;
switch(Dx)
{
case D0:
vps = VideoPowerOn;
break;
case D1:
vps = VideoPowerStandBy;
break;
case D2:
vps = VideoPowerSuspend;
break;
case D3: // D3 and D4 are identical because the display can't be a wake source
case D4:
vps = VideoPowerOff;
break;
default:
DPFWARNING((L"PmToVideoPowerState: mapping unknown PM state %d to VideoPowerOn", Dx));
vps = VideoPowerOn;
break;
}
return vps;
}
static CEDEVICE_POWER_STATE VideoToPmPowerState( VIDEO_POWER_STATE PowerState )
{
// VideoToPmPowerState
// this routine maps video power states to PM power states.
// Local variables.
CEDEVICE_POWER_STATE Dx;
switch(PowerState)
{
case VideoPowerOn:
Dx = D0;
break;
case VideoPowerStandBy:
Dx = D1;
break;
case VideoPowerSuspend:
Dx = D2;
break;
case VideoPowerOff:
Dx = D4;
break;
default:
Dx = D0;
DPFWARNING((L"VideoToPmPowerState: mapping unknown video state %d to pm state %d", PowerState, Dx));
break;
}
return Dx;
}
CEDEVICE_POWER_STATE MBX::GetPowerState()
{
return (VideoToPmPowerState(m_ePowerState));
}
BOOL MBX::SetPowerState(VIDEO_POWER_STATE vps)
{
PVR_POWER_STATE ePVRState;
switch (vps)
{
case VideoPowerOn: /* D0 - Full on */
default:
ePVRState = PVRSRV_POWER_STATE_D0;
DPFINFO((L"Switching to VideoPowerOn state, full power"));
break;
case VideoPowerStandBy: /* D1 - low power, Blits done */
ePVRState = PVRSRV_POWER_STATE_D1;
DPFINFO((L"Switching to VideoPowerStandBy state, slower clocks"));
break;
case VideoPowerSuspend: /* D2 - standby, Blits done */
ePVRState = PVRSRV_POWER_STATE_D2;
DPFINFO((L"Switching to VideoPowerSuspend state, reduced functionality"));
break;
case VideoPowerOff: /* D3 /D4 - off, no blits */
DPFINFO((L"Switching to VideoPowerOff state, loss of FB data"));
ePVRState = PVRSRV_POWER_STATE_D3;
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryEnable(m_sDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
// Save local memory surfaces into system memory
m_cl2DMemNodes.SaveSurfToSystemMem();
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryDisable(m_sDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
break;
}
if (ePVRState != m_sDevData.psDevInfoUM->ePowerState)
{
/*
handle power management for both local devices and those accessed via
the services module
*/
/* advise 2D*/
GPE_Power(m_sDevData.psDevInfoUM->ePowerState, PVRSRV_SEVERE_LOSS_OF_CONTEXT | PVRSRV_PRE_STATE_CHANGE_MASK);
/* advise PDP */
m_clDisplay.PDP_Power(ePVRState, PVRSRV_SEVERE_LOSS_OF_CONTEXT | PVRSRV_PRE_STATE_CHANGE_MASK);
PVRSRVSetPowerState(&m_sDevData, (IMG_BOOL)(vps > m_ePowerState), ePVRState);
/* restore saved surfaces from system memory upon resume from D3 */
if(ePVRState == PVRSRV_POWER_STATE_D0 && m_sDevData.psDevInfoUM->ePowerState == PVRSRV_POWER_STATE_D3)
{
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryEnable(m_sDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
m_cl2DMemNodes.RestoreSystemMemtoSurf();
#ifdef LOCAL_MEMORY_SELF_REFRESH
SysLocalMemoryDisable(m_sDevData.psDevInfoKM);
#endif // LOCAL_MEMORY_SELF_REFRESH
}
/* advise 2D and PDP*/
m_clDisplay.PDP_Power(ePVRState, PVRSRV_SEVERE_LOSS_OF_CONTEXT);
GPE_Power(m_sDevData.psDevInfoUM->ePowerState, PVRSRV_SEVERE_LOSS_OF_CONTEXT);
/* update new state record */
m_sDevData.psDevInfoUM->ePowerState = ePVRState;
m_ePowerState = vps;
}
else
{
DPFINFO((L"Already in PVR power state %d", m_sDevData.psDevInfoUM->ePowerState));
}
//#endif /* FIXME */
return (TRUE);
}
BOOL MBX::SetPowerState(CEDEVICE_POWER_STATE NewDx)
{
return SetPowerState(PmToVideoPowerState(NewDx));
}
#endif
/********************************** end of file ******************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -