internal/graphicsdriver/opengl: refactoring: remove SetCanvas

This commit is contained in:
Hajime Hoshi 2022-11-13 15:18:44 +09:00
parent a0a5f2b301
commit 42566c6c9a
2 changed files with 10 additions and 13 deletions

View File

@ -18,11 +18,7 @@ import (
"syscall/js" "syscall/js"
) )
func (g *Graphics) init(_ any) error { func (g *Graphics) init(canvas any) error {
// Do nothing. g.context.canvas = canvas.(js.Value)
return nil return nil
} }
func (g *Graphics) SetCanvas(canvas js.Value) {
g.context.canvas = canvas
}

View File

@ -26,15 +26,17 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/hooks" "github.com/hajimehoshi/ebiten/v2/internal/hooks"
) )
type graphicsDriverCreatorImpl struct{} type graphicsDriverCreatorImpl struct {
canvas js.Value
}
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) { func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
graphics, err := g.newOpenGL() graphics, err := g.newOpenGL()
return graphics, GraphicsLibraryOpenGL, err return graphics, GraphicsLibraryOpenGL, err
} }
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) { func (g *graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
return opengl.NewGraphics(nil) return opengl.NewGraphics(g.canvas)
} }
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) { func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
@ -645,14 +647,13 @@ func (u *userInterfaceImpl) Run(game Game) error {
} }
} }
u.running = true u.running = true
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}) g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
canvas: canvas,
})
if err != nil { if err != nil {
return err return err
} }
u.graphicsDriver = g u.graphicsDriver = g
if g, ok := u.graphicsDriver.(interface{ SetCanvas(js.Value) }); ok {
g.SetCanvas(canvas)
}
return <-u.loop(game) return <-u.loop(game)
} }