mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 04:22:05 +01:00
shareable: Add MakeVolatile
This commit is contained in:
parent
5147bbde9d
commit
5fed3d3bed
10
image.go
10
image.go
@ -66,12 +66,10 @@ func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
|||||||
if w2 == 0 || h2 == 0 {
|
if w2 == 0 || h2 == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var s *shareable.Image
|
s := shareable.NewImage(w2, h2)
|
||||||
if m.orig.IsVolatile() {
|
if m.orig.IsVolatile() {
|
||||||
// TODO: As s is cleared every frame, is there any reason to keep it?
|
// TODO: As s is cleared every frame, is there any reason to keep it?
|
||||||
s = shareable.NewVolatileImage(w2, h2)
|
s.MakeVolatile()
|
||||||
} else {
|
|
||||||
s = shareable.NewImage(w2, h2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var src *shareable.Image
|
var src *shareable.Image
|
||||||
@ -743,8 +741,10 @@ func NewImage(width, height int, filter Filter) (*Image, error) {
|
|||||||
//
|
//
|
||||||
// If width or height is less than 1 or more than device-dependent maximum size, newVolatileImage panics.
|
// If width or height is less than 1 or more than device-dependent maximum size, newVolatileImage panics.
|
||||||
func newVolatileImage(width, height int) *Image {
|
func newVolatileImage(width, height int) *Image {
|
||||||
|
s := shareable.NewImage(width, height)
|
||||||
|
s.MakeVolatile()
|
||||||
i := &Image{
|
i := &Image{
|
||||||
mipmap: newMipmap(shareable.NewVolatileImage(width, height)),
|
mipmap: newMipmap(s),
|
||||||
}
|
}
|
||||||
i.addr = i
|
i.addr = i
|
||||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||||
|
@ -481,22 +481,13 @@ func (i *Image) allocate(shareable bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVolatileImage(width, height int) *Image {
|
func (i *Image) MakeVolatile() {
|
||||||
backendsM.Lock()
|
backendsM.Lock()
|
||||||
defer backendsM.Unlock()
|
defer backendsM.Unlock()
|
||||||
|
|
||||||
r := restorable.NewImage(width, height)
|
i.ensureNotShared()
|
||||||
r.MakeVolatile()
|
i.backend.restorable.MakeVolatile()
|
||||||
i := &Image{
|
i.neverShared = true
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
backend: &backend{
|
|
||||||
restorable: r,
|
|
||||||
},
|
|
||||||
neverShared: true,
|
|
||||||
}
|
|
||||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
|
||||||
return i
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewScreenFramebufferImage(width, height int) *Image {
|
func NewScreenFramebufferImage(width, height int) *Image {
|
||||||
|
@ -140,7 +140,8 @@ func Disabled_TestReshared(t *testing.T) {
|
|||||||
}
|
}
|
||||||
img2.ReplacePixels(pix)
|
img2.ReplacePixels(pix)
|
||||||
|
|
||||||
img3 := NewVolatileImage(size, size)
|
img3 := NewImage(size, size)
|
||||||
|
img3.MakeVolatile()
|
||||||
defer img3.Dispose()
|
defer img3.Dispose()
|
||||||
img1.ReplacePixels(make([]byte, 4*size*size))
|
img1.ReplacePixels(make([]byte, 4*size*size))
|
||||||
want = false
|
want = false
|
||||||
|
Loading…
Reference in New Issue
Block a user