I am using SurfaceView for my game and I am loading all of the bitmaps that are the right size for the screen (pre-scaled in mipmap folder) into a class when the game starts. And I am drawing the bitmaps to the canvas using the drawBitmap method.

Though all of the bitmaps are compressed in 8 bit PNG format and scaled for the screen size, I am getting an awful FPS rate (around 40 FPS)

Things I have tried:

Made sure drawBitmap is the cause of the issue by recording the performance via performance monitor and examining the results. Basically, that is the only method that is causing an overhead. Trimmed all of the transparent bits that are on the sides and used the fill canvas method for the background. Scaled and compressed the bitmaps properly Made sure nothing above or below the screen gets rendered So this left me wondering; is a modern phone equipped with who knows how many times more powerful CPU and GPU than the computers in the early 2000s unable to utilize its hardware and thus unable to perform such a simple rendering request that those computers that are 2 decades old managed to do? I know drawBitmap uses CPU but nonetheless...

I am only drawing a bitmap that is 1/3 of the size of the screen and 2-3 small bitmaps on top of it (1/6 of the screen size) seeing as low as 30 FPS in such a simple task after all those optimizations is simply disappointing. Migrating to OpenGL will break so many parts of the code and obviously will be more challenging. And as far as I know, there isn't a library that simplifies drawing bitmaps by handling the OpenGL side and only exposes the canvas-like API.

So is there anything else I can do to increase the performance?

  • \$\begingroup\$ Sounds like you answered your own question: "I know drawBitmap uses CPU". On a 1080p screen, the pixel ops you describe amount to about 2 million blending steps to be done. Quadruple that on a higher-res screen. Would you rather do those steps one at a time in sequence on a single core as DrawBitmap does, or send them to the GPU to do hundreds of steps in parallel while your CPU is free to do other stuff with its time? \$\endgroup\$
    – DMGregory
    Oct 13 '20 at 11:50
  • \$\begingroup\$ You may want to look into using something like LibGDX(libgdx.badlogicgames.com) to work on your projects. It is super easy to use and there are plenty of tutorials out there to get started (happycoding.io/tutorials/libgdx). Also, you can write once, and deploy for Android/Iphone/Desktop/HTML. LibGDX will handle image performance for you. Good luck! \$\endgroup\$ Feb 7 '21 at 0:23

You must log in to answer this question.

Browse other questions tagged .