Skip to content

Commit

Permalink
restorable: Add ResetRestoringState to reset the state
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hajimehoshi committed Jul 20, 2019
1 parent 3f6628f commit 2d079b1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions internal/restorable/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions internal/shareable/shareable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions mipmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion uicontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down

0 comments on commit 2d079b1

Please sign in to comment.