开发者

Poor performance of Android Canvas.drawBitmap - switch to OpenGL?

开发者 https://www.devze.com 2023-03-20 17:57 出处:网络
I\'m porting a 2D action game from Windows Phone 7 (developed in XNA 4.开发者_运维知识库0) over to Android. I\'m using a lot of Canvas.drawBitmap() calls - around 200-300 per frame update - with diffe

I'm porting a 2D action game from Windows Phone 7 (developed in XNA 4.开发者_运维知识库0) over to Android. I'm using a lot of Canvas.drawBitmap() calls - around 200-300 per frame update - with different Paints for each call to handle varying transparency and colourisation at draw-time. This is managing particle systems and various other overlays and in-game effects as well as a tiled background and in-game sprites. I'm not doing any on-demand resizing or rotating, it's simple src->dest rectangles of the same size.

On WP7 this runs at 30+fps but I'm struggling to get 12fps on my test 'droid hardware (Samsung Galaxy S). This is making the game unplayable. Having profiled the code, I've confirmed that all my time is being lost in Canvas.drawBitmap()

I seem to be following all the usual performance advice - using a SurfaceView, mindful of GC so not creating loads of throwaway objects, and avoiding Drawables.

Am I right in understanding that Canvas.drawBitmap() is CPU-bound, and if I want to improve performance I have to switch to OpenGL which will use the GPU? I can't find it stated that baldly anywhere, but reading between the lines of some comments I think that might have to be my next step...?


This is normal. Canvas is amazingly slow when using transparency (like ARGB_8888).

2 options:

  • Switch to OpenGL ES
  • Use the least possible transparency on your bitmaps (i.e use RGB_565 the most you can).


Perhaps this will run better on Android 3+ since it uses hardware acceleration for canvas operations.

0

精彩评论

暂无评论...
验证码 换一张
取 消