optimize canvas
adapted for Android