Skip to main content

Crate mln_rs

Crate mln_rs 

Source
Expand description

A MapLibre map renderer written in Rust.

The root holds the thread-safe handles of mln_runtime: a Runtime and its Maps, whose commands run on the runtime’s thread and report through a Completion, and the RenderSessions that draw them.

The library crates of https://github.com/maplibre/mln-rs are re-exported here under their crate names: mln_rs::mln_engine, mln_rs::mln_style, mln_rs::mln_builtins, and so on. They are published as the mln-rs-* packages, which only exist for this crate. The tile worker codec’s encoding (mln_wire) is internal to mln-rs: layer re-exports only what a layer type’s buckets implement, the Wire trait and its derive, with its Reader and Writer.

The library logs through tracing and installs no subscriber: install one, such as tracing-subscriber’s, to read its events. An event’s target is <crate>::<event>, where the event says what logged it, as the C API’s log events do: mln_style::parse_style, mln_engine::database, mln_vulkan::render. The offline database’s errors carry their SQLite or I/O error code in a code field. An event is a static message plus named fields, such as source_id or error, for a subscriber to filter and format. wgpu and naga log through log; a subscriber reads their records with tracing-log’s LogTracer.

A crate that adds a custom layer writes a mln_plugin::LayerPlugin and registers it in the RegistryBuilder of the map’s Registry via RegistryBuilder::add_layer_plugin (Runtime::with_registry). Lower-level engine-internal layer and source contracts live in layer and source.

GeoJSON is the geojson crate’s and feature geometry is geo_types’. Both crates are re-exported.

Each backend is a feature, which re-exports its crate: metal (mln_mtl), vulkan (mln_vulkan), d3d12 (mln_d3d12), gl (mln_gl) and webgpu (mln_webgpu). All but webgpu are on by default; natively, wgpu renders through the same APIs as the others, so turn it on to share a wgpu device or surface with the map.

The sqlite feature, on by default, gives a native runtime its cache database: the ambient cache, offline regions and mbtiles:// sources. An app links one sqlite3, so with this feature the app’s own rusqlite, if it has one, must accept a version that mln-rs accepts too. An app that doesn’t need the cache database can turn the feature off and keep the backends it uses:

cargo add mln-rs --no-default-features --features metal,vulkan,d3d12,gl

Without it, RuntimeOptions::cache_path, Runtime::run_cache_database_operation, Runtime::set_maximum_ambient_cache_size and Runtime::offline’s calls fail with ErrorKind::Unsupported, as they do in the browser build.

Re-exports§

pub use mln_runtime;
pub use geo_types;
pub use geojson;
pub use glam;
pub use mln_builtins;
pub use mln_d3d12;
pub use mln_engine;
pub use mln_gfx;
pub use mln_gl;
pub use mln_mtl;
pub use mln_plugin;
pub use mln_runtime;
pub use mln_style;
pub use mln_vulkan;

Modules§

frame_pacer
Frame pacing: a FramePacer calls back at a display’s refreshes, at the rate a Limit allows, so that a host draws each frame when the display is ready for it rather than on a timer of its own.
layer
What a crate needs to write a layer type: the engine’s layer contract (Layer and its contexts, inputs, layouts and buckets, which derive Wire to cross to and from tile workers), the style half (StyleLayerType, its properties declared with layer_properties! and the extension members it reads, Member), the registration (RegistryBuilder::add_layer_type), and what a layer draws with (draw, shaders), places with (placement) and routes other layers’ draws through (Router).
registry
The registrations that a runtime’s maps, their renderers and their tile workers share: the expression functions, the layer types, the source types and the projections.
source
What a crate needs to write a source type: the engine half (SourceType, with its description’s Load, its Supply of tiles from a DataOrigin or of an image, and the kinds of data it supplies: GeometryTiles, RasterTiles and DemTiles), the style half (StyleSourceType and its SourceTypeInfo), and the registration (RegistryBuilder::add_source_type).

Structs§

