Skip to main content

nativeview_abi/runtime/
mod.rs

1//! Zero-copy host runtime C ABI (`nv_runtime_get_interface`, `NvRuntimeApi`,
2//! `NvSceneView`, `NvNodeRow`, `NvLayoutRect`, `NvRuntimeConfig`,
3//! `NvRuntimeMetrics`, `NvRuntimeStatus`): the one scene ABI every host reads.
4
5mod focus;
6mod gesture;
7mod input;
8mod overlay;
9mod paragraph;
10mod scene_facts;
11mod scene_view;
12mod tick;
13mod vtable;
14mod wm;
15
16use core::ffi::c_void;
17use core::mem::{align_of, offset_of, size_of};
18
19use nativeview_abi_macros::{NvAbi, ReprEnum};
20
21use crate::id::NodeId;
22use crate::schema::{
23    concat_abi_slices, hash_abi_descriptor_into, hash_tag_str, AbiAliasDescriptor,
24    AbiCallbackDescriptor,
25    AbiEnumDescriptor, AbiFileDescriptor, AbiRecordDescriptor, AbiVtableDescriptor,
26    NvAliasSchema, NvEnumSchema,
27    NvStructSchema, NvVtableSchema,
28};
29use crate::value::NvStrSlice;
30
31pub use focus::{
32    FocusMove, NV_FOCUS_DIR_DOWN, NV_FOCUS_DIR_FIRST, NV_FOCUS_DIR_LAST, NV_FOCUS_DIR_LEFT,
33    NV_FOCUS_DIR_NEXT, NV_FOCUS_DIR_PREV, NV_FOCUS_DIR_RIGHT, NV_FOCUS_DIR_UP,
34    NV_FOCUS_TRAVERSE_MASK, NV_FOCUS_TRAVERSE_NONE, NV_FOCUS_TRAVERSE_NO_WRAP,
35    NV_FOCUS_TRAVERSE_OUT_SCROLLED, NV_FOCUS_TRAVERSE_OUT_TRAPPED, NV_FOCUS_TRAVERSE_OUT_WRAPPED,
36    NV_FOCUS_TRAVERSE_SCROLL_INTO_VIEW,
37};
38pub use gesture::{
39    NvGestureSettings, DOUBLE_TAP_MS, GESTURE_POLICY, LONG_PRESS_MS, MAX_ACTIVE_POINTERS,
40    MIN_FLING_DP_S, MOUSE_DRAG_SLOP_PX, TOUCH_SLOP_DP,
41};
42pub use input::{
43    NvInputDisposition, PointerOutcomeFlags, NV_INPUT_DISPOSITION_CONSUMED,
44    NV_INPUT_DISPOSITION_CONSUMED_PREVENT_DEFAULT, NV_INPUT_DISPOSITION_MASK,
45    NV_INPUT_DISPOSITION_PASS_THROUGH, NV_POINTER_OUTCOME_CAPTURED, NV_POINTER_OUTCOME_CLAIMED,
46    NV_POINTER_OUTCOME_MODAL_BARRIER, NV_POINTER_OUTCOME_REFUSED, NV_POINTER_OUTCOME_TARGETED,
47};
48pub use overlay::{NvOverlayFlags, NvOverlayItem, NvOverlayLayer};
49pub use scene_facts::{
50    is_close_request_key, NvSceneFact, SceneFact, SceneFactElem, SceneFactShape, SceneFactSpec,
51    CLOSE_KEY_ESCAPE, CLOSE_KEY_GO_BACK, CLOSE_REQUEST_KEYS,
52};
53pub use scene_view::NvSceneView;
54pub use paragraph::{
55    NvParagraphSpan, NvTextParagraphView, NvTextRun, ParagraphRunCount, ParagraphRunIndex,
56    TextRunFlags,
57};
58pub use tick::{
59    NvTickOutcome, NV_TICK_DEMAND_AFTER_MS, NV_TICK_DEMAND_IDLE, NV_TICK_DEMAND_NEXT_FRAME,
60};
61pub use vtable::{NvRuntimeApi, NvRuntimeGetInterfaceFn};
62pub use wm::{
63    NvWmEvent, NvWmOpenDesc, NvWmRect, NvWmStatus, NvWmToggleDebounce,
64    NV_WM_ANCHOR_NONE, NV_WM_ANCHOR_SCREEN_RECT, NV_WM_ANCHOR_STATUS_ITEM,
65    NV_WM_ANCHOR_SURFACE_RECT, NV_WM_EVENT_CLOSED, NV_WM_EVENT_CLOSE_REQUESTED,
66    NV_WM_EVENT_FOCUSED, NV_WM_EVENT_MOVED, NV_WM_EVENT_OPENED, NV_WM_EVENT_RESIZED,
67    NV_WM_EVENT_SCENE_STATE_CHANGED, NV_WM_EVENT_STATE_CHANGED, NV_WM_PRES_ANCHORED_FLYOUT,
68    NV_WM_PRES_FLOATING_PANEL, NV_WM_PRES_HEADLESS, NV_WM_PRES_PIP, NV_WM_PRES_PRIMARY,
69    NV_WM_PRES_SECONDARY, NV_WM_PRES_SHEET,
70};
71
72nativeview_abi_macros::abi_consts! {
73    const RUNTIME_BASE_CONSTS;
74
75    /// Current C ABI version expected by `nv_runtime_get_interface(uint32_t abi_version)`.
76    pub const NV_RUNTIME_ABI_VERSION: u32 = 16;
77    /// Exact byte size of one `NvLayoutRect` record (16 bytes).
78    pub const NV_LAYOUT_RECT_SIZE: usize = 16;
79    /// Exact byte size of one `NvNodeRow` record (32 bytes, matching `nativeview_store::NodeRow`).
80    pub const NV_NODE_ROW_SIZE: usize = 32;
81    /// Exact byte size of one `NvTextRun` record (48 bytes).
82    pub const NV_TEXT_RUN_SIZE: usize = 48;
83    /// Exact byte size of one `NvParagraphSpan` record (32 bytes).
84    pub const NV_PARAGRAPH_SPAN_SIZE: usize = 32;
85    /// Exact byte size of one `NvOverlayItem` record (32 bytes).
86    pub const NV_OVERLAY_ITEM_SIZE: usize = 32;
87    /// `NvOverlayItem::flags`: overlay is modal (blocks background pointer, scroll, focus, and
88    /// a11y; owns close requests even without `CLOSE_ON_ESCAPE`).
89    pub const NV_OVERLAY_FLAG_MODAL: u16 = 1 << 0;
90    /// `NvOverlayItem::flags`: paint a viewport scrim of `NvOverlayItem::backdrop_color` behind this overlay.
91    pub const NV_OVERLAY_FLAG_BACKDROP_SCRIM: u16 = 1 << 1;
92    /// `NvOverlayItem::flags`: outside/backdrop press emits `Custom { name: "close" }`.
93    pub const NV_OVERLAY_FLAG_LIGHT_DISMISS: u16 = 1 << 2;
94    /// `NvOverlayItem::flags`: an unconsumed close request (`Escape` / `GoBack` key down) emits
95    /// a target-only `Custom { name: "close" }` to this overlay; the runtime routes it, hosts never do.
96    pub const NV_OVERLAY_FLAG_CLOSE_ON_ESCAPE: u16 = 1 << 3;
97    /// Every defined `NvOverlayItem::flags` bit; readers reject any other bit.
98    pub const NV_OVERLAY_FLAG_MASK: u16 = 0xF;
99    /// `NvOverlayItem::layer`: anchored or manual popover.
100    pub const NV_OVERLAY_LAYER_POPOVER: u8 = 0;
101    /// `NvOverlayItem::layer`: modal dialog / sheet.
102    pub const NV_OVERLAY_LAYER_MODAL: u8 = 1;
103    /// `NvOverlayItem::layer`: tooltip (`popover="hint"`).
104    pub const NV_OVERLAY_LAYER_TOOLTIP: u8 = 2;
105    /// `NvOverlayItem::layer`: menu / listbox.
106    pub const NV_OVERLAY_LAYER_MENU: u8 = 3;
107    /// Largest valid `NvOverlayItem::layer`; readers reject anything above it.
108    pub const NV_OVERLAY_LAYER_MAX: u8 = 3;
109    /// Most entries a reader accepts in `NvSceneView::facts` (scanned once per frame).
110    pub const NV_SCENE_FACT_MAX: u32 = 16;
111    /// `top_layer_states` scene fact: not a top-layer root.
112    pub const NV_TOP_LAYER_STATE_NONE: u8 = 0;
113    /// `top_layer_states` scene fact: effectively-open top-layer root (listed in `overlays`).
114    pub const NV_TOP_LAYER_STATE_HOISTED: u8 = 1;
115    /// `top_layer_states` scene fact: closed overlay root; its subtree stays alive but hidden.
116    pub const NV_TOP_LAYER_STATE_HIDDEN: u8 = 2;
117    /// `box_kinds` scene fact: the node generates a box (also every inline run of a rendered
118    /// paragraph, which the paragraph root lays out).
119    pub const NV_BOX_KIND_BOX: u8 = 0;
120    /// `box_kinds` scene fact: effective `display: contents` (no box, no native view; its
121    /// children attach to the nearest box-generating ancestor).
122    pub const NV_BOX_KIND_CONTENTS: u8 = 1;
123    /// `box_kinds` scene fact: effectively `display: none` (its native view hides its subtree).
124    pub const NV_BOX_KIND_NONE: u8 = 2;
125    /// Sentinel value in `NvSceneView::node_to_paragraph` meaning the node is not a paragraph root.
126    #[nativeview_abi(hex)]
127    pub const NV_PARAGRAPH_NONE: u32 = u32::MAX;
128    /// Flag bit in `NvNodeRow::flags` indicating an allocated live node slot (`nativeview_store::LIVE`).
129    pub const NV_NODE_ROW_FLAG_LIVE: u8 = 1 << 0;
130    /// Flag bit in `NvNodeRow::flags` indicating an inline run/container inside a paragraph root (`nativeview_store::INLINE`).
131    pub const NV_NODE_ROW_FLAG_INLINE: u8 = 1 << 1;
132    /// `NvParagraphSpan::flags`: text slice lives zero-copy in `NvSceneView::text_slab`.
133    pub const NV_PARAGRAPH_FLAG_STORE_TEXT_SLAB: u8 = 1 << 0;
134    /// `NvParagraphSpan::flags`: at least one run has `INTERACTIVE` (gates per-run hit-testing).
135    pub const NV_PARAGRAPH_FLAG_HAS_INTERACTIVE_RUNS: u8 = 1 << 1;
136    /// `NvParagraphSpan::flags`: paragraph has `run_len > 1` or non-trivial run background/decoration.
137    pub const NV_PARAGRAPH_FLAG_MULTI_STYLE: u8 = 1 << 2;
138    /// `NvTextRun::run_flags`: run has an inline `Interaction` listener/cursor/`StateRules` or interactive ARIA role inside its paragraph.
139    pub const NV_TEXT_RUN_FLAG_INTERACTIVE: u8 = 1 << 1;
140    /// `NvTextRun::run_flags`: run has `white_space` = `NoWrap` or `Pre`.
141    pub const NV_TEXT_RUN_FLAG_NOWRAP: u8 = 1 << 2;
142    /// `NvTextRun::run_flags`: run has `Visibility::Hidden` (occupies layout space, skipped during paint).
143    pub const NV_TEXT_RUN_FLAG_HIDDEN: u8 = 1 << 3;
144    /// `NvParagraphSpan::base_direction`: infer base direction from strong BiDi characters.
145    pub const NV_BASE_DIR_AUTO: u8 = 0;
146    /// `NvParagraphSpan::base_direction`: force left-to-right base direction.
147    pub const NV_BASE_DIR_LTR: u8 = 1;
148    /// `NvParagraphSpan::base_direction`: force right-to-left base direction.
149    pub const NV_BASE_DIR_RTL: u8 = 2;
150    /// `NvTextRun::line_height_unit`: absolute line height in points.
151    pub const NV_LINE_HEIGHT_POINTS: u8 = 0;
152    /// `NvTextRun::line_height_unit`: multiplier × 100 of `font_size`.
153    pub const NV_LINE_HEIGHT_PERCENT: u8 = 1;
154    /// `NvTextRun::line_height_unit`: `normal` (the font's own line height).
155    pub const NV_LINE_HEIGHT_AUTO: u8 = 2;
156    /// Flag bit in `measure_surface`: pure sizing pass; never mutates committed viewport/rects or publishes.
157    pub const NV_MEASURE_FLAG_DRY_RUN: u32 = 1 << 0;
158    /// Flag bit in `measure_surface`: intrinsic/unconstrained sizing pass.
159    pub const NV_MEASURE_FLAG_IDEAL: u32 = 1 << 1;
160    /// Flag bit in `NvRuntimeConfig::flags`: headless controller surface (`SurfacePresentation::Headless`).
161    /// Allocates zero layout engine / scene / GPU resources while keeping app logic, events, wakes,
162    /// and atomic module reloads live at 0 visible windows.
163    pub const NV_RUNTIME_FLAG_HEADLESS: u32 = 1 << 0;
164}
165
166nativeview_abi_macros::abi_aliases! {
167    const RUNTIME_HANDLE_ALIASES;
168
169    /// Opaque handle to a live `nativeview-runtime` surface instance.
170    pub type NvRuntimeHandle = *mut c_void;
171    /// Opaque handle to a shared loaded app module (`NvAppModule`) attached across N surfaces.
172    pub type NvModuleHandle = *mut c_void;
173}
174
175concat_abi_slices!(RUNTIME_ALIASES: [AbiAliasDescriptor] = [
176    RUNTIME_HANDLE_ALIASES,
177    &[
178        <NvOverlayFlags as NvAliasSchema>::SCHEMA,
179        <NvOverlayLayer as NvAliasSchema>::SCHEMA,
180    ],
181]);
182
183nativeview_abi_macros::abi_callbacks! {
184    const RUNTIME_HOOK_CALLBACKS;
185
186    /// Wake callback; may fire on any thread.
187    pub type NvRuntimeWakeFn = unsafe extern "C" fn(ctx: *mut c_void);
188
189    /// Native multi-run paragraph measurer; owner thread, during layout; measures `paragraph`
190    /// (borrowed for the call); `max_width` is INFINITY when unconstrained.
191    pub type NvRuntimeMeasureParagraphFn = unsafe extern "C" fn(
192        ctx: *mut c_void,
193        paragraph: *const NvTextParagraphView,
194        max_width: f32,
195        out_width: *mut f32,
196        out_height: *mut f32,
197    );
198
199    /// Optional native per-run glyph hit-tester; owner thread; given content-box local `(local_x,
200    /// local_y)` inside a paragraph of width `box_width`, returns the hit run's owning `NodeId`
201    /// (`NodeId::NULL` = 0 when clicking trailing whitespace / no glyph hit).
202    pub type NvRuntimeHitTestParagraphFn = unsafe extern "C" fn(
203        ctx: *mut c_void,
204        paragraph: *const NvTextParagraphView,
205        box_width: f32,
206        local_x: f32,
207        local_y: f32,
208    ) -> NodeId;
209
210    /// Intrinsic-size-invalidated callback; owner thread, invoked outside internal locks after
211    /// layout-affecting commits.
212    pub type NvRuntimeIntrinsicSizeInvalidatedFn = unsafe extern "C" fn(ctx: *mut c_void);
213}
214
215
216/// Status codes returned by [`NvRuntimeApi`] entry points.
217#[repr(i32)]
218#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NvAbi, ReprEnum)]
219#[nativeview_abi(c_prefix = "NV_RUNTIME_")]
220#[repr_enum(fallback = Error)]
221pub enum NvRuntimeStatus {
222    Ok = 0,
223    InvalidArg = 1,
224    Unsupported = 2,
225    Busy = 3,
226    Io = 4,
227    Panic = 5,
228    NotFound = 6,
229    Error = 7,
230}
231
232/// Zero-copy 16-byte absolute layout rectangle indexed by `NodeIndex` (`1..node_capacity`).
233#[repr(C)]
234#[derive(Debug, Clone, Copy, Default, PartialEq, NvAbi)]
235#[nativeview_abi(size = 16)]
236pub struct NvLayoutRect {
237    #[nativeview_abi(offset = 0)]
238    pub x: f32,
239    #[nativeview_abi(offset = 4)]
240    pub y: f32,
241    #[nativeview_abi(offset = 8)]
242    pub width: f32,
243    #[nativeview_abi(offset = 12)]
244    pub height: f32,
245}
246
247/// Measured surface dimensions and optional baselines returned by [`NvRuntimeApi::measure_surface`].
248///
249/// `first_baseline` and `last_baseline` are `NaN` when absent.
250#[repr(C)]
251#[derive(Debug, Clone, Copy, PartialEq, NvAbi)]
252#[nativeview_abi(size = 16)]
253pub struct NvSurfaceMeasure {
254    #[nativeview_abi(offset = 0)]
255    pub width: f32,
256    #[nativeview_abi(offset = 4)]
257    pub height: f32,
258    /// Distance from the top edge to the first alphabetic baseline (`NaN` = absent).
259    #[nativeview_abi(offset = 8)]
260    pub first_baseline: f32,
261    /// Distance from the top edge to the last alphabetic baseline (`NaN` = absent).
262    #[nativeview_abi(offset = 12)]
263    pub last_baseline: f32,
264}
265
266impl NvSurfaceMeasure {
267    pub const ZERO: Self = Self {
268        width: 0.0,
269        height: 0.0,
270        first_baseline: f32::NAN,
271        last_baseline: f32::NAN,
272    };
273
274    #[inline]
275    pub const fn from_size(width: f32, height: f32) -> Self {
276        Self {
277            width,
278            height,
279            first_baseline: f32::NAN,
280            last_baseline: f32::NAN,
281        }
282    }
283}
284
285impl Default for NvSurfaceMeasure {
286    #[inline]
287    fn default() -> Self {
288        Self::ZERO
289    }
290}
291
292/// Published 12-byte scroll state of one scroll container: the visual child shift (scroll offset
293/// minus any `Scroll::virtual_top_spacer`) that hosts subtract from descendants' absolute
294/// (pre-scroll) [`NvLayoutRect`]s.
295#[repr(C)]
296#[derive(Debug, Clone, Copy, Default, PartialEq, NvAbi)]
297#[nativeview_abi(size = 12)]
298pub struct NvScrollOffset {
299    /// Raw `NodeId` of the scroll container.
300    #[nativeview_abi(offset = 0)]
301    pub node_id: u32,
302    #[nativeview_abi(offset = 4)]
303    pub x: f32,
304    #[nativeview_abi(offset = 8)]
305    pub y: f32,
306}
307
308/// Zero-copy 32-byte per-node header mirroring `nativeview_store::NodeRow` directly across C FFI.
309///
310/// Uses `[u32; 4]` instead of `u128` so C11/C++20/MSVC/32-bit/Swift ClangImporter all agree on
311/// exact byte offsets with zero target ABI variance.
312#[repr(C)]
313#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, NvAbi)]
314#[nativeview_abi(size = 32)]
315pub struct NvNodeRow {
316    /// 128-bit attached-table bitset in little-endian 32-bit words (`bit s = word[s/32] & (1<<(s%32))`).
317    #[nativeview_abi(offset = 0)]
318    pub table_set: [u32; 4],
319    /// Parent `NodeId` (`0` = root / detached).
320    #[nativeview_abi(offset = 16)]
321    pub parent: u32,
322    /// Element offset (in `u32` entries) into `NvSceneView::children_slab`.
323    #[nativeview_abi(offset = 20)]
324    pub child_off: u32,
325    /// Number of child `u32` `NodeId`s in `NvSceneView::children_slab`.
326    #[nativeview_abi(offset = 24)]
327    pub child_len: u32,
328    /// Slot generation counter (`1..=255`).
329    #[nativeview_abi(offset = 28)]
330    pub generation: u8,
331    /// Highest-priority realizing `TableSlot` (`0xFF` = plain container).
332    #[nativeview_abi(offset = 29)]
333    pub primary_slot: u8,
334    /// Internal per-frame `effect::*` scratch byte in `nativeview-store`; always `0` over FFI (cleared
335    /// before publication).
336    #[nativeview_abi(offset = 30)]
337    pub effects: u8,
338    /// Node row flags (`NV_NODE_ROW_FLAG_LIVE` = bit 0, `NV_NODE_ROW_FLAG_INLINE` = bit 1).
339    #[nativeview_abi(offset = 31)]
340    pub flags: u8,
341}
342
343impl NvNodeRow {
344    #[inline]
345    pub const fn is_live(&self) -> bool {
346        (self.flags & NV_NODE_ROW_FLAG_LIVE) != 0
347    }
348
349    #[inline]
350    pub const fn is_inline(&self) -> bool {
351        (self.flags & NV_NODE_ROW_FLAG_INLINE) != 0
352    }
353
354    #[inline]
355    pub const fn has_table(&self, slot: u8) -> bool {
356        if slot >= 128 {
357            return false;
358        }
359        let word = (slot as usize) >> 5;
360        let bit = (slot as u32) & 31;
361        (self.table_set[word] & (1u32 << bit)) != 0
362    }
363}
364
365/// Configuration passed to [`NvRuntimeApi::create`].
366#[repr(C)]
367#[derive(Debug, Clone, Copy, PartialEq, NvAbi)]
368#[nativeview_abi(size = 24)]
369pub struct NvRuntimeConfig {
370    #[nativeview_abi(offset = 0)]
371    pub surface_id: u32,
372    #[nativeview_abi(offset = 4)]
373    pub width: f32,
374    #[nativeview_abi(offset = 8)]
375    pub height: f32,
376    #[nativeview_abi(offset = 12)]
377    pub scale_factor: f32,
378    #[nativeview_abi(offset = 16)]
379    pub flags: u32,
380    #[nativeview_abi(offset = 20)]
381    pub _reserved: u32,
382}
383
384impl Default for NvRuntimeConfig {
385    fn default() -> Self {
386        Self {
387            surface_id: 1,
388            width: 800.0,
389            height: 600.0,
390            scale_factor: 1.0,
391            flags: 0,
392            _reserved: 0,
393        }
394    }
395}
396
397/// Live telemetry counters snapshot returned by [`NvRuntimeApi::get_metrics`].
398#[repr(C)]
399#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, NvAbi)]
400#[nativeview_abi(size = 64)]
401pub struct NvRuntimeMetrics {
402    #[nativeview_abi(offset = 0)]
403    pub frame_id: u64,
404    #[nativeview_abi(offset = 8)]
405    pub reconcile_us: u64,
406    #[nativeview_abi(offset = 16)]
407    pub layout_us: u64,
408    #[nativeview_abi(offset = 24)]
409    pub publish_us: u64,
410    #[nativeview_abi(offset = 32)]
411    pub wire_bytes_rx: u64,
412    #[nativeview_abi(offset = 40)]
413    pub wire_bytes_tx: u64,
414    #[nativeview_abi(offset = 48)]
415    pub live_nodes: u32,
416    #[nativeview_abi(offset = 52)]
417    pub dirty_nodes: u32,
418    #[nativeview_abi(offset = 56)]
419    pub pair_connected: u32,
420    #[nativeview_abi(offset = 60)]
421    pub _reserved: u32,
422}
423
424const _: () = {
425    assert!(size_of::<NvLayoutRect>() == NV_LAYOUT_RECT_SIZE);
426    assert!(align_of::<NvLayoutRect>() == 4);
427    assert!(size_of::<NvSurfaceMeasure>() == 16);
428    assert!(align_of::<NvSurfaceMeasure>() == 4);
429    assert!(offset_of!(NvSurfaceMeasure, width) == 0);
430    assert!(offset_of!(NvSurfaceMeasure, height) == 4);
431    assert!(offset_of!(NvSurfaceMeasure, first_baseline) == 8);
432    assert!(offset_of!(NvSurfaceMeasure, last_baseline) == 12);
433    assert!(size_of::<NvScrollOffset>() == 12);
434    assert!(align_of::<NvScrollOffset>() == 4);
435    assert!(size_of::<NvNodeRow>() == NV_NODE_ROW_SIZE);
436    assert!(align_of::<NvNodeRow>() == 4);
437    assert!(size_of::<NvTextRun>() == NV_TEXT_RUN_SIZE);
438    assert!(align_of::<NvTextRun>() == 4);
439    assert!(size_of::<NvParagraphSpan>() == NV_PARAGRAPH_SPAN_SIZE);
440    assert!(align_of::<NvParagraphSpan>() == 4);
441    assert!(offset_of!(NvTextParagraphView, text) == 16);
442    assert!(offset_of!(NvTextParagraphView, font_families_slab) == 16 + size_of::<NvStrSlice>());
443    assert!(offset_of!(NvTextParagraphView, runs) == 16 + 2 * size_of::<NvStrSlice>());
444    assert!(
445        size_of::<NvTextParagraphView>()
446            == 16 + 2 * size_of::<NvStrSlice>() + size_of::<*const NvTextRun>()
447    );
448    assert!(size_of::<NvOverlayItem>() == NV_OVERLAY_ITEM_SIZE);
449    assert!(offset_of!(NvSceneView, rows) == 72);
450    assert!(size_of::<NvSceneView>().is_multiple_of(8));
451    assert!(offset_of!(NvSceneView, fact_count) == 72 + 16 * size_of::<*const u8>());
452    assert!(size_of::<NvSceneView>() == 72 + 16 * size_of::<*const u8>() + 8);
453    assert!(size_of::<NvSceneFact>() == 24);
454    assert!(size_of::<NvRuntimeConfig>() == 24);
455    assert!(align_of::<NvRuntimeConfig>() == 4);
456    assert!(size_of::<NvRuntimeMetrics>() == 64);
457    // 8 on every data model except i386 System V, where `u64` fields are 4-byte aligned.
458    assert!(align_of::<NvRuntimeMetrics>() == align_of::<u64>());
459};
460
461concat_abi_slices!(RUNTIME_CONSTS: [crate::schema::AbiConstDescriptor] = [
462    RUNTIME_BASE_CONSTS,
463    focus::FOCUS_CONSTS,
464    input::INPUT_CONSTS,
465    tick::TICK_CONSTS,
466    wm::WM_CONSTS,
467]);
468
469concat_abi_slices!(RUNTIME_CALLBACKS: [AbiCallbackDescriptor] = [
470    RUNTIME_HOOK_CALLBACKS,
471    vtable::RUNTIME_ENTRY_CALLBACKS,
472]);
473
474const RUNTIME_ENUMS: &[AbiEnumDescriptor] = &[
475    <NvRuntimeStatus as NvEnumSchema>::SCHEMA,
476    <NvWmStatus as NvEnumSchema>::SCHEMA,
477];
478
479const RUNTIME_RECORDS: &[AbiRecordDescriptor] = &[
480    AbiRecordDescriptor::Struct(<NvLayoutRect as NvStructSchema>::SCHEMA),
481    AbiRecordDescriptor::Struct(<NvSurfaceMeasure as NvStructSchema>::SCHEMA),
482    AbiRecordDescriptor::Struct(<NvScrollOffset as NvStructSchema>::SCHEMA),
483    AbiRecordDescriptor::Struct(<NvOverlayItem as NvStructSchema>::SCHEMA),
484    AbiRecordDescriptor::Struct(<NvSceneFact as NvStructSchema>::SCHEMA),
485    AbiRecordDescriptor::Struct(<NvNodeRow as NvStructSchema>::SCHEMA),
486    AbiRecordDescriptor::Struct(<NvTextRun as NvStructSchema>::SCHEMA),
487    AbiRecordDescriptor::Struct(<NvParagraphSpan as NvStructSchema>::SCHEMA),
488    AbiRecordDescriptor::Struct(<NvTextParagraphView as NvStructSchema>::SCHEMA),
489    AbiRecordDescriptor::Struct(<NvRuntimeConfig as NvStructSchema>::SCHEMA),
490    AbiRecordDescriptor::Struct(<NvRuntimeMetrics as NvStructSchema>::SCHEMA),
491    AbiRecordDescriptor::Struct(<NvTickOutcome as NvStructSchema>::SCHEMA),
492    AbiRecordDescriptor::Struct(<NvGestureSettings as NvStructSchema>::SCHEMA),
493    AbiRecordDescriptor::Struct(<NvSceneView as NvStructSchema>::SCHEMA),
494    AbiRecordDescriptor::Struct(<NvWmRect as NvStructSchema>::SCHEMA),
495    AbiRecordDescriptor::Struct(<NvWmOpenDesc as NvStructSchema>::SCHEMA),
496    AbiRecordDescriptor::Struct(<NvWmEvent as NvStructSchema>::SCHEMA),
497    AbiRecordDescriptor::Struct(<NvWmToggleDebounce as NvStructSchema>::SCHEMA),
498];
499
500const RUNTIME_VTABLES: &[AbiVtableDescriptor] = &[<NvRuntimeApi as NvVtableSchema>::SCHEMA];
501
502/// Returns the single-source-of-truth Runtime ABI descriptor derived directly from the compiled
503/// `#[derive(NvAbi)]` types in `packages/core/abi/src/runtime/`.
504pub const fn runtime_abi_descriptor() -> AbiFileDescriptor {
505    AbiFileDescriptor {
506        namespace: Some("NvRuntimeAbi"),
507        consts: RUNTIME_CONSTS,
508        aliases: RUNTIME_ALIASES,
509        callbacks: RUNTIME_CALLBACKS,
510        enums: RUNTIME_ENUMS,
511        records: RUNTIME_RECORDS,
512        vtables: RUNTIME_VTABLES,
513    }
514}
515
516/// Computes the deterministic, target-independent compile-time XXH64 fingerprint of
517/// [`runtime_abi_descriptor`] chained with [`crate::ffi::NV_CORE_ABI_SCHEMA_HASH`].
518pub const fn compute_runtime_schema_hash() -> u64 {
519    let mut h = crate::Xxh64Hasher::new(0);
520    hash_tag_str(&mut h, "nv.runtime_abi.v2");
521    h.update_u64(crate::ffi::NV_CORE_ABI_SCHEMA_HASH);
522    hash_abi_descriptor_into(&mut h, &runtime_abi_descriptor());
523    SceneFact::hash_registry_into(&mut h);
524    h.digest()
525}
526
527/// Deterministic XXH64 fingerprint of the zero-copy runtime scene and vtable ABI.
528pub const NV_RUNTIME_SCHEMA_HASH: u64 = compute_runtime_schema_hash();