From ce3f83958eda510277965be1b1d4507f8243c203 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 14 Feb 2022 00:18:37 +0900 Subject: [PATCH] internal/graphicscommand: rename RunOnMainThread -> RunOnRenderingThread --- internal/graphicscommand/command.go | 8 ++++---- internal/graphicscommand/thread.go | 8 ++++---- internal/ui/run_notsinglethread.go | 6 +++--- internal/ui/run_singlethread.go | 2 +- internal/ui/ui_mobile.go | 2 +- run.go | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 4f0aeddb9..f1c9f5c73 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -225,7 +225,7 @@ func (q *commandQueue) Enqueue(command command) { // Flush flushes the command queue. func (q *commandQueue) Flush() (err error) { - RunOnMainThread(func() { + RunOnRenderingThread(func() { err = q.flush() }) return @@ -701,7 +701,7 @@ func (c *newShaderCommand) Exec(indexOffset int) error { // InitializeGraphicsDriverState initialize the current graphics driver state. func InitializeGraphicsDriverState() (err error) { - RunOnMainThread(func() { + RunOnRenderingThread(func() { err = theGraphicsDriver.Initialize() }) return @@ -711,7 +711,7 @@ func InitializeGraphicsDriverState() (err error) { // If the graphics driver doesn't have an API to reset, ResetGraphicsDriverState does nothing. func ResetGraphicsDriverState() (err error) { if r, ok := theGraphicsDriver.(interface{ Reset() error }); ok { - RunOnMainThread(func() { + RunOnRenderingThread(func() { err = r.Reset() }) } @@ -721,7 +721,7 @@ func ResetGraphicsDriverState() (err error) { // MaxImageSize returns the maximum size of an image. func MaxImageSize() int { var size int - RunOnMainThread(func() { + RunOnRenderingThread(func() { size = theGraphicsDriver.MaxImageSize() }) return size diff --git a/internal/graphicscommand/thread.go b/internal/graphicscommand/thread.go index 6b6d8a426..408e510a9 100644 --- a/internal/graphicscommand/thread.go +++ b/internal/graphicscommand/thread.go @@ -20,13 +20,13 @@ type Thread interface { Call(f func()) } -// SetMainThread must be called from the main thread (i.e, the goroutine where the thread is created). -func SetMainThread(thread Thread) { +// SetRenderingThread must be called from the rendering thread where e.g. OpenGL works. +func SetRenderingThread(thread Thread) { theThread = thread } -// RunOnMainThread calls f on the main thread, and returns an error if any. -func RunOnMainThread(f func()) { +// RunOnRenderingThread calls f on the rendering thread, and returns an error if any. +func RunOnRenderingThread(f func()) { // The thread is nil when 1) GOOS=js or 2) using golang.org/x/mobile/gl. // When golang.org/x/mobile/gl is used, all the GL functions are called via Context, which already runs on an // appropriate thread. diff --git a/internal/ui/run_notsinglethread.go b/internal/ui/run_notsinglethread.go index 584419860..93beb2a1d 100644 --- a/internal/ui/run_notsinglethread.go +++ b/internal/ui/run_notsinglethread.go @@ -27,7 +27,7 @@ func (u *UserInterface) Run(game Game) error { // Initialize the main thread first so the thread is available at u.run (#809). u.t = thread.NewOSThread() - graphicscommand.SetMainThread(u.t) + graphicscommand.SetRenderingThread(u.t) ch := make(chan error, 1) go func() { @@ -65,11 +65,11 @@ func (u *UserInterface) runOnAnotherThreadFromMainThread(f func() error) error { t := u.t defer func() { u.t = t - graphicscommand.SetMainThread(t) + graphicscommand.SetRenderingThread(t) }() u.t = thread.NewOSThread() - graphicscommand.SetMainThread(u.t) + graphicscommand.SetRenderingThread(u.t) var err error go func() { diff --git a/internal/ui/run_singlethread.go b/internal/ui/run_singlethread.go index bf8f0d0d7..eb738fea8 100644 --- a/internal/ui/run_singlethread.go +++ b/internal/ui/run_singlethread.go @@ -27,7 +27,7 @@ func (u *UserInterface) Run(game Game) error { // Initialize the main thread first so the thread is available at u.run (#809). u.t = thread.NewNoopThread() - graphicscommand.SetMainThread(u.t) + graphicscommand.SetRenderingThread(u.t) u.setRunning(true) diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index d5bd9968a..e48f6bd17 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -286,7 +286,7 @@ func (u *UserInterface) run(game Game, mainloop bool) (err error) { graphics().(*opengl.Graphics).SetGomobileGLContext(ctx) } else { u.t = thread.NewOSThread() - graphicscommand.SetMainThread(u.t) + graphicscommand.SetRenderingThread(u.t) } // If gomobile-build is used, wait for the outside size fixed. diff --git a/run.go b/run.go index 7de963b8f..f4e024e28 100644 --- a/run.go +++ b/run.go @@ -164,7 +164,7 @@ func RunGame(game Game) error { // RunOnMainThread calls the given f on the main thread, and blocks until f returns. func RunOnMainThread(f func()) { - graphicscommand.RunOnMainThread(f) + graphicscommand.RunOnRenderingThread(f) } func isRunGameEnded() bool {