Skip to main content

mln_runtime/
lib.rs

1//! Thread-safe handles over mln-rs's maps, which mirror
2//! the C API (`mln-rs-c`) one to one.
3//!
4//! A [`Runtime`] owns a thread, and the file sources, cache and offline
5//! regions of its maps. Each [`Map`] lives on its runtime's thread, and its
6//! handle sends commands there: they run in the order sent, across the
7//! runtime and all its maps, and report through a [`Completion`]. A map
8//! publishes a [`MapSnapshot`] after each command, which any thread reads
9//! without waiting, and the events of the runtime and its maps reach one
10//! handler in batches. A [`RenderSession`] that [`Map::attach`] creates
11//! draws a map's frames offscreen or onto a surface, on a thread of its own,
12//! or on the host's graphics thread through its [`DriverWork`].
13//!
14//! The synchronous, single-thread core that these handles drive is
15//! `mln_engine::map`'s; [`Map::with_core`] runs a closure on it.
16//!
17//! Sessions render with the backends of the crate's features: `metal`,
18//! `vulkan`, `d3d12` and `gl`, on by default, and `webgpu`, each where its
19//! platform has it. A session's [`Device`] picks its backend.
20//!
21//! In the browser (wasm32-unknown-unknown, without threads), a runtime's
22//! thread and its sessions' are the one that made the runtime: their work
23//! runs in short tasks on that thread's event loop (`mln_web_host`'s pump),
24//! never inside the call that sent it, and nothing blocks. Sessions present
25//! to a canvas (`Surface::web_canvas`) with the browser's WebGPU or WebGL2,
26//! and put their tiles' workers in Web Workers.
27
28#[cfg(not(any(
29    feature = "webgpu",
30    feature = "metal",
31    feature = "vulkan",
32    // Outside Windows, `d3d12` builds no backend.
33    all(feature = "d3d12", windows),
34    feature = "gl"
35)))]
36compile_error!(
37    "mln_runtime renders with at least one backend: enable `webgpu`, `metal`, `vulkan`, `gl` or, on Windows, `d3d12`"
38);
39
40#[cfg(all(feature = "bench", not(target_family = "wasm")))]
41#[doc(hidden)]
42pub mod bench;
43mod camera;
44mod completion;
45mod event;
46mod feature_state;
47pub mod frame_pacer;
48mod gestures;
49mod map;
50#[cfg(not(target_family = "wasm"))]
51mod offline;
52#[cfg(target_family = "wasm")]
53#[path = "offline_web.rs"]
54mod offline;
55pub mod registry;
56mod render;
57mod resources;
58mod runtime;
59mod style;
60#[cfg(target_family = "wasm")]
61mod web;
62
63/// The `log` targets of this crate's records. Each names the event that
64/// `mln_c` reports the record under (`mln_c::logging`).
65mod log_target {
66    pub(crate) const GENERAL: &str = "mln_runtime::general";
67    pub(crate) const CRASH: &str = "mln_runtime::crash";
68    pub(crate) const RENDER: &str = "mln_runtime::render";
69    pub(crate) const HTTP_REQUEST: &str = "mln_runtime::http_request";
70}
71
72pub use camera::{CameraFitArea, CameraFitOptions, CameraFitUpdate, TileOptions, ViewportOptions};
73pub use completion::Completion;
74pub use event::{EventHandler, EventMask, EventSource, EventType, RuntimeEvent, RuntimeEventKind};
75pub use feature_state::{FeatureState, FeatureStateSelector};
76pub use map::{Applied, CameraQuery, CommandGroup, Map, MapId, MapOptions};
77pub use mln_engine::camera::{ClipDepthRange, FrameProjection, LogicalExtent};
78pub use mln_engine::map::MapSnapshot;
79pub use mln_engine::query::{RenderedQueryOptions, SourceQueryOptions};
80pub use mln_style::error::{Error, ErrorKind};
81pub use offline::Offline;
82pub use render::{
83    AcquiredFrame, Adapter, AttachOptions, BackendRef, BackendType, BorrowedRing, CanvasFormat, ConsumerSync,
84    DemandMode, DepthStencilFormat, DepthStencilFormats, Device, DeviceOptions, DmaBufFormat, DmaBufPlane, Driver,
85    DriverWork, ExportKind, ExportKinds, ExportedImage, ExportedRing, FrameDemand, FrameDepth, FrameDisposition,
86    FrameResult, FrameTexture, FrameTextureKind, FrameView, GlApi, GpuSync, LocalTarget, NativeTexture, RenderSession,
87    RenderSessionCapabilities, RenderSessionSnapshot, RenderSessionState, RenderTarget, RenderedQueryGeometry, Surface,
88    SurfaceOverlay, SurfaceType, SyncKind, SyncKinds, Wake,
89};
90pub use resources::{CacheDatabaseOperation, ResourceProvider, ResourceRequest, is_managed_http_header};
91pub use runtime::{Runtime, RuntimeOptions};
92pub use style::{CustomSourceCallbacks, GeoJsonSourceOptions, LayerInfo, SourceInfo, SourceKind, SourceTiles};