use nativeview_abi::table::MAX_TABLE_SLOTS;
use nativeview_abi::SceneFact;
use nativeview_hash::xxh64;
pub const HEADER: &[&str] = &[
"schema",
"frame_id",
"node_capacity",
"dirty_count",
"moved_count",
"removed_count",
"text_len",
"children_len",
"table_count",
"scroll_count",
"scene_epoch",
"dirty_resource_count",
"paragraph_count",
"paragraph_run_count",
"paragraph_text_len",
"overlay_count",
];
pub const TABLE_HEADER: &[&str] = &[
"key",
"slot",
"words",
"row_count",
"dirty_count",
"detached_count",
"row_index_dir_len",
"row_index_page_count",
];
pub const SLABS: &[&str] = &[
"rows",
"rects",
"text",
"children",
"dirty",
"moved",
"removed",
"dirty_resources",
"scroll_offsets",
"node_to_paragraph",
"paragraphs",
"paragraph_runs",
"paragraph_text",
"overlays",
];
pub const TABLE_SLABS: &[&str] = &[
"rows",
"owners",
"dirty_owners",
"detached_owners",
"row_index_dir",
"row_index_pages",
];
#[derive(Debug)]
pub struct Slot {
pub name: String,
pub index: usize,
}
#[derive(Debug)]
pub(crate) struct JniFrameModel {
pub header: Vec<Slot>,
pub table_header: Vec<Slot>,
pub slabs: Vec<Slot>,
pub table_slabs: Vec<Slot>,
pub max_tables: usize,
pub header_len: usize,
pub slabs_len: usize,
pub facts_base: usize,
pub layout_hash: u64,
}
fn group<S: AsRef<str>>(prefix: &str, names: &[S]) -> Vec<Slot> {
names
.iter()
.enumerate()
.map(|(index, n)| Slot { name: format!("{prefix}_{}", n.as_ref().to_ascii_uppercase()), index })
.collect()
}
impl JniFrameModel {
pub fn new() -> Self {
let slabs: Vec<String> = SLABS
.iter()
.map(|s| (*s).to_owned())
.chain(SceneFact::ALL.iter().map(|f| format!("fact_{}", f.name())))
.collect();
let mut desc = String::new();
for g in [HEADER, TABLE_HEADER] {
desc.push_str(&g.join(","));
desc.push(';');
}
desc.push_str(&slabs.join(","));
desc.push(';');
desc.push_str(&TABLE_SLABS.join(","));
desc.push(';');
desc.push_str(&MAX_TABLE_SLOTS.to_string());
Self {
header: group("H", HEADER),
table_header: group("TH", TABLE_HEADER),
slabs: group("S", &slabs),
table_slabs: group("TS", TABLE_SLABS),
max_tables: MAX_TABLE_SLOTS,
header_len: HEADER.len() + MAX_TABLE_SLOTS * TABLE_HEADER.len(),
slabs_len: slabs.len() + MAX_TABLE_SLOTS * TABLE_SLABS.len(),
facts_base: SLABS.len(),
layout_hash: xxh64(desc.as_bytes(), 0),
}
}
}
impl Default for JniFrameModel {
fn default() -> Self {
Self::new()
}
}