1mod 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 pub const NV_RUNTIME_ABI_VERSION: u32 = 16;
77 pub const NV_LAYOUT_RECT_SIZE: usize = 16;
79 pub const NV_NODE_ROW_SIZE: usize = 32;
81 pub const NV_TEXT_RUN_SIZE: usize = 48;
83 pub const NV_PARAGRAPH_SPAN_SIZE: usize = 32;
85 pub const NV_OVERLAY_ITEM_SIZE: usize = 32;
87 pub const NV_OVERLAY_FLAG_MODAL: u16 = 1 << 0;
90 pub const NV_OVERLAY_FLAG_BACKDROP_SCRIM: u16 = 1 << 1;
92 pub const NV_OVERLAY_FLAG_LIGHT_DISMISS: u16 = 1 << 2;
94 pub const NV_OVERLAY_FLAG_CLOSE_ON_ESCAPE: u16 = 1 << 3;
97 pub const NV_OVERLAY_FLAG_MASK: u16 = 0xF;
99 pub const NV_OVERLAY_LAYER_POPOVER: u8 = 0;
101 pub const NV_OVERLAY_LAYER_MODAL: u8 = 1;
103 pub const NV_OVERLAY_LAYER_TOOLTIP: u8 = 2;
105 pub const NV_OVERLAY_LAYER_MENU: u8 = 3;
107 pub const NV_OVERLAY_LAYER_MAX: u8 = 3;
109 pub const NV_SCENE_FACT_MAX: u32 = 16;
111 pub const NV_TOP_LAYER_STATE_NONE: u8 = 0;
113 pub const NV_TOP_LAYER_STATE_HOISTED: u8 = 1;
115 pub const NV_TOP_LAYER_STATE_HIDDEN: u8 = 2;
117 pub const NV_BOX_KIND_BOX: u8 = 0;
120 pub const NV_BOX_KIND_CONTENTS: u8 = 1;
123 pub const NV_BOX_KIND_NONE: u8 = 2;
125 #[nativeview_abi(hex)]
127 pub const NV_PARAGRAPH_NONE: u32 = u32::MAX;
128 pub const NV_NODE_ROW_FLAG_LIVE: u8 = 1 << 0;
130 pub const NV_NODE_ROW_FLAG_INLINE: u8 = 1 << 1;
132 pub const NV_PARAGRAPH_FLAG_STORE_TEXT_SLAB: u8 = 1 << 0;
134 pub const NV_PARAGRAPH_FLAG_HAS_INTERACTIVE_RUNS: u8 = 1 << 1;
136 pub const NV_PARAGRAPH_FLAG_MULTI_STYLE: u8 = 1 << 2;
138 pub const NV_TEXT_RUN_FLAG_INTERACTIVE: u8 = 1 << 1;
140 pub const NV_TEXT_RUN_FLAG_NOWRAP: u8 = 1 << 2;
142 pub const NV_TEXT_RUN_FLAG_HIDDEN: u8 = 1 << 3;
144 pub const NV_BASE_DIR_AUTO: u8 = 0;
146 pub const NV_BASE_DIR_LTR: u8 = 1;
148 pub const NV_BASE_DIR_RTL: u8 = 2;
150 pub const NV_LINE_HEIGHT_POINTS: u8 = 0;
152 pub const NV_LINE_HEIGHT_PERCENT: u8 = 1;
154 pub const NV_LINE_HEIGHT_AUTO: u8 = 2;
156 pub const NV_MEASURE_FLAG_DRY_RUN: u32 = 1 << 0;
158 pub const NV_MEASURE_FLAG_IDEAL: u32 = 1 << 1;
160 pub const NV_RUNTIME_FLAG_HEADLESS: u32 = 1 << 0;
164}
165
166nativeview_abi_macros::abi_aliases! {
167 const RUNTIME_HANDLE_ALIASES;
168
169 pub type NvRuntimeHandle = *mut c_void;
171 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 pub type NvRuntimeWakeFn = unsafe extern "C" fn(ctx: *mut c_void);
188
189 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 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 pub type NvRuntimeIntrinsicSizeInvalidatedFn = unsafe extern "C" fn(ctx: *mut c_void);
213}
214
215
216#[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#[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#[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 #[nativeview_abi(offset = 8)]
260 pub first_baseline: f32,
261 #[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#[repr(C)]
296#[derive(Debug, Clone, Copy, Default, PartialEq, NvAbi)]
297#[nativeview_abi(size = 12)]
298pub struct NvScrollOffset {
299 #[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#[repr(C)]
313#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, NvAbi)]
314#[nativeview_abi(size = 32)]
315pub struct NvNodeRow {
316 #[nativeview_abi(offset = 0)]
318 pub table_set: [u32; 4],
319 #[nativeview_abi(offset = 16)]
321 pub parent: u32,
322 #[nativeview_abi(offset = 20)]
324 pub child_off: u32,
325 #[nativeview_abi(offset = 24)]
327 pub child_len: u32,
328 #[nativeview_abi(offset = 28)]
330 pub generation: u8,
331 #[nativeview_abi(offset = 29)]
333 pub primary_slot: u8,
334 #[nativeview_abi(offset = 30)]
337 pub effects: u8,
338 #[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#[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#[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 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
502pub 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
516pub 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
527pub const NV_RUNTIME_SCHEMA_HASH: u64 = compute_runtime_schema_hash();