restorable: Refactoring

This commit is contained in:
Hajime Hoshi 2019-07-15 04:14:57 +09:00
parent 701c4eeb7c
commit 7e4e9cc893
2 changed files with 6 additions and 3 deletions

View File

@ -180,7 +180,7 @@ func NewScreenFramebufferImage(width, height int) *Image {
return i return i
} }
func (i *Image) Fill(r, g, b, a uint8) { func (i *Image) Fill(r, g, b, a byte) {
theImages.makeStaleIfDependingOn(i) theImages.makeStaleIfDependingOn(i)
i.fill(r, g, b, a) i.fill(r, g, b, a)
} }
@ -191,7 +191,7 @@ func (i *Image) clearForInitialization() {
i.fill(0, 0, 0, 0) i.fill(0, 0, 0, 0)
} }
func (i *Image) fill(r, g, b, a uint8) { func (i *Image) fill(r, g, b, a byte) {
if i.priority { if i.priority {
panic("restorable: clear cannot be called on a priority image") panic("restorable: clear cannot be called on a priority image")
} }
@ -533,7 +533,7 @@ func (i *Image) restore() error {
gimg.ReplacePixels(i.basePixels.Slice(), 0, 0, w, h) gimg.ReplacePixels(i.basePixels.Slice(), 0, 0, w, h)
} else { } else {
// Clear the image explicitly. // Clear the image explicitly.
pix := make([]uint8, w*h*4) pix := make([]byte, w*h*4)
gimg.ReplacePixels(pix, 0, 0, w, h) gimg.ReplacePixels(pix, 0, 0, w, h)
} }
for _, c := range i.drawTrianglesHistory { for _, c := range i.drawTrianglesHistory {

View File

@ -90,6 +90,9 @@ func RestoreIfNeeded() error {
return theImages.restore() return theImages.restore()
} }
// Images returns all the current images.
//
// This is for testing usage.
func Images() []image.Image { func Images() []image.Image {
var imgs []image.Image var imgs []image.Image
for img := range theImages.images { for img := range theImages.images {