SurfaceView draw performance

梦想与她 提交于 2019-12-08 20:48:27

SurfaceView has two parts, the Surface and the View. The View integrates into all the other UI elements, and can be layered with standard components. You can create a custom View and draw on it with a Canvas. On all recent devices, that will take advantage of hardware acceleration, though not all of the Canvas API is implemented.

The Surface is a completely independent layer that is composited above or below the layer that has the rendered View elements. You can draw on it in software, using Canvas, or with the GPU by using OpenGL ES. GLSurfaceView is a wrapper around SurfaceView that takes care of EGL setup and some threading issues, but there's nothing special about it. For examples of using GLES with plain SurfaceView and TextureView, see Grafika, which has a handy library with all the EGL stuff taken care of.

Canvas rendering onto a Surface is not hardware accelerated. As screens get larger (pixel-wise), rendering becomes increasingly expensive. The Nexus 4 has a pretty good ratio of CPU+bus speed to pixel count. Animation that would be smooth on the Nexus 4 would choke a bit on the Nexus 10. (Try the Grafika "multi-surface test", select "bounce", watch the frame rate in the log.)

To get good performance, and save yourself a lot of work, it might be worth your while to investigate an open-source graphics or game engine. Or start with a small existing project like Android Breakout.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!