internal/atlas: remvoe 'disposed' state

Updates #2808
This commit is contained in:
Hajime Hoshi 2023-11-03 14:33:11 +09:00
parent d72c4ec90b
commit 258f0fd941

View File

@ -137,7 +137,6 @@ type Image struct {
width int width int
height int height int
imageType ImageType imageType ImageType
disposed bool
backend *backend backend *backend
backendCreatedInThisFrame bool backendCreatedInThisFrame bool
@ -170,8 +169,8 @@ func (i *Image) moveTo(dst *Image) {
dst.deallocate() dst.deallocate()
*dst = *i *dst = *i
// i is no longer available but Dispose must not be called // i is no longer available but the finalizer must not be called
// since i and dst have the same values as node. // since i and dst share the same backend and the same node.
runtime.SetFinalizer(i, nil) runtime.SetFinalizer(i, nil)
} }
@ -336,18 +335,11 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
} }
func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, evenOdd bool, keepOnAtlas bool) { func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, evenOdd bool, keepOnAtlas bool) {
if i.disposed {
panic("atlas: the drawing target image must not be disposed (DrawTriangles)")
}
backends := make([]*backend, 0, len(srcs)) backends := make([]*backend, 0, len(srcs))
for _, src := range srcs { for _, src := range srcs {
if src == nil { if src == nil {
continue continue
} }
if src.disposed {
panic("atlas: the drawing source image must not be disposed (DrawTriangles)")
}
if src.backend == nil { if src.backend == nil {
// It is possible to spcify i.backend as a forbidden backend, but this might prevent a good allocation for a source image. // It is possible to spcify i.backend as a forbidden backend, but this might prevent a good allocation for a source image.
// If the backend becomes the same as i's, i's backend will be changed at ensureIsolatedFromSource. // If the backend becomes the same as i's, i's backend will be changed at ensureIsolatedFromSource.
@ -455,10 +447,6 @@ func (i *Image) WritePixels(pix []byte, region image.Rectangle) {
} }
func (i *Image) writePixels(pix []byte, region image.Rectangle) { func (i *Image) writePixels(pix []byte, region image.Rectangle) {
if i.disposed {
panic("atlas: the image must not be disposed at writePixels")
}
if l := 4 * region.Dx() * region.Dy(); len(pix) != l { if l := 4 * region.Dx() * region.Dy(); len(pix) != l {
panic(fmt.Sprintf("atlas: len(p) must be %d but %d", l, len(pix))) panic(fmt.Sprintf("atlas: len(p) must be %d but %d", l, len(pix)))
} }
@ -563,7 +551,6 @@ 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.deallocate() i.deallocate()
i.disposed = true
runtime.SetFinalizer(i, nil) runtime.SetFinalizer(i, nil)
}) })
} }
@ -578,10 +565,6 @@ func (i *Image) deallocate() {
i.usedAsDestinationCount = 0 i.usedAsDestinationCount = 0
imagesUsedAsDestination.remove(i) imagesUsedAsDestination.remove(i)
if i.disposed {
return
}
if i.backend == nil { if i.backend == nil {
// Not allocated yet. // Not allocated yet.
return return