internal/uidriver/glfw: Bug fix: Disable vsync when resizing the window

Closes #1740
This commit is contained in:
Hajime Hoshi 2021-08-06 03:08:01 +09:00
parent 14f0fbf844
commit cc1accc32a
2 changed files with 15 additions and 2 deletions

View File

@ -30,6 +30,7 @@ type view struct {
windowChanged bool
vsync bool
vsyncInited bool
device mtl.Device
ml ca.MetalLayer
@ -46,8 +47,12 @@ func (v *view) getMTLDevice() mtl.Device {
}
func (v *view) setDisplaySyncEnabled(enabled bool) {
if v.vsync == enabled && !v.vsyncInited {
return
}
v.ml.SetDisplaySyncEnabled(enabled)
v.vsync = enabled
v.vsyncInited = true
}
func (v *view) colorPixelFormat() mtl.PixelFormat {
@ -75,7 +80,9 @@ func (v *view) reset() error {
v.ml.SetMaximumDrawableCount(2)
// The vsync state might be reset. Set the state again (#1364).
if v.vsyncInited {
v.ml.SetDisplaySyncEnabled(v.vsync)
}
v.ml.SetFramebufferOnly(true)
return nil

View File

@ -781,6 +781,9 @@ func (u *UserInterface) registerWindowSetSizeCallback() {
}
if err := u.runOnAnotherThreadFromMainThread(func() error {
// Disable Vsync temporarily. On macOS, getting a next frame can get stuck (#1740).
u.Graphics().SetVsyncEnabled(false)
var outsideWidth, outsideHeight float64
var outsideSizeChanged bool
@ -967,10 +970,13 @@ func (u *UserInterface) update() (float64, float64, bool, error) {
// Calling this inside setWindowSize didn't work (#1363).
if !u.fpsModeInited {
u.fpsMode = u.getInitFPSMode()
u.updateVsync()
u.fpsModeInited = true
}
// Call updateVsync even though fpsMode is not updated.
// The vsync state might be changed in other places (e.g., the SetSizeCallback).
u.updateVsync()
outsideWidth, outsideHeight, outsideSizeChanged := u.updateSize()
if u.fpsMode != driver.FPSModeVsyncOffMinimum {