buffered: Defer ReplacePixels when possible

This commit is contained in:
Hajime Hoshi 2020-06-14 04:39:55 +09:00
parent cf3436da21
commit 1395ab5e84

View File

@ -203,7 +203,13 @@ func (i *Image) ReplacePixels(pix []byte, x, y, width, height int) error {
if x == 0 && y == 0 && width == i.width && height == i.height { if x == 0 && y == 0 && width == i.width && height == i.height {
i.invalidatePendingPixels() i.invalidatePendingPixels()
i.img.ReplacePixels(pix)
// Don't call (*mipmap.Mipmap).ReplacePixels here. Let's defer it to reduce GPU operations as much as
// posssible.
copied := make([]byte, len(pix))
copy(copied, pix)
i.pixels = copied
i.needsToResolvePixels = true
return nil return nil
} }