library/map: convert JNI surface to shared jni macros
- Commit
781ec29d7fd87de6f0b41d2d4e076ae94eeee1cb- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 20:19 UTC (4 days ago)
- Parents
7b3f39e
Honest re-measurement of the Phase 5 estimate (~3%,
jni_fn!-only) with the full macro family. Fresh count of
the ten bridge files carrying JNI methods (1,772 lines,
32 JNI methods): 7 pure with_env methods, 21 direct _env
handle ops, and 4 methods that fit neither macro -
create interleaves three with_env calls with direct
window/renderer work, and setRoute/setRailLines/
setMoonTextures run handle/size guards before their
with_env call. Those four stay hand-written; moving a
guard inside the closure would change its order.
Conversion: 7 jni_fn!, 21 jni_direct! (which adds no
with_env/LogErrorAndDefault layer the direct methods
never had, so exception behaviour is unchanged).
destroy converts as jni_direct! with its verbatim body,
not jni_destroy!: its hand-written form is
unsafe { drop(Box::from_raw(..)) }, while jni_destroy!
generates drop(unsafe { Box::from_raw(..) }) - same
effect, different tokens. Bodies verified token-for-
token against HEAD by script.
Lines: bridge JNI files 1,772 -> 1,569 (-203, -11.5%),
clearing the 10% bar; structure_check lines: OK.
Cargo.lock gains only the jni_bridge edge for
map_renderer. The host build needs the SPIR-V shaders,
reproduced with the NDK glslc into the gitignored
build/spirv directory (27 shaders).
Verified: nm -D on libmap_renderer.so
(aarch64-linux-android) before/after - exported symbol
set identical (32/32 Java_ MapNative symbols); cargo
test -p map_renderer 589 passed, 8 ignored, identical
to baseline; cargo fmt --check -p map_renderer clean.Diff
Cargo.lock
diff --git a/Cargo.lock b/Cargo.lockindex f03f3e6cc1..5022c07acc 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3565,6 +3565,7 @@ dependencies = [ "ab_glyph", "ash", "jni",+ "jni_bridge", "jni_http", "memmap2", "png",
library/map/src/main/rust/Cargo.toml
diff --git a/library/map/src/main/rust/Cargo.toml b/library/map/src/main/rust/Cargo.tomlindex 9387ba4c65..39f09f1562 100644--- a/library/map/src/main/rust/Cargo.toml+++ b/library/map/src/main/rust/Cargo.toml@@ -30,6 +30,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] jni.workspace = true+jni_bridge = { path = "../../../../../library/jni-bridge/src/main/rust" } # Cache keys are SHA-256(url + range), as the Kotlin cache in `maps` uses. Already a # workspace dependency, so this adds nothing to the lockfile. sha2.workspace = true
library/map/src/main/rust/src/bridge/frame.rs
diff --git a/library/map/src/main/rust/src/bridge/frame.rs b/library/map/src/main/rust/src/bridge/frame.rsindex 1ba585a45b..f3dfefbfec 100644--- a/library/map/src/main/rust/src/bridge/frame.rs+++ b/library/map/src/main/rust/src/bridge/frame.rs@@ -14,25 +14,10 @@ use crate::timing::{nanos_since, Step}; use jni::objects::JClass; use jni::sys::{jfloat, jlong}; use jni::EnvUnowned;-/// Draw one frame from a camera snapshot. Returns false if the frame was skipped.-#[no_mangle]+use jni_bridge::{jni_direct, jni_fn};+jni_direct! { /// Draw one frame from a camera snapshot. Returns false if the frame was skipped. #[allow(clippy::too_many_arguments)]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_render<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- center_lon: jfloat,- center_lat: jfloat,- zoom: jfloat,- bearing: jfloat,- pitch: jfloat,- width_dp: jfloat,- height_dp: jfloat,- density: jfloat,- frame_time_nanos: jlong,- globe: bool,- moon: bool,-) -> bool {+Java_com_vayunmathur_library_map_MapNative_render -> bool; (_class: JClass<'l>, handle: jlong, center_lon: jfloat, center_lat: jfloat, zoom: jfloat, bearing: jfloat, pitch: jfloat, width_dp: jfloat, height_dp: jfloat, density: jfloat, frame_time_nanos: jlong, globe: bool, moon: bool) { let Some(map) = handle_mut(handle) else { return false; };@@ -378,20 +363,14 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_render<'l>( false } }-}+} } -/// The last frame's per-step times in nanos, in [`Step::ALL`](crate::timing::Step) order.+jni_fn! { /// The last frame's per-step times in nanos, in [`Step::ALL`](crate::timing::Step) order. /// /// For the debug overlay's slow poll (~2–4 Hz): a copy, so the render thread never blocks on it. /// A dead handle (or a JNI failure) answers an empty array rather than crashing — the overlay /// reads that as "no data yet". Must never drive `needs_frame` or alter the frame loop.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_lastFrameStepTimesNanos<'l>(- mut env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) -> jni::sys::jlongArray {- env.with_env(|env| -> jni::errors::Result<jni::sys::jlongArray> {+Java_com_vayunmathur_library_map_MapNative_lastFrameStepTimesNanos -> jni::sys::jlongArray; (_class: JClass<'l>, handle: jlong) |env| { let empty = env.new_long_array(0)?; let Some(map) = handle_mut(handle) else { return Ok(empty.into_raw());@@ -409,9 +388,7 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_lastFrameStepT return Ok(empty.into_raw()); } Ok(out.into_raw())- })- .resolve::<jni::errors::LogErrorAndDefault>()-}+ } } /// The distinct `cap`-zoom ancestors of every visible tile deeper than `cap`, in first-seen /// order: what a layer the archive stops emitting at `cap` (the z14 wash, the z12
library/map/src/main/rust/src/bridge/geometry.rs
diff --git a/library/map/src/main/rust/src/bridge/geometry.rs b/library/map/src/main/rust/src/bridge/geometry.rsindex c81ccd79d5..b03c5e3ef1 100644--- a/library/map/src/main/rust/src/bridge/geometry.rs+++ b/library/map/src/main/rust/src/bridge/geometry.rs@@ -33,6 +33,7 @@ use crate::tile::source::{discover, FileRangeReader}; use jni::objects::{JClass, JObject, JString}; use jni::sys::{jdouble, jint, jobjectArray}; use jni::{jni_str, EnvUnowned};+use jni_bridge::jni_fn; use std::sync::Arc; use tilecodec::mamaps::read::{LeafCache, MamapsArchive}; @@ -56,21 +57,9 @@ fn rows_to_array<'l>(env: &mut jni::Env<'l>, rows: &[String]) -> jni::errors::Re Ok(out.into_raw()) } -/// Query basemap geometry in a bbox from the on-device archive at+jni_fn! { /// Query basemap geometry in a bbox from the on-device archive at /// `local_path`. See the module docs for the wire shape and bounds.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_queryGeometry<'l>(- mut env: EnvUnowned<'l>,- _class: JClass<'l>,- local_path: JString<'l>,- west: jdouble,- south: jdouble,- east: jdouble,- north: jdouble,- kinds_mask: jint,- max_features: jint,-) -> jobjectArray {- env.with_env(|env| -> jni::errors::Result<jobjectArray> {+Java_com_vayunmathur_library_map_MapNative_queryGeometry -> jobjectArray; (_class: JClass<'l>, local_path: JString<'l>, west: jdouble, south: jdouble, east: jdouble, north: jdouble, kinds_mask: jint, max_features: jint) |env| { let unavailable = vec!["UNAVAILABLE".to_string()]; let path: String = if local_path.is_null() { return rows_to_array(env, &unavailable);@@ -148,6 +137,4 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_queryGeometry< )); } rows_to_array(env, &rows)- })- .resolve::<jni::errors::LogErrorAndDefault>()-}+ } }
library/map/src/main/rust/src/bridge/layers.rs
diff --git a/library/map/src/main/rust/src/bridge/layers.rs b/library/map/src/main/rust/src/bridge/layers.rsindex d48e55c22a..80e4c0b1d6 100644--- a/library/map/src/main/rust/src/bridge/layers.rs+++ b/library/map/src/main/rust/src/bridge/layers.rs@@ -7,7 +7,8 @@ use crate::style::{self, LayerToggles}; use jni::objects::{JClass, JIntArray, JLongArray, JString}; use jni::sys::jlong; use jni::EnvUnowned;-/// Turn the optional layers on or off, and narrow POI to a set of kinds.+use jni_bridge::{jni_direct, jni_fn};+jni_fn! { /// Turn the optional layers on or off, and narrow POI to a set of kinds. /// /// Not free, unlike [`setPalette`](Java_com_vayunmathur_library_map_MapNative_setPalette): /// POI and transit are gated at tessellation time so that leaving them off costs nothing,@@ -27,16 +28,7 @@ use jni::EnvUnowned; /// /// A call that changes nothing bumps nothing, because the host is expected to call this /// from a Compose effect that may re-run for unrelated reasons.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setLayers<'l>(- mut env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- poi: bool,- transit: bool,- kinds: JString<'l>,-) {- env.with_env(|env| -> jni::errors::Result<()> {+Java_com_vayunmathur_library_map_MapNative_setLayers; (_class: JClass<'l>, handle: jlong, poi: bool, transit: bool, kinds: JString<'l>) |env| { let names: String = kinds.try_to_string(env).unwrap_or_default(); let filter = style::KindFilter::new( names@@ -58,11 +50,9 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setLayers<'l>( } } Ok(())- })- .resolve::<jni::errors::LogErrorAndDefault>()-}+ } } -/// Turn the live-traffic overlay on or off.+jni_direct! { /// Turn the live-traffic overlay on or off. /// /// Gates the overlay at **tessellation** like [`setLayers`], so an archive without the layer — /// or a consumer that never enables traffic — pays nothing: flipping it on bumps the toggle@@ -74,13 +64,7 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setLayers<'l>( /// [`setTrafficSpeeds`](Java_com_vayunmathur_library_map_MapNative_setTrafficSpeeds); this call /// is only the geometry gate. Its own entry point rather than a fourth argument to [`setLayers`] /// so the existing layer call keeps its shape.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setTrafficEnabled<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- enabled: bool,-) {+Java_com_vayunmathur_library_map_MapNative_setTrafficEnabled; (_class: JClass<'l>, handle: jlong, enabled: bool) { if let Some(map) = handle_mut(handle) { let on = enabled; // The renderer's per-frame draw guard, set every call so it tracks the toggle even@@ -94,20 +78,14 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setTrafficEnab log_info(&format!("traffic layer {}", if on { "on" } else { "off" })); } }-}+} } -/// Turn the safety overlay (stop signs, signals, cameras) on or off.+jni_direct! { /// Turn the safety overlay (stop signs, signals, cameras) on or off. /// /// Gated at tessellation exactly like [`setTrafficEnabled`]: the current POI/transit/traffic/kinds /// snapshot is kept and only `safety` flips, sharing the one generation counter. An archive built /// before the `safety` layer simply has nothing behind the gate.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setSafetyEnabled<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- enabled: bool,-) {+Java_com_vayunmathur_library_map_MapNative_setSafetyEnabled; (_class: JClass<'l>, handle: jlong, enabled: bool) { if let Some(map) = handle_mut(handle) { let (current, kinds, _) = map.toggles.get(); let wanted = LayerToggles { safety: enabled, ..current };@@ -115,9 +93,9 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setSafetyEnabl log_info(&format!("safety layer {}", if enabled { "on" } else { "off" })); } }-}+} } -/// Push the live-traffic colour table: `ids[i]` is a segment's `component_id` and+jni_fn! { /// Push the live-traffic colour table: `ids[i]` is a segment's `component_id` and /// `colors[i]` the fully-resolved ARGB the device wants drawn for it. /// /// Two parallel arrays rather than a packed buffer, agreed with the device workstream: it is@@ -131,15 +109,7 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setSafetyEnabl /// Ids absent from the table draw nothing (the basemap road shows through), which is the /// no-data behaviour. Mismatched lengths are truncated to the shorter. This is a pure /// state swap — no tessellation and no upload — so it is the recolour hot path and is cheap.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setTrafficSpeeds<'l>(- mut env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- ids: JLongArray<'l>,- colors: JIntArray<'l>,-) {- env.with_env(|env| -> jni::errors::Result<()> {+Java_com_vayunmathur_library_map_MapNative_setTrafficSpeeds; (_class: JClass<'l>, handle: jlong, ids: JLongArray<'l>, colors: JIntArray<'l>) |env| { let Some(map) = handle_mut(handle) else { return Ok(()); };@@ -165,23 +135,16 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setTrafficSpee let colors_u32: Vec<u32> = color_buf.into_iter().map(|v| v as u32).collect(); map.renderer.set_traffic_speeds(&ids_u64, &colors_u32); Ok(())- })- .resolve::<jni::errors::LogErrorAndDefault>()-}+ } } -/// Take the live-traffic overlay away: the toggle went off, or the viewport moved off the+jni_direct! { /// Take the live-traffic overlay away: the toggle went off, or the viewport moved off the /// squares the host has readings for. /// /// Clears the pushed colours so the overlay stops drawing on the very next frame, without /// waiting for the toggle-driven re-tessellation to evict the geometry. Cheap and idempotent, /// like [`clearRegionMask`](Java_com_vayunmathur_library_map_MapNative_clearRegionMask).-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_clearTraffic<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) {+Java_com_vayunmathur_library_map_MapNative_clearTraffic; (_class: JClass<'l>, handle: jlong) { if let Some(map) = handle_mut(handle) { map.renderer.clear_traffic(); }-}+} }
library/map/src/main/rust/src/bridge/lifecycle.rs
diff --git a/library/map/src/main/rust/src/bridge/lifecycle.rs b/library/map/src/main/rust/src/bridge/lifecycle.rsindex 9d4bb68294..fb003ce72c 100644--- a/library/map/src/main/rust/src/bridge/lifecycle.rs+++ b/library/map/src/main/rust/src/bridge/lifecycle.rs@@ -14,6 +14,7 @@ use crate::vulkan::renderer::Renderer; use jni::objects::{JClass, JObject, JString}; use jni::sys::{jint, jlong}; use jni::EnvUnowned;+use jni_bridge::jni_direct; use std::collections::HashSet; use std::os::raw::c_void; use std::sync::{Arc, Mutex};@@ -160,7 +161,7 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_create<'l>( Box::into_raw(handle) as jlong } -/// How long the host may wait before the next frame: `0` to draw again now, a positive number+jni_direct! { /// How long the host may wait before the next frame: `0` to draw again now, a positive number /// of milliseconds to draw again then, or `-1` when nothing is pending at all. /// /// The host renders on demand rather than every vsync, and asks this after each frame. It@@ -183,12 +184,7 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_create<'l>( /// /// Errs toward drawing throughout. A wasted frame costs one frame; a wrong `-1` freezes the /// map until the user touches it.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_nextFrameDelayMillis<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) -> jlong {+Java_com_vayunmathur_library_map_MapNative_nextFrameDelayMillis -> jlong; (_class: JClass<'l>, handle: jlong) { let Some(map) = handle_mut(handle) else { return -1; };@@ -205,74 +201,43 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_nextFrameDelay Some(at) => (at - now).as_millis().max(1).min(jlong::MAX as u128) as jlong, None => -1, }-}+} } -#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_resize<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- width: jint,- height: jint,-) {+jni_direct! { Java_com_vayunmathur_library_map_MapNative_resize; (_class: JClass<'l>, handle: jlong, width: jint, height: jint) { if let Some(map) = handle_mut(handle) { map.renderer.resize(width.max(0) as u32, height.max(0) as u32); }-}+} } -/// Switch palette. Free: colour is a push constant and the layer set is identical, so+jni_direct! { /// Switch palette. Free: colour is a push constant and the layer set is identical, so /// nothing is re-tessellated or re-uploaded.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setPalette<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- dark: bool,- muted: bool,-) {+Java_com_vayunmathur_library_map_MapNative_setPalette; (_class: JClass<'l>, handle: jlong, dark: bool, muted: bool) { if let Some(map) = handle_mut(handle) { map.palette = Palette::new(dark, muted); }-}+} } -#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setOnline<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- online: bool,-) {+jni_direct! { Java_com_vayunmathur_library_map_MapNative_setOnline; (_class: JClass<'l>, handle: jlong, online: bool) { if let Some(map) = handle_mut(handle) { map.online.set(online); }-}+} } -/// Destroy the renderer and release its window.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_destroy<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) {+jni_direct! { /// Destroy the renderer and release its window.+Java_com_vayunmathur_library_map_MapNative_destroy; (_class: JClass<'l>, handle: jlong) { if handle == 0 { return; } // Dropping the handle drops the sender, which ends the worker's `recv` loop, and then // the renderer, which waits for the device to go idle before freeing anything. unsafe { drop(Box::from_raw(handle as *mut MapHandle)) };-}+} } -/// Give memory back under system pressure (`onTrimMemory`). With `keep_visible` the tiles on+jni_direct! { /// Give memory back under system pressure (`onTrimMemory`). With `keep_visible` the tiles on /// screen stay; without it every tile goes and the next frame refetches what it needs.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_trimMemory<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- keep_visible: bool,-) {+Java_com_vayunmathur_library_map_MapNative_trimMemory; (_class: JClass<'l>, handle: jlong, keep_visible: bool) { if let Some(map) = handle_mut(handle) { let keep = if keep_visible { map.last_visible.clone() } else { HashSet::new() }; map.renderer.trim(&keep); }-}+} }
library/map/src/main/rust/src/bridge/markers.rs
diff --git a/library/map/src/main/rust/src/bridge/markers.rs b/library/map/src/main/rust/src/bridge/markers.rsindex b84d783c32..3d9c0cf1a8 100644--- a/library/map/src/main/rust/src/bridge/markers.rs+++ b/library/map/src/main/rust/src/bridge/markers.rs@@ -7,7 +7,8 @@ use crate::marker::Marker; use jni::objects::{JClass, JFloatArray, JIntArray, JLongArray, JObjectArray, JString}; use jni::sys::jlong; use jni::{Env, EnvUnowned};-/// Replace the app's pins with a marker set, drawn by the renderer as billboarded sprites.+use jni_bridge::{jni_direct, jni_fn};+jni_fn! { /// Replace the app's pins with a marker set, drawn by the renderer as billboarded sprites. /// /// Four parallel bulk arrays, the same convention as /// [`setRoute`](Java_com_vayunmathur_library_map_MapNative_setRoute) and@@ -27,18 +28,8 @@ use jni::{Env, EnvUnowned}; /// [`clearMarkers`](Java_com_vayunmathur_library_map_MapNative_clearMarkers). Arrays that cannot be /// read leave the markers **unchanged** rather than blanking them. A label that cannot be read /// degrades to the empty string (icon alone) rather than failing the whole push.-#[no_mangle] #[allow(clippy::too_many_arguments)]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setMarkers<'l>(- mut env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- ids: JLongArray<'l>,- lon_lat: JFloatArray<'l>,- icons: JIntArray<'l>,- labels: JObjectArray<'l>,-) {- env.with_env(|env| -> jni::errors::Result<()> {+Java_com_vayunmathur_library_map_MapNative_setMarkers; (_class: JClass<'l>, handle: jlong, ids: JLongArray<'l>, lon_lat: JFloatArray<'l>, icons: JIntArray<'l>, labels: JObjectArray<'l>) |env| { let Some(map) = handle_mut(handle) else { return Ok(()); };@@ -79,21 +70,14 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setMarkers<'l> (0..n).map(|i| read_marker_label(env, &labels, i as i32)).collect(); map.renderer.set_markers(markers, marker_labels); Ok(())- })- .resolve::<jni::errors::LogErrorAndDefault>()-}+ } } -/// Take every marker away: the host cleared its pins.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_clearMarkers<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) {+jni_direct! { /// Take every marker away: the host cleared its pins.+Java_com_vayunmathur_library_map_MapNative_clearMarkers; (_class: JClass<'l>, handle: jlong) { if let Some(map) = handle_mut(handle) { map.renderer.set_markers(Vec::new(), Vec::new()); }-}+} } /// One marker's display name from the parallel labels array. ///@@ -113,7 +97,7 @@ fn read_marker_label(env: &mut Env<'_>, labels: &JObjectArray<'_>, index: i32) - string.try_to_string(env).unwrap_or_default() } -/// Replace the simulated transit vehicles with a set the renderer draws as billboarded sprites.+jni_fn! { /// Replace the simulated transit vehicles with a set the renderer draws as billboarded sprites. /// /// The same three parallel bulk arrays as /// [`setMarkers`](Java_com_vayunmathur_library_map_MapNative_setMarkers) — `ids[i]` the host's@@ -131,17 +115,7 @@ fn read_marker_label(env: &mut Env<'_>, labels: &JObjectArray<'_>, index: i32) - /// out rather than linger. Mismatched lengths are truncated to the shortest; an empty set is the /// same as [`clearVehicles`](Java_com_vayunmathur_library_map_MapNative_clearVehicles). Arrays that /// cannot be read leave the vehicles **unchanged** rather than blanking them.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setVehicles<'l>(- mut env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- ids: JLongArray<'l>,- lon_lat: JFloatArray<'l>,- icons: JIntArray<'l>,- colors: JIntArray<'l>,-) {- env.with_env(|env| -> jni::errors::Result<()> {+Java_com_vayunmathur_library_map_MapNative_setVehicles; (_class: JClass<'l>, handle: jlong, ids: JLongArray<'l>, lon_lat: JFloatArray<'l>, icons: JIntArray<'l>, colors: JIntArray<'l>) |env| { let Some(map) = handle_mut(handle) else { return Ok(()); };@@ -180,18 +154,11 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setVehicles<'l .collect(); map.renderer.set_vehicles(vehicles); Ok(())- })- .resolve::<jni::errors::LogErrorAndDefault>()-}+ } } -/// Take every simulated vehicle away: the transit toggle went off, or the surface was hidden.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_clearVehicles<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) {+jni_direct! { /// Take every simulated vehicle away: the transit toggle went off, or the surface was hidden.+Java_com_vayunmathur_library_map_MapNative_clearVehicles; (_class: JClass<'l>, handle: jlong) { if let Some(map) = handle_mut(handle) { map.renderer.set_vehicles(Vec::new()); }-}+} }
library/map/src/main/rust/src/bridge/moon.rs
diff --git a/library/map/src/main/rust/src/bridge/moon.rs b/library/map/src/main/rust/src/bridge/moon.rsindex 39a0466365..57dec67c53 100644--- a/library/map/src/main/rust/src/bridge/moon.rs+++ b/library/map/src/main/rust/src/bridge/moon.rs@@ -7,6 +7,7 @@ use super::log::log; use jni::objects::{JByteArray, JClass}; use jni::sys::{jint, jlong}; use jni::EnvUnowned;+use jni_bridge::jni_direct; /// Upload the Moon raster pair: the converted LROC color (RGBA8) and the /// converted LDEM (RG8 packed uint16, see `analysis/convert_moon.py`). ///@@ -86,16 +87,11 @@ fn bytemuck_cast(bytes: &mut [u8]) -> &mut [i8] { unsafe { std::slice::from_raw_parts_mut(bytes.as_mut_ptr() as *mut i8, bytes.len()) } } -/// Drop the Moon raster pair (~40 MB of GPU images) when the host leaves the Moon; a later+jni_direct! { /// Drop the Moon raster pair (~40 MB of GPU images) when the host leaves the Moon; a later /// [`setMoonTextures`](Java_com_vayunmathur_library_map_MapNative_setMoonTextures) uploads it /// again.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_clearMoonTextures<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) {+Java_com_vayunmathur_library_map_MapNative_clearMoonTextures; (_class: JClass<'l>, handle: jlong) { if let Some(map) = handle_mut(handle) { map.renderer.clear_moon_textures(); }-}+} }
library/map/src/main/rust/src/bridge/pick.rs
diff --git a/library/map/src/main/rust/src/bridge/pick.rs b/library/map/src/main/rust/src/bridge/pick.rsindex e313e295d1..73b2f4af1d 100644--- a/library/map/src/main/rust/src/bridge/pick.rs+++ b/library/map/src/main/rust/src/bridge/pick.rs@@ -5,7 +5,8 @@ use super::handle::handle_mut; use jni::objects::{JClass, JObject}; use jni::sys::{jdouble, jfloat, jlong, jobjectArray}; use jni::{jni_str, EnvUnowned};-/// Task-17 pick: placed labels intersecting the query box (Dp from the+use jni_bridge::{jni_direct, jni_fn};+jni_fn! { /// Task-17 pick: placed labels intersecting the query box (Dp from the /// viewport top-left). Returns `\u{1}`-joined `layerId/name/kind/lon/lat/featureId/regionId` /// strings in placement order (topmost first); empty when nothing hits. Dp→device-px via the /// last frame's density, remembered on the map handle (same density the@@ -15,17 +16,7 @@ use jni::{jni_str, EnvUnowned}; /// `cafe` rather than `restaurant`. `featureId` is the archive's stable id, or `0` for a /// feature that has none. `regionId` is the tagged relation id of the boundary the label /// names from the tile's `region_links` table, or `0` (`REGION_NONE`) when linked to nothing.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_pickLabels<'l>(- mut env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- x0_dp: jfloat,- y0_dp: jfloat,- x1_dp: jfloat,- y1_dp: jfloat,-) -> jobjectArray {- env.with_env(|env| -> jni::errors::Result<jobjectArray> {+Java_com_vayunmathur_library_map_MapNative_pickLabels -> jobjectArray; (_class: JClass<'l>, handle: jlong, x0_dp: jfloat, y0_dp: jfloat, x1_dp: jfloat, y1_dp: jfloat) |env| { let empty = env.new_object_array(0, jni_str!("java/lang/String"), JObject::null())?; let Some(map) = handle_mut(handle) else { return Ok(empty.into_raw());@@ -56,11 +47,9 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_pickLabels<'l> let _ = env.set_object_array_element(&out, i, js); } Ok(out.into_raw())- })- .resolve::<jni::errors::LogErrorAndDefault>()-}+ } } -/// Pick the renderer-drawn marker under a tap: the id-buffer readback path.+jni_direct! { /// Pick the renderer-drawn marker under a tap: the id-buffer readback path. /// /// `x`/`y` are Dp from the viewport top-left, converted to device px with the last frame's /// density (the same conversion [`pickLabels`](Java_com_vayunmathur_library_map_MapNative_pickLabels)@@ -69,14 +58,7 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_pickLabels<'l> /// host rejoins the tap to its feature without matching on position, or `0` when the tap hit no /// marker. That replaces the Compose CPU hit-test, which trailed the basemap on a pan and could not /// place a pin's box under tilt at all.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_pickAt<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- x_dp: jfloat,- y_dp: jfloat,-) -> jlong {+Java_com_vayunmathur_library_map_MapNative_pickAt -> jlong; (_class: JClass<'l>, handle: jlong, x_dp: jfloat, y_dp: jfloat) { let Some(map) = handle_mut(handle) else { return 0; };@@ -86,9 +68,9 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_pickAt<'l>( let x = (x_dp.max(0.0) * density).round() as u32; let y = (y_dp.max(0.0) * density).round() as u32; map.renderer.pick_at(x, y) as jlong-}+} } -/// Tilt-pivot elevation under a geo point, in world px at `zoom`.+jni_direct! { /// Tilt-pivot elevation under a geo point, in world px at `zoom`. /// /// The host-side counterpart of the renderer's per-frame pivot resolution (see /// `Renderer::render`): the Compose overlay [`Projection`](../../../..) — which@@ -99,17 +81,9 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_pickAt<'l>( /// tiles), exactly the fallback the renderer uses, so both sides agree there /// too. `lon`/`lat`/`zoom` are `Float` for the same significant-digits reason /// as [`render`](Java_com_vayunmathur_library_map_MapNative_render)'s camera.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_tiltPivotDp<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- lon: jfloat,- lat: jfloat,- zoom: jfloat,-) -> jdouble {+Java_com_vayunmathur_library_map_MapNative_tiltPivotDp -> jdouble; (_class: JClass<'l>, handle: jlong, lon: jfloat, lat: jfloat, zoom: jfloat) { let Some(map) = handle_mut(handle) else { return 0.0; }; map.renderer.pivot_dp_at(lon as f64, lat as f64, zoom as f64)-}+} }
library/map/src/main/rust/src/bridge/puck.rs
diff --git a/library/map/src/main/rust/src/bridge/puck.rs b/library/map/src/main/rust/src/bridge/puck.rsindex 177d06f803..5515dd1049 100644--- a/library/map/src/main/rust/src/bridge/puck.rs+++ b/library/map/src/main/rust/src/bridge/puck.rs@@ -6,7 +6,8 @@ use crate::vulkan::renderer::UserPuck; use jni::objects::JClass; use jni::sys::{jfloat, jlong}; use jni::EnvUnowned;-/// Show the user-location puck at `lon`/`lat`, drawn inside the renderer's own frame.+use jni_bridge::jni_direct;+jni_direct! { /// Show the user-location puck at `lon`/`lat`, drawn inside the renderer's own frame. /// /// Free in the same sense as /// [`setPalette`](Java_com_vayunmathur_library_map_MapNative_setPalette): pure state,@@ -16,16 +17,7 @@ use jni::EnvUnowned; /// `bearing` is degrees clockwise from north and is only read when `has_bearing` is set; /// without it the dot draws and the cone does not, which is what a fix with no heading /// should look like rather than one pointing north.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setUserPuck<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- lon: jfloat,- lat: jfloat,- bearing: jfloat,- has_bearing: bool,-) {+Java_com_vayunmathur_library_map_MapNative_setUserPuck; (_class: JClass<'l>, handle: jlong, lon: jfloat, lat: jfloat, bearing: jfloat, has_bearing: bool) { if let Some(map) = handle_mut(handle) { map.renderer.set_user_puck(Some(UserPuck { lon: lon as f64,@@ -33,16 +25,11 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setUserPuck<'l bearing: has_bearing.then_some(bearing), })); }-}+} } -/// Take the puck away: no fix, or a host that stopped asking for one.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_clearUserPuck<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) {+jni_direct! { /// Take the puck away: no fix, or a host that stopped asking for one.+Java_com_vayunmathur_library_map_MapNative_clearUserPuck; (_class: JClass<'l>, handle: jlong) { if let Some(map) = handle_mut(handle) { map.renderer.set_user_puck(None); }-}+} }
library/map/src/main/rust/src/bridge/region.rs
diff --git a/library/map/src/main/rust/src/bridge/region.rs b/library/map/src/main/rust/src/bridge/region.rsindex cb2ed27162..911d230212 100644--- a/library/map/src/main/rust/src/bridge/region.rs+++ b/library/map/src/main/rust/src/bridge/region.rs@@ -6,7 +6,8 @@ use crate::style::Palette; use jni::objects::JClass; use jni::sys::{jfloat, jint, jlong}; use jni::EnvUnowned;-/// Mask everything outside the region with this id, or clear the mask when it is zero.+use jni_bridge::jni_direct;+jni_direct! { /// Mask everything outside the region with this id, or clear the mask when it is zero. /// /// The id is the tagged OSM relation id of an admin boundary, baked onto the tapped place label at /// build time (see the `places` region-link table) — so the label names its own outline directly@@ -14,13 +15,7 @@ use jni::EnvUnowned; /// a zero id) **and** a resident tile actually carries that region, 0 when the region's tiles are /// not loaded yet so the host retries next frame. `RegionBuffers::id` is what `record_region_mask` /// filters on, so once a piece is resident the mask draws.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setRegionMask<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,- region_id: jlong,-) -> jlong {+Java_com_vayunmathur_library_map_MapNative_setRegionMask -> jlong; (_class: JClass<'l>, handle: jlong, region_id: jlong) { let Some(map) = handle_mut(handle) else { return 0; };@@ -37,16 +32,11 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setRegionMask< } else { 0 }-}+} } -/// Take the region mask away: the details sheet closed, or the selection moved on.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_clearRegionMask<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) {+jni_direct! { /// Take the region mask away: the details sheet closed, or the selection moved on.+Java_com_vayunmathur_library_map_MapNative_clearRegionMask; (_class: JClass<'l>, handle: jlong) { if let Some(map) = handle_mut(handle) { map.renderer.set_region_mask(None); }-}+} }
library/map/src/main/rust/src/bridge/route.rs
diff --git a/library/map/src/main/rust/src/bridge/route.rs b/library/map/src/main/rust/src/bridge/route.rsindex 30c6e48632..17c051d982 100644--- a/library/map/src/main/rust/src/bridge/route.rs+++ b/library/map/src/main/rust/src/bridge/route.rs@@ -7,6 +7,7 @@ use crate::overlay::{RouteSegment, RouteStyle}; use jni::objects::{JClass, JFloatArray, JIntArray}; use jni::sys::{jfloat, jint, jlong}; use jni::EnvUnowned;+use jni_bridge::jni_direct; /// Draw a navigation route line over the basemap and under the puck. /// /// `points` is a flat `[lon0, lat0, lon1, lat1, …]` array holding every coloured run's@@ -107,19 +108,14 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setRoute<'l>( .resolve::<jni::errors::LogErrorAndDefault>() } -/// Take the route away: navigation ended, or the host cleared it.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_clearRoute<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) {+jni_direct! { /// Take the route away: navigation ended, or the host cleared it.+Java_com_vayunmathur_library_map_MapNative_clearRoute; (_class: JClass<'l>, handle: jlong) { if let Some(map) = handle_mut(handle) { if let Err(e) = map.renderer.set_route(None) { log(&format!("clearing the route failed: {e}")); } }-}+} } /// Draw the pack-driven rail-lines network under the navigation route. ///@@ -193,16 +189,11 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setRailLines<' .resolve::<jni::errors::LogErrorAndDefault>() } -/// Take the rail network away: the transit toggle went off, or the host cleared it.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_clearRailLines<'l>(- _env: EnvUnowned<'l>,- _class: JClass<'l>,- handle: jlong,-) {+jni_direct! { /// Take the rail network away: the transit toggle went off, or the host cleared it.+Java_com_vayunmathur_library_map_MapNative_clearRailLines; (_class: JClass<'l>, handle: jlong) { if let Some(map) = handle_mut(handle) { if let Err(e) = map.renderer.set_rail_lines(None) { log(&format!("clearing the rail network failed: {e}")); } }-}+} }