AcquiredFrame
A frame of a borrowed ring that the host acquired, until it gives it back. Dropping it gives it back as release with SyncKind::CpuComplete does.
Applied
What a map command left behind once it ran.
AttachOptions
How a session attaches to its map.
BorrowedRing
A ring of the host’s textures, of one backend.
CameraFitOptions
How a camera fits an area in the map’s view.
CameraFitUpdate
Moves the camera to fit an area: CameraUpdate’s counterpart for Map::fit_camera.
CameraQuery
The camera, and the generation of the map that it belongs to.
CommandGroup
A command group of a map that ends when it drops.
Completion
The result of a command, which arrives once the command has run.
ConsumerSync
What the host’s reads of a frame’s texture end with, which a target waits for before it draws into the texture again. The target takes the sync file, or the GLsync that sync names; dropping it closes the sync file.
DepthStencilFormats
A set of DepthStencilFormats.
DeviceOptions
How to create a Device.
DmaBufFormat
A DRM format and modifier that the host imports.
DmaBufPlane
Where one plane of a dmabuf keeps its data.
DriverWork
The graphics work of a render session that attached with Driver::CallerThread, which runs only when the host’s graphics thread calls service.
Error
A failed call: its ErrorKind and a message that says what failed.
EventMask
A set of event types. The bits are the C API’s mln_runtime_event_flag: 1 << type for each type.
ExportKinds
A set of ExportKinds.
ExportedRing
A ring of images that the target allocates, as the host asks for it: depth images, shared in a kind of kinds.
FeatureStateSelector
The features whose state to set, read or remove.
FrameDemand
A demand for one frame.
FrameDepth
The texture that holds a frame’s depth and stencil.
FrameProjection
Where a frame drew the map, and the depth its 3D layers wrote there.
FrameResult
How one frame demand finished.
FrameTexture
The host’s texture that an acquired frame was rendered into, of size pixels.
FrameView
A view of an acquired frame, which AcquiredFrame::view opens, until it drops.
GeoJsonSourceOptions
The options of a GeoJSON source, which stay fixed for as long as the style holds it. The defaults are the style specification’s.
GpuSync
A point in one side’s GPU work that the other side waits for before it uses a shared texture: the object to wait on, as an integer, for the kinds that name one, and the value a timeline reaches.
LayerInfo
A layer of the map’s style.
LocalTarget
A render target built on this thread: the backend, on the target’s device, the frames it draws into, and the renderer that draws them, which the target owns and lends the backend’s Gpu to.
LogicalExtent
A size in logical pixels, and the physical pixels in each logical pixel.
Map
A handle to a map, which lives on its runtime’s thread.
MapId
The ID of a map, unique within its runtime.
MapOptions
How to create a map.
MapSnapshot
A map’s state at one moment.
Offline
The offline regions in a runtime’s cache database, from Runtime::offline. Each call is a command of the runtime, and the regions download on the database’s thread.
RenderSession
A render session: a renderer that draws a map into a target, on a thread of its own or on the host’s.
RenderSessionCapabilities
What a render session can do.
RenderSessionSnapshot
The state of a render session at one moment.
RenderedQueryOptions
Options for query rendered features.
ResourceRequest
A network request that a ResourceProvider serves.
Runtime
A runtime: a thread of its own that holds maps, and the resource loading, cache and offline regions that they share.
RuntimeEvent
An event of a runtime or of one of its maps.
RuntimeOptions
Where a runtime keeps its assets and its cache, and the network status its requests follow.
SourceInfo
A source of the map’s style.
SourceQueryOptions
Options for query source features
SourceTiles
The tiles that a source lists in the style itself, rather than at a URL.
Surface
What a surface session presents to.
SyncKinds
A set of SyncKinds.
TileOptions
How the map picks the tiles to load, as its snapshot’s TileSettings report it. A setting that is None keeps its value.
ViewportOptions
How the map orients and constrains its view. A setting that is None keeps its value.

Enums§

Adapter
A GPU, by what names it to a backend.
BackendRef
A target’s backend, by its type, for a host that reads what the backend tells of its device.
BackendType
CacheDatabaseOperation
A maintenance action on a runtime’s cache database.
CameraFitArea
An area for a camera to fit in the map’s view.
CanvasFormat
A GPUTextureFormat that a WebGPU canvas takes.
ClipDepthRange
How a graphics API’s clip space holds depth.
DemandMode
When a demand draws a frame.
DepthStencilFormat
A format of depth and stencil textures.
Device
A GPU that sessions on many maps and threads share: one backend’s device. Sessions on it keep working after the last handle drops, until they detach.
Driver
The thread that runs a render session’s graphics work.
ErrorKind
What went wrong, as a caller would react to it.
EventSource
What raised an event.
EventType
The type of an event. The values are the C API’s mln_runtime_event_type.
ExportKind
A way to share a texture’s memory with another API or process.
ExportedImage
The shared memory of a frame’s image. The objects it names are the target’s, and stay valid until the host gives the frame back.
FrameDisposition
How a frame demand finished.
FrameTextureKind
A FrameTexture’s backend objects.
GlApi
The OpenGL API that an OpenGL device renders with. By default the platform’s: desktop OpenGL on Windows, and OpenGL ES elsewhere.
NativeTexture
A texture as the API of the device that drew into it names it.
RenderSessionState
Where a render session is in its life.
RenderTarget
What a render session renders into. The session builds it into the backend’s objects on the thread that renders, on device, or on a device that Device::new makes when that is None. The device’s backend is the session’s.
RenderedQueryGeometry
The screen area that a rendered feature query covers, in logical pixels from the top left corner.
RuntimeEventKind
What an event reports.
SurfaceOverlay
What a host draws over each frame that a surface session presents, after the map and before the frame is presented (and read back): the overlay of the backend that the session presents with (DriverWork::set_overlay).
SurfaceType
A kind of window or layer that a session presents to.
SyncKind
How one side of a shared texture waits for the other’s GPU work on it.

Traits§

ResourceProvider
Serves a runtime’s network requests in place of the library.

Functions§

is_managed_http_header
Whether the library or the platform manages the HTTP header name, in any letter case, so that a header transform can’t set it.

Type Aliases§

EventHandler
The runtime’s event handler. It runs on the runtime’s thread with each batch of events, oldest first.
FeatureState
The state of one feature: keys and their values.
Wake
A callback that tells the host about something it should act on, such as frame results to drain. It runs on a library thread and must not block.