win32: Change DWMTweaks to DWMSync option.

This commit is contained in:
Brandon Wright 2019-03-04 14:40:32 -06:00
parent 958a5d47db
commit da37d725ec
3 changed files with 23 additions and 8 deletions

View File

@ -759,7 +759,7 @@ void WinRegisterConfigItems()
AddBoolC("HideMenu", GUI.HideMenu, false, "true to auto-hide the menu bar on startup."); AddBoolC("HideMenu", GUI.HideMenu, false, "true to auto-hide the menu bar on startup.");
AddBoolC("Vsync", GUI.Vsync, false, "true to enable Vsync"); AddBoolC("Vsync", GUI.Vsync, false, "true to enable Vsync");
AddBoolC("ReduceInputLag", GUI.ReduceInputLag, false, "true to reduce input lag by hard synchronization"); AddBoolC("ReduceInputLag", GUI.ReduceInputLag, false, "true to reduce input lag by hard synchronization");
AddBoolC("DWMTweaks", GUI.DWMTweaks, false, "true to try and avoid DWM stutter"); AddBoolC("DWMSync", GUI.DWMSync, false, "sync to DWM compositor if it is running instead of vsync (OpenGL)");
AddBoolC("FilterMessageFont", GUI.filterMessagFont, true, "true to filter message font with EPX on 2x/3x scales if MessagesInImage is false)"); AddBoolC("FilterMessageFont", GUI.filterMessagFont, true, "true to filter message font with EPX on 2x/3x scales if MessagesInImage is false)");
#undef CATEGORY #undef CATEGORY
#define CATEGORY "Settings" #define CATEGORY "Settings"

View File

@ -34,6 +34,11 @@ COpenGL OpenGL;
SSurface Src = {0}; SSurface Src = {0};
extern BYTE *ScreenBufferBlend; extern BYTE *ScreenBufferBlend;
typedef HRESULT (*DWMFLUSHPROC)();
typedef HRESULT (*DWMISCOMPOSITIONENABLEDPROC)(BOOL *);
DWMFLUSHPROC DwmFlushProc = NULL;
DWMISCOMPOSITIONENABLEDPROC DwmIsCompositionEnabledProc = NULL;
// Interface used to access the display output // Interface used to access the display output
IS9xDisplayOutput *S9xDisplayOutput=&Direct3D; IS9xDisplayOutput *S9xDisplayOutput=&Direct3D;
@ -119,16 +124,17 @@ bool WinDisplayReset(void)
S9xSetWinPixelFormat (); S9xSetWinPixelFormat ();
S9xGraphicsInit(); S9xGraphicsInit();
if (GUI.DWMTweaks) if (GUI.DWMSync)
{ {
HMODULE dwmlib = LoadLibrary(TEXT("dwmapi")); HMODULE dwmlib = LoadLibrary(TEXT("dwmapi"));
if (dwmlib) DwmFlushProc = (DWMFLUSHPROC)GetProcAddress(dwmlib, "DwmFlush");
DwmIsCompositionEnabledProc = (DWMISCOMPOSITIONENABLEDPROC)GetProcAddress(dwmlib, "DwmIsCompositionEnabled");
if (!DwmFlushProc || !DwmIsCompositionEnabledProc)
{ {
HRESULT(WINAPI *dwmEnableMMCSS)(BOOL) = (HRESULT(WINAPI *)(BOOL))GetProcAddress(dwmlib, "DwmEnableMMCSS"); MessageBox(GUI.hWnd, TEXT("Couldn't load DWM functions. DWM Sync is disabled."), TEXT("Warning"), MB_OK | MB_ICONWARNING);
dwmEnableMMCSS(true); GUI.DWMSync = false;
return true;
} }
MessageBox(GUI.hWnd, TEXT("Couldn't enable MMCSS for DWM"), TEXT("Warning"), MB_OK | MB_ICONWARNING);
} }
return true; return true;
@ -283,6 +289,15 @@ bool8 S9xDeinitUpdate (int Width, int Height)
WinRefreshDisplay(); WinRefreshDisplay();
if (GUI.DWMSync)
{
BOOL DWMEnabled = false;
DwmIsCompositionEnabledProc(&DWMEnabled);
if (DWMEnabled)
DwmFlushProc();
}
return (true); return (true);
} }

View File

@ -156,7 +156,7 @@ struct sGUI {
bool Vsync; bool Vsync;
bool ReduceInputLag; bool ReduceInputLag;
bool shaderEnabled; bool shaderEnabled;
bool DWMTweaks; bool DWMSync;
TCHAR D3DshaderFileName[MAX_PATH]; TCHAR D3DshaderFileName[MAX_PATH];
TCHAR OGLshaderFileName[MAX_PATH]; TCHAR OGLshaderFileName[MAX_PATH];