Marco
Marco

Reputation: 499

SurfaceView refresh rate implementation

I'm constantly updating a SurfaceView in a dedicated thread with a tight loop that starts with lockCanvas and ends with unlockCanvasAndPost.

No matter how simple is the drawing, I do not get more than 60FPS, which makes sense as that is the refresh rate for the display.

My question is: how is this maximum rate enforced?

I would expect lockCanvas to be the blocking method (i.e., the method that inserts the appropriate delay), but profiling seems to show that both lockCanvas and unlockCanvasAndPost contribute to the delay that bounds the rate.

Upvotes: 0

Views: 466

Answers (1)

fadden
fadden

Reputation: 52323

lockCanvas() acquires a buffer to draw in, unlockCanvas() submits the buffer to the system compositor. If there are no free buffers, lockCanvas() will block until one is available. unlockCanvas() could stall if SurfaceFlinger doesn't process the IPC message right away, but generally the unlock should return quickly.

If you want to understand how the graphics system works, see the graphics architecture doc. Of particular interest will be the section on game loops; what you're doing is "queue stuffing", which is easy to do but has slightly worse latency characteristics than a Choreographer-based approach.

Upvotes: 2

Related Questions