Surface buffer. Use it when your app already has stereoscopic content, such as side-by-side video, top-bottom video, stereo photos, or custom rendered stereo content that should appear inside a 2D Android panel on Horizon OS.SurfaceView, VideoView, or an app-managed SurfaceControl.AndroidManifest.xml must declare the uses-horizonos-sdk element to access these APIs.Surface pipeline. Common use cases include:| Mode | Constant | Buffer layout | Use case |
|---|---|---|---|
Mono | SurfaceControlExt.STEREO_COMPOSITION_MONO | One standard single-view image. | Normal non-stereo video or UI content. |
Side by side | SurfaceControlExt.STEREO_COMPOSITION_SIDE_BY_SIDE | Left eye in the left half, right eye in the right half. | Stereo content encoded at double width. |
Top bottom | SurfaceControlExt.STEREO_COMPOSITION_TOP_BOTTOM | Left eye in the top half, right eye in the bottom half. | Stereo content encoded at double height. |
Side-by-side packed buffer +----------------------+----------------------+ | Left eye image | Right eye image | +----------------------+----------------------+ 0 W 2W Encoded buffer size: 2W x H Per-eye content size: W x H
Top-bottom packed buffer +----------------------+ | Left eye image | +----------------------+ | Right eye image | +----------------------+ 0 W Encoded buffer size: W x 2H Per-eye content size: W x H
SurfaceViewExt.setStereoComposition(). VideoView extends SurfaceView, so the same API also applies to VideoView.import horizonos.view.SurfaceControlExt
import horizonos.view.SurfaceViewExt
SurfaceViewExt.setStereoComposition(
surfaceView,
SurfaceControlExt.STEREO_COMPOSITION_SIDE_BY_SIDE,
)
SurfaceViewExt.setStereoComposition(
surfaceView,
SurfaceControlExt.STEREO_COMPOSITION_MONO,
)
SurfaceViewExt.setStereoComposition() on the UI thread. When switching between stereo modes, update both the content source and the composition mode so the buffer layout matches the selected mode.SurfaceControl directly, use SurfaceControlExt.setStereoComposition() with a SurfaceControl.Transaction:import android.view.SurfaceControl
import horizonos.view.SurfaceControlExt
val transaction = SurfaceControl.Transaction()
SurfaceControlExt.setStereoComposition(
surfaceControl,
transaction,
SurfaceControlExt.STEREO_COMPOSITION_TOP_BOTTOM,
)
transaction.apply()
SurfaceControl obtained from a SurfaceView. For SurfaceView and VideoView, use SurfaceViewExt.setStereoComposition().| Mode | Encoded buffer size | Per-eye display size |
|---|---|---|
Mono | width x height | width x height |
Side by side | 2 * width x height | width x height |
Top bottom | width x 2 * height | width x height |
2560 x 720, each eye receives a 1280 x 720 image. The visual aspect ratio should be based on 1280 x 720, not 2560 x 720.1280 x 1440, each eye receives a 1280 x 720 image. The visual aspect ratio should be based on 1280 x 720, not 1280 x 1440.val displayWidth = when (mode) {
SurfaceControlExt.STEREO_COMPOSITION_SIDE_BY_SIDE -> encodedWidth / 2
else -> encodedWidth
}
val displayHeight = when (mode) {
SurfaceControlExt.STEREO_COMPOSITION_TOP_BOTTOM -> encodedHeight / 2
else -> encodedHeight
}
View objects may report different measured view sizes as the app panel is resized or as VideoView preserves the aspect ratio of the current video. That is expected. The important part is that the content buffer layout and selected composition mode match.private fun selectVideoSource(source: VideoSource) {
SurfaceViewExt.setStereoComposition(surfaceView, source.stereoComposition)
videoView.setVideoURI(source.uri)
videoView.start()
}
SurfaceViewExt for SurfaceView and VideoView. Use SurfaceControlExt only when your app manages a SurfaceControl directly.SurfaceViewExt.setStereoComposition() with VideoView.SurfaceViewExt.setStereoComposition() with SurfaceView and MediaPlayer.horizonos.view.SurfaceViewExt.setStereoComposition(SurfaceView, int)horizonos.view.SurfaceControlExt.setStereoComposition(SurfaceControl, SurfaceControl.Transaction, int)horizonos.view.SurfaceControlExt.STEREO_COMPOSITION_MONOhorizonos.view.SurfaceControlExt.STEREO_COMPOSITION_SIDE_BY_SIDEhorizonos.view.SurfaceControlExt.STEREO_COMPOSITION_TOP_BOTTOM