2

I was looking at the Camera2 API of Android. In the code at https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java#L210, they use the classes SurfaceView, TextureView, Texture and Surface without explaining too much. The documentation is also not a great help when it comes to distinguishing those 4 classes.

Therefore, my question(s): What is a SurfaceView, TextureView, Texture and Texture ? What distinguishes them ? What separates them ? What is used for what ?

Every non-document-like explanation would be great.

Thanks in advance,

abdullah celik
  • 327
  • 2
  • 12

1 Answers1

7

Surface is a generic object that can have image buffers drawn into it, which is accepted by a number of Android APIs as a destination for output.

The camera2 API is one of them, but EGL, MediaCodec, etc, can all use them as well. Concrete endpoints that can accept image buffers can usually be converted to a Surface one way or another. These include things like some Android Views, Media classes like MediaRecorder for video encoding, the ImageReader class for efficient CPU access to the underlying graphics buffers, etc.

SurfaceView is an Android View that represents a hardware overlay surface; it's the most efficient way to draw image buffers to screen. Because it represents a low-level display primitive, it's a bit clunky to use; you can get a Surface for it from its SurfaceHolder child object's lifecycle callback.

TextureView is an Android View that draws image buffers via the GPU. It's more flexible than SurfaceView, but requires GPU composition to operate so it adds a bit of latency and power overhead. It can provide a SurfaceTexture to draw into.

SurfaceTexture is a representation of a GPU texture that can be drawn into. You can use it in EGL to render from via its texture ID, and you can create a Surface from it via one of the Surface constructors to give to other APIs to draw into. TextureView uses it since it's a GPU-based View.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47