본문 바로가기

공부/안드로이드

[Android][View] Surface 와 Texture

1. 정의

(1) Surface 


Handle onto a raw buffer that is being managed by the screen compositor.

A Surface is generally created by or from a consumer of image buffers (such as aSurfaceTexture, MediaRecorder, or Allocation), and is handed to some kind of producer (such as OpenGL, MediaPlayer, or CameraDevice) to draw into.

 

  • Screen compositor에 의해 관리되는 쌩 버퍼이다.
  • Surface는 이미지 버퍼의 consumer로부터 생성되어서 그려지기 위해 producer로 넘겨져서 처리된다.

(2) SurfaceView


Provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen

The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed. The view hierarchy will take care of correctly compositing with the Surface any siblings of the SurfaceView that would normally appear on top of it. This can be used to place overlays such as buttons on top of the Surface, though note however that it can have an impact on performance since a full alpha-blended composite will be performed each time the Surface changes.

The transparent region that makes the surface visible is based on the layout positions in the view hierarchy. If the post-layout transform properties are used to draw a sibling view on top of the SurfaceView, the view may not be properly composited with the surface.

  • 뷰의 계층 구조 내부에 surface를 그리기 위한 전용 View다. surface의 형식이나 사이즈를 조절할 수 있다. Surfaceview는 스크린상에 surface가 올바른 위치에 올 수 있도록 설정할 수 있다. 
  • Surface들은 Z값에 따라 SurfaceView를 들고 있는 윈도우 뒤쪽에 정렬됩니다.  그리고 SurfaceView는 surface들이 나타날 수 있도록 윈도우에 일종의 '구멍을 뚫어버린다'. 그러고나면, View 계층구조는 surface 제일 위에 오는 SurfaceView에 속하는  Surface 요소들을 올바르게 관리하게된다. 이 점을 활용해서, Surface 위에 버튼을 구현하는 방식을 구현할 수도 있지만, 성능에 영향을 미칠 수가 있다. 왜냐하면, full alpha-blended composite가 Surface 변경시마다 동작하기 때문에 그렇다.
  • Surface가 보이는 transparent 영역은 View 계층 구조 내부에 '레이아웃 위치'에 결정된다. 앞단의 레이아웃의 transform 속성이 SurfaceView 위에 있는 sibling view를 그리기 위해 사용된다면, 해당 sibling view는 surface와 적절히 배치가 되지 않을 것이다.

 

(3) TextureView

A TextureView can be used to display a content stream. Such a content stream can for instance be a video or an OpenGL scene. The content stream can come from the application's process as well as a remote process.

TextureView can only be used in a hardware accelerated window. When rendered in software, TextureView will draw nothing.

Unlike SurfaceView, TextureView does not create a separate window but behaves as a regular View. This key difference allows a TextureView to be moved, transformed, animated, etc. For instance, you can make a TextureView semi-translucent by calling

  • 연속적인 이미지/비디오 값들을 출력할 때 사용하는 뷰가 된다. 어플리케이션 내부에서 받아올 수도 있고, 외부(원격)으로부터 받을 수 도 있다.
  • TextureView는 하드웨어 가속된 상태에서만 동작을 한다. 그래서 소프트웨어 상으로만 렌더링을 시도하게 된다면 TextureView에는 아무것도 그려지지 않게 된다.
  • SurfaceView와는 다르게, 분리된 window 화면을 생성하지 않고 단일 Regular View처럼 동작한다. 이 주요한 차이때문에, TextureView는 이동/변형/애니메이션 등 기능들이 가능해진다. 예를 들어, 반투명과 같은 기능들을 함수콜로 불러내서 사용할 수 있다.

 

 

2. 그래서?

(1) 사용되는 용도

  • TextureView : 카메라를 이용한 무언가의 기능을 만들어 낼 때 사용. ex) 스트리밍 서비스, 실시간 얼굴 인식
  • SurfaceView : 이미지 프로세싱과 관련된 기능을 만들어 낼 때 사용. ex) 사진 보정

3. 다른 개념

2019/07/04 - [공부/안드로이드] - [Android][Core] Hardware acceleration

2019/07/04 - [공부/안드로이드] - [Android][platform] Consumer

- Screen compositor

- producer (such as OpenGL, MediaPlayer, or CameraDevice)