Skip to content

Commit

Permalink
internal/graphicscommand: rename RunOnMainThread -> RunOnRenderingThread
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Feb 13, 2022
1 parent b695cb9 commit ce3f839
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions internal/graphicscommand/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
})
}
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/graphicscommand/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions internal/ui/run_notsinglethread.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/run_singlethread.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion internal/ui/ui_mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ce3f839

Please sign in to comment.