attachWin32Window method

RenderSessionHandle attachWin32Window(
  1. Win32WindowDescriptor descriptor,
  2. RenderSessionAttachOptions options, {
  3. VulkanDeviceHandle? device,
})

Creates a session that presents the map to a Win32 window, with a graphics context that the library creates.

A Vulkan build presents with device, or, when device is null, with a device that the library creates. An OpenGL build uses a WGL context, and device must be null. Attach with RenderDriverKind.coreWorker.

An OpenGL build sets the window's pixel format, so don't set one yourself.

The session presents without waiting for the display, so demand at most one frame per display refresh. While the window is minimized, frame demands finish with RenderResult.targetNotReady.

Keep the window until a release or replacement of the target, or a detach of the session, completes.

See mln_map_attach_win32_window in the C API reference.

Errors:

  • Status.invalidArgument when window isn't a window, or, in an OpenGL build, already has another pixel format.
  • Status.invalidState when window is minimized or has no client area.
  • Status.unsupported when you created device without VulkanDeviceOptions.presentation.
  • Status.invalidState when window was minimized before the attach ran.
  • Status.unsupported when the GPU or the Vulkan loader can't present.
  • Status.nativeError when the library can't create the graphics context or present to the window.

Implementation

RenderSessionHandle attachWin32Window(
  Win32WindowDescriptor descriptor,
  RenderSessionAttachOptions options, {
  VulkanDeviceHandle? device,
}) {
  final registrations = _NativeRegistrations(_CallbackRoots());
  return _attach(
    (arena, completion, outSession) => registrations.run(
      () => raw.mln_map_attach_win32_window(
        _handle.raw,
        _writeWin32WindowDescriptor(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));
      },
    ),
  );
}