graphics: Skip clearing if possible

This commit is contained in:
Hajime Hoshi 2016-07-20 01:21:40 +09:00
parent aa96822ce5
commit b2ed6ef027
2 changed files with 10 additions and 0 deletions

View File

@ -112,6 +112,9 @@ func (i *imageImpl) Fill(clr color.Color) error {
if i.disposed { if i.disposed {
return errors.New("ebiten: image is already disposed") return errors.New("ebiten: image is already disposed")
} }
if clr == color.Transparent && i.pixels.isCleared() {
return nil
}
i.pixels.fill(clr) i.pixels.fill(clr)
return i.image.Fill(clr) return i.image.Fill(clr)
} }
@ -125,6 +128,9 @@ func (i *imageImpl) clearIfVolatile() error {
if !i.volatile { if !i.volatile {
return nil return nil
} }
if i.pixels.isCleared() {
return nil
}
i.pixels.clear() i.pixels.clear()
return i.image.Fill(color.Transparent) return i.image.Fill(color.Transparent)
} }

View File

@ -53,6 +53,10 @@ func (p *pixels) clear() {
p.drawImageHistory = nil p.drawImageHistory = nil
} }
func (p *pixels) isCleared() bool {
return p.basePixels == nil && p.baseColor == nil && p.drawImageHistory == nil
}
func (p *pixels) fill(clr color.Color) { func (p *pixels) fill(clr color.Color) {
p.basePixels = nil p.basePixels = nil
p.baseColor = clr p.baseColor = clr