driver: Move ui.GraphicsContext to driver

This commit is contained in:
Hajime Hoshi 2019-04-07 10:42:55 +09:00
parent b579bd7fd0
commit 1b8d4abfdb
5 changed files with 31 additions and 16 deletions

20
internal/driver/ui.go Normal file
View File

@ -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
}

View File

@ -18,11 +18,6 @@ import (
"errors" "errors"
) )
type GraphicsContext interface {
SetSize(width, height int, scale float64)
Update(afterFrameUpdate func()) error
}
// RegularTermination represents a regular termination. // RegularTermination represents a regular termination.
// Run can return this error, and if this error is received, // Run can return this error, and if this error is received,
// the game loop should be terminated as soon as possible. // the game loop should be terminated as soon as possible.

View File

@ -568,7 +568,7 @@ func DeviceScaleFactor() float64 {
return f 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 u := currentUI
_ = mainthread.Run(func() error { _ = mainthread.Run(func() error {
u.graphics = graphics u.graphics = graphics
@ -714,7 +714,7 @@ func (u *userInterface) actualScreenScale() float64 {
return u.getScale() * devicescale.GetAt(u.currentMonitor().GetPos()) return u.getScale() * devicescale.GetAt(u.currentMonitor().GetPos())
} }
func (u *userInterface) updateGraphicsContext(g GraphicsContext) { func (u *userInterface) updateGraphicsContext(g driver.GraphicsContext) {
actualScale := 0.0 actualScale := 0.0
sizeChanged := false sizeChanged := false
// TODO: Is it possible to reduce 'runOnMainThread' calls? // 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 shouldClose := false
_ = mainthread.Run(func() error { _ = mainthread.Run(func() error {
shouldClose = u.window.ShouldClose() shouldClose = u.window.ShouldClose()
@ -802,7 +802,7 @@ func (u *userInterface) update(g GraphicsContext) error {
return nil return nil
} }
func (u *userInterface) loop(g GraphicsContext) error { func (u *userInterface) loop(g driver.GraphicsContext) error {
defer func() { defer func() {
_ = mainthread.Run(func() error { _ = mainthread.Run(func() error {
glfw.Terminate() glfw.Terminate()

View File

@ -187,7 +187,7 @@ func (u *userInterface) actualScreenScale() float64 {
return u.getScale() * devicescale.GetAt(0, 0) return u.getScale() * devicescale.GetAt(0, 0)
} }
func (u *userInterface) updateGraphicsContext(g GraphicsContext) { func (u *userInterface) updateGraphicsContext(g driver.GraphicsContext) {
a := u.actualScreenScale() a := u.actualScreenScale()
if u.lastActualScale != a { if u.lastActualScale != a {
u.updateScreenSize() u.updateScreenSize()
@ -204,7 +204,7 @@ func (u *userInterface) suspended() bool {
return !u.runnableInBackground && (!u.windowFocus || !u.pageVisible) 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() { if u.suspended() {
hooks.SuspendAudio() hooks.SuspendAudio()
return nil return nil
@ -221,7 +221,7 @@ func (u *userInterface) update(g GraphicsContext) error {
return nil return nil
} }
func (u *userInterface) loop(g GraphicsContext) <-chan error { func (u *userInterface) loop(g driver.GraphicsContext) <-chan error {
ch := make(chan error) ch := make(chan error)
var cf js.Callback var cf js.Callback
f := func([]js.Value) { f := func([]js.Value) {
@ -385,7 +385,7 @@ func Loop(ch <-chan error) error {
return <-ch 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 := currentUI
u.input = input.(inputDriver) u.input = input.(inputDriver)

View File

@ -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() { if graphics != opengl.Get() {
panic("ui: graphics driver must be OpenGL") panic("ui: graphics driver must be OpenGL")
} }
@ -190,7 +190,7 @@ func Loop(ch <-chan error) error {
return nil return nil
} }
func (u *userInterface) updateGraphicsContext(g GraphicsContext) { func (u *userInterface) updateGraphicsContext(g driver.GraphicsContext) {
width, height := 0, 0 width, height := 0, 0
actualScale := 0.0 actualScale := 0.0
@ -229,7 +229,7 @@ func (u *userInterface) scaleImpl() float64 {
return scale return scale
} }
func (u *userInterface) update(g GraphicsContext) error { func (u *userInterface) update(g driver.GraphicsContext) error {
render: render:
for { for {
select { select {