internal/restorable: extend the staleRegion when the image is already stale on WritePixels

This is a kind of refactoring. There seems no case that this condition
change is really needed, but this is more logical.
This commit is contained in:
Hajime Hoshi 2022-09-13 06:53:30 -07:00
parent 67ceaf5874
commit 6b906bb813

View File

@ -314,7 +314,8 @@ func (i *Image) WritePixels(pixels []byte, x, y, width, height int) {
i.image.WritePixels(make([]byte, 4*width*height), x, y, width, height)
}
if !needsRestoring() || !i.needsRestoring() {
// Even if the image is already stale, call makeStale to extend the stale region.
if !needsRestoring() || !i.needsRestoring() || i.stale {
i.makeStale(image.Rect(x, y, x+width, y+height))
return
}
@ -341,11 +342,6 @@ func (i *Image) WritePixels(pixels []byte, x, y, width, height int) {
return
}
if i.stale {
// TODO: panic here?
return
}
if pixels != nil {
// pixels can point to a shared region.
// This function is responsible to copy this.