uidriver/glfw: Eliminate (*thread).Call at (*UserInterface).update

Updates #1367
This commit is contained in:
Hajime Hoshi 2020-10-17 06:01:05 +09:00
parent ee50f611ee
commit cbb70d045c

View File

@ -791,11 +791,11 @@ func (u *UserInterface) updateSize() (float64, float64, bool) {
return w, h, true
}
func (u *UserInterface) update() error {
if err := u.t.Call(func() error {
// update must be called from the main thread.
func (u *UserInterface) update() (float64, float64, bool, error) {
shouldClose := u.window.ShouldClose()
if shouldClose {
return driver.RegularTermination
return 0, 0, false, driver.RegularTermination
}
if u.isInitFullscreen() {
@ -819,25 +819,8 @@ func (u *UserInterface) update() error {
u.reqWidth = 0
u.reqHeight = 0
return nil
}); err != nil {
return err
}
outsideWidth, outsideHeight, outsideSizeChanged := u.updateSize()
var w, h float64
var changed bool
// This call is needed for initialization.
_ = u.t.Call(func() error {
w, h, changed = u.updateSize()
return nil
})
if changed {
u.context.Layout(w, h)
}
_ = u.t.Call(func() error {
glfw.PollEvents()
u.input.update(u.window, u.context)
@ -848,10 +831,8 @@ func (u *UserInterface) update() error {
time.Sleep(time.Second / 60)
glfw.PollEvents()
}
return nil
})
return nil
return outsideWidth, outsideHeight, outsideSizeChanged, nil
}
func (u *UserInterface) loop() error {
@ -876,9 +857,20 @@ func (u *UserInterface) loop() error {
if unfocused {
t1 = time.Now()
}
if err := u.update(); err != nil {
var outsideWidth, outsideHeight float64
var outsideSizeChanged bool
if err := u.t.Call(func() error {
var err error
outsideWidth, outsideHeight, outsideSizeChanged, err = u.update()
return err
}); err != nil {
return err
}
if outsideSizeChanged {
u.context.Layout(outsideWidth, outsideHeight)
}
if err := u.context.Update(); err != nil {
return err
}