attachOffscreen method

RenderSessionHandle attachOffscreen(
  1. OffscreenDescriptor descriptor,
  2. RenderSessionAttachOptions options, {
  3. OffscreenDeviceHandle? device,
})

Attaches a render session that renders the map offscreen.

Read each image's pixels with RenderSessionHandle.readTexture().

The session renders on device. When device is null, the session creates a device with the default options, and releases it when the session ends.

See mln_map_attach_offscreen in the C API reference.

Errors:

  • Status.invalidState when the map already has a render session.
  • Status.nativeError when device is null and the platform can't create a device.

Implementation

RenderSessionHandle attachOffscreen(
  OffscreenDescriptor descriptor,
  RenderSessionAttachOptions options, {
  OffscreenDeviceHandle? device,
}) {
  final registrations = _NativeRegistrations(_CallbackRoots());
  return _attach(
    (arena, completion, outSession) => registrations.run(
      () => raw.mln_map_attach_offscreen(
        _handle.raw,
        _writeOffscreenDescriptor(descriptor, arena),
        _writeRenderSessionAttachOptions(options, arena, registrations),
        (device?._handle.raw ?? 0),
        outSession,
        completion,
        nativeDiagnostic,
      ),
    ),
    (handle, ready) => _adoptOwned(
      handle,
      () =>
          (RenderSessionHandle._(this, _NativeRenderSession(handle), ready)
            .._state.retain(registrations)),
      (handle) {
        _check(raw.mln_render_session_dispose(handle, nativeDiagnostic));
      },
    ),
  );
}