Search code examples
androidperformanceandroid-camerapreviewandroid-textureview

Which View is best choice for android camera preview?


As we know, we can choose TextureView, SurfaceView and GLSurfaceView for android camera preview.

Which one is best choice for camera preview ? I'm focused on the camera performance.


Solution

  • From a performance perspective, SurfaceView is the winner.

    With SurfaceView, frames come from the camera and are forwarded to the system graphics compositor (SurfaceFlinger) with no copying. In most cases, any scaling will be done by the display processor rather than the GPU, which means that instead of scanning the pixels once for scaling and again for scan-out, they're only scanned once.

    GLSurfaceView is a SurfaceView with some wrapper classes that handle EGL setup and thread management. You can't use OpenGL ES on a Surface that is receiving camera frames, so you're doing extra work with no benefit. (The overhead is minor one-time setup, not per-frame, so you likely won't be able to measure the difference.)

    TextureView receives the frames in a SurfaceTexture as an "external" OpenGL ES texture, then uses GLES to render them onto the app's UI surface. The scaling and rendering are performed by the GPU, and the result is then forwarded to SurfaceFlinger. This is the slowest option, but also the most flexible of the Views.

    If you'd like to learn more about how the system works, see the Android Graphics Architecture document.