internal/ui: refactoring: reduce usages of renderThread

Updates #2714
This commit is contained in:
Hajime Hoshi 2023-12-17 15:36:12 +09:00
parent d6439c9e6c
commit d7ebc19d04
3 changed files with 10 additions and 6 deletions

View File

@ -45,12 +45,16 @@ const (
var vsyncEnabled int32 = 1
func SetVsyncEnabled(enabled bool) {
func SetVsyncEnabled(enabled bool, graphicsDriver graphicsdriver.Graphics) {
if enabled {
atomic.StoreInt32(&vsyncEnabled, 1)
} else {
atomic.StoreInt32(&vsyncEnabled, 0)
}
runOnRenderThread(func() {
graphicsDriver.SetVsyncEnabled(enabled)
}, true)
}
// FlushCommands flushes the command queue and present the screen if needed.

View File

@ -81,6 +81,8 @@ type UserInterface struct {
whiteImage *Image
mainThread thread.Thread
// TODO: Remove this (#2714).
renderThread thread.Thread
userInterfaceImpl

View File

@ -1287,10 +1287,7 @@ func (u *UserInterface) setFPSMode(fpsMode FPSModeType) error {
}
vsyncEnabled := u.fpsMode == FPSModeVsyncOn
graphicscommand.SetVsyncEnabled(vsyncEnabled)
u.renderThread.CallAsync(func() {
u.graphicsDriver.SetVsyncEnabled(vsyncEnabled)
})
graphicscommand.SetVsyncEnabled(vsyncEnabled, u.graphicsDriver)
return nil
}
@ -1341,6 +1338,7 @@ func (u *UserInterface) update() (float64, float64, error) {
// Initialize vsync after SetMonitor is called. See the comment in updateVsync.
// Calling this inside setWindowSize didn't work (#1363).
// Also, setFPSMode has to be called after graphicscommand.SetRenderThread is called (#2714).
if !u.fpsModeInited {
if err := u.setFPSMode(u.fpsMode); err != nil {
return 0, 0, err