internal/ui: remove renderThread

Updates #2714
This commit is contained in:
Hajime Hoshi 2024-01-02 16:54:07 +09:00
parent f99c979c98
commit 2da56c00c8
4 changed files with 13 additions and 17 deletions

View File

@ -15,16 +15,20 @@
package graphicscommand package graphicscommand
import ( import (
"context"
"github.com/hajimehoshi/ebiten/v2/internal/thread" "github.com/hajimehoshi/ebiten/v2/internal/thread"
) )
var theRenderThread thread.Thread = thread.NewNoopThread() var theRenderThread thread.Thread = thread.NewNoopThread()
// SetRenderThread must be called from the rendering thread where e.g. OpenGL works. // SetOSThreadAsRenderThread sets an OS thread as rendering thread e.g. for OpenGL.
// func SetOSThreadAsRenderThread() {
// TODO: Create thread in this package instead of setting it externally. theRenderThread = thread.NewOSThread()
func SetRenderThread(thread thread.Thread) { }
theRenderThread = thread
func LoopRenderThread(ctx context.Context) {
_ = theRenderThread.Loop(ctx)
} }
// runOnRenderThread calls f on the rendering thread. // runOnRenderThread calls f on the rendering thread.

View File

@ -35,8 +35,7 @@ func (u *UserInterface) Run(game Game, options *RunOptions) error {
func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error { func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
u.mainThread = thread.NewOSThread() u.mainThread = thread.NewOSThread()
u.renderThread = thread.NewOSThread() graphicscommand.SetOSThreadAsRenderThread()
graphicscommand.SetRenderThread(u.renderThread)
// Set the running state true after the main thread is set, and before initOnMainThread is called (#2742). // Set the running state true after the main thread is set, and before initOnMainThread is called (#2742).
// TODO: As the existence of the main thread is the same as the value of `running`, this is redundant. // TODO: As the existence of the main thread is the same as the value of `running`, this is redundant.
@ -58,7 +57,7 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
// Run the render thread. // Run the render thread.
wg.Go(func() error { wg.Go(func() error {
defer cancel() defer cancel()
_ = u.renderThread.Loop(ctx) graphicscommand.LoopRenderThread(ctx)
return nil return nil
}) })
@ -76,8 +75,6 @@ func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error {
func (u *UserInterface) runSingleThread(game Game, options *RunOptions) error { func (u *UserInterface) runSingleThread(game Game, options *RunOptions) error {
// Initialize the main thread first so the thread is available at u.run (#809). // Initialize the main thread first so the thread is available at u.run (#809).
u.mainThread = thread.NewNoopThread() u.mainThread = thread.NewNoopThread()
u.renderThread = thread.NewNoopThread()
graphicscommand.SetRenderThread(u.renderThread)
u.setRunning(true) u.setRunning(true)
defer u.setRunning(false) defer u.setRunning(false)

View File

@ -82,9 +82,6 @@ type UserInterface struct {
mainThread thread.Thread mainThread thread.Thread
// TODO: Remove this (#2714).
renderThread thread.Thread
userInterfaceImpl userInterfaceImpl
} }

View File

@ -38,7 +38,6 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver" "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/hook" "github.com/hajimehoshi/ebiten/v2/internal/hook"
"github.com/hajimehoshi/ebiten/v2/internal/restorable" "github.com/hajimehoshi/ebiten/v2/internal/restorable"
"github.com/hajimehoshi/ebiten/v2/internal/thread"
) )
var ( var (
@ -91,7 +90,7 @@ func (u *UserInterface) Update() error {
cancel() cancel()
}() }()
_ = u.renderThread.Loop(ctx) graphicscommand.LoopRenderThread(ctx)
return nil return nil
} }
@ -273,8 +272,7 @@ func (u *UserInterface) runMobile(game Game, mainloop bool, options *RunOptions)
// gl.Context so that they are called on the appropriate thread. // gl.Context so that they are called on the appropriate thread.
mgl = <-glContextCh mgl = <-glContextCh
} else { } else {
u.renderThread = thread.NewOSThread() graphicscommand.SetOSThreadAsRenderThread()
graphicscommand.SetRenderThread(u.renderThread)
} }
u.setRunning(true) u.setRunning(true)