internal/graphicscommand: rename SetRenderingThread -> SetRenderThread

This commit is contained in:
Hajime Hoshi 2022-12-30 13:51:32 +09:00
parent fa4916d063
commit e1992347b7
4 changed files with 15 additions and 15 deletions

View File

@ -164,7 +164,7 @@ func (q *commandQueue) Enqueue(command command) {
// Flush flushes the command queue.
func (q *commandQueue) Flush(graphicsDriver graphicsdriver.Graphics, endFrame bool) (err error) {
runOnRenderingThread(func() {
runOnRenderThread(func() {
err = q.flush(graphicsDriver, endFrame)
})
if endFrame {
@ -538,7 +538,7 @@ func (c *isInvalidatedCommand) Exec(graphicsDriver graphicsdriver.Graphics, inde
// InitializeGraphicsDriverState initialize the current graphics driver state.
func InitializeGraphicsDriverState(graphicsDriver graphicsdriver.Graphics) (err error) {
runOnRenderingThread(func() {
runOnRenderThread(func() {
err = graphicsDriver.Initialize()
})
return
@ -548,7 +548,7 @@ func InitializeGraphicsDriverState(graphicsDriver graphicsdriver.Graphics) (err
// If the graphics driver doesn't have an API to reset, ResetGraphicsDriverState does nothing.
func ResetGraphicsDriverState(graphicsDriver graphicsdriver.Graphics) (err error) {
if r, ok := graphicsDriver.(interface{ Reset() error }); ok {
runOnRenderingThread(func() {
runOnRenderThread(func() {
err = r.Reset()
})
}
@ -558,7 +558,7 @@ func ResetGraphicsDriverState(graphicsDriver graphicsdriver.Graphics) (err error
// MaxImageSize returns the maximum size of an image.
func MaxImageSize(graphicsDriver graphicsdriver.Graphics) int {
var size int
runOnRenderingThread(func() {
runOnRenderThread(func() {
size = graphicsDriver.MaxImageSize()
})
return size

View File

@ -18,20 +18,20 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/thread"
)
var theThread Thread = thread.NewNoopThread()
var theRenderThread Thread = thread.NewNoopThread()
type Thread interface {
Call(f func())
}
// SetRenderingThread must be called from the rendering thread where e.g. OpenGL works.
// SetRenderThread must be called from the rendering thread where e.g. OpenGL works.
//
// TODO: Create thread in this package instead of setting it externally.
func SetRenderingThread(thread Thread) {
theThread = thread
func SetRenderThread(thread Thread) {
theRenderThread = thread
}
// runOnRenderingThread calls f on the rendering thread, and returns an error if any.
func runOnRenderingThread(f func()) {
theThread.Call(f)
// runOnRenderThread calls f on the rendering thread, and returns an error if any.
func runOnRenderThread(f func()) {
theRenderThread.Call(f)
}

View File

@ -30,7 +30,7 @@ func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
// Initialize the main thread first so the thread is available at u.run (#809).
u.mainThread = thread.NewOSThread()
graphicscommand.SetRenderingThread(u.mainThread)
graphicscommand.SetRenderThread(u.mainThread)
u.setRunning(true)
defer u.setRunning(false)
@ -70,11 +70,11 @@ func (u *userInterfaceImpl) runOnAnotherThreadFromMainThread(f func()) {
t := u.mainThread
defer func() {
u.mainThread = t
graphicscommand.SetRenderingThread(t)
graphicscommand.SetRenderThread(t)
}()
u.mainThread = thread.NewOSThread()
graphicscommand.SetRenderingThread(u.mainThread)
graphicscommand.SetRenderThread(u.mainThread)
ctx, cancel := stdcontext.WithCancel(stdcontext.Background())
defer cancel()

View File

@ -26,7 +26,7 @@ func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
// Initialize the main thread first so the thread is available at u.run (#809).
u.mainThread = thread.NewNoopThread()
graphicscommand.SetRenderingThread(u.mainThread)
graphicscommand.SetRenderThread(u.mainThread)
u.setRunning(true)
defer u.setRunning(false)