From 55281cebd218896443ddedaa774d4086cc8bfe5c Mon Sep 17 00:00:00 2001 From: Chris Pable Date: Thu, 25 May 2017 02:34:33 -0500 Subject: [PATCH] keep xp on life support a bit longer, check for vista+ stuff (#1456) --- src/arch/Sound/DSoundHelpers.cpp | 10 ++++++++- src/archutils/Win32/DirectXHelpers.h | 19 +++++++++++++++++ src/archutils/Win32/GraphicsWindow.cpp | 29 ++++++++++++++++++++++---- src/archutils/Win32/GraphicsWindow.h | 5 +++++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/arch/Sound/DSoundHelpers.cpp b/src/arch/Sound/DSoundHelpers.cpp index 111816d534..74a27ec41a 100644 --- a/src/arch/Sound/DSoundHelpers.cpp +++ b/src/arch/Sound/DSoundHelpers.cpp @@ -210,7 +210,15 @@ RString DSoundBuf::Init( DSound &ds, DSoundBuf::hw hardware, DSBUFFERDESC format; memset( &format, 0, sizeof(format) ); format.dwSize = sizeof(format); - format.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLVOLUME; + + if (at_least_vista()) + { + format.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLVOLUME | DSBCAPS_TRUEPLAYPOSITION; + } + else + { + format.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLVOLUME; + } /* Don't use DSBCAPS_STATIC. It's meant for static buffers, and we * only use streaming buffers. */ diff --git a/src/archutils/Win32/DirectXHelpers.h b/src/archutils/Win32/DirectXHelpers.h index 7729751e44..b8438f1fce 100644 --- a/src/archutils/Win32/DirectXHelpers.h +++ b/src/archutils/Win32/DirectXHelpers.h @@ -1,8 +1,27 @@ #ifndef DIRECTX_HELPERS_H #define DIRECTX_HELPERS_H +#include "windows.h" RString hr_ssprintf( int hr, const char *fmt, ... ); +//Keep XP on life support +static bool at_least_vista() +{ +OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, { 0 }, 0, 0 }; +DWORDLONG const dwlConditionMask = VerSetConditionMask( + VerSetConditionMask( + VerSetConditionMask( + 0, VER_MAJORVERSION, VER_GREATER_EQUAL), + VER_MINORVERSION, VER_GREATER_EQUAL), + VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); + +osvi.dwMajorVersion = 0x0600; +osvi.dwMinorVersion = 0x0; +osvi.wServicePackMajor = 0; + +return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != false; +} + #endif /* diff --git a/src/archutils/Win32/GraphicsWindow.cpp b/src/archutils/Win32/GraphicsWindow.cpp index 5722701ed2..81f5836270 100644 --- a/src/archutils/Win32/GraphicsWindow.cpp +++ b/src/archutils/Win32/GraphicsWindow.cpp @@ -12,8 +12,7 @@ #include "archutils/Win32/WindowIcon.h" #include "archutils/Win32/GetFileInformation.h" #include "CommandLineActions.h" -#include -#pragma comment(lib, "dwmapi.lib") +#include "DirectXHelpers.h" #include @@ -417,6 +416,19 @@ void GraphicsWindow::Initialize( bool bD3D ) // A few things need to be handled differently for D3D. g_bD3D = bD3D; + //keeping xp on life support -- check for vista+ for dwm + if (at_least_vista()) + { + hInstanceDwmapi = LoadLibraryA("dwmapi.dll"); + } + + //if we have dwm, get function pointers to the dll functions + if( hInstanceDwmapi != NULL ) + { + PFN_DwmFlush = (HRESULT (WINAPI *)(VOID))GetProcAddress( hInstanceDwmapi, "DwmFlush" ); + PFN_DwmIsCompositionEnabled = (HRESULT (WINAPI *)(BOOL*))GetProcAddress( hInstanceDwmapi, "DwmIsCompositionEnabled" ); + } + AppInstance inst; do { @@ -498,8 +510,17 @@ void GraphicsWindow::Update() HOOKS->SetHasFocus( g_bHasFocus ); if (g_CurrentParams.vsync) - { - DwmFlush(); + { + //if we can use DWM + if( hInstanceDwmapi != NULL ) + { + BOOL compositeEnabled = true; + PFN_DwmIsCompositionEnabled(&compositeEnabled); + if (compositeEnabled) + { + PFN_DwmFlush(); + } + } } if( g_bResolutionChanged && DISPLAY != NULL ) diff --git a/src/archutils/Win32/GraphicsWindow.h b/src/archutils/Win32/GraphicsWindow.h index 6e1e6ebcef..7d3cd08e6a 100644 --- a/src/archutils/Win32/GraphicsWindow.h +++ b/src/archutils/Win32/GraphicsWindow.h @@ -35,6 +35,11 @@ namespace GraphicsWindow void Update(); HWND GetHwnd(); + + //dwm functions for vista+ + static HINSTANCE hInstanceDwmapi = NULL; + static HRESULT(WINAPI* PFN_DwmIsCompositionEnabled)(BOOL*); + static HRESULT (WINAPI* PFN_DwmFlush)(VOID); }; #endif