feat: render source paint overrides with read-only object dependencies
Verify Tessera GUI / verify (push) Failing after 7m37s
Verify Tessera GUI / verify (push) Failing after 7m37s
This commit is contained in:
+66
-1
@@ -46,6 +46,7 @@ pub const QUERY_NAMES: &[&str] = &["isInstance", "isSubtype"];
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct UiNode {
|
||||
pub block_id: String,
|
||||
pub protocol_key: String,
|
||||
pub slots: Vec<u64>,
|
||||
pub interactive: bool,
|
||||
pub kind: UiKind,
|
||||
@@ -63,6 +64,7 @@ impl UiNode {
|
||||
|
||||
pub fn shallow_eq(&self, other: &Self) -> bool {
|
||||
if self.block_id != other.block_id
|
||||
|| self.protocol_key != other.protocol_key
|
||||
|| self.slots != other.slots
|
||||
|| self.interactive != other.interactive
|
||||
{
|
||||
@@ -177,6 +179,7 @@ struct Session {
|
||||
mounts: crate::mount::MountTable,
|
||||
published_version: u64,
|
||||
force_frame: bool,
|
||||
paint_reads: std::collections::BTreeMap<ObjectRef, u64>,
|
||||
snapshot_visited: usize,
|
||||
snapshot_reused: usize,
|
||||
}
|
||||
@@ -521,6 +524,11 @@ impl NativeCallable for Function {
|
||||
return Ok(NativeResult::Return(Value::Bool(value)));
|
||||
}
|
||||
if matches!(self.operation, Invalidate) {
|
||||
if cx.store().is_read_only() {
|
||||
return Err(invalid(
|
||||
"invalidation is forbidden during read-only rendering",
|
||||
));
|
||||
}
|
||||
let reason = args
|
||||
.first()
|
||||
.map(|value| text(Some(value)))
|
||||
@@ -1125,6 +1133,13 @@ impl UiBridge {
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
let active = state.pending.unwrap_or(state.active);
|
||||
if state
|
||||
.paint_reads
|
||||
.iter()
|
||||
.any(|(object, version)| vm.change_version(*object).ok() != Some(*version))
|
||||
{
|
||||
state.force_frame = true;
|
||||
}
|
||||
state.render_cache.invalidate(changes);
|
||||
let root = active
|
||||
.map(|v| state.render_cache.snapshot(vm.object_store(), v))
|
||||
@@ -1195,6 +1210,44 @@ impl UiBridge {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn paint_frame(
|
||||
&self,
|
||||
vm: &mut Vm,
|
||||
root: Option<&UiNode>,
|
||||
frame: &mut crate::document::Frame,
|
||||
) -> Result<()> {
|
||||
let (desktop, mounts) = {
|
||||
let state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
let mounts = frame
|
||||
.mounts
|
||||
.iter()
|
||||
.map(|mount| {
|
||||
state
|
||||
.mounts
|
||||
.active
|
||||
.get(&mount.id)
|
||||
.copied()
|
||||
.map(|weak| (mount.id, weak))
|
||||
.ok_or_else(|| anyhow::anyhow!("paint Mount is unavailable"))
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
(state.desktop, mounts)
|
||||
};
|
||||
let reads = crate::source_paint::render(vm, desktop, mounts, root, frame)?;
|
||||
let reads = reads
|
||||
.into_iter()
|
||||
.map(|object| vm.change_version(object).map(|version| (object, version)))
|
||||
.collect::<Result<std::collections::BTreeMap<_, _>, _>>()?;
|
||||
self.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?
|
||||
.paint_reads = reads;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn layout_frame(&self, vm: &Vm, root: &UiNode) -> Result<crate::document::Frame> {
|
||||
let mut state = self
|
||||
.session
|
||||
@@ -1244,6 +1297,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
mounts: crate::mount::MountTable::default(),
|
||||
published_version: 0,
|
||||
force_frame: false,
|
||||
paint_reads: std::collections::BTreeMap::new(),
|
||||
snapshot_visited: 0,
|
||||
snapshot_reused: 0,
|
||||
}));
|
||||
@@ -1298,10 +1352,21 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
("Mount", "Object", None),
|
||||
("Event", "Object", Some("event")),
|
||||
("Subscription", "Object", None),
|
||||
("ObjectList", "Object", None),
|
||||
("ObjectList", "Object", Some("object-list")),
|
||||
] {
|
||||
let base = object(Some(&vm.get_attr(ui, base_name)?))?;
|
||||
let constructor = match constructor_name {
|
||||
Some("object-list") => {
|
||||
let factory = vm.allocate(ContextNativeFunction::new(
|
||||
"object-list",
|
||||
crate::object_list::Constructor { desktop },
|
||||
vec![desktop],
|
||||
))?;
|
||||
roots.push(factory);
|
||||
let function_type = object(Some(&vm.get_attr(ui, "Function")?))?;
|
||||
vm.attach_type(factory, function_type)?;
|
||||
TypeConstructor::NativeTyped(factory)
|
||||
}
|
||||
Some("event") => {
|
||||
let factory = vm.allocate(ContextNativeFunction::new(
|
||||
"event",
|
||||
|
||||
Reference in New Issue
Block a user