mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
graraphics: Refactoring: Remove imageImpl.disposed
This commit is contained in:
parent
959abec06d
commit
3ad6dc4679
23
imageimpl.go
23
imageimpl.go
@ -28,7 +28,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type imageImpl struct {
|
type imageImpl struct {
|
||||||
disposed bool
|
|
||||||
restorable *restorable.Image
|
restorable *restorable.Image
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
@ -89,7 +88,7 @@ func newScreenImageImpl(width, height int) (*imageImpl, error) {
|
|||||||
func (i *imageImpl) Fill(clr color.Color) error {
|
func (i *imageImpl) Fill(clr color.Color) error {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.disposed {
|
if i.restorable == nil {
|
||||||
return errors.New("ebiten: image is already disposed")
|
return errors.New("ebiten: image is already disposed")
|
||||||
}
|
}
|
||||||
rgba := color.RGBAModel.Convert(clr).(color.RGBA)
|
rgba := color.RGBAModel.Convert(clr).(color.RGBA)
|
||||||
@ -102,7 +101,7 @@ func (i *imageImpl) Fill(clr color.Color) error {
|
|||||||
func (i *imageImpl) clearIfVolatile() error {
|
func (i *imageImpl) clearIfVolatile() error {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.disposed {
|
if i.restorable == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := i.restorable.ClearIfVolatile(); err != nil {
|
if err := i.restorable.ClearIfVolatile(); err != nil {
|
||||||
@ -141,7 +140,7 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
|||||||
}
|
}
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.disposed {
|
if i.restorable == nil {
|
||||||
return errors.New("ebiten: image is already disposed")
|
return errors.New("ebiten: image is already disposed")
|
||||||
}
|
}
|
||||||
geom := options.GeoM
|
geom := options.GeoM
|
||||||
@ -159,7 +158,7 @@ func (i *imageImpl) At(x, y int, context *opengl.Context) color.Color {
|
|||||||
}
|
}
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.disposed {
|
if i.restorable == nil {
|
||||||
return color.Transparent
|
return color.Transparent
|
||||||
}
|
}
|
||||||
w, _ := i.restorable.Size()
|
w, _ := i.restorable.Size()
|
||||||
@ -174,7 +173,7 @@ func (i *imageImpl) At(x, y int, context *opengl.Context) color.Color {
|
|||||||
func (i *imageImpl) resolveStalePixels(context *opengl.Context) error {
|
func (i *imageImpl) resolveStalePixels(context *opengl.Context) error {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.disposed {
|
if i.restorable == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := i.restorable.ReadPixelsFromVRAMIfStale(context); err != nil {
|
if err := i.restorable.ReadPixelsFromVRAMIfStale(context); err != nil {
|
||||||
@ -189,7 +188,7 @@ func (i *imageImpl) resetPixelsIfDependingOn(target *imageImpl, context *opengl.
|
|||||||
if i == target {
|
if i == target {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if i.disposed {
|
if i.restorable == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if target.isDisposed() {
|
if target.isDisposed() {
|
||||||
@ -210,7 +209,7 @@ func (i *imageImpl) hasDependency() bool {
|
|||||||
func (i *imageImpl) restore(context *opengl.Context) error {
|
func (i *imageImpl) restore(context *opengl.Context) error {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.disposed {
|
if i.restorable == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := i.restorable.Restore(context); err != nil {
|
if err := i.restorable.Restore(context); err != nil {
|
||||||
@ -222,13 +221,13 @@ func (i *imageImpl) restore(context *opengl.Context) error {
|
|||||||
func (i *imageImpl) Dispose() error {
|
func (i *imageImpl) Dispose() error {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.disposed {
|
if i.restorable == nil {
|
||||||
return errors.New("ebiten: image is already disposed")
|
return errors.New("ebiten: image is already disposed")
|
||||||
}
|
}
|
||||||
if err := i.restorable.Dispose(); err != nil {
|
if err := i.restorable.Dispose(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.disposed = true
|
i.restorable = nil
|
||||||
runtime.SetFinalizer(i, nil)
|
runtime.SetFinalizer(i, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -240,7 +239,7 @@ func (i *imageImpl) ReplacePixels(p []uint8) error {
|
|||||||
}
|
}
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.disposed {
|
if i.restorable == nil {
|
||||||
return errors.New("ebiten: image is already disposed")
|
return errors.New("ebiten: image is already disposed")
|
||||||
}
|
}
|
||||||
if err := i.restorable.ReplacePixels(p); err != nil {
|
if err := i.restorable.ReplacePixels(p); err != nil {
|
||||||
@ -252,7 +251,7 @@ func (i *imageImpl) ReplacePixels(p []uint8) error {
|
|||||||
func (i *imageImpl) isDisposed() bool {
|
func (i *imageImpl) isDisposed() bool {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
return i.disposed
|
return i.restorable == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) isInvalidated(context *opengl.Context) bool {
|
func (i *imageImpl) isInvalidated(context *opengl.Context) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user