Various fixes and improvements for a fairly-well-working dirty region repainting.