shareable: Bug fix: Image invalidation by ReplacePixels

ReplacePixels on a part of image might invalidate the other part of
the image on MacBook Pro 2013, especially when the other part is
rendered by DrawImage.

Fixes #593 #758
This commit is contained in:
Hajime Hoshi 2018-12-20 23:24:26 +09:00
parent cae5f6bf4b
commit e809991c9f

View File

@ -65,9 +65,11 @@ func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
newImg := restorable.NewImage(s, s, false) newImg := restorable.NewImage(s, s, false)
oldImg := b.restorable oldImg := b.restorable
w, h := oldImg.Size() w, h := oldImg.Size()
vs := graphics.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1) // Do not use DrawImage here. ReplacePixels will be called on a part of newImg later, and it looked like
is := graphics.QuadIndices() // ReplacePixels on a part of image deletes other region that are rendered by DrawImage (#593, 758).
newImg.DrawImage(oldImg, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest) // TODO: Add validations to ensure that an image cannot accept DrawImage after ReplacePixels on a part of
// it.
newImg.ReplacePixels(oldImg.Pixels(), 0, 0, w, h)
oldImg.Dispose() oldImg.Dispose()
b.restorable = newImg b.restorable = newImg