by date
TGB: GetVideoAccelerationLevel (code inside)
TGB: GetVideoAccelerationLevel (code inside)
| Name: | amaranthia | |
|---|---|---|
| Date Posted: | Jul 09, 2008 | |
| Rating: | 3.7 out of 5 | |
| Public: | YES | |
| Comments: | YES | |
| RSS Feed: | or Subscribe with . | |
| Profile Page: | View profile page for amaranthia |
Blog post
Hi everyone, I wanted to post the first of two functions that Bryce wrote so that we can determine what level of video acceleration a user has. We've found that in a lot of cases, a user may have hardware acceleration turned on, but only to 0, 1, 2, or 3. This function will help you determine what level your player is using.
In the next post, I'll post SetVideoAccelerationLevel, which will let you change the acceleration level for your users.
From Bryce:
In WinVideo.h, add the following line:
In WinVideo.CC, add the following code:
Lastly, provide a scripting interface for the new service routine... I put this one in WinWindow.CC under PlatformWin32, as it is Win32 specific.
In the next post, I'll post SetVideoAccelerationLevel, which will let you change the acceleration level for your users.
From Bryce:
In WinVideo.h, add the following line:
static int GetVideoAccelerationLevel(void);
In WinVideo.CC, add the following code:
int WinDisplayDevice::GetVideoAccelerationLevel()
{
// Open HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\VIDEO
// Get Content of \Device\Video0 key
// Take the GUID from the end and open HKLM\System\CurrentControlSet\Control\Video\{GUID}\0000
// Now, look for "Acceleration.Level"
// If the key is NOT present, the level is on full HW assist
// If the key is present, the level is 1 to 5 with 5 being the NO HW Support, and 1 being almost full HW support!
//
HKEY hKey;
int nRet = -1;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DEVICEMAP\\VIDEO"), 0, KEY_QUERY_VALUE , &hKey))
{
LPSTR lpszBuffer = NULL;
DWORD dwType, dwSize;
LPCSTR lpszSearchKey = "\\Device\\Video0";
dwType = dwSize = 0;
if (ERROR_SUCCESS == RegQueryValueExA(hKey, lpszSearchKey, 0, &dwType, (LPBYTE)lpszBuffer, &dwSize))
{
HANDLE hHeap = GetProcessHeap();
if (lpszBuffer = (LPSTR)HeapAlloc(hHeap, HEAP_ZERO_MEMORY, dwSize))
{
dwType = REG_SZ;
if (ERROR_SUCCESS == RegQueryValueExA(hKey, lpszSearchKey, 0, &dwType, (LPBYTE)lpszBuffer, &dwSize))
{
LPCSTR lpszRet = dStrchr(lpszBuffer, '{');
HKEY hKeyVideo;
char tszRegKey[128] = {"SYSTEM\\CurrentControlSet\\Control\\Video\\"};
lstrcpyA(&tszRegKey[39], lpszRet);
if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE, tszRegKey, 0, KEY_QUERY_VALUE , &hKeyVideo))
{
DWORD dwAccelVal;
LPCTSTR lpszOutputMsg;
dwType = REG_DWORD;
nRet = 5; // Set the return to 5 here to use to invert the level in the registry.
if (ERROR_SUCCESS == RegQueryValueEx(hKeyVideo, TEXT("Acceleration.Level"), 0, &dwType, (LPBYTE)&dwAccelVal, &dwSize))
{
nRet -= dwAccelVal;
}
RegCloseKey(hKeyVideo);
}
else
{
// Set the default to '1' here to reflect that the hardware is on... the default, which is provided when no key is present.
nRet = 1;
}
}
HeapFree(hHeap, 0, lpszBuffer);
}
}
RegCloseKey(hKey);
}
return nRet;
}
Lastly, provide a scripting interface for the new service routine... I put this one in WinWindow.CC under PlatformWin32, as it is Win32 specific.
//--------------------------------------
// Returns VideoAccelerationLevel:
// The range is 1 to 5 with 1 being the NO HW Support, and 5 being full HW support.
//--------------------------------------
ConsoleFunction( GetVideoAccelerationLevel, int, 1, 1, "int GetVideoAccelerationLevel(void)" )
{
return WinDisplayDevice::GetVideoAccelerationLevel();
}
Submit your own resources!| Brian Wilson (Jul 09, 2008 at 22:16 GMT) |
| James Ford (Jul 09, 2008 at 23:29 GMT) Resource Rating: 3 |
| BryceJ (Jul 10, 2008 at 05:29 GMT) Resource Rating: 4 |
As for the indents... it's not that bad... it's just a formatting issue caused by the copy from VS to the forums.
| amaranthia (Jul 10, 2008 at 05:34 GMT) |
| David Montgomery-Blake (Jul 10, 2008 at 13:06 GMT) |
You must be a member and be logged in to either append comments or rate this resource.


3.7 out of 5


