attachAndroidHardwareBufferRing method
- AndroidHardwareBufferRingDescriptor descriptor,
- RenderSessionAttachOptions options, {
- VulkanDeviceHandle? device,
Creates a session that renders the map into a ring of Android hardware buffers that the library allocates.
Acquire each frame with RenderSessionHandle.acquireFrame(), and get its
buffer with AcquiredFrameHandle.withAndroidHardwareBuffer().
RenderSessionHandle.resize() gives the ring new buffers of the new size.
A Vulkan build renders with device, or, when device is null, with a
device that the library creates. An OpenGL build uses an EGL context on
the default display, and device must be null. Attach with
RenderDriverKind.coreWorker.
To show the buffers through Android's UI, such as with
Bitmap.wrapHardwareBuffer, attach without GpuSyncKindFlag.syncFd in
RenderSessionAttachOptions.producerSyncKinds, so that each frame
finishes before you acquire it. Keep each frame acquired until the next
one replaces it on screen, then release it with GpuSyncKind.cpuComplete.
Give the ring 3 buffers, so the session can render while you hold two
frames.
See mln_map_attach_android_hardware_buffer_ring in the
C API reference.
Errors:
Status.unsupportedwhen Android is older than 8.0, API level 26, or when the graphics context can't render into hardware buffers: the Vulkan device lacks VK_ANDROID_external_memory_android_hardware_buffer, or the EGL display lacks EGL_ANDROID_get_native_client_buffer or EGL_ANDROID_image_native_buffer.Status.nativeErrorwhen the library can't create its Vulkan device or initialize the default EGL display.
Implementation
RenderSessionHandle attachAndroidHardwareBufferRing(
AndroidHardwareBufferRingDescriptor descriptor,
RenderSessionAttachOptions options, {
VulkanDeviceHandle? device,
}) {
final registrations = _NativeRegistrations(_CallbackRoots());
return _attach(
(arena, completion, outSession) => registrations.run(
() => raw.mln_map_attach_android_hardware_buffer_ring(
_handle.raw,
_writeAndroidHardwareBufferRingDescriptor(descriptor, arena),
(device?._handle.raw ?? 0),
_writeRenderSessionAttachOptions(options, arena, registrations),
outSession,
completion,
nativeDiagnostic,
),
),
(handle, ready) => _adoptOwned(
handle,
() =>
(RenderSessionHandle._(this, _NativeRenderSession(handle), ready)
.._state.retain(registrations)),
(handle) {
_check(raw.mln_render_session_dispose(handle, nativeDiagnostic));
},
),
);
}