mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
restorable: Refactoring
This commit is contained in:
parent
bc105e7350
commit
8b48d010ed
2
image.go
2
image.go
@ -167,7 +167,7 @@ func (i *Image) Dispose() error {
|
||||
if i.restorable == nil {
|
||||
return nil
|
||||
}
|
||||
restorable.Images().Remove(i.restorable)
|
||||
i.restorable.Dispose()
|
||||
i.restorable = nil
|
||||
runtime.SetFinalizer(i, nil)
|
||||
return nil
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"errors"
|
||||
"image"
|
||||
"image/color"
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
@ -55,6 +56,7 @@ func NewImage(width, height int, filter opengl.Filter, volatile bool) *Image {
|
||||
volatile: volatile,
|
||||
}
|
||||
theImages.add(i)
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
return i
|
||||
}
|
||||
|
||||
@ -70,6 +72,7 @@ func NewImageFromImage(source *image.RGBA, width, height int, filter opengl.Filt
|
||||
filter: filter,
|
||||
}
|
||||
theImages.add(i)
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
return i
|
||||
}
|
||||
|
||||
@ -80,6 +83,7 @@ func NewScreenFramebufferImage(width, height int) *Image {
|
||||
screen: true,
|
||||
}
|
||||
theImages.add(i)
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
return i
|
||||
}
|
||||
|
||||
@ -275,7 +279,7 @@ func (p *Image) restore(context *opengl.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Image) dispose() {
|
||||
func (p *Image) Dispose() {
|
||||
theImages.resetPixelsIfDependingOn(p)
|
||||
p.image.Dispose()
|
||||
p.image = nil
|
||||
@ -283,6 +287,8 @@ func (p *Image) dispose() {
|
||||
p.baseColor = color.RGBA{}
|
||||
p.drawImageHistory = nil
|
||||
p.stale = false
|
||||
theImages.remove(p)
|
||||
runtime.SetFinalizer(p, nil)
|
||||
}
|
||||
|
||||
func (p *Image) IsInvalidated(context *opengl.Context) bool {
|
||||
|
@ -15,7 +15,6 @@
|
||||
package restorable
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||
@ -39,15 +38,12 @@ func (i *images) add(img *Image) {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
i.images[img] = struct{}{}
|
||||
runtime.SetFinalizer(img, theImages.Remove)
|
||||
}
|
||||
|
||||
func (i *images) Remove(img *Image) {
|
||||
img.dispose()
|
||||
func (i *images) remove(img *Image) {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
delete(i.images, img)
|
||||
runtime.SetFinalizer(img, nil)
|
||||
}
|
||||
|
||||
func (i *images) ResolveStalePixels(context *opengl.Context) error {
|
||||
|
Loading…
Reference in New Issue
Block a user