restorable: Remove Image()

This commit is contained in:
Hajime Hoshi 2016-09-04 00:07:06 +09:00
parent 82febc9c6e
commit 02151e48ea
3 changed files with 22 additions and 15 deletions

View File

@ -95,7 +95,7 @@ func (i *images) restore(context *opengl.Context) error {
if img.isDisposed() { if img.isDisposed() {
continue continue
} }
if err := img.restorable.Image().Dispose(); err != nil { if err := img.restorable.DisposeOnlyImage(); err != nil {
return err return err
} }
} }

View File

@ -256,11 +256,6 @@ func (i *imageImpl) Dispose() error {
if i.disposed { if i.disposed {
return errors.New("ebiten: image is already disposed") return errors.New("ebiten: image is already disposed")
} }
if !i.screen {
if err := i.restorable.Image().Dispose(); err != nil {
return err
}
}
if err := i.restorable.Dispose(); err != nil { if err := i.restorable.Dispose(); err != nil {
return err return err
} }
@ -275,11 +270,13 @@ func (i *imageImpl) ReplacePixels(p []uint8) error {
} }
i.m.Lock() i.m.Lock()
defer i.m.Unlock() defer i.m.Unlock()
i.restorable.ReplacePixels(p)
if i.disposed { if i.disposed {
return errors.New("ebiten: image is already disposed") return errors.New("ebiten: image is already disposed")
} }
return i.restorable.Image().ReplacePixels(p) if err := i.restorable.ReplacePixels(p); err != nil {
return err
}
return nil
} }
func (i *imageImpl) isDisposed() bool { func (i *imageImpl) isDisposed() bool {
@ -291,5 +288,5 @@ func (i *imageImpl) isDisposed() bool {
func (i *imageImpl) isInvalidated(context *opengl.Context) bool { func (i *imageImpl) isInvalidated(context *opengl.Context) bool {
i.m.Lock() i.m.Lock()
defer i.m.Unlock() defer i.m.Unlock()
return i.restorable.Image().IsInvalidated(context) return i.restorable.IsInvalidated(context)
} }

View File

@ -105,7 +105,10 @@ func (p *Image) Fill(clr color.RGBA) error {
return nil return nil
} }
func (p *Image) ReplacePixels(pixels []uint8) { func (p *Image) ReplacePixels(pixels []uint8) error {
if err := p.image.ReplacePixels(pixels); err != nil {
return err
}
if p.basePixels == nil { if p.basePixels == nil {
p.basePixels = make([]uint8, len(pixels)) p.basePixels = make([]uint8, len(pixels))
} }
@ -113,6 +116,7 @@ func (p *Image) ReplacePixels(pixels []uint8) {
p.baseColor = color.RGBA{} p.baseColor = color.RGBA{}
p.drawImageHistory = nil p.drawImageHistory = nil
p.stale = false p.stale = false
return nil
} }
func (p *Image) DrawImage(img *Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) error { func (p *Image) DrawImage(img *Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) error {
@ -127,11 +131,6 @@ func (p *Image) DrawImage(img *Image, vertices []int16, geom graphics.Matrix, co
return nil return nil
} }
func (p *Image) Image() *graphics.Image {
// TODO: This function is temporary. Remove this.
return p.image
}
func (p *Image) appendDrawImageHistory(image *graphics.Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) { func (p *Image) appendDrawImageHistory(image *graphics.Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) {
if p.stale { if p.stale {
return return
@ -279,3 +278,14 @@ func (p *Image) Dispose() error {
p.stale = false p.stale = false
return nil return nil
} }
func (p *Image) DisposeOnlyImage() error {
if err := p.image.Dispose(); err != nil {
return err
}
return nil
}
func (p *Image) IsInvalidated(context *opengl.Context) bool {
return p.image.IsInvalidated(context)
}