From 40f728a3263c33e4fe9ba0681711a38799621405 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 12 Feb 2019 16:13:33 +0900 Subject: [PATCH] shareable: Call (*restorable.Image).Clear() when possible This is a kind of relanding of c68c36b0b70e77af1d7892eb8e2d89fa13526112. Clearing the restorable.Image state can reduce the operations for restoring. --- internal/restorable/image.go | 5 +++++ internal/shareable/shareable.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 68544de26..1fd0b4612 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -103,6 +103,11 @@ func NewScreenFramebufferImage(width, height int) *Image { return i } +func (i *Image) Clear() { + theImages.makeStaleIfDependingOn(i) + i.clear() +} + func (i *Image) clear() { if i.priority { panic("restorable: clear cannot be called on a priority image") diff --git a/internal/shareable/shareable.go b/internal/shareable/shareable.go index 6bc3207fa..92442c1a3 100644 --- a/internal/shareable/shareable.go +++ b/internal/shareable/shareable.go @@ -278,6 +278,11 @@ func (i *Image) Fill(r, g, b, a uint8) { i.ensureNotShared() backendsM.Unlock() + if r == 0 && g == 0 && b == 0 && a == 0 { + i.backend.restorable.Clear() + return + } + rf := float32(0) gf := float32(0) bf := float32(0)