restorable: Add ResetRestoringState to reset the state

After Fill command, the image doesn't have to keep the restoring
information. Now Fill command is as same as DrawTriangles, there
is no way for restorable.Image to know whether it can reset the
state or not. ResetRestoringState clears the state explicitly.
This commit is contained in:
Hajime Hoshi 2019-07-20 13:57:16 +09:00
parent 3f6628f1cc
commit 2d079b123f
5 changed files with 29 additions and 1 deletions

View File

@ -127,6 +127,10 @@ func (i *Image) Fill(clr color.Color) error {
if af < 1.0 {
op.CompositeMode = CompositeModeCopy
}
// As Fill will change all the pixels of the image into the same color, all the information for restoring
// will be invalidated.
// TODO: This is a little hacky. Is there a better way?
i.mipmap.resetRestoringState()
i.DrawImage(emptyImage, op)
return nil
}

View File

@ -224,7 +224,14 @@ func (i *Image) clear() {
}
clearImage(i.image)
i.ResetRestoringState()
}
// ResetRestoringState resets all the information for restoring.
// ResetRestoringState doen't affect the underlying image.
//
// After ResetRestoringState, the image is assumed to be cleared.
func (i *Image) ResetRestoringState() {
i.basePixels = &Pixels{}
i.drawTrianglesHistory = nil
i.stale = false

View File

@ -312,6 +312,15 @@ func (i *Image) ClearFramebuffer() {
i.backend.restorable.Clear()
}
func (i *Image) ResetRestoringState() {
backendsM.Lock()
defer backendsM.Unlock()
if i.backend == nil {
return
}
i.backend.restorable.ResetRestoringState()
}
func (i *Image) ReplacePixels(p []byte) {
backendsM.Lock()
defer backendsM.Unlock()

View File

@ -112,6 +112,14 @@ func (m *mipmap) disposeMipmaps() {
}
}
func (m *mipmap) clearFramebuffer() {
m.orig.ClearFramebuffer()
}
func (m *mipmap) resetRestoringState() {
m.orig.ResetRestoringState()
}
// mipmapLevel returns an appropriate mipmap level for the given determinant of a geometry matrix.
//
// mipmapLevel returns -1 if det is 0.

View File

@ -111,7 +111,7 @@ func (c *uiContext) Update(afterFrameUpdate func()) error {
}
// This clear is needed for fullscreen mode or some mobile platforms (#622).
c.screen.mipmap.orig.ClearFramebuffer()
c.screen.mipmap.clearFramebuffer()
op := &DrawImageOptions{}