Only repaint canvas when necessary