1

The FPS is around 60, but the animation still glitches sometimes. I did threads profiling and discovered that on Samsung S4 or Samsung S3 lockCanvas() could take up to 20ms sometimes. Is there any specific reason for it? How to avoid such glitches.

Taras
  • 2,526
  • 3
  • 33
  • 63
  • Are you regulating the frame-rate yourself by sleeping the thread? I found I only got 55 fps consistently with surfaceview. Otherwise you are at the mercy of your cpu's speed and hence the glitching if it decides it is doing too much work and slows down some frames with the lock time or decides to process some other frames faster. And if you lower the framerate to 30 fps, the lockcanvas time goes down to 0-1ms and no more glitching. You could try Textureview (api 14), as the lock time is only 0-1ms running full throttle (I had to regulate the frame rate cause my animation was running to fast). – Whitney Nov 11 '14 at 15:43

1 Answers1

1

Some devices, particularly those based around qcom CPUs, will aggressively manage power by lowering clocks, so you will see occasionally glitches in 60fps animation when your finger isn't actively moving across the touchscreen.

The best way to handle this is to drop frames when necessary. The "Record GL app" activity in Grafika uses a simple trick with Choreographer to do this. For a detailed explanation, see this appendix in the graphics architecture doc.

I should also point out that Canvas rendering on a SurfaceView surface isn't hardware-accelerated, and as pixel counts increase the rendering time will increase as well, making it more likely that you'll miss your window. In some ways the added CPU load can actually make things smoother -- if the power management believes the device is heavily loaded it won't lower the clocks -- but it does drain the battery faster.

Community
  • 1
  • 1
fadden
  • 51,356
  • 5
  • 116
  • 166