From 02b4fc79179d14e1c8d9e29bac75e3beac7c1b82 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 28 Feb 2018 22:58:23 +0900 Subject: [PATCH] graphics: Reduce num of Image.Clear() calls --- graphicscontext.go | 5 ++++- internal/restorable/image.go | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/graphicscontext.go b/graphicscontext.go index 5597a41df..fe0101ffc 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -87,7 +87,6 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error { return err } for i := 0; i < updateCount; i++ { - restorable.ClearVolatileImages() setRunningSlowly(i < updateCount-1) if err := hooks.Run(); err != nil { return err @@ -98,6 +97,10 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error { afterFrameUpdate() } if 0 < updateCount { + // Call ClearFramebuffer instead of c.screen.Clear() + // to clear the whole region including fullscreen's padding. + c.screen.restorable.ClearFramebuffer() + dw, dh := c.screen.Size() sw, _ := c.offscreen.Size() scale := float64(dw) / float64(sw) diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 38ae12e4a..0ab17579b 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -90,7 +90,7 @@ func NewImage(width, height int, volatile bool) *Image { func NewScreenFramebufferImage(width, height int) *Image { i := &Image{ image: graphics.NewScreenFramebufferImage(width, height), - volatile: true, + volatile: false, screen: true, } theImages.add(i) @@ -129,6 +129,10 @@ func (i *Image) clearIfVolatile() { if !i.volatile { return } + i.ClearFramebuffer() +} + +func (i *Image) ClearFramebuffer() { i.basePixels = nil i.drawImageHistory = nil i.stale = false @@ -167,7 +171,7 @@ func (i *Image) DrawImage(img *Image, sx0, sy0, sx1, sy1 int, geom *affine.GeoM, return } theImages.makeStaleIfDependingOn(i) - if img.stale || img.volatile || !IsRestoringEnabled() { + if img.stale || img.volatile || i.screen || !IsRestoringEnabled() { i.makeStale() } else { i.appendDrawImageHistory(img, vs, colorm, mode, filter) @@ -177,7 +181,7 @@ func (i *Image) DrawImage(img *Image, sx0, sy0, sx1, sy1 int, geom *affine.GeoM, // appendDrawImageHistory appends a draw-image history item to the image. func (i *Image) appendDrawImageHistory(image *Image, vertices []float32, colorm *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) { - if i.stale || i.volatile { + if i.stale || i.volatile || i.screen { return } if len(i.drawImageHistory) > 0 { @@ -253,6 +257,9 @@ func (i *Image) resolveStale() error { if i.volatile { return nil } + if i.screen { + return nil + } if !i.stale { return nil }