restorable: Remove graphics.Image.Fill usage

This commit is contained in:
Hajime Hoshi 2018-02-24 16:13:25 +09:00
parent 2ba89591db
commit fe7aae32a0
2 changed files with 21 additions and 3 deletions

View File

@ -145,6 +145,15 @@ func (i *Image) makeStale() {
i.stale = true
}
var (
dummyImage = graphics.NewImage(16, 16)
clearColorM = &affine.ColorM{}
)
func init() {
clearColorM.Scale(0, 0, 0, 0)
}
// clearIfVolatile clears the image if the image is volatile.
func (i *Image) clearIfVolatile() {
if !i.volatile {
@ -156,7 +165,17 @@ func (i *Image) clearIfVolatile() {
if i.image == nil {
panic("not reached")
}
i.image.Fill(0, 0, 0, 0)
w, h := i.image.Size()
wf, hf := float32(w), float32(h)
// For the rule of values, see vertices.go.
clearVertices := []float32{
0, 0, 0, 0, 1, 1,
wf, 0, 1, 0, 0, 1,
0, hf, 0, 1, 1, 0,
wf, hf, 1, 1, 0, 0,
}
i.image.DrawImage(dummyImage, clearVertices, clearColorM, opengl.CompositeModeCopy, graphics.FilterNearest)
}
// ReplacePixels replaces the image pixels with the given pixels slice.

View File

@ -102,7 +102,6 @@ func TestRestore(t *testing.T) {
}
func vertices(sw, sh int, x, y int) []float32 {
const a, b, c, d = 1, 0, 0, 1
swf := float32(sw)
shf := float32(sh)
tx := float32(x)
@ -111,8 +110,8 @@ func vertices(sw, sh int, x, y int) []float32 {
// For the rule of values, see vertices.go.
return []float32{
0 + tx, 0 + ty, 0, 0, 1, 1,
0 + tx, shf + ty, 0, 1, 1, 0,
swf + tx, 0 + ty, 1, 0, 0, 1,
0 + tx, shf + ty, 0, 1, 1, 0,
swf + tx, shf + ty, 1, 1, 0, 0,
}
}