From 1b8d4abfdb65abfa71e7173a108ff9aa7d046e4a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 7 Apr 2019 10:42:55 +0900 Subject: [PATCH] driver: Move ui.GraphicsContext to driver --- internal/driver/ui.go | 20 ++++++++++++++++++++ internal/ui/ui.go | 5 ----- internal/ui/ui_glfw.go | 8 ++++---- internal/ui/ui_js.go | 8 ++++---- internal/ui/ui_mobile.go | 6 +++--- 5 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 internal/driver/ui.go diff --git a/internal/driver/ui.go b/internal/driver/ui.go new file mode 100644 index 000000000..cf7476cef --- /dev/null +++ b/internal/driver/ui.go @@ -0,0 +1,20 @@ +// Copyright 2019 The Ebiten Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package driver + +type GraphicsContext interface { + SetSize(width, height int, scale float64) + Update(afterFrameUpdate func()) error +} diff --git a/internal/ui/ui.go b/internal/ui/ui.go index 8c6549aa7..024d4dea9 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -18,11 +18,6 @@ import ( "errors" ) -type GraphicsContext interface { - SetSize(width, height int, scale float64) - Update(afterFrameUpdate func()) error -} - // RegularTermination represents a regular termination. // Run can return this error, and if this error is received, // the game loop should be terminated as soon as possible. diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 1e53c74f8..3e43adcd4 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -568,7 +568,7 @@ func DeviceScaleFactor() float64 { return f } -func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error { +func Run(width, height int, scale float64, title string, g driver.GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error { u := currentUI _ = mainthread.Run(func() error { u.graphics = graphics @@ -714,7 +714,7 @@ func (u *userInterface) actualScreenScale() float64 { return u.getScale() * devicescale.GetAt(u.currentMonitor().GetPos()) } -func (u *userInterface) updateGraphicsContext(g GraphicsContext) { +func (u *userInterface) updateGraphicsContext(g driver.GraphicsContext) { actualScale := 0.0 sizeChanged := false // TODO: Is it possible to reduce 'runOnMainThread' calls? @@ -738,7 +738,7 @@ func (u *userInterface) updateGraphicsContext(g GraphicsContext) { } } -func (u *userInterface) update(g GraphicsContext) error { +func (u *userInterface) update(g driver.GraphicsContext) error { shouldClose := false _ = mainthread.Run(func() error { shouldClose = u.window.ShouldClose() @@ -802,7 +802,7 @@ func (u *userInterface) update(g GraphicsContext) error { return nil } -func (u *userInterface) loop(g GraphicsContext) error { +func (u *userInterface) loop(g driver.GraphicsContext) error { defer func() { _ = mainthread.Run(func() error { glfw.Terminate() diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 2eb488e6f..4f05af658 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -187,7 +187,7 @@ func (u *userInterface) actualScreenScale() float64 { return u.getScale() * devicescale.GetAt(0, 0) } -func (u *userInterface) updateGraphicsContext(g GraphicsContext) { +func (u *userInterface) updateGraphicsContext(g driver.GraphicsContext) { a := u.actualScreenScale() if u.lastActualScale != a { u.updateScreenSize() @@ -204,7 +204,7 @@ func (u *userInterface) suspended() bool { return !u.runnableInBackground && (!u.windowFocus || !u.pageVisible) } -func (u *userInterface) update(g GraphicsContext) error { +func (u *userInterface) update(g driver.GraphicsContext) error { if u.suspended() { hooks.SuspendAudio() return nil @@ -221,7 +221,7 @@ func (u *userInterface) update(g GraphicsContext) error { return nil } -func (u *userInterface) loop(g GraphicsContext) <-chan error { +func (u *userInterface) loop(g driver.GraphicsContext) <-chan error { ch := make(chan error) var cf js.Callback f := func([]js.Value) { @@ -385,7 +385,7 @@ func Loop(ch <-chan error) error { return <-ch } -func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error { +func Run(width, height int, scale float64, title string, g driver.GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error { u := currentUI u.input = input.(inputDriver) diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index d58941bbe..effa4752e 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -148,7 +148,7 @@ func appMain(a app.App) { } } -func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error { +func Run(width, height int, scale float64, title string, g driver.GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error { if graphics != opengl.Get() { panic("ui: graphics driver must be OpenGL") } @@ -190,7 +190,7 @@ func Loop(ch <-chan error) error { return nil } -func (u *userInterface) updateGraphicsContext(g GraphicsContext) { +func (u *userInterface) updateGraphicsContext(g driver.GraphicsContext) { width, height := 0, 0 actualScale := 0.0 @@ -229,7 +229,7 @@ func (u *userInterface) scaleImpl() float64 { return scale } -func (u *userInterface) update(g GraphicsContext) error { +func (u *userInterface) update(g driver.GraphicsContext) error { render: for { select {