From b2ed6ef02747175350a85e695158607753b54680 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 20 Jul 2016 01:21:40 +0900 Subject: [PATCH] graphics: Skip clearing if possible --- imageimpl.go | 6 ++++++ pixels.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/imageimpl.go b/imageimpl.go index 0abb39f3f..585d82163 100644 --- a/imageimpl.go +++ b/imageimpl.go @@ -112,6 +112,9 @@ func (i *imageImpl) Fill(clr color.Color) error { if i.disposed { return errors.New("ebiten: image is already disposed") } + if clr == color.Transparent && i.pixels.isCleared() { + return nil + } i.pixels.fill(clr) return i.image.Fill(clr) } @@ -125,6 +128,9 @@ func (i *imageImpl) clearIfVolatile() error { if !i.volatile { return nil } + if i.pixels.isCleared() { + return nil + } i.pixels.clear() return i.image.Fill(color.Transparent) } diff --git a/pixels.go b/pixels.go index e6d86f15f..feed15c4a 100644 --- a/pixels.go +++ b/pixels.go @@ -53,6 +53,10 @@ func (p *pixels) clear() { 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) { p.basePixels = nil p.baseColor = clr