Cache source measurements and propagate native viewport inputs
Verify Tessera GUI / verify (push) Failing after 7m29s
Verify Tessera GUI / verify (push) Failing after 7m29s
This commit is contained in:
+88
-3
@@ -181,6 +181,7 @@ struct Session {
|
||||
force_frame: bool,
|
||||
paint_reads: std::collections::BTreeMap<ObjectRef, u64>,
|
||||
layout_reads: std::collections::BTreeMap<ObjectRef, u64>,
|
||||
measure_cache: crate::source_layout::Cache,
|
||||
snapshot_visited: usize,
|
||||
snapshot_reused: usize,
|
||||
}
|
||||
@@ -193,6 +194,7 @@ enum Operation {
|
||||
OpenValue,
|
||||
Mounts,
|
||||
Stats,
|
||||
Viewport,
|
||||
State,
|
||||
StateSet,
|
||||
Increment,
|
||||
@@ -494,7 +496,7 @@ impl NativeCallable for Function {
|
||||
use Operation::*;
|
||||
let (minimum, maximum) = match self.operation {
|
||||
IsInstance | IsSubtype => (2, 2),
|
||||
Stats | Mounts => (0, 0),
|
||||
Stats | Viewport | Mounts => (0, 0),
|
||||
State | StateSet => (1, 1),
|
||||
Increment => (0, 0),
|
||||
TextOf => (2, 4),
|
||||
@@ -555,6 +557,7 @@ impl NativeCallable for Function {
|
||||
}
|
||||
}
|
||||
if reason != "paint" {
|
||||
session.measure_cache.invalidate(&affected);
|
||||
for block in &affected {
|
||||
session.layout.invalidate(&block.to_string());
|
||||
}
|
||||
@@ -605,7 +608,32 @@ impl NativeCallable for Function {
|
||||
)?;
|
||||
return Ok(NativeResult::Return(Value::Object(set)));
|
||||
}
|
||||
if matches!(self.operation, Viewport) {
|
||||
let desktop = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?
|
||||
.desktop;
|
||||
let Value::Object(input) = cx.store().get_attr(desktop, "viewport")? else {
|
||||
return Err(invalid("window viewport is unavailable"));
|
||||
};
|
||||
let width = cx.store().get_attr(input, "width")?;
|
||||
let height = cx.store().get_attr(input, "height")?;
|
||||
return Ok(NativeResult::Return(Value::Object(
|
||||
crate::native_visual::record(
|
||||
cx,
|
||||
desktop,
|
||||
"MeasureResult",
|
||||
vec![("width", width), ("height", height)],
|
||||
)?,
|
||||
)));
|
||||
}
|
||||
if matches!(self.operation, Stats) {
|
||||
if cx.store().is_read_only() {
|
||||
return Err(invalid(
|
||||
"runtime statistics are unavailable during read-only rendering",
|
||||
));
|
||||
}
|
||||
let session = self
|
||||
.session
|
||||
.lock()
|
||||
@@ -632,6 +660,8 @@ impl NativeCallable for Function {
|
||||
("snapshotVisited", session.snapshot_visited as i64),
|
||||
("snapshotReused", session.snapshot_reused as i64),
|
||||
("measured", session.layout.measured as i64),
|
||||
("sourceMeasureHits", session.measure_cache.hits as i64),
|
||||
("sourceMeasureMisses", session.measure_cache.misses as i64),
|
||||
("arranged", session.layout.arranged as i64),
|
||||
] {
|
||||
cx.set_attr(stats, name, Value::Number(value.into()))?;
|
||||
@@ -1020,6 +1050,41 @@ pub struct UiBridge {
|
||||
}
|
||||
|
||||
impl UiBridge {
|
||||
pub fn set_viewport(&self, vm: &mut Vm, viewport: Option<crate::layout::Size>) -> Result<bool> {
|
||||
if let Some(size) = viewport
|
||||
&& (!size.width.is_finite()
|
||||
|| !size.height.is_finite()
|
||||
|| !(0.0..=MAX_DIMENSION as f32).contains(&size.width)
|
||||
|| !(0.0..=MAX_DIMENSION as f32).contains(&size.height))
|
||||
{
|
||||
bail!("invalid window viewport");
|
||||
}
|
||||
let mut state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
if state.layout.viewport == viewport {
|
||||
return Ok(false);
|
||||
}
|
||||
if let Some(size) = viewport {
|
||||
let input = vm.new_object()?;
|
||||
let result = (|| {
|
||||
vm.set_attr(input, "width", Value::Number((size.width as f64).into()))?;
|
||||
vm.set_attr(input, "height", Value::Number((size.height as f64).into()))?;
|
||||
vm.set_attr(state.desktop, "viewport", Value::Object(input))
|
||||
})();
|
||||
vm.release(input)?;
|
||||
result?;
|
||||
} else {
|
||||
vm.set_attr(state.desktop, "viewport", Value::Nil)?;
|
||||
}
|
||||
state.layout.viewport = viewport;
|
||||
// A fresh Console domain can own window inputs without replacing the
|
||||
// preserved displayed page until it actually opens/renders something.
|
||||
state.force_frame |= state.active.is_some() || state.pending.flatten().is_some();
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub fn install_globals(&self, vm: &mut Vm, globals: ObjectRef) -> Result<()> {
|
||||
vm.dict_set(globals, Value::Text("ui".into()), Value::Object(self.ui))?;
|
||||
for name in TYPE_NAMES.iter().chain(QUERY_NAMES) {
|
||||
@@ -1047,7 +1112,7 @@ impl UiBridge {
|
||||
input
|
||||
.validate()
|
||||
.map_err(|message| anyhow::anyhow!(message))?;
|
||||
let (weak, desktop, candidates) = {
|
||||
let (weak, desktop, candidates, viewport) = {
|
||||
let state = self
|
||||
.session
|
||||
.lock()
|
||||
@@ -1063,9 +1128,17 @@ impl UiBridge {
|
||||
.ok_or_else(|| anyhow::anyhow!("Mount is no longer active"))?,
|
||||
state.desktop,
|
||||
state.mounts.ordered(),
|
||||
state.layout.viewport,
|
||||
)
|
||||
};
|
||||
let mount = if let (Some(press), Some(release)) = (input.press_point, input.point) {
|
||||
if viewport.is_some_and(|size| {
|
||||
[press, release]
|
||||
.iter()
|
||||
.any(|point| point[0] >= size.width || point[1] >= size.height)
|
||||
}) {
|
||||
return Ok(());
|
||||
}
|
||||
let Some(mount) = crate::source_hit::resolve(vm, desktop, candidates, press, release)?
|
||||
else {
|
||||
return Ok(());
|
||||
@@ -1273,6 +1346,11 @@ impl UiBridge {
|
||||
root: Option<Arc<UiNode>>,
|
||||
) -> Result<crate::document::Frame> {
|
||||
let Some(root) = root else {
|
||||
self.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?
|
||||
.measure_cache
|
||||
.clear();
|
||||
self.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?
|
||||
@@ -1282,13 +1360,14 @@ impl UiBridge {
|
||||
self.commit_frame(vm, None, &frame)?;
|
||||
return Ok(frame);
|
||||
};
|
||||
let (mut layout, desktop, page, nodes) = {
|
||||
let (mut layout, mut cache, desktop, page, nodes) = {
|
||||
let state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
(
|
||||
state.layout.clone(),
|
||||
state.measure_cache.clone(),
|
||||
state.desktop,
|
||||
state.pending.unwrap_or(state.active),
|
||||
state.nodes.clone(),
|
||||
@@ -1313,6 +1392,7 @@ impl UiBridge {
|
||||
root.clone(),
|
||||
&mut frame,
|
||||
&mut layout,
|
||||
&mut cache,
|
||||
)?;
|
||||
// Capture versions before lifecycle hooks can change a dependency.
|
||||
let reads = reads
|
||||
@@ -1332,6 +1412,7 @@ impl UiBridge {
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
state.layout = layout;
|
||||
state.measure_cache = cache;
|
||||
state.layout_reads = reads;
|
||||
}
|
||||
self.commit_frame(vm, Some(root), &frame)?;
|
||||
@@ -1372,6 +1453,7 @@ impl UiBridge {
|
||||
pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
let desktop = vm.new_object()?;
|
||||
roots.push(desktop);
|
||||
vm.set_attr(desktop, "viewport", Value::Nil)?;
|
||||
let tabs = vm.new_dict()?;
|
||||
roots.push(tabs);
|
||||
vm.set_attr(desktop, "tabs", Value::Object(tabs))?;
|
||||
@@ -1391,6 +1473,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
force_frame: false,
|
||||
paint_reads: std::collections::BTreeMap::new(),
|
||||
layout_reads: std::collections::BTreeMap::new(),
|
||||
measure_cache: crate::source_layout::Cache::default(),
|
||||
snapshot_visited: 0,
|
||||
snapshot_reused: 0,
|
||||
}));
|
||||
@@ -1409,6 +1492,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
("state", Operation::State),
|
||||
("textOf", Operation::TextOf),
|
||||
("stats", Operation::Stats),
|
||||
("viewport", Operation::Viewport),
|
||||
] {
|
||||
let function = vm.allocate(ContextNativeFunction::new(
|
||||
name,
|
||||
@@ -1560,6 +1644,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
"state",
|
||||
"textOf",
|
||||
"stats",
|
||||
"viewport",
|
||||
"isInstance",
|
||||
"isSubtype",
|
||||
] {
|
||||
|
||||
Reference in New Issue
Block a user