mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +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 {
|
||||
return nil
|
||||
}
|
||||
var s *shareable.Image
|
||||
s := shareable.NewImage(w2, h2)
|
||||
if m.orig.IsVolatile() {
|
||||
// TODO: As s is cleared every frame, is there any reason to keep it?
|
||||
s = shareable.NewVolatileImage(w2, h2)
|
||||
} else {
|
||||
s = shareable.NewImage(w2, h2)
|
||||
s.MakeVolatile()
|
||||
}
|
||||
|
||||
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.
|
||||
func newVolatileImage(width, height int) *Image {
|
||||
s := shareable.NewImage(width, height)
|
||||
s.MakeVolatile()
|
||||
i := &Image{
|
||||
mipmap: newMipmap(shareable.NewVolatileImage(width, height)),
|
||||
mipmap: newMipmap(s),
|
||||
}
|
||||
i.addr = i
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
|
@ -481,22 +481,13 @@ func (i *Image) allocate(shareable bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func NewVolatileImage(width, height int) *Image {
|
||||
func (i *Image) MakeVolatile() {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
|
||||
r := restorable.NewImage(width, height)
|
||||
r.MakeVolatile()
|
||||
i := &Image{
|
||||
width: width,
|
||||
height: height,
|
||||
backend: &backend{
|
||||
restorable: r,
|
||||
},
|
||||
neverShared: true,
|
||||
}
|
||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||
return i
|
||||
i.ensureNotShared()
|
||||
i.backend.restorable.MakeVolatile()
|
||||
i.neverShared = true
|
||||
}
|
||||
|
||||
func NewScreenFramebufferImage(width, height int) *Image {
|
||||
|
@ -140,7 +140,8 @@ func Disabled_TestReshared(t *testing.T) {
|
||||
}
|
||||
img2.ReplacePixels(pix)
|
||||
|
||||
img3 := NewVolatileImage(size, size)
|
||||
img3 := NewImage(size, size)
|
||||
img3.MakeVolatile()
|
||||
defer img3.Dispose()
|
||||
img1.ReplacePixels(make([]byte, 4*size*size))
|
||||
want = false
|
||||
|
Loading…
Reference in New Issue
Block a user