graphics: Reduce num of Image.Clear() calls

This commit is contained in:
Hajime Hoshi 2018-02-28 22:58:23 +09:00
parent 9db042ae9e
commit 02b4fc7917
2 changed files with 14 additions and 4 deletions

View File

@ -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)

View File

@ -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
}