shareable: Call (*restorable.Image).Clear() when possible

This is a kind of relanding of c68c36b0b7.
Clearing the restorable.Image state can reduce the operations for
restoring.
This commit is contained in:
Hajime Hoshi 2019-02-12 16:13:33 +09:00
parent 5990da4844
commit 40f728a326
2 changed files with 10 additions and 0 deletions

View File

@ -103,6 +103,11 @@ func NewScreenFramebufferImage(width, height int) *Image {
return i return i
} }
func (i *Image) Clear() {
theImages.makeStaleIfDependingOn(i)
i.clear()
}
func (i *Image) clear() { func (i *Image) clear() {
if i.priority { if i.priority {
panic("restorable: clear cannot be called on a priority image") panic("restorable: clear cannot be called on a priority image")

View File

@ -278,6 +278,11 @@ func (i *Image) Fill(r, g, b, a uint8) {
i.ensureNotShared() i.ensureNotShared()
backendsM.Unlock() backendsM.Unlock()
if r == 0 && g == 0 && b == 0 && a == 0 {
i.backend.restorable.Clear()
return
}
rf := float32(0) rf := float32(0)
gf := float32(0) gf := float32(0)
bf := float32(0) bf := float32(0)