gq3 gq3 - 4 years ago 222
Android Question

Android OpenGL occasional stutter

I've written an OpenGL ES 2 app using NativeActivity that renders around 6 textured triangles that you can drag around using touch input. The app is rendering as fast as possible, calling

before and
after rendering. As expected the frame rate is capped to the display frequency of around 60 fps and the scene moves around smoothly. However, after some time (10 to 60 seconds) the movement starts to stutter even though the frame rate is still 60 fps. The device I'm using is OnePlus 3.

At first I suspected the culprit was battery saving mode, but investigation revealed no correlation between cpus' frequencies and the stutter.

I did notice something interesting though, the stutter starts when
execution time goes up.

This is the systrace before stutter:
Before stutter
This is the systrace after stutter:
After stutter
This is the systrace during the transition from before to after:

How do I stop the app from stuttering?

gq3 gq3
Answer Source

I still don't know the exact cause of the stuttering, but I managed to find a work-around: Only render frames on Choreographer.postFrameCallback and set eglPresentationTimeANDROID to two vsyncs in the future. This avoids filling up the buffer queue, which seems to be one of the causes of the stuttering.

As a bonus it also improved the touch input latency a little.

More info here: Minimize Android GLSurfaceView lag

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download