From 12ce5ae83a0d99b74ca3bccc9e2fbbd8acf05c74 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 21 Mar 2022 16:48:33 +0900 Subject: [PATCH] internal/ui: remove the call of graphicsDriver() from the context --- internal/ui/context.go | 16 ++++++++-------- internal/ui/ui_glfw.go | 4 ++-- internal/ui/ui_js.go | 4 ++-- internal/ui/ui_mobile.go | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/ui/context.go b/internal/ui/context.go index c3132144d..bc07dbfc9 100644 --- a/internal/ui/context.go +++ b/internal/ui/context.go @@ -55,16 +55,16 @@ func newContextImpl(game Game) *contextImpl { } } -func (c *contextImpl) updateFrame(outsideWidth, outsideHeight float64, deviceScaleFactor float64) error { +func (c *contextImpl) updateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error { // TODO: If updateCount is 0 and vsync is disabled, swapping buffers can be skipped. - return c.updateFrameImpl(clock.Update(theGlobalState.maxTPS()), outsideWidth, outsideHeight, deviceScaleFactor) + return c.updateFrameImpl(graphicsDriver, clock.Update(theGlobalState.maxTPS()), outsideWidth, outsideHeight, deviceScaleFactor) } -func (c *contextImpl) forceUpdateFrame(outsideWidth, outsideHeight float64, deviceScaleFactor float64) error { - return c.updateFrameImpl(1, outsideWidth, outsideHeight, deviceScaleFactor) +func (c *contextImpl) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error { + return c.updateFrameImpl(graphicsDriver, 1, outsideWidth, outsideHeight, deviceScaleFactor) } -func (c *contextImpl) updateFrameImpl(updateCount int, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error { +func (c *contextImpl) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, updateCount int, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error { if err := theGlobalState.error(); err != nil { return err } @@ -82,7 +82,7 @@ func (c *contextImpl) updateFrameImpl(updateCount int, outsideWidth, outsideHeig debug.Logf("----\n") - if err := buffered.BeginFrame(graphicsDriver()); err != nil { + if err := buffered.BeginFrame(graphicsDriver); err != nil { return err } @@ -110,14 +110,14 @@ func (c *contextImpl) updateFrameImpl(updateCount int, outsideWidth, outsideHeig // Draw the game. screenScale, offsetX, offsetY := c.screenScaleAndOffsets(deviceScaleFactor) - if err := c.game.Draw(screenScale, offsetX, offsetY, graphicsDriver().NeedsClearingScreen(), graphicsDriver().FramebufferYDirection(), theGlobalState.isScreenClearedEveryFrame(), theGlobalState.isScreenFilterEnabled()); err != nil { + if err := c.game.Draw(screenScale, offsetX, offsetY, graphicsDriver.NeedsClearingScreen(), graphicsDriver.FramebufferYDirection(), theGlobalState.isScreenClearedEveryFrame(), theGlobalState.isScreenFilterEnabled()); err != nil { return err } // All the vertices data are consumed at the end of the frame, and the data backend can be // available after that. Until then, lock the vertices backend. return graphicspkg.LockAndResetVertices(func() error { - if err := buffered.EndFrame(graphicsDriver()); err != nil { + if err := buffered.EndFrame(graphicsDriver); err != nil { return err } return nil diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 06156bdee..8681ee5a4 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -715,7 +715,7 @@ func (u *UserInterface) registerWindowSetSizeCallback() { // In order to call it safely, use runOnAnotherThreadFromMainThread. var err error u.runOnAnotherThreadFromMainThread(func() { - err = u.context.forceUpdateFrame(outsideWidth, outsideHeight, deviceScaleFactor) + err = u.context.forceUpdateFrame(graphicsDriver(), outsideWidth, outsideHeight, deviceScaleFactor) }) if err != nil { u.err = err @@ -1025,7 +1025,7 @@ func (u *UserInterface) loop() error { return err } - if err := u.context.updateFrame(outsideWidth, outsideHeight, deviceScaleFactor); err != nil { + if err := u.context.updateFrame(graphicsDriver(), outsideWidth, outsideHeight, deviceScaleFactor); err != nil { return err } diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index c3abdda12..7013d0a76 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -284,11 +284,11 @@ func (u *UserInterface) updateImpl(force bool) error { w, h := u.outsideSize() if force { - if err := u.context.forceUpdateFrame(w, h, u.DeviceScaleFactor()); err != nil { + if err := u.context.forceUpdateFrame(graphicsDriver(), w, h, u.DeviceScaleFactor()); err != nil { return err } } else { - if err := u.context.updateFrame(w, h, u.DeviceScaleFactor()); err != nil { + if err := u.context.updateFrame(graphicsDriver(), w, h, u.DeviceScaleFactor()); err != nil { return err } } diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index 27467fd9f..e7c8335cf 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -321,7 +321,7 @@ func (u *UserInterface) update() error { }() w, h := u.outsideSize() - if err := u.context.updateFrame(w, h, deviceScale()); err != nil { + if err := u.context.updateFrame(graphicsDriver(), w, h, deviceScale()); err != nil { return err } return nil