diff --git a/win32/wconfig.cpp b/win32/wconfig.cpp index aa01fb8f..900bd7fa 100644 --- a/win32/wconfig.cpp +++ b/win32/wconfig.cpp @@ -759,7 +759,7 @@ void WinRegisterConfigItems() AddBoolC("HideMenu", GUI.HideMenu, false, "true to auto-hide the menu bar on startup."); AddBoolC("Vsync", GUI.Vsync, false, "true to enable Vsync"); 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)"); #undef CATEGORY #define CATEGORY "Settings" diff --git a/win32/win32_display.cpp b/win32/win32_display.cpp index 6236855d..b84dad69 100644 --- a/win32/win32_display.cpp +++ b/win32/win32_display.cpp @@ -34,6 +34,11 @@ COpenGL OpenGL; SSurface Src = {0}; extern BYTE *ScreenBufferBlend; +typedef HRESULT (*DWMFLUSHPROC)(); +typedef HRESULT (*DWMISCOMPOSITIONENABLEDPROC)(BOOL *); +DWMFLUSHPROC DwmFlushProc = NULL; +DWMISCOMPOSITIONENABLEDPROC DwmIsCompositionEnabledProc = NULL; + // Interface used to access the display output IS9xDisplayOutput *S9xDisplayOutput=&Direct3D; @@ -119,16 +124,17 @@ bool WinDisplayReset(void) S9xSetWinPixelFormat (); S9xGraphicsInit(); - if (GUI.DWMTweaks) + if (GUI.DWMSync) { 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"); - dwmEnableMMCSS(true); - return true; + MessageBox(GUI.hWnd, TEXT("Couldn't load DWM functions. DWM Sync is disabled."), TEXT("Warning"), MB_OK | MB_ICONWARNING); + GUI.DWMSync = false; } - MessageBox(GUI.hWnd, TEXT("Couldn't enable MMCSS for DWM"), TEXT("Warning"), MB_OK | MB_ICONWARNING); } return true; @@ -283,6 +289,15 @@ bool8 S9xDeinitUpdate (int Width, int Height) WinRefreshDisplay(); + if (GUI.DWMSync) + { + BOOL DWMEnabled = false; + + DwmIsCompositionEnabledProc(&DWMEnabled); + if (DWMEnabled) + DwmFlushProc(); + } + return (true); } diff --git a/win32/wsnes9x.h b/win32/wsnes9x.h index ed522248..e5c88cd8 100644 --- a/win32/wsnes9x.h +++ b/win32/wsnes9x.h @@ -156,7 +156,7 @@ struct sGUI { bool Vsync; bool ReduceInputLag; bool shaderEnabled; - bool DWMTweaks; + bool DWMSync; TCHAR D3DshaderFileName[MAX_PATH]; TCHAR OGLshaderFileName[MAX_PATH];