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 return
} }
origNum := len(i.staleRegions)
i.staleRegions = i.appendRegionsForDrawTriangles(i.staleRegions) i.staleRegions = i.appendRegionsForDrawTriangles(i.staleRegions)
if !rect.Empty() { if !rect.Empty() {
i.staleRegions = append(i.staleRegions, rect) i.staleRegions = append(i.staleRegions, rect)
@ -274,6 +275,11 @@ func (i *Image) makeStale(rect image.Rectangle) {
i.clearDrawTrianglesHistory() 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. // Don't have to call makeStale recursively here.
// Restoring is done after topological sorting is done. // Restoring is done after topological sorting is done.
// If an image depends on another stale image, this means that // If an image depends on another stale image, this means that