mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
graphics: Remove 'evacuated' state
This commit is contained in:
parent
f71dcd3466
commit
127cd4cab6
25
image.go
25
image.go
@ -66,9 +66,8 @@ func (t *delayedImageTasks) exec() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type images struct {
|
type images struct {
|
||||||
images map[*imageImpl]struct{}
|
images map[*imageImpl]struct{}
|
||||||
evacuated bool
|
m sync.Mutex
|
||||||
m sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var theImages = images{
|
var theImages = images{
|
||||||
@ -78,9 +77,6 @@ var theImages = images{
|
|||||||
func (i *images) add(img *imageImpl) (*Image, error) {
|
func (i *images) add(img *imageImpl) (*Image, error) {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.evacuated {
|
|
||||||
return nil, errors.New("ebiten: images must not be evacuated")
|
|
||||||
}
|
|
||||||
i.images[img] = struct{}{}
|
i.images[img] = struct{}{}
|
||||||
eimg := &Image{img}
|
eimg := &Image{img}
|
||||||
runtime.SetFinalizer(eimg, theImages.remove)
|
runtime.SetFinalizer(eimg, theImages.remove)
|
||||||
@ -93,24 +89,14 @@ func (i *images) remove(img *Image) {
|
|||||||
delete(i.images, img.impl)
|
delete(i.images, img.impl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *images) isEvacuated() bool {
|
|
||||||
i.m.Lock()
|
|
||||||
defer i.m.Unlock()
|
|
||||||
return i.evacuated
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *images) restorePixels() error {
|
func (i *images) restorePixels() error {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if !i.evacuated {
|
|
||||||
return errors.New("ebiten: images must be evacuated")
|
|
||||||
}
|
|
||||||
for img := range i.images {
|
for img := range i.images {
|
||||||
if err := img.restorePixels(); err != nil {
|
if err := img.restorePixels(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i.evacuated = false
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +199,6 @@ type imageImpl struct {
|
|||||||
texture *graphics.Texture
|
texture *graphics.Texture
|
||||||
defaultFramebuffer bool
|
defaultFramebuffer bool
|
||||||
disposed bool
|
disposed bool
|
||||||
evacuated bool
|
|
||||||
pixels []uint8
|
pixels []uint8
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
@ -311,18 +296,12 @@ func (i *imageImpl) At(x, y int) color.Color {
|
|||||||
func (i *imageImpl) restorePixels() error {
|
func (i *imageImpl) restorePixels() error {
|
||||||
imageM.Lock()
|
imageM.Lock()
|
||||||
defer imageM.Unlock()
|
defer imageM.Unlock()
|
||||||
defer func() {
|
|
||||||
i.evacuated = false
|
|
||||||
}()
|
|
||||||
if i.defaultFramebuffer {
|
if i.defaultFramebuffer {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if i.disposed {
|
if i.disposed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !i.evacuated {
|
|
||||||
return errors.New("ebiten: image must be evacuated")
|
|
||||||
}
|
|
||||||
if i.pixels == nil {
|
if i.pixels == nil {
|
||||||
return errors.New("ebiten: pixels must not be nil")
|
return errors.New("ebiten: pixels must not be nil")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user