From b8deabbd94eee23dc4fb758c04199691496cd418 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 1 Mar 2018 23:05:10 +0900 Subject: [PATCH] graphics: Reland: Bug fix: a too old frame was rendered at least on Android Fixes #525 --- graphicscontext.go | 39 ++++++++++++++++++++---------------- internal/restorable/image.go | 4 ---- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/graphicscontext.go b/graphicscontext.go index 5e79d44d4..2377dbaf9 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -16,6 +16,7 @@ package ebiten import ( "github.com/hajimehoshi/ebiten/internal/clock" + "github.com/hajimehoshi/ebiten/internal/graphics" "github.com/hajimehoshi/ebiten/internal/hooks" "github.com/hajimehoshi/ebiten/internal/restorable" "github.com/hajimehoshi/ebiten/internal/ui" @@ -97,27 +98,31 @@ 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) + // Clear the screen framebuffer by DrawImage instad of Fill + // to clear the whole region including fullscreen's padding. + op := &DrawImageOptions{} + w, h := emptyImage.Size() + // graphics.MaxImageSize should be the maximum size of framebuffer. + op.GeoM.Scale(graphics.MaxImageSize/float64(w), graphics.MaxImageSize/float64(h)) + op.CompositeMode = CompositeModeCopy + op.Filter = filterScreen // any filter is fine: just use the same filter as below. + c.screen.DrawImage(emptyImage, op) - op := &DrawImageOptions{} + dw, dh := c.screen.Size() + sw, _ := c.offscreen.Size() + scale := float64(dw) / float64(sw) - // c.screen is special: its Y axis is down to up, - // and the origin point is lower left. - op.GeoM.Scale(scale, -scale) - op.GeoM.Translate(0, float64(dh)) - op.GeoM.Translate(c.offsetX, c.offsetY) + op = &DrawImageOptions{} + // c.screen is special: its Y axis is down to up, + // and the origin point is lower left. + op.GeoM.Scale(scale, -scale) + op.GeoM.Translate(0, float64(dh)) + op.GeoM.Translate(c.offsetX, c.offsetY) - op.CompositeMode = CompositeModeCopy - op.Filter = filterScreen - _ = c.screen.DrawImage(c.offscreen, op) - } + op.CompositeMode = CompositeModeCopy + op.Filter = filterScreen + _ = c.screen.DrawImage(c.offscreen, op) if err := restorable.ResolveStaleImages(); err != nil { return err diff --git a/internal/restorable/image.go b/internal/restorable/image.go index a7e8ffb54..90c923fa1 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -129,10 +129,6 @@ func (i *Image) clearIfVolatile() { if !i.volatile { return } - i.ClearFramebuffer() -} - -func (i *Image) ClearFramebuffer() { i.basePixels = nil i.drawImageHistory = nil i.stale = false