maplibre_native_ffi/generated/render_session.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 render session draws a map into a surface or a texture.
8 ///
9 /// See `mln_render_session` in the
10 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/base_8h.html).
11 pub struct RenderSessionHandle(mln_render_session) dispose |raw| crate::error::check(|out_diagnostic| unsafe { sys::mln_render_session_dispose(raw, out_diagnostic) });
12 /// Returns the native handle value.
13 fn id;
14}
15
16impl RenderSessionHandle {
17 /// Stops the session right away, without running its pending graphics work.
18 ///
19 /// Use it when the target's graphics objects are going away and a detach
20 /// can't finish first. Pending work completes with `Status::TargetLost`,
21 /// and pending frame demands finish with `RenderResult::TargetNotReady`.
22 /// Once the call returns, the library no longer uses your graphics objects,
23 /// and you can attach another session to the map. Release the session
24 /// afterward.
25 ///
26 /// Abandon keeps the session's OpenGL and WebGPU objects until the process
27 /// exits, and reports how many it kept. Detach the session instead to free
28 /// them.
29 ///
30 /// See `mln_render_session_abandon` in the
31 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
32 pub fn abandon(&self) -> Result<RenderAbandonResult> {
33 let mut call = self.inner.call();
34 let mut out_result: sys::mln_render_abandon_result = unsafe { std::mem::zeroed() };
35 out_result.size = std::mem::size_of::<sys::mln_render_abandon_result>() as _;
36 call.status(|session, out_diagnostic| unsafe {
37 sys::mln_render_session_abandon(session, &mut out_result, out_diagnostic)
38 })?;
39 Ok(unsafe { from_native(out_result) }?)
40 }
41
42 /// Takes the newest rendered frame from the session's texture ring, if one
43 /// is ready.
44 ///
45 /// Older frames that you haven't acquired are dropped, and the session can
46 /// render over a frame before you acquire it. While you hold a frame in
47 /// every texture of the ring, new frames wait until you release one. When
48 /// no frame is ready, it succeeds and writes the null handle.
49 ///
50 /// See `mln_render_session_acquire_frame` in the
51 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
52 ///
53 /// # Errors
54 ///
55 /// - `Status::Unsupported` when the session lacks
56 /// `RenderSessionCapabilityFlag::FRAME_ACQUISITION`.
57 /// - `Status::TargetLost` or `Status::NativeError`, as
58 /// `RenderSessionSnapshot::failure_status` reports, when the session has
59 /// failed.
60 /// - `Status::InvalidState` when you detached, abandoned, released, or
61 /// disposed the session.
62 pub fn acquire_frame(&self) -> Result<Option<AcquiredFrameHandle>> {
63 let mut call = self.inner.call();
64 let mut out_frame = sys::mln_acquired_frame(0);
65 call.status(|session, out_diagnostic| unsafe {
66 sys::mln_render_session_acquire_frame(session, &mut out_frame, out_diagnostic)
67 })?;
68 if out_frame.0 == 0 {
69 return Ok(None);
70 }
71 Ok(Some(AcquiredFrameHandle::adopt(out_frame)?))
72 }
73
74 /// Ends the session's pending frame demands and waits for its earlier work.
75 ///
76 /// Frame demands that haven't started, including those that wait for a map
77 /// update, finish with `RenderResult::NoUpdate`.
78 ///
79 /// See `mln_render_session_barrier` in the
80 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
81 ///
82 /// # Errors
83 ///
84 /// - `Status::TargetLost` when the session loses its target before the
85 /// barrier runs.
86 pub fn barrier(&self) -> Result<NativeFuture<()>> {
87 let call = self.inner.call();
88 call.complete(
89 |session, completion, out_diagnostic| unsafe {
90 sys::mln_render_session_barrier(session, completion, out_diagnostic)
91 },
92 completion::unit,
93 )
94 }
95
96 /// Clears the data that the session's renderer holds, such as loaded tiles,
97 /// and draws the map again.
98 ///
99 /// See `mln_render_session_clear_data` in the
100 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
101 ///
102 /// # Errors
103 ///
104 /// - `Status::TargetLost` when the session loses its target before the work
105 /// runs.
106 pub fn clear_data(&self) -> Result<NativeFuture<()>> {
107 let call = self.inner.call();
108 call.complete(
109 |session, completion, out_diagnostic| unsafe {
110 sys::mln_render_session_clear_data(session, completion, out_diagnostic)
111 },
112 completion::unit,
113 )
114 }
115
116 /// Asks the session to render a frame.
117 ///
118 /// The frame shows the map commands that you sent before the call, except
119 /// the changes that an open command group holds back.
120 ///
121 /// You can call it once the attach call returns. While the attach runs, the
122 /// demand waits for it to complete. Every demand finishes with one frame
123 /// result that carries its token, and
124 /// `RenderSessionHandle::drain_frame_results()` takes it. A demand without
125 /// `FrameDemandFlag::FORCE` replaces each pending demand with the same
126 /// flags.
127 ///
128 /// See `mln_render_session_demand_frame` in the
129 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
130 ///
131 /// # Errors
132 ///
133 /// - `Status::TargetLost` or `Status::NativeError`, as
134 /// `RenderSessionSnapshot::failure_status` reports, when the session has
135 /// failed.
136 /// - `Status::InvalidState` when you detached, abandoned, released, or
137 /// disposed the session, or discarded a frame from every texture of its
138 /// ring.
139 pub fn demand_frame(&self, demand: &FrameDemand) -> Result<()> {
140 let mut call = self.inner.call();
141 let demand = call.reference(&demand)?;
142 call.status(|session, out_diagnostic| unsafe {
143 sys::mln_render_session_demand_frame(session, demand, out_diagnostic)
144 })?;
145 Ok(())
146 }
147
148 /// Detaches the session from its map and frees its graphics objects.
149 ///
150 /// Release every acquired frame first. Pending frame demands finish with
151 /// `RenderResult::TargetNotReady`. Once the detach completes, the library
152 /// no longer uses your graphics objects, and you can attach another session
153 /// to the map. Release the session afterward.
154 ///
155 /// See `mln_render_session_detach` in the
156 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
157 ///
158 /// # Errors
159 ///
160 /// - `Status::TargetLost` when the session loses its target before the
161 /// detach runs.
162 pub fn detach(&self) -> Result<NativeFuture<()>> {
163 let call = self.inner.call();
164 call.complete(
165 |session, completion, out_diagnostic| unsafe {
166 sys::mln_render_session_detach(session, completion, out_diagnostic)
167 },
168 completion::unit,
169 )
170 }
171
172 /// Releases the session in any state, and finishes in the background.
173 ///
174 /// Use it from destructors and finalizers, and
175 /// `RenderSessionHandle::release()` elsewhere. It ends the session as a
176 /// release does, except that it abandons a session whose frames you hold,
177 /// which ends those frames. Keep servicing a session driven by
178 /// `RenderDriverKind::CallerGraphicsThread` until
179 /// `RenderSessionHandle::service_driver_work()` no longer accepts it.
180 ///
181 /// See `mln_render_session_dispose` in the
182 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
183 pub fn dispose(self) -> std::result::Result<RetiringRenderSession, ReleaseError<Self>> {
184 self.consume(|session| {
185 let mut call = Call::new(session);
186 call.status(|session, out_diagnostic| unsafe {
187 sys::mln_render_session_dispose(session, out_diagnostic)
188 })
189 .map(|()| RetiringRenderSession(session))
190 })
191 }
192
193 /// Takes the frame results that the session has queued.
194 ///
195 /// When no result is queued, it succeeds and writes the null handle and an
196 /// empty view.
197 ///
198 /// See `mln_render_session_drain_frame_results` in the
199 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
200 pub fn drain_frame_results(&self) -> Result<Vec<RenderFrameResult>> {
201 let mut call = self.inner.call();
202 let mut out_batch = sys::mln_render_frame_batch(0);
203 let mut out_view: sys::mln_render_frame_batch_view = unsafe { std::mem::zeroed() };
204 out_view.size = std::mem::size_of::<sys::mln_render_frame_batch_view>() as _;
205 call.status(|session, out_diagnostic| unsafe {
206 sys::mln_render_session_drain_frame_results(
207 session,
208 &mut out_batch,
209 &mut out_view,
210 out_diagnostic,
211 )
212 })?;
213 if out_batch.0 == 0 {
214 return Ok(Vec::new());
215 }
216 // SAFETY: native published the batch to this call alone.
217 let _batch =
218 unsafe { crate::handle::Drained::new(out_batch, sys::mln_render_frame_batch_release) };
219 Ok(unsafe {
220 convert::copy_strided(
221 out_view.results,
222 out_view.result_count,
223 out_view.result_size,
224 )
225 }?)
226 }
227
228 /// Logs debugging information about the session's renderer.
229 ///
230 /// See `mln_render_session_dump_debug_logs` in the
231 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
232 ///
233 /// # Errors
234 ///
235 /// - `Status::TargetLost` when the session loses its target before the work
236 /// runs.
237 pub fn dump_debug_logs(&self) -> Result<NativeFuture<()>> {
238 let call = self.inner.call();
239 call.complete(
240 |session, completion, out_diagnostic| unsafe {
241 sys::mln_render_session_dump_debug_logs(session, completion, out_diagnostic)
242 },
243 completion::unit,
244 )
245 }
246
247 /// Reads what the session supports.
248 ///
249 /// See `mln_render_session_get_capabilities` in the
250 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
251 pub fn get_capabilities(&self) -> Result<RenderSessionCapabilities> {
252 let mut call = self.inner.call();
253 let mut out_capabilities: sys::mln_render_session_capabilities =
254 unsafe { std::mem::zeroed() };
255 out_capabilities.size = std::mem::size_of::<sys::mln_render_session_capabilities>() as _;
256 call.status(|session, out_diagnostic| unsafe {
257 sys::mln_render_session_get_capabilities(session, &mut out_capabilities, out_diagnostic)
258 })?;
259 Ok(unsafe { from_native(out_capabilities) }?)
260 }
261
262 /// Reads the children of a cluster in a clustered GeoJSON source.
263 ///
264 /// `cluster_id` is the "cluster_id" property of a cluster feature. The
265 /// result is a GeoJSON feature collection of the clusters and points that
266 /// the cluster splits into at the next zoom level.
267 ///
268 /// The query reads the source's data from the session's most recent render
269 /// attempt, so a change to the data shows once the session tries to render
270 /// again.
271 ///
272 /// A cluster ID belongs to one version of the source's data. After the data
273 /// changes, feature queries can return IDs from the earlier version until
274 /// the source's tiles reload, and such an ID completes with
275 /// `Status::NotFound` or names a different cluster. Query the features
276 /// again for current IDs.
277 ///
278 /// See `mln_render_session_get_cluster_children` in the
279 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/query_8h.html).
280 ///
281 /// # Errors
282 ///
283 /// - `Status::NotFound` when the session's most recent render attempt had
284 /// no source named `source_id`, or the source has no cluster
285 /// `cluster_id`.
286 /// - `Status::InvalidArgument` when the source isn't a GeoJSON source with
287 /// clustering turned on.
288 pub fn get_cluster_children(
289 &self,
290 source_id: &str,
291 cluster_id: u32,
292 ) -> Result<NativeFuture<String>> {
293 let mut call = self.inner.call();
294 let source_id = call.input(&source_id)?;
295 call.complete(
296 |session, completion, out_diagnostic| unsafe {
297 sys::mln_render_session_get_cluster_children(
298 session,
299 source_id,
300 cluster_id,
301 completion,
302 out_diagnostic,
303 )
304 },
305 completion::value::<sys::mln_buffer_view, _>,
306 )
307 }
308
309 /// Reads the zoom level at which a cluster of a clustered GeoJSON source
310 /// splits.
311 ///
312 /// `cluster_id` is the "cluster_id" property of a cluster feature. At the
313 /// result's zoom level, the cluster splits into two or more clusters or
314 /// points.
315 ///
316 /// A cluster ID can go out of date as
317 /// `RenderSessionHandle::get_cluster_children()` describes.
318 ///
319 /// See `mln_render_session_get_cluster_expansion_zoom` in the
320 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/query_8h.html).
321 ///
322 /// # Errors
323 ///
324 /// - `Status::NotFound` when the session's most recent render attempt had
325 /// no source named `source_id`, or the source has no cluster
326 /// `cluster_id`.
327 /// - `Status::InvalidArgument` when the source isn't a GeoJSON source with
328 /// clustering turned on.
329 pub fn get_cluster_expansion_zoom(
330 &self,
331 source_id: &str,
332 cluster_id: u32,
333 ) -> Result<NativeFuture<u32>> {
334 let mut call = self.inner.call();
335 let source_id = call.input(&source_id)?;
336 call.complete(
337 |session, completion, out_diagnostic| unsafe {
338 sys::mln_render_session_get_cluster_expansion_zoom(
339 session,
340 source_id,
341 cluster_id,
342 completion,
343 out_diagnostic,
344 )
345 },
346 |result| {
347 let value = completion::copy_value::<u32>(result)?;
348 Ok(value)
349 },
350 )
351 }
352
353 /// Reads the points in a cluster of a clustered GeoJSON source.
354 ///
355 /// `cluster_id` is the "cluster_id" property of a cluster feature. The
356 /// result is a GeoJSON feature collection of the original point features.
357 /// It skips the first `offset` points and then holds up to `limit` of them,
358 /// so a `limit` of 0 gives an empty collection.
359 ///
360 /// A cluster ID can go out of date as
361 /// `RenderSessionHandle::get_cluster_children()` describes.
362 ///
363 /// See `mln_render_session_get_cluster_leaves` in the
364 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/query_8h.html).
365 ///
366 /// # Errors
367 ///
368 /// - `Status::NotFound` when the session's most recent render attempt had
369 /// no source named `source_id`, or the source has no cluster
370 /// `cluster_id`.
371 /// - `Status::InvalidArgument` when the source isn't a GeoJSON source with
372 /// clustering turned on.
373 pub fn get_cluster_leaves(
374 &self,
375 source_id: &str,
376 cluster_id: u32,
377 limit: u32,
378 offset: u32,
379 ) -> Result<NativeFuture<String>> {
380 let mut call = self.inner.call();
381 let source_id = call.input(&source_id)?;
382 call.complete(
383 |session, completion, out_diagnostic| unsafe {
384 sys::mln_render_session_get_cluster_leaves(
385 session,
386 source_id,
387 cluster_id,
388 limit,
389 offset,
390 completion,
391 out_diagnostic,
392 )
393 },
394 completion::value::<sys::mln_buffer_view, _>,
395 )
396 }
397
398 /// Reads the message of the error that made the session fail.
399 ///
400 /// `RenderSessionSnapshot::failure_status` reports the error's status. The
401 /// message is empty while the session hasn't failed, and doesn't change
402 /// once it fails.
403 ///
404 /// See `mln_render_session_get_failure` in the
405 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
406 pub fn get_failure(&self) -> Result<String> {
407 let mut call = self.inner.call();
408 let mut out_message = Vec::new();
409 call.status(|session, out_diagnostic| unsafe {
410 convert::caller_sized_text(
411 &mut out_message,
412 |out_message, message_capacity, out_message_length| {
413 sys::mln_render_session_get_failure(
414 session,
415 out_message,
416 message_capacity,
417 out_message_length,
418 out_diagnostic,
419 )
420 },
421 )
422 })?;
423 Ok(convert::utf8(out_message)?)
424 }
425
426 /// Reads the session's current state.
427 ///
428 /// See `mln_render_session_get_snapshot` in the
429 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
430 pub fn get_snapshot(&self) -> Result<RenderSessionSnapshot> {
431 let mut call = self.inner.call();
432 let mut out_snapshot: sys::mln_render_session_snapshot = unsafe { std::mem::zeroed() };
433 out_snapshot.size = std::mem::size_of::<sys::mln_render_session_snapshot>() as _;
434 call.status(|session, out_diagnostic| unsafe {
435 sys::mln_render_session_get_snapshot(session, &mut out_snapshot, out_diagnostic)
436 })?;
437 Ok(unsafe { from_native(out_snapshot) }?)
438 }
439
440 /// Finds the features that the session drew in an area of the screen.
441 ///
442 /// The query reads the last frame that the session rendered. A feature that
443 /// several layers draw appears once for each layer.
444 ///
445 /// See `mln_render_session_query_rendered_features` in the
446 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/query_8h.html).
447 pub fn query_rendered_features(
448 &self,
449 geometry: &RenderedQueryGeometry,
450 options: Option<&RenderedFeatureQueryOptions<'_>>,
451 ) -> Result<NativeFuture<Vec<RenderedFeature>>> {
452 let mut call = self.inner.call();
453 let geometry = call.reference(&geometry)?;
454 let options = call.optional_reference(options.as_ref())?;
455 call.complete(
456 |session, completion, out_diagnostic| unsafe {
457 sys::mln_render_session_query_rendered_features(
458 session,
459 geometry,
460 options,
461 completion,
462 out_diagnostic,
463 )
464 },
465 completion::list::<sys::mln_rendered_feature, _>,
466 )
467 }
468
469 /// Finds the features of the source named `source_id`.
470 ///
471 /// The query covers only the tiles that the source has loaded for the
472 /// current view. A source loads tiles only while a visible layer uses it.
473 ///
474 /// See `mln_render_session_query_source_features` in the
475 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/query_8h.html).
476 pub fn query_source_features(
477 &self,
478 source_id: &str,
479 options: Option<&SourceFeatureQueryOptions<'_>>,
480 ) -> Result<NativeFuture<Vec<SourceFeature>>> {
481 let mut call = self.inner.call();
482 let source_id = call.input(&source_id)?;
483 let options = call.optional_reference(options.as_ref())?;
484 call.complete(
485 |session, completion, out_diagnostic| unsafe {
486 sys::mln_render_session_query_source_features(
487 session,
488 source_id,
489 options,
490 completion,
491 out_diagnostic,
492 )
493 },
494 completion::list::<sys::mln_source_feature, _>,
495 )
496 }
497
498 /// Reads the pixels of the last frame that the session rendered.
499 ///
500 /// See `mln_render_session_read_texture` in the
501 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/texture_8h.html).
502 ///
503 /// # Errors
504 ///
505 /// - `Status::Unsupported` when the session's capabilities lack
506 /// `RenderSessionCapabilityFlag::READBACK`.
507 /// - `Status::InvalidState` when the session hasn't rendered a frame since
508 /// it attached, resized, or changed its target.
509 pub fn read_texture(&self) -> Result<NativeFuture<TextureReadbackResult>> {
510 let call = self.inner.call();
511 call.complete(
512 |session, completion, out_diagnostic| unsafe {
513 sys::mln_render_session_read_texture(session, completion, out_diagnostic)
514 },
515 completion::value::<sys::mln_texture_readback_result, _>,
516 )
517 }
518
519 /// Frees memory that the session's renderer can rebuild, such as caches.
520 ///
521 /// See `mln_render_session_reduce_memory_use` in the
522 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
523 ///
524 /// # Errors
525 ///
526 /// - `Status::TargetLost` when the session loses its target before the work
527 /// runs.
528 pub fn reduce_memory_use(&self) -> Result<NativeFuture<()>> {
529 let call = self.inner.call();
530 call.complete(
531 |session, completion, out_diagnostic| unsafe {
532 sys::mln_render_session_reduce_memory_use(session, completion, out_diagnostic)
533 },
534 completion::unit,
535 )
536 }
537
538 /// Releases the session, detaching it first when it is attached.
539 ///
540 /// Pending frame demands finish with `RenderResult::TargetNotReady`. Once
541 /// the release completes, the library no longer uses your graphics objects,
542 /// and you can attach another session to the map.
543 ///
544 /// A session driven by `RenderDriverKind::CallerGraphicsThread` detaches at
545 /// your next `RenderSessionHandle::service_driver_work()`, so keep
546 /// servicing it until the release completes. When the session isn't
547 /// attached, such as while it attaches or after it fails, or when you
548 /// release or dispose its map before that service, the release abandons it
549 /// as `RenderSessionHandle::abandon()` does.
550 ///
551 /// See `mln_render_session_release` in the
552 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
553 ///
554 /// # Errors
555 ///
556 /// - `Status::InvalidState` while you hold one of the session's acquired
557 /// frames. Release or discard them first.
558 pub fn release(
559 self,
560 ) -> std::result::Result<(NativeFuture<()>, RetiringRenderSession), ReleaseError<Self>> {
561 self.consume(|session| {
562 let call = Call::new(session);
563 call.complete(
564 |session, completion, out_diagnostic| unsafe {
565 sys::mln_render_session_release(session, completion, out_diagnostic)
566 },
567 completion::unit,
568 )
569 .map(|value| (value, RetiringRenderSession(session)))
570 })
571 }
572
573 /// Lets go of the session's surface or textures, and keeps the rest of the
574 /// session.
575 ///
576 /// Use it when the platform takes a surface away, such as when your app
577 /// goes to the background. Release every acquired frame first. Frame
578 /// demands that are still pending, and later ones until you give the
579 /// session a new target, finish with `RenderResult::TargetNotReady`. Once
580 /// the release completes, you can destroy the old target. An Android or
581 /// OpenHarmony window can go away sooner, as
582 /// `MapHandle::attach_android_surface()` and
583 /// `MapHandle::attach_ohos_surface()` say.
584 ///
585 /// See `mln_render_session_release_target` in the
586 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
587 ///
588 /// # Errors
589 ///
590 /// - `Status::Unsupported` when the session renders offscreen or into
591 /// Android hardware buffers, dmabufs, DXGI shared textures, or IOSurfaces
592 /// that it allocates.
593 /// - `Status::Unsupported` when the target is a WebGL canvas.
594 /// - `Status::TargetLost` when the session loses its target before the
595 /// release runs.
596 pub fn release_target(&self) -> Result<NativeFuture<()>> {
597 let call = self.inner.call();
598 call.complete(
599 |session, completion, out_diagnostic| unsafe {
600 sys::mln_render_session_release_target(session, completion, out_diagnostic)
601 },
602 completion::unit,
603 )
604 }
605
606 /// Resizes the session's target and its map.
607 ///
608 /// The session renders at the map's scale factor. Release every acquired
609 /// frame first.
610 ///
611 /// See `mln_render_session_resize` in the
612 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
613 ///
614 /// # Errors
615 ///
616 /// - `Status::Unsupported` when the session renders into a borrowed ring.
617 /// Give it new textures of the new size instead.
618 /// - `Status::TargetLost` when the session loses its target before the
619 /// resize applies.
620 pub fn resize(&self, logical_size: LogicalSize) -> Result<NativeFuture<CommandCompletion>> {
621 let mut call = self.inner.call();
622 let logical_size = call.input(&logical_size)?;
623 call.command(|session, completion, out_diagnostic| unsafe {
624 sys::mln_render_session_resize(session, logical_size, completion, out_diagnostic)
625 })
626 }
627
628 /// Runs the session's ready graphics work on your graphics thread.
629 ///
630 /// Use it with `RenderDriverKind::CallerGraphicsThread`, and call it from
631 /// the same thread every time. Call it each time
632 /// `RenderSessionAttachOptions::driver_work_wake` is called, even while you
633 /// demand no frames, until a detach, release, or disposal of the session
634 /// finishes. It returns once no work is ready.
635 ///
636 /// It accepts a released or disposed session until that release or disposal
637 /// finishes.
638 ///
639 /// See `mln_render_session_service_driver_work` in the
640 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
641 pub fn service_driver_work(&self) -> Result<()> {
642 let mut call = self.inner.call();
643 call.status(|session, out_diagnostic| unsafe {
644 sys::mln_render_session_service_driver_work(session, out_diagnostic)
645 })?;
646 Ok(())
647 }
648
649 /// Replaces the Android window that the session presents to.
650 ///
651 /// Use it to give the session a window again after
652 /// `RenderSessionHandle::release_target()`, to move it to another window,
653 /// or to resize it. Once the replacement completes, the session no longer
654 /// uses the old window.
655 ///
656 /// See `mln_render_session_set_android_surface_target` in the
657 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/android_8h.html).
658 ///
659 /// # Errors
660 ///
661 /// - `Status::InvalidArgument` when `surface` has no window, such as after
662 /// the platform destroyed it.
663 /// - `Status::Unsupported` when, in a Vulkan build, the new window needs a
664 /// different color format or pre-rotation support than the old one.
665 /// Attach a new session instead.
666 /// - `Status::NativeError` when the library can't create the window's
667 /// surface.
668 ///
669 /// # Safety
670 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
671 #[cfg(target_os = "android")]
672 pub unsafe fn set_android_surface_target(
673 &self,
674 replacement: &AndroidSurfaceReplacement,
675 ) -> Result<NativeFuture<()>> {
676 let mut call = self.inner.call();
677 let replacement = call.reference(&replacement)?;
678 call.complete(
679 |session, completion, out_diagnostic| unsafe {
680 sys::mln_render_session_set_android_surface_target(
681 session,
682 replacement,
683 completion,
684 out_diagnostic,
685 )
686 },
687 completion::unit,
688 )
689 }
690
691 /// Sets the frame pacer that demands the session's frames.
692 ///
693 /// At the first display refresh after the session has something new to
694 /// draw, `pacer` demands a frame without flags and with token 0. One pacer
695 /// can serve many sessions. A null `pacer` stops pacing the session. You
696 /// can call it once the attach call returns.
697 ///
698 /// See `mln_render_session_set_frame_pacer` in the
699 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
700 ///
701 /// # Errors
702 ///
703 /// - `Status::TargetLost` or `Status::NativeError`, as
704 /// `RenderSessionSnapshot::failure_status` reports, when the session has
705 /// failed.
706 /// - `Status::InvalidState` when you attached the session with a redraw
707 /// wake, or detached, abandoned, released, or disposed it.
708 pub fn set_frame_pacer(&self, pacer: Option<&FramePacerHandle>) -> Result<()> {
709 let mut call = self.inner.call();
710 let pacer = pacer.map_or(sys::mln_frame_pacer(0), |pacer| pacer.inner.native());
711 call.status(|session, out_diagnostic| unsafe {
712 sys::mln_render_session_set_frame_pacer(session, pacer, out_diagnostic)
713 })?;
714 Ok(())
715 }
716
717 /// Replaces the Metal textures that a borrowed ring renders into.
718 ///
719 /// Use it to resize the ring, or to give the session textures again after
720 /// `RenderSessionHandle::release_target()`. Release every acquired frame
721 /// first. Once the replacement completes, the session no longer uses the
722 /// old textures.
723 ///
724 /// See `mln_render_session_set_metal_borrowed_texture_target` in the
725 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/texture_8h.html).
726 ///
727 /// # Errors
728 ///
729 /// - `Status::Unsupported` when the new textures have a different pixel
730 /// format than the old ones. Attach a new session to change it.
731 ///
732 /// # Safety
733 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
734 #[cfg(any(
735 target_os = "ios",
736 target_os = "macos",
737 target_os = "tvos",
738 target_os = "visionos"
739 ))]
740 pub unsafe fn set_metal_borrowed_texture_target(
741 &self,
742 replacement: &MetalBorrowedTextureReplacement,
743 ) -> Result<NativeFuture<()>> {
744 let mut call = self.inner.call();
745 let replacement = call.reference(&replacement)?;
746 call.complete(
747 |session, completion, out_diagnostic| unsafe {
748 sys::mln_render_session_set_metal_borrowed_texture_target(
749 session,
750 replacement,
751 completion,
752 out_diagnostic,
753 )
754 },
755 completion::unit,
756 )
757 }
758
759 /// Replaces the Metal layer that the session renders to.
760 ///
761 /// Use it to give the session a layer again after
762 /// `RenderSessionHandle::release_target()`, to move it to another layer, or
763 /// to resize it. Once the replacement completes, the session no longer uses
764 /// the old layer.
765 ///
766 /// See `mln_render_session_set_metal_surface_target` in the
767 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/surface_8h.html).
768 ///
769 /// # Safety
770 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
771 #[cfg(any(
772 target_os = "ios",
773 target_os = "macos",
774 target_os = "tvos",
775 target_os = "visionos"
776 ))]
777 pub unsafe fn set_metal_surface_target(
778 &self,
779 replacement: &MetalSurfaceReplacement,
780 ) -> Result<NativeFuture<()>> {
781 let mut call = self.inner.call();
782 let replacement = call.reference(&replacement)?;
783 call.complete(
784 |session, completion, out_diagnostic| unsafe {
785 sys::mln_render_session_set_metal_surface_target(
786 session,
787 replacement,
788 completion,
789 out_diagnostic,
790 )
791 },
792 completion::unit,
793 )
794 }
795
796 /// Replaces the OpenHarmony window that the session presents to.
797 ///
798 /// Use it to give the session a window again after
799 /// `RenderSessionHandle::release_target()`, to move it to another window,
800 /// or to resize it. Once the replacement completes, the session no longer
801 /// uses the old window.
802 ///
803 /// See `mln_render_session_set_ohos_surface_target` in the
804 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/ohos_8h.html).
805 ///
806 /// # Errors
807 ///
808 /// - `Status::InvalidArgument` when no surface in this process has
809 /// `OhosSurfaceReplacement::surface_id`, such as after the platform
810 /// destroyed it.
811 /// - `Status::Unsupported` when, in a Vulkan build, the new window needs a
812 /// different color format or pre-rotation support than the old one.
813 /// Attach a new session instead.
814 /// - `Status::NativeError` when the library can't create the window's
815 /// surface.
816 ///
817 /// # Safety
818 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
819 #[cfg(target_env = "ohos")]
820 pub unsafe fn set_ohos_surface_target(
821 &self,
822 replacement: &OhosSurfaceReplacement,
823 ) -> Result<NativeFuture<()>> {
824 let mut call = self.inner.call();
825 let replacement = call.reference(&replacement)?;
826 call.complete(
827 |session, completion, out_diagnostic| unsafe {
828 sys::mln_render_session_set_ohos_surface_target(
829 session,
830 replacement,
831 completion,
832 out_diagnostic,
833 )
834 },
835 completion::unit,
836 )
837 }
838
839 /// Replaces the OpenGL textures that a borrowed ring renders into.
840 ///
841 /// Use it to resize the ring, or to give the session textures again after
842 /// `RenderSessionHandle::release_target()`. Release every acquired frame
843 /// first. Once the replacement completes, the session no longer uses the
844 /// old textures.
845 ///
846 /// See `mln_render_session_set_open_gl_borrowed_texture_target` in the
847 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/texture_8h.html).
848 ///
849 /// # Safety
850 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
851 pub unsafe fn set_open_gl_borrowed_texture_target(
852 &self,
853 replacement: &OpenGlBorrowedTextureReplacement,
854 ) -> Result<NativeFuture<()>> {
855 let mut call = self.inner.call();
856 let replacement = call.reference(&replacement)?;
857 call.complete(
858 |session, completion, out_diagnostic| unsafe {
859 sys::mln_render_session_set_open_gl_borrowed_texture_target(
860 session,
861 replacement,
862 completion,
863 out_diagnostic,
864 )
865 },
866 completion::unit,
867 )
868 }
869
870 /// Replaces the OpenGL surface that the session presents to.
871 ///
872 /// Use it to give the session a surface again after
873 /// `RenderSessionHandle::release_target()`, to move it to another surface,
874 /// or to resize it. Once the replacement completes, the session no longer
875 /// uses the old surface.
876 ///
877 /// See `mln_render_session_set_open_gl_surface_target` in the
878 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/surface_8h.html).
879 ///
880 /// # Safety
881 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
882 pub unsafe fn set_open_gl_surface_target(
883 &self,
884 replacement: &OpenGlSurfaceReplacement,
885 ) -> Result<NativeFuture<()>> {
886 let mut call = self.inner.call();
887 let replacement = call.reference(&replacement)?;
888 call.complete(
889 |session, completion, out_diagnostic| unsafe {
890 sys::mln_render_session_set_open_gl_surface_target(
891 session,
892 replacement,
893 completion,
894 out_diagnostic,
895 )
896 },
897 completion::unit,
898 )
899 }
900
901 /// Replaces the Vulkan images that a borrowed ring renders into.
902 ///
903 /// Use it to resize the ring, or to give the session images again after
904 /// `RenderSessionHandle::release_target()`. Release every acquired frame
905 /// first. Once the replacement completes, the session no longer uses the
906 /// old images.
907 ///
908 /// See `mln_render_session_set_vulkan_borrowed_texture_target` in the
909 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/texture_8h.html).
910 ///
911 /// # Safety
912 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
913 #[cfg(any(
914 target_os = "android",
915 target_os = "freebsd",
916 target_os = "linux",
917 target_os = "macos",
918 target_os = "windows"
919 ))]
920 pub unsafe fn set_vulkan_borrowed_texture_target(
921 &self,
922 replacement: &VulkanBorrowedTextureReplacement,
923 ) -> Result<NativeFuture<()>> {
924 let mut call = self.inner.call();
925 let replacement = call.reference(&replacement)?;
926 call.complete(
927 |session, completion, out_diagnostic| unsafe {
928 sys::mln_render_session_set_vulkan_borrowed_texture_target(
929 session,
930 replacement,
931 completion,
932 out_diagnostic,
933 )
934 },
935 completion::unit,
936 )
937 }
938
939 /// Replaces the Vulkan surface that the session presents to.
940 ///
941 /// Use it to give the session a surface again after
942 /// `RenderSessionHandle::release_target()`, to move it to another surface,
943 /// or to resize it. Once the replacement completes, the session no longer
944 /// uses the old surface.
945 ///
946 /// See `mln_render_session_set_vulkan_surface_target` in the
947 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/surface_8h.html).
948 ///
949 /// # Errors
950 ///
951 /// - `Status::Unsupported` when the new surface needs a different color
952 /// format or pre-rotation support than the old one. Attach a new session
953 /// instead.
954 ///
955 /// # Safety
956 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
957 #[cfg(any(
958 target_os = "android",
959 target_os = "freebsd",
960 target_os = "linux",
961 target_os = "macos",
962 target_os = "windows"
963 ))]
964 pub unsafe fn set_vulkan_surface_target(
965 &self,
966 replacement: &VulkanSurfaceReplacement,
967 ) -> Result<NativeFuture<()>> {
968 let mut call = self.inner.call();
969 let replacement = call.reference(&replacement)?;
970 call.complete(
971 |session, completion, out_diagnostic| unsafe {
972 sys::mln_render_session_set_vulkan_surface_target(
973 session,
974 replacement,
975 completion,
976 out_diagnostic,
977 )
978 },
979 completion::unit,
980 )
981 }
982
983 /// Replaces the Wayland surface that the session presents to.
984 ///
985 /// Use it to give the session a surface again after
986 /// `RenderSessionHandle::release_target()`, to move it to another surface,
987 /// or to resize it. Once the replacement completes, the session no longer
988 /// uses the old surface.
989 ///
990 /// See `mln_render_session_set_wayland_surface_target` in the
991 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/wayland_8h.html).
992 ///
993 /// # Errors
994 ///
995 /// - `Status::Unsupported` when, in a Vulkan build, the new surface needs a
996 /// different color format than the old one. Attach a new session instead.
997 /// - `Status::NativeError` when the library can't present to the new
998 /// surface.
999 ///
1000 /// # Safety
1001 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
1002 #[cfg(any(
1003 target_os = "freebsd",
1004 all(target_os = "linux", not(target_env = "ohos"))
1005 ))]
1006 pub unsafe fn set_wayland_surface_target(
1007 &self,
1008 replacement: &WaylandSurfaceReplacement,
1009 ) -> Result<NativeFuture<()>> {
1010 let mut call = self.inner.call();
1011 let replacement = call.reference(&replacement)?;
1012 call.complete(
1013 |session, completion, out_diagnostic| unsafe {
1014 sys::mln_render_session_set_wayland_surface_target(
1015 session,
1016 replacement,
1017 completion,
1018 out_diagnostic,
1019 )
1020 },
1021 completion::unit,
1022 )
1023 }
1024
1025 /// Replaces the WebGPU textures that a borrowed ring renders into.
1026 ///
1027 /// Use it to resize the ring, or to give the session textures again after
1028 /// `RenderSessionHandle::release_target()`. Release every acquired frame
1029 /// first. Once the replacement completes, the session no longer uses the
1030 /// old textures.
1031 ///
1032 /// See `mln_render_session_set_web_gpu_borrowed_texture_target` in the
1033 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/texture_8h.html).
1034 ///
1035 /// # Safety
1036 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
1037 #[cfg(target_os = "emscripten")]
1038 pub unsafe fn set_web_gpu_borrowed_texture_target(
1039 &self,
1040 replacement: &WebGpuBorrowedTextureReplacement,
1041 ) -> Result<NativeFuture<()>> {
1042 let mut call = self.inner.call();
1043 let replacement = call.reference(&replacement)?;
1044 call.complete(
1045 |session, completion, out_diagnostic| unsafe {
1046 sys::mln_render_session_set_web_gpu_borrowed_texture_target(
1047 session,
1048 replacement,
1049 completion,
1050 out_diagnostic,
1051 )
1052 },
1053 completion::unit,
1054 )
1055 }
1056
1057 /// Replaces the WebGPU surface that the session presents to.
1058 ///
1059 /// Use it to give the session a surface again after
1060 /// `RenderSessionHandle::release_target()`, to move it to another surface,
1061 /// or to resize it. Once the replacement completes, the session no longer
1062 /// uses the old surface.
1063 ///
1064 /// See `mln_render_session_set_web_gpu_surface_target` in the
1065 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/surface_8h.html).
1066 ///
1067 /// # Safety
1068 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
1069 #[cfg(target_os = "emscripten")]
1070 pub unsafe fn set_web_gpu_surface_target(
1071 &self,
1072 replacement: &WebGpuSurfaceReplacement,
1073 ) -> Result<NativeFuture<()>> {
1074 let mut call = self.inner.call();
1075 let replacement = call.reference(&replacement)?;
1076 call.complete(
1077 |session, completion, out_diagnostic| unsafe {
1078 sys::mln_render_session_set_web_gpu_surface_target(
1079 session,
1080 replacement,
1081 completion,
1082 out_diagnostic,
1083 )
1084 },
1085 completion::unit,
1086 )
1087 }
1088
1089 /// Replaces the Win32 window that the session presents to.
1090 ///
1091 /// Use it to give the session a window again after
1092 /// `RenderSessionHandle::release_target()`, to move it to another window,
1093 /// or to resize it. Once the replacement completes, the session no longer
1094 /// uses the old window.
1095 ///
1096 /// See `mln_render_session_set_win32_window_target` in the
1097 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/win32_8h.html).
1098 ///
1099 /// # Errors
1100 ///
1101 /// - `Status::InvalidArgument` when `window` isn't a window, or, in an
1102 /// OpenGL build, already has another pixel format.
1103 /// - `Status::InvalidState` when `window` is minimized or has no client
1104 /// area.
1105 /// - `Status::InvalidState` when `window` was minimized before the
1106 /// replacement ran.
1107 /// - `Status::Unsupported` when, in a Vulkan build, the new window needs a
1108 /// different color format than the old one. Attach a new session instead.
1109 /// - `Status::NativeError` when the library can't present to the new
1110 /// window.
1111 ///
1112 /// # Safety
1113 /// Native graphics objects must have the types, lifetimes, and synchronization required by the C operation.
1114 #[cfg(target_os = "windows")]
1115 pub unsafe fn set_win32_window_target(
1116 &self,
1117 replacement: &Win32WindowReplacement,
1118 ) -> Result<NativeFuture<()>> {
1119 let mut call = self.inner.call();
1120 let replacement = call.reference(&replacement)?;
1121 call.complete(
1122 |session, completion, out_diagnostic| unsafe {
1123 sys::mln_render_session_set_win32_window_target(
1124 session,
1125 replacement,
1126 completion,
1127 out_diagnostic,
1128 )
1129 },
1130 completion::unit,
1131 )
1132 }
1133}
1134
1135/// What a release of [`RenderSessionHandle`] leaves while native retires the
1136/// handle. Its functions stay callable until the handle retires, and
1137/// fail with `Status::InvalidState` afterwards. It owns nothing, so
1138/// dropping it changes nothing.
1139#[derive(Debug)]
1140pub struct RetiringRenderSession(sys::mln_render_session);
1141impl RetiringRenderSession {
1142 /// Returns the native handle value.
1143 pub fn id(&self) -> u64 {
1144 self.0.0
1145 }
1146
1147 /// Runs the session's ready graphics work on your graphics thread.
1148 ///
1149 /// Use it with `RenderDriverKind::CallerGraphicsThread`, and call it from
1150 /// the same thread every time. Call it each time
1151 /// `RenderSessionAttachOptions::driver_work_wake` is called, even while you
1152 /// demand no frames, until a detach, release, or disposal of the session
1153 /// finishes. It returns once no work is ready.
1154 ///
1155 /// It accepts a released or disposed session until that release or disposal
1156 /// finishes.
1157 ///
1158 /// See `mln_render_session_service_driver_work` in the
1159 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
1160 pub fn service_driver_work(&self) -> Result<()> {
1161 let mut call = Call::new(self.0);
1162 call.status(|session, out_diagnostic| unsafe {
1163 sys::mln_render_session_service_driver_work(session, out_diagnostic)
1164 })?;
1165 Ok(())
1166 }
1167}
1168
1169/// Submits [`RenderSessionHandle`] commands without a completion. Each call returns
1170/// the same acceptance status as its completing form, and native logs a
1171/// command that later fails as a warning through the log handler.
1172pub struct RenderSessionHandleDiscarding<'a>(&'a RenderSessionHandle);
1173impl RenderSessionHandle {
1174 pub fn discarding(&self) -> RenderSessionHandleDiscarding<'_> {
1175 RenderSessionHandleDiscarding(self)
1176 }
1177}
1178impl RenderSessionHandleDiscarding<'_> {
1179 /// Resizes the session's target and its map.
1180 ///
1181 /// The session renders at the map's scale factor. Release every acquired
1182 /// frame first.
1183 ///
1184 /// See `mln_render_session_resize` in the
1185 /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/render__session_8h.html).
1186 ///
1187 /// # Errors
1188 ///
1189 /// - `Status::Unsupported` when the session renders into a borrowed ring.
1190 /// Give it new textures of the new size instead.
1191 pub fn resize(&self, logical_size: LogicalSize) -> Result<()> {
1192 let mut call = self.0.inner.call();
1193 let logical_size = call.input(&logical_size)?;
1194 call.discard(|session, completion, out_diagnostic| unsafe {
1195 sys::mln_render_session_resize(session, logical_size, completion, out_diagnostic)
1196 })
1197 }
1198}