Skip to content

Commit

Permalink
internal/graphicsdriver/metal, internal/graphicsdriver/opengl: change…
Browse files Browse the repository at this point in the history
… the return type to pointers

On second thought, returning pointers is more natural. Handling
nil is a caller's responsibility.
  • Loading branch information
hajimehoshi committed Mar 24, 2022
1 parent 7bb7e45 commit eeb5687
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion internal/graphicsdriver/metal/graphics_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func init() {

var theGraphics Graphics

func Get() graphicsdriver.Graphics {
func Get() *Graphics {
if !isMetalAvailable {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/graphicsdriver/opengl/graphics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

var theGraphics Graphics

func Get() graphicsdriver.Graphics {
func Get() *Graphics {
return &theGraphics
}

Expand Down
7 changes: 5 additions & 2 deletions internal/ui/ui_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ type graphicsDriverGetterImpl struct {
}

func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return opengl.Get()
return g.getOpenGL()
}

func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get()
if g := opengl.Get(); g != nil {
return g
}
return nil
}

func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {
Expand Down
9 changes: 6 additions & 3 deletions internal/ui/ui_cbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ import (

type graphicsDriverGetterImpl struct{}

func (*graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return opengl.Get()
func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return g.getOpenGL()
}

func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get()
if g := opengl.Get(); g != nil {
return g
}
return nil
}

func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {
Expand Down
10 changes: 8 additions & 2 deletions internal/ui/ui_glfw_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,17 @@ func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
}

func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get()
if g := opengl.Get(); g != nil {
return g
}
return nil
}

func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {
return metal.Get()
if m := metal.Get(); m != nil {
return m
}
return nil
}

// clearVideoModeScaleCache must be called from the main thread.
Expand Down
9 changes: 6 additions & 3 deletions internal/ui/ui_glfw_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ import (

type graphicsDriverGetterImpl struct{}

func (*graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return opengl.Get()
func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return g.getOpenGL()
}

func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get()
if g := opengl.Get(); g != nil {
return g
}
return nil
}

func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {
Expand Down
9 changes: 6 additions & 3 deletions internal/ui/ui_glfw_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ import (

type graphicsDriverGetterImpl struct{}

func (*graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return opengl.Get()
func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return g.getOpenGL()
}

func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get()
if g := opengl.Get(); g != nil {
return g
}
return nil
}

func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {
Expand Down
5 changes: 4 additions & 1 deletion internal/ui/ui_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
}

func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get()
if g := opengl.Get(); g != nil {
return g
}
return nil
}

func (g *graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {
Expand Down
9 changes: 6 additions & 3 deletions internal/ui/ui_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ import (

type graphicsDriverGetterImpl struct{}

func (*graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return opengl.Get()
func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return g.getOpenGL()
}

func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get()
if g := opengl.Get(); g != nil {
return g
}
return nil
}

func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {
Expand Down

0 comments on commit eeb5687

Please sign in to comment.