internal/atlas: refactoring

This commit is contained in:
Hajime Hoshi 2023-11-03 14:09:44 +09:00
parent 4a00891960
commit d72c4ec90b

View File

@ -167,7 +167,7 @@ type Image struct {
// //
// moveTo is similar to C++'s move semantics. // moveTo is similar to C++'s move semantics.
func (i *Image) moveTo(dst *Image) { func (i *Image) moveTo(dst *Image) {
dst.dispose(false) dst.deallocate()
*dst = *i *dst = *i
// i is no longer available but Dispose must not be called // i is no longer available but Dispose must not be called
@ -562,23 +562,21 @@ func (i *Image) readPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte
func (i *Image) MarkDisposed() { func (i *Image) MarkDisposed() {
// As MarkDisposed can be invoked from finalizers, backendsM should not be used. // As MarkDisposed can be invoked from finalizers, backendsM should not be used.
appendDeferred(func() { appendDeferred(func() {
i.dispose(true) i.deallocate()
i.disposed = true
runtime.SetFinalizer(i, nil)
}) })
} }
func (i *Image) dispose(markDisposed bool) { func (i *Image) deallocate() {
defer func() { defer func() {
if markDisposed {
i.disposed = true
}
i.backend = nil i.backend = nil
i.node = nil i.node = nil
if markDisposed {
runtime.SetFinalizer(i, nil)
}
}() }()
i.resetUsedAsSourceCount() i.resetUsedAsSourceCount()
i.usedAsDestinationCount = 0
imagesUsedAsDestination.remove(i)
if i.disposed { if i.disposed {
return return