Axarydax
Axarydax

Reputation: 16603

How to optimize Canvas drawing - drawBitmap on Android?

I've done my profiling and it seems that most of my time is spent during drawBitmap, which is called (understandingly) on every frame.

I use SurfaceView/updating thread/canvas locking approach as demonstrated in LunarLander sample. But I've changed it (according to this question) as to

Traceview showed me that this drawBitmap takes 5ms for each frame on my 800x480 device. Can I get any better than that or is it just something that is 'carved into the stone' and I just have to optimize other parts of the code to achieve good frames per second?

Upvotes: 6

Views: 8157

Answers (2)

hamish
hamish

Reputation: 1182

there is a competition running for the fastest drawing library... libgdx is currently winning... the sample apps also use 800x480 just like you are.

http://code.google.com/p/libgdx/wiki/SimpleApp#Project_Setup

Upvotes: 0

Romain Guy
Romain Guy

Reputation: 98501

It depends on many things, but usually drawBitmap() will be as fast as it can get. In your particular case, if you don't need blending, make sure your are using an opaque bitmap. In addition, try to use a Bitmap in a format compatible with your Surface. For instance, if you are using a 16 bits Surface, drawing a 16-bits (RGB565) bitmap will be very fast (it's just a memcpy call.) If your Surface is 32 bits, use an ARGB8888 opaque Bitmap.

Upvotes: 10

Related Questions