Skip to main content

maplibre_native_ffi/generated/
global.rs

1// Generated from C headers by tools/bindgen. Do not edit.
2use super::*;
3
4/// Creates a frame pacer that follows the display through the calling
5/// thread's `AChoreographer`.
6///
7/// Call it on a thread with an `ALooper`, such as the app's main thread,
8/// and keep that thread running its looper while sessions use the pacer.
9///
10/// See `mln_android_frame_pacer_create` in the
11/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/android_8h.html).
12///
13/// # Errors
14///
15/// - `Status::InvalidState` when the calling thread has no `ALooper`.
16#[cfg(target_os = "android")]
17pub fn android_frame_pacer_create(options: Option<&FramePacerOptions>) -> Result<FramePacerHandle> {
18    let mut call = Call::global();
19    crate::abi::validate_abi_version()?;
20    let mut out_pacer = sys::mln_frame_pacer(0);
21    let options = call.optional_reference(options.as_ref())?;
22    call.status(|_, out_diagnostic| unsafe {
23        sys::mln_android_frame_pacer_create(options, &mut out_pacer, out_diagnostic)
24    })?;
25    Ok(FramePacerHandle::adopt(out_pacer)?)
26}
27
28/// Gives the library the Java VM and the app context that it needs on
29/// Android.
30///
31/// Call it before creating a runtime. `jni_env` is the calling thread's
32/// `JNIEnv*`, and `context` is an Android `Context`, such as the
33/// application.
34///
35/// See `mln_android_init` in the
36/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/android_8h.html).
37///
38/// # Safety
39/// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
40#[cfg(target_os = "android")]
41pub unsafe fn init_android(
42    jni_env: *mut std::ffi::c_void,
43    context: *mut std::ffi::c_void,
44) -> Result<()> {
45    let mut call = Call::global();
46    crate::abi::validate_abi_version()?;
47    call.status(|_, out_diagnostic| unsafe {
48        sys::mln_android_init(jni_env, context, out_diagnostic)
49    })?;
50    Ok(())
51}
52
53/// Creates a frame pacer that follows the display through a
54/// `CADisplayLink`.
55///
56/// You can call it on any thread. The pacer needs no run loop of yours. On
57/// macOS, it follows the main display, the one with the menu bar.
58///
59/// With `FramePacerOptions::maximum_frames_per_second`, the pacer also asks
60/// the system for that refresh rate. On iPhone, a rate above 60 needs
61/// `CADisableMinimumFrameDurationOnPhone` in the app's `Info.plist`.
62///
63/// See `mln_apple_frame_pacer_create` in the
64/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/apple_8h.html).
65///
66/// # Errors
67///
68/// - `Status::NativeError` when the system has no display to follow.
69#[cfg(any(target_os = "ios", target_os = "macos", target_os = "tvos"))]
70pub fn apple_frame_pacer_create(options: Option<&FramePacerOptions>) -> Result<FramePacerHandle> {
71    let mut call = Call::global();
72    crate::abi::validate_abi_version()?;
73    let mut out_pacer = sys::mln_frame_pacer(0);
74    let options = call.optional_reference(options.as_ref())?;
75    call.status(|_, out_diagnostic| unsafe {
76        sys::mln_apple_frame_pacer_create(options, &mut out_pacer, out_diagnostic)
77    })?;
78    Ok(FramePacerHandle::adopt(out_pacer)?)
79}
80
81/// Returns the API epoch of the library.
82///
83/// Headers and a library with different epochs aren't compatible.
84///
85/// See `mln_c_version` in the
86/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/base_8h.html).
87pub fn c_version() -> u32 {
88    let mut call = Call::global();
89    let value = call.run(|_| unsafe { sys::mln_c_version() });
90    value
91}
92
93/// Computes the camera that shows exactly one tile on a square map.
94///
95/// Jump a map in `MapMode::Tile` to the camera to render `tile`, where
96/// `logical_size` is the map's size. The camera centers the tile, zooms
97/// until the tile fills the map, and looks straight down with north up and
98/// no padding. The map keeps its camera within its zoom limits, so for a
99/// deep tile, raise the maximum zoom past the camera's with
100/// `MapHandle::set_bounds()`.
101///
102/// See `mln_camera_for_tile` in the
103/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/camera_8h.html).
104///
105/// # Errors
106///
107/// - `Status::InvalidArgument` when `logical_size` isn't square, or is
108///   wider than 512 pixels. For denser tiles, raise the map's scale factor
109///   instead.
110/// - `Status::InvalidArgument` when `tile.x` or `tile.y` isn't less than 2
111///   to the power `tile.z`, or when the tile can't fill the map at a zoom
112///   from 0 to 25.5, as for tile 0/0/0 on a 256-pixel map.
113pub fn camera_for_tile(tile: CanonicalTileId, logical_size: LogicalSize) -> Result<CameraOptions> {
114    let mut call = Call::global();
115    crate::abi::validate_abi_version()?;
116    let mut out_camera: sys::mln_camera_options = unsafe { std::mem::zeroed() };
117    out_camera.size = std::mem::size_of::<sys::mln_camera_options>() as _;
118    let tile = call.input(&tile)?;
119    let logical_size = call.input(&logical_size)?;
120    call.status(|_, out_diagnostic| unsafe {
121        sys::mln_camera_for_tile(tile, logical_size, &mut out_camera, out_diagnostic)
122    })?;
123    Ok(unsafe { from_native(out_camera) }?)
124}
125
126/// Converts meters in the Web Mercator projection to a coordinate.
127///
128/// See `mln_lat_lng_for_projected_meters` in the
129/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/projection_8h.html).
130pub fn lat_lng_for_projected_meters(meters: ProjectedMeters) -> Result<LatLng> {
131    let mut call = Call::global();
132    crate::abi::validate_abi_version()?;
133    let mut out_coordinate: sys::mln_lat_lng = unsafe { std::mem::zeroed() };
134    let meters = call.input(&meters)?;
135    call.status(|_, out_diagnostic| unsafe {
136        sys::mln_lat_lng_for_projected_meters(meters, &mut out_coordinate, out_diagnostic)
137    })?;
138    Ok(unsafe { from_native(out_coordinate) }?)
139}
140
141/// Sends log messages to the platform's log again, instead of a callback.
142///
143/// See `mln_log_clear_callback` in the
144/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/logging_8h.html).
145pub fn clear_log_callback() -> Result<()> {
146    let mut call = Call::global();
147    crate::abi::validate_abi_version()?;
148    call.status(|_, out_diagnostic| unsafe { sys::mln_log_clear_callback(out_diagnostic) })?;
149    Ok(())
150}
151
152/// Selects the severities that the library logs on a background thread.
153///
154/// The library logs other severities on the thread that logged them. `mask`
155/// applies to every runtime in the process.
156///
157/// See `mln_log_set_async_severity_mask` in the
158/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/logging_8h.html).
159pub fn set_log_async_severity_mask(mask: LogSeverityFlag) -> Result<()> {
160    let mut call = Call::global();
161    crate::abi::validate_abi_version()?;
162    call.status(|_, out_diagnostic| unsafe {
163        sys::mln_log_set_async_severity_mask(mask.bits(), out_diagnostic)
164    })?;
165    Ok(())
166}
167
168/// Sends the log messages of every runtime in the process to a callback.
169///
170/// The callback replaces the one set before.
171///
172/// Runs on the thread that logged the message, or on a background thread
173/// for the severities that `set_log_async_severity_mask()` selects. The
174/// callback can't call the library.
175///
176/// See `mln_log_set_callback` in the
177/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/logging_8h.html).
178pub fn set_log_callback(handler: LogHandler) -> Result<()> {
179    let mut call = Call::global();
180    crate::abi::validate_abi_version()?;
181    let handler = call.reference(&handler)?;
182    call.status(|_, out_diagnostic| unsafe { sys::mln_log_set_callback(handler, out_diagnostic) })?;
183    Ok(())
184}
185
186/// Computes the size in pixels of a target with a logical size and scale
187/// factor.
188///
189/// See `mln_logical_extent_physical_size` in the
190/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__target_8h.html).
191pub fn logical_extent_physical_size(extent: LogicalExtent) -> Result<(u32, u32)> {
192    let mut call = Call::global();
193    crate::abi::validate_abi_version()?;
194    let mut out_width: u32 = Default::default();
195    let mut out_height: u32 = Default::default();
196    let extent = call.input(&extent)?;
197    call.status(|_, out_diagnostic| unsafe {
198        sys::mln_logical_extent_physical_size(
199            extent,
200            &mut out_width,
201            &mut out_height,
202            out_diagnostic,
203        )
204    })?;
205    Ok((out_width, out_height))
206}
207
208/// Reads whether the library may use the network.
209///
210/// See `mln_network_get_status` in the
211/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/runtime_8h.html).
212pub fn get_network_status() -> Result<NetworkStatus> {
213    let mut call = Call::global();
214    crate::abi::validate_abi_version()?;
215    let mut out_status: sys::mln_network_status = Default::default();
216    call.status(|_, out_diagnostic| unsafe {
217        sys::mln_network_get_status(&mut out_status, out_diagnostic)
218    })?;
219    Ok(NetworkStatus::from_raw(out_status))
220}
221
222/// Tells the library whether it may use the network.
223///
224/// While the status is `NetworkStatus::Offline`, the library starts no
225/// network requests. The requests that wait start when the status returns
226/// to `NetworkStatus::Online`. The status starts as online and applies to
227/// every runtime in the process.
228///
229/// See `mln_network_set_status` in the
230/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/runtime_8h.html).
231pub fn set_network_status(status: NetworkStatus) -> Result<()> {
232    let mut call = Call::global();
233    crate::abi::validate_abi_version()?;
234    call.status(|_, out_diagnostic| unsafe {
235        sys::mln_network_set_status(status.as_raw(), out_diagnostic)
236    })?;
237    Ok(())
238}
239
240/// Creates a frame pacer that follows the display through OpenHarmony's
241/// `OH_NativeVSync`.
242///
243/// You can call it on any thread. The pacer needs no event loop of yours.
244///
245/// See `mln_ohos_frame_pacer_create` in the
246/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/ohos_8h.html).
247///
248/// # Errors
249///
250/// - `Status::NativeError` when the system can't report the display's
251///   refreshes to the process.
252#[cfg(target_env = "ohos")]
253pub fn ohos_frame_pacer_create(options: Option<&FramePacerOptions>) -> Result<FramePacerHandle> {
254    let mut call = Call::global();
255    crate::abi::validate_abi_version()?;
256    let mut out_pacer = sys::mln_frame_pacer(0);
257    let options = call.optional_reference(options.as_ref())?;
258    call.status(|_, out_diagnostic| unsafe {
259        sys::mln_ohos_frame_pacer_create(options, &mut out_pacer, out_diagnostic)
260    })?;
261    Ok(FramePacerHandle::adopt(out_pacer)?)
262}
263
264/// Reports the OpenGL context platforms that this build of the library has.
265///
266/// See `mln_open_gl_supported_context_provider_mask` in the
267/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__target_8h.html).
268pub fn open_gl_supported_context_provider_mask() -> OpenGlContextProviderFlag {
269    let mut call = Call::global();
270    crate::abi::require_abi_version();
271    let value = call.run(|_| unsafe { sys::mln_open_gl_supported_context_provider_mask() });
272    OpenGlContextProviderFlag::from_bits_retain(value)
273}
274
275/// Returns the function that registers a plugin's style layer types.
276///
277/// Pass the function to the plugin's registration entry point before
278/// loading a style that uses the plugin's layer types. Plugin callbacks run
279/// on library threads and can keep running while the process exits, so they
280/// must not use state that the process destroys at exit.
281///
282/// See `mln_plugin_get_register_function_v1` in the
283/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/plugin_8h.html).
284pub fn get_plugin_register_function_v1() -> sys::mln_plugin_register_function_v1 {
285    let mut call = Call::global();
286    crate::abi::require_abi_version();
287    let value = call.run(|_| unsafe { sys::mln_plugin_get_register_function_v1() });
288    value
289}
290
291/// Converts a coordinate to meters in the Web Mercator projection.
292///
293/// See `mln_projected_meters_for_lat_lng` in the
294/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/projection_8h.html).
295pub fn projected_meters_for_lat_lng(coordinate: LatLng) -> Result<ProjectedMeters> {
296    let mut call = Call::global();
297    crate::abi::validate_abi_version()?;
298    let mut out_meters: sys::mln_projected_meters = unsafe { std::mem::zeroed() };
299    let coordinate = call.input(&coordinate)?;
300    call.status(|_, out_diagnostic| unsafe {
301        sys::mln_projected_meters_for_lat_lng(coordinate, &mut out_meters, out_diagnostic)
302    })?;
303    Ok(unsafe { from_native(out_meters) }?)
304}
305
306/// Returns the render backends that this build of the library draws with.
307///
308/// See `mln_supported_render_backend_mask` in the
309/// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/base_8h.html).
310pub fn supported_render_backend_mask() -> RenderBackendFlag {
311    let mut call = Call::global();
312    crate::abi::require_abi_version();
313    let value = call.run(|_| unsafe { sys::mln_supported_render_backend_mask() });
314    RenderBackendFlag::from_bits_retain(value)
315}