internal/glfw: bug fix: limit the DWM swap interval to Vista and 7

This change applies the bug fix at glfw/glfw#1072.

Updates #2961
This commit is contained in:
Hajime Hoshi 2024-04-14 15:31:10 +09:00
parent d5f15f9354
commit 86e0bcc264

View File

@ -261,23 +261,18 @@ func makeContextCurrentWGL(window *Window) error {
}
func swapBuffersWGL(window *Window) error {
if window.monitor == nil && winver.IsWindowsVistaOrGreater() {
// DWM Composition is always enabled on Win8+
enabled := winver.IsWindows8OrGreater()
if !enabled {
var err error
enabled, err = _DwmIsCompositionEnabled()
if window.monitor == nil {
// HACK: Use DwmFlush when desktop composition is enabled on Windows Vista and 7
if !winver.IsWindows8OrGreater() && winver.IsWindowsVistaOrGreater() {
enabled, err := _DwmIsCompositionEnabled()
if err != nil {
return err
}
}
// HACK: Use DwmFlush when desktop composition is enabled
if enabled {
for i := 0; i < window.context.platform.interval; i++ {
// Ignore an error from DWM functions as they might not be implemented e.g. on Proton (#2113).
_ = _DwmFlush()
if enabled {
for i := 0; i < window.context.platform.interval; i++ {
// Ignore an error from DWM functions as they might not be implemented e.g. on Proton (#2113).
_ = _DwmFlush()
}
}
}
}
@ -297,22 +292,18 @@ func swapIntervalWGL(interval int) error {
window.context.platform.interval = interval
if window.monitor == nil && winver.IsWindowsVistaOrGreater() {
// DWM Composition is always enabled on Win8+
enabled := winver.IsWindows8OrGreater()
if !enabled {
e, err := _DwmIsCompositionEnabled()
if window.monitor == nil {
// HACK: Disable WGL swap interval when desktop composition is enabled on Windows
// Vista and 7 to avoid interfering with DWM vsync
if !winver.IsWindows8OrGreater() && winver.IsWindowsVistaOrGreater() {
enabled, err := _DwmIsCompositionEnabled()
// Ignore an error from DWM functions as they might not be implemented e.g. on Proton (#2113).
if err == nil {
enabled = e
enabled = false
}
if enabled {
interval = 0
}
}
// HACK: Disable WGL swap interval when desktop composition is enabled to
// avoid interfering with DWM vsync
if enabled {
interval = 0
}
}