maplibre_native_ffi/generated/offscreen_device.rs
1// Generated from C headers by tools/bindgen. Do not edit.
2use super::*;
3
4native_owner! {
5 /// Owns one native handle.
6 ///
7 /// A GPU device that the library creates to render maps offscreen.
8 ///
9 /// See `mln_offscreen_device` in the
10 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/base_8h.html).
11 pub struct OffscreenDeviceHandle(mln_offscreen_device) dispose |raw| { unsafe { sys::mln_offscreen_device_release(raw) }; Ok(()) };
12 /// Returns the native handle value.
13 fn id;
14}
15
16impl OffscreenDeviceHandle {
17 /// Creates a GPU device for rendering maps offscreen.
18 ///
19 /// `MapHandle::attach_offscreen()` creates a device of its own when it gets
20 /// none. Create one to share it among the sessions on many maps, or to pick
21 /// a GPU.
22 ///
23 /// In a browser WebGPU build, attach without a device instead.
24 ///
25 /// See `mln_offscreen_device_create` in the
26 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/offscreen_8h.html).
27 ///
28 /// # Errors
29 ///
30 /// - `Status::Unsupported` in a browser WebGPU build, or when the device
31 /// can't render with `client_api`.
32 /// - `Status::NativeError` when `adapter_index` names no GPU, or the
33 /// platform can't create the device.
34 pub fn create(options: Option<&OffscreenDeviceOptions>) -> Result<OffscreenDeviceHandle> {
35 let mut call = Call::global();
36 crate::abi::validate_abi_version()?;
37 let mut out_device = sys::mln_offscreen_device(0);
38 let options = call.optional_reference(options.as_ref())?;
39 call.status(|_, out_diagnostic| unsafe {
40 sys::mln_offscreen_device_create(options, &mut out_device, out_diagnostic)
41 })?;
42 Ok(OffscreenDeviceHandle::adopt(out_device)?)
43 }
44
45 /// Releases an offscreen device.
46 ///
47 /// Render sessions on the device keep working until they detach.
48 ///
49 /// See `mln_offscreen_device_release` in the
50 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/offscreen_8h.html).
51 pub fn release(self) -> std::result::Result<(), ReleaseError<Self>> {
52 self.consume(|device| {
53 let mut call = Call::new(device);
54 call.run(|device| unsafe { sys::mln_offscreen_device_release(device) });
55 Ok(())
56 })
57 }
58}