Poor Android Canvas.drawBitmap performance - switching to OpenGL?

I am transferring a 2D game from Windows Phone 7 (developed in XNA 4.0) to Android. I use a lot of calls to Canvas.drawBitmap () - about 200-300 to update each frame - with different colors for each call to handle different transparency and color when painting. This control of particle systems and various other overlays and in-game effects, as well as tiled backgrounds and game sprites. I do not make any changes or rotations on demand, these are simple src-> dest rectangles of the same size.

In WP7, this works at 30 + fps, but I'm struggling to get 12 frames per second on my Android hardware (Samsung Galaxy S). This makes the game unplayable. By profiling the code, I confirmed that all my time is wasted in Canvas.drawBitmap ()

I seem to follow all the usual performance recommendations - using SurfaceView, mindful of the GC, so as not to create loads of dropped objects and avoid Drawables.

I understand correctly that Canvas.drawBitmap () is processor-bound, and if I want to improve performance, do I need to switch to OpenGL, which will use the GPU? I can’t find that he stated that he was bald anywhere, but, reading between the lines of some comments, I think that perhaps this will be my next step ...?

+8
android opengl-es xna android-canvas frame-rate
source share
2 answers

This is normal. Canvas is surprisingly slow when using transparency (e.g. ARGB_8888 ).

2 options:

  • Switch to OpenGL ES
  • Use the highest possible transparency on your bitmaps (i.e. use RGB_565 , which you can).
+7
source share

Perhaps this will improve on Android 3+, as it uses hardware acceleration for canvas operations.

+1
source share

All Articles