Fix const-correctness and optimize layer painting in lazy-block case.