Display Android Surface content
You can use XR Composition Layer to efficiently display native, hardware-decoded, or security-sensitive content (such as video) without routing it through Unity’s rendering pipeline. When you are working with Android development, you can render Android Surface content directly to a quad or cylinder composition layers by choosing Android Surface as the source of the Source Texture component.
Access Android Surface objects with OpenXR
The Unity OpenXR Plug-in provides composition layers support for Android Surface. To obtain the Android Surface object to use for a layer, you must call the OpenXR GetLayerAndroidSurfaceObject in a script.
The following example shows how you can use GetLayerAndroidSurfaceObject to access the Android Surface object to use for a layer:
// Get Android Surface Object
IntPtr surface = IntPtr.Zero;
surface = OpenXRLayerUtility.GetLayerAndroidSurfaceObject(layer.GetInstanceID());
You can access a sample using Android Surface from the Package Manager, as outlined in the following instructions:
- Open the Package Manager (menu: Window > Package Manager)
- Select the XR Composition Layers package in the list of packages in your project.
- Towards the bottom of the window, select the Samples tab.
- Click Import next to the Sample External Android Surface Project item.
Additional resources
- Android Surface (Android developer documentation)
- XR_KHR_android_surface_swapchain (Khronos)