avatarRomain Guy

Summarize

Your first conclusion ("Avoid drawing on Jetpack Compose Canvas directly for drawing intensive work. Instead, draw on a blank Bitmap first then transfer over.") is too simplistic and incomplete. The reason why it was slow in your particular case is because you were making individual drawPoint calls to the GPU backed Canvas. It is indeed highly inefficient to render each pixel on screen this way for the GOU: first because of the sheer number of GPU commands to issue (which can be optimized by using a single drawPoints) but also because of something called quad shading amongst other things. There is no real difference between Bitmap and SurfaceView rendering here because unless you lock a hardware Canvas, both will use the CPU rendering backend.

Other kinds of complex drawings may likely be a lot faster on the GPU than the CPU. It depends on what and *how* you render it. You should avoid absolute conclusions based on a single “benchmark”.

Note that you could probably do even better by using setPixels on Bitmap instead of calling drawPoint.

Recommended from ReadMedium