I was asking myself how a SurfaceView handles drawing outside the visible area. I made some online research but couldn’t find anyone that ask or anything that answers the question. So I made some testing, my test setup looks like this:
I draw 5000 circles on a SurfaceView with an x-axis offset of -100 and an additional -100 offset for every 1000 circles. The offset is stored in a Matrix as a translation and applied to the canvas before drawing using Canvas.concat(). The result is a SurfaceView with 5000 circles drawn on it but initially they are all outside the visible area and you don’t see them on the screen. I ran my test application, applied a translation to the Canvas, so that the circle stacks appeared one after another, and measured the frames per second. All update and drawing is done using a simple thread that loops as often as possible.
The measured results are:
- 0 visible circles -> ~ 40 FPS
- 1000 visible circles -> ~ 30 FPS
- 2000 visible circles -> ~ 20 FPS
- 3000 visible circles -> ~ 15 FPS
- 4000 visible circles -> ~ 12 FPS
- 5000 visible circles -> ~ 10 FPS
I need to mention that this is all done using my own 2D engine. Without any elements on it, it runs at 60 FPS. I think the first “missing” 20 FPS could result by my rendering pipeline that iterates over the 5000 elements.
Does anyone know more about the SurfaceView or Canvas and can explain this behavior?
Thanks in advance!
Test setup: Nexus 10, Android 4.2.1, min SDK: 14, target SDK: 17
Based on the explanation about graphics hardware WarrenFaith posted I measured the difference between drawing all circles and check before drawing. It turns out there is absolutely no difference! To be sure I even increased the circle count to 50000 and both tests ran on about 4 to 5 FPS with no visible circles.