Make canvas painting more flexible and efficient