graphics: Refactoring: Remove imports

This commit is contained in:
Hajime Hoshi 2019-09-19 02:13:11 +09:00
parent e0790ee950
commit 95bc445fea
3 changed files with 22 additions and 10 deletions

View File

@ -23,7 +23,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/shareable"
)
var (
@ -748,9 +747,8 @@ type DrawImageOptions struct {
//
// Error returned by NewImage is always nil as of 1.5.0-alpha.
func NewImage(width, height int, filter Filter) (*Image, error) {
s := shareable.NewImage(width, height)
i := &Image{
mipmap: newMipmap(s),
mipmap: newMipmap(width, height),
filter: filter,
}
i.addr = i
@ -780,7 +778,7 @@ func (i *Image) makeVolatile() {
if i.isDisposed() {
return
}
i.mipmap.orig.MakeVolatile()
i.mipmap.makeVolatile()
i.disposeMipmaps()
}
@ -797,9 +795,8 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
width, height := size.X, size.Y
s := shareable.NewImage(width, height)
i := &Image{
mipmap: newMipmap(s),
mipmap: newMipmap(width, height),
filter: filter,
}
i.addr = i
@ -810,7 +807,7 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
func newScreenFramebufferImage(width, height int) *Image {
i := &Image{
mipmap: newMipmap(shareable.NewScreenFramebufferImage(width, height)),
mipmap: newScreenFramebufferMipmap(width, height),
filter: FilterDefault,
}
i.addr = i

View File

@ -52,7 +52,7 @@ func takeScreenshot(screen *Image) error {
return err
}
if err := screen.mipmap.orig.Dump(newname); err != nil {
if err := screen.mipmap.dump(newname); err != nil {
return err
}

View File

@ -31,9 +31,16 @@ type mipmap struct {
imgs map[image.Rectangle]levelToImage
}
func newMipmap(s *shareable.Image) *mipmap {
func newMipmap(width, height int) *mipmap {
return &mipmap{
orig: s,
orig: shareable.NewImage(width, height),
imgs: map[image.Rectangle]levelToImage{},
}
}
func newScreenFramebufferMipmap(width, height int) *mipmap {
return &mipmap{
orig: shareable.NewScreenFramebufferImage(width, height),
imgs: map[image.Rectangle]levelToImage{},
}
}
@ -42,6 +49,14 @@ func (m *mipmap) original() *shareable.Image {
return m.orig
}
func (m *mipmap) makeVolatile() {
m.orig.MakeVolatile()
}
func (m *mipmap) dump(name string) error {
return m.orig.Dump(name)
}
func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
if level == 0 {
panic("ebiten: level must be non-zero at level")