internal/restorble: clear pixels when possible to save memory

This commit is contained in:
Hajime Hoshi 2023-02-25 23:57:34 +09:00
parent f04d9d6925
commit df944fdf90

View File

@ -267,6 +267,7 @@ func (i *Image) makeStale(rect image.Rectangle) {
return
}
origNum := len(i.staleRegions)
i.staleRegions = i.appendRegionsForDrawTriangles(i.staleRegions)
if !rect.Empty() {
i.staleRegions = append(i.staleRegions, rect)
@ -274,6 +275,11 @@ func (i *Image) makeStale(rect image.Rectangle) {
i.clearDrawTrianglesHistory()
// Clear pixels to save memory.
for _, r := range i.staleRegions[origNum:] {
i.basePixels.Clear(r.Min.X, r.Min.Y, r.Dx(), r.Dy())
}
// Don't have to call makeStale recursively here.
// Restoring is done after topological sorting is done.
// If an image depends on another stale image, this means that