mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 04:22:05 +01:00
shareable: Refactoring: Add moveTo
This commit is contained in:
parent
693116ffd6
commit
b2a4ddf853
@ -95,6 +95,15 @@ type Image struct {
|
|||||||
countForShare int
|
countForShare int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Image) moveTo(dst *Image) {
|
||||||
|
dst.dispose(false)
|
||||||
|
*dst = *i
|
||||||
|
|
||||||
|
// i is no longer available but Dispose must not be called
|
||||||
|
// since i and dst have the same values like node.
|
||||||
|
runtime.SetFinalizer(i, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Image) isShared() bool {
|
func (i *Image) isShared() bool {
|
||||||
return i.node != nil
|
return i.node != nil
|
||||||
}
|
}
|
||||||
@ -154,11 +163,8 @@ func (i *Image) forceShared() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
newI.replacePixels(pixels)
|
newI.replacePixels(pixels)
|
||||||
i.dispose(false)
|
newI.moveTo(i)
|
||||||
*i = *newI
|
i.countForShare = 0
|
||||||
// TODO: This is a very tricky hack not to call Dispose twice for the same backend.
|
|
||||||
// Avoid such hack.
|
|
||||||
runtime.SetFinalizer(newI, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) region() (x, y, width, height int) {
|
func (i *Image) region() (x, y, width, height int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user