Isolate rendering state per window presentation
Verify Tessera GUI / verify (push) Failing after 7m26s
Verify Tessera GUI / verify (push) Failing after 7m26s
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
| mount.rs | Managed per-occurrence contexts, weak reverse links, ordered mount/unmount hooks, geometry and focus queries |
|
||||
| events.rs | Bounded native input transport to the owning VM |
|
||||
| event_dispatch.rs | Managed Event, weak Subscription tokens, Block-owned connections and occurrence-specific capture/target/bubble through a budgeted VM driver |
|
||||
| presentation.rs | Per-window layout, Mount/focus/tab state and read dependencies; VM changes fan out before any view consumes work |
|
||||
| tabs.rs | Immutable tab chrome, shared draw/hit geometry, overflow navigation and opaque published Page identities |
|
||||
| window.rs | Managed native Window resource, ordered Page roots, read-only guards and coalesced scalar GUI projections |
|
||||
| vm_sequence.rs | Shared validated call-sequence builder for event and lifecycle batches in the existing VM frame loop |
|
||||
|
||||
+8
-2
@@ -293,6 +293,11 @@ fn code_request(
|
||||
"X-Tessera-Session",
|
||||
¤t.document.frame.session.to_string(),
|
||||
);
|
||||
add_header(
|
||||
&mut response,
|
||||
"X-Tessera-Window",
|
||||
¤t.document.frame.window.to_string(),
|
||||
);
|
||||
add_header(
|
||||
&mut response,
|
||||
"X-Tessera-Layout-Version",
|
||||
@@ -546,7 +551,8 @@ impl Worker {
|
||||
Err(_) => return error_response(StatusCode(500), "namespace lock poisoned"),
|
||||
};
|
||||
let frame = ¤t.document.frame;
|
||||
if frame.session != input.session
|
||||
if frame.window != input.window
|
||||
|| frame.session != input.session
|
||||
|| frame.layout_version != input.layout_version
|
||||
|| frame.fault.is_some()
|
||||
|| if matches!(input.kind.as_str(), "tab-activate" | "tab-close") {
|
||||
@@ -901,7 +907,7 @@ Source measure and arrange overrides execute bottom-up and top-down in one read-
|
||||
|
||||
Source paint overrides execute in the actual frame pipeline under a read-only heap policy. Source hitTest overrides similarly refine native pointer targets in VM paint order; Point.inside(bounds) and Point.inCircle(cx, cy, radius) provide primitive shape queries. Managed DisplayList/ObjectList/PaintCommand and Constraints/Bounds/Point results are ordinary runtime objects.
|
||||
|
||||
Native input POST /events is a transport envelope, not Endor source. Tab actions use kind tab-activate/tab-close and the mount wire field carries the opaque tab ID from frame.tabs; point/press_point must be omitted. All actions validate session and layout_version before dispatch. The window
|
||||
Native input POST /events is a transport envelope, not Endor source. Each frame and input carries an opaque runtime window identity; omitted input window defaults to 1 for existing clients. GET /code exposes X-Tessera-Window. A window/session/layout identity mismatch is rejected before invoking code. Tab actions use kind tab-activate/tab-close and the mount wire field carries the opaque tab ID from frame.tabs; point/press_point must be omitted. All actions validate session and layout_version before dispatch. The window
|
||||
sends current session, layout_version and Mount identity; stale positions fail without calling a callback. Pointer clicks also include point and press_point [x,y] in logical page coordinates. Both targets are resolved through read-only hitTest, with fallback behind a rejected candidate; a click is dispatched only when both resolve to the same Mount. Keyboard/code clicks omit coordinates and remain semantic activation. GET /code also exposes X-Tessera-Session and X-Tessera-Layout-Version headers for transport clients. Native mouse, Tab, Enter and Space delegate to the same
|
||||
managed click/focus methods used by code. Events appear in Network, not Console source history.
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ impl TesseraApp {
|
||||
.focus
|
||||
.filter(|_| frame.fault.is_none())
|
||||
.map(|mount| crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: frame.session,
|
||||
layout_version: frame.layout_version,
|
||||
mount,
|
||||
@@ -275,6 +276,7 @@ impl TesseraApp {
|
||||
let point = Point::new(self.pointer.x, self.pointer.y - offset);
|
||||
let mount = frame.hit_test(point)?;
|
||||
Some(crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: frame.session,
|
||||
layout_version: frame.layout_version,
|
||||
mount: mount.id,
|
||||
@@ -299,6 +301,7 @@ impl TesseraApp {
|
||||
(active + 1) % frame.tabs.len()
|
||||
};
|
||||
Some(crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: frame.session,
|
||||
layout_version: frame.layout_version,
|
||||
mount: frame.tabs[index].id,
|
||||
@@ -331,6 +334,7 @@ impl TesseraApp {
|
||||
let width = window.inner_size().width as f32 / window.scale_factor() as f32;
|
||||
let (id, close) = crate::tabs::hit(&frame.tabs, width, self.pointer)?;
|
||||
Some(crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: frame.session,
|
||||
layout_version: frame.layout_version,
|
||||
mount: id,
|
||||
@@ -378,6 +382,7 @@ impl TesseraApp {
|
||||
current.map(|i| (i + 1) % targets.len()).unwrap_or(0)
|
||||
};
|
||||
Some(crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: frame.session,
|
||||
layout_version: frame.layout_version,
|
||||
mount: targets[index].id,
|
||||
|
||||
@@ -112,6 +112,9 @@ impl RenderDocument {
|
||||
bail!("frame exceeds the 10,000 command limit");
|
||||
}
|
||||
|
||||
if self.frame.window == 0 {
|
||||
bail!("invalid window identity");
|
||||
}
|
||||
parse_color(&self.frame.background)?;
|
||||
for command in &self.frame.commands {
|
||||
command.validate()?;
|
||||
@@ -262,6 +265,8 @@ impl CodeNode {
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Frame {
|
||||
#[serde(default = "default_window")]
|
||||
pub window: u64,
|
||||
#[serde(default = "default_background")]
|
||||
pub background: String,
|
||||
#[serde(default)]
|
||||
@@ -283,6 +288,7 @@ pub struct Frame {
|
||||
impl Default for Frame {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
background: default_background(),
|
||||
commands: Vec::new(),
|
||||
mounts: Vec::new(),
|
||||
@@ -322,6 +328,10 @@ impl Frame {
|
||||
}
|
||||
}
|
||||
|
||||
fn default_window() -> u64 {
|
||||
crate::window::MAIN_WINDOW
|
||||
}
|
||||
|
||||
fn default_background() -> String {
|
||||
"#F7F7F5".to_owned()
|
||||
}
|
||||
|
||||
@@ -858,6 +858,7 @@ mod tests {
|
||||
assert_eq!(initial.frame.tabs[0].title, "First");
|
||||
assert!(initial.frame.tabs[1].active);
|
||||
let input = crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: 120,
|
||||
layout_version: initial.frame.layout_version,
|
||||
mount: initial.frame.tabs[0].id,
|
||||
@@ -884,6 +885,7 @@ mod tests {
|
||||
assert_eq!(renamed.frame.tabs[0].id, initial.frame.tabs[0].id);
|
||||
let closed = session
|
||||
.dispatch(&crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: 120,
|
||||
layout_version: renamed.frame.layout_version,
|
||||
mount: renamed.frame.tabs[1].id,
|
||||
@@ -1097,6 +1099,7 @@ mod tests {
|
||||
.unwrap();
|
||||
session
|
||||
.dispatch(&crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: session.id,
|
||||
layout_version: document.frame.layout_version,
|
||||
mount: mount.id,
|
||||
@@ -1422,6 +1425,7 @@ mod tests {
|
||||
.unwrap();
|
||||
session
|
||||
.dispatch(&crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: 81,
|
||||
layout_version: initial.frame.layout_version,
|
||||
mount: circle.id,
|
||||
@@ -1464,6 +1468,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let error = session
|
||||
.dispatch(&crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: 82,
|
||||
layout_version: initial.frame.layout_version,
|
||||
mount: circle.id,
|
||||
@@ -1928,6 +1933,7 @@ mod tests {
|
||||
.unwrap();
|
||||
session
|
||||
.dispatch(&crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: 41,
|
||||
layout_version: document.frame.layout_version,
|
||||
mount: mount.id,
|
||||
@@ -2206,6 +2212,7 @@ mod tests {
|
||||
.find(|mount| mount.interactive)
|
||||
.unwrap();
|
||||
let event = crate::events::Input {
|
||||
window: crate::window::MAIN_WINDOW,
|
||||
session: 1,
|
||||
layout_version: initial.frame.layout_version,
|
||||
mount: mount.id,
|
||||
|
||||
@@ -12,6 +12,8 @@ use winit::event_loop::EventLoopProxy;
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Input {
|
||||
#[serde(default = "default_window")]
|
||||
pub window: u64,
|
||||
pub session: u64,
|
||||
pub layout_version: u64,
|
||||
pub mount: u64,
|
||||
@@ -22,8 +24,15 @@ pub struct Input {
|
||||
pub press_point: Option<[f32; 2]>,
|
||||
}
|
||||
|
||||
fn default_window() -> u64 {
|
||||
crate::window::MAIN_WINDOW
|
||||
}
|
||||
|
||||
impl Input {
|
||||
pub fn validate(&self) -> Result<(), &'static str> {
|
||||
if self.window == 0 {
|
||||
return Err("window identity must be nonzero");
|
||||
}
|
||||
match (self.point, self.press_point) {
|
||||
(None, None) => Ok(()),
|
||||
(Some(point), Some(press))
|
||||
@@ -93,3 +102,18 @@ fn send(input: &Input) -> anyhow::Result<()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn legacy_event_window_defaults_but_zero_is_never_a_resource() {
|
||||
let mut input: Input =
|
||||
serde_json::from_str(r#"{"session":1,"layout_version":2,"mount":3,"kind":"focus"}"#)
|
||||
.unwrap();
|
||||
assert_eq!(input.window, crate::window::MAIN_WINDOW);
|
||||
assert!(input.validate().is_ok());
|
||||
input.window = 0;
|
||||
assert!(input.validate().is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ mod layout;
|
||||
mod mount;
|
||||
mod native_visual;
|
||||
mod object_list;
|
||||
mod presentation;
|
||||
mod scene;
|
||||
mod snapshot;
|
||||
mod software_renderer;
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
//! Per-window rendering state. Business objects and code remain in one VM.
|
||||
//! Registries and caches borrow checked identities; the managed desktop owns
|
||||
//! presentation roots through its pending/mount dictionaries.
|
||||
use crate::ui_bridge::UiNode;
|
||||
use endor_core::{ChangeBatch, NativeContext, ObjectRef, Vm, VmError, WeakObjectRef};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Presentation {
|
||||
pub desktop: ObjectRef,
|
||||
pub tabs: ObjectRef,
|
||||
pub active: Option<ObjectRef>,
|
||||
pub pending: Option<Option<ObjectRef>>,
|
||||
pub last_snapshot: Option<Arc<UiNode>>,
|
||||
pub tab_ids: Vec<(WeakObjectRef, u64)>,
|
||||
pub next_tab: u64,
|
||||
pub last_tabs: Vec<crate::tabs::Tab>,
|
||||
pub render_cache: crate::snapshot::RenderCache,
|
||||
pub layout: crate::layout::LayoutRuntime,
|
||||
pub mounts: crate::mount::MountTable,
|
||||
pub published_version: u64,
|
||||
pub force_frame: bool,
|
||||
pub paint_reads: std::collections::BTreeMap<ObjectRef, u64>,
|
||||
pub layout_reads: std::collections::BTreeMap<ObjectRef, u64>,
|
||||
pub measure_cache: crate::source_layout::Cache,
|
||||
pub snapshot_visited: usize,
|
||||
pub snapshot_reused: usize,
|
||||
}
|
||||
|
||||
impl Presentation {
|
||||
pub fn observe_changes(&mut self, vm: &Vm, changes: &ChangeBatch) {
|
||||
if self
|
||||
.paint_reads
|
||||
.iter()
|
||||
.chain(self.layout_reads.iter())
|
||||
.any(|(object, version)| vm.change_version(*object).ok() != Some(*version))
|
||||
{
|
||||
self.force_frame = true;
|
||||
}
|
||||
self.render_cache.invalidate(ChangeBatch {
|
||||
changes: changes.changes.clone(),
|
||||
rescan_required: changes.rescan_required,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn invalidate(
|
||||
&mut self,
|
||||
cx: &mut NativeContext<'_>,
|
||||
affected: &std::collections::HashSet<ObjectRef>,
|
||||
reason: &str,
|
||||
) -> Result<(), VmError> {
|
||||
if reason != "paint" {
|
||||
self.measure_cache.invalidate(affected);
|
||||
for block in affected {
|
||||
self.layout.invalidate(&block.to_string());
|
||||
}
|
||||
}
|
||||
if reason == "content" {
|
||||
self.render_cache
|
||||
.invalidate_objects(affected.iter().copied());
|
||||
}
|
||||
for weak in self.mounts.active.values() {
|
||||
if let Some(mount) = cx.upgrade(*weak)?
|
||||
&& affected.contains(
|
||||
&cx.store()
|
||||
.payload::<crate::mount::Mount>(mount, "Mount")?
|
||||
.block,
|
||||
)
|
||||
{
|
||||
self.force_frame = true;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new(desktop: ObjectRef, tabs: ObjectRef) -> Self {
|
||||
Self {
|
||||
desktop,
|
||||
tabs,
|
||||
active: None,
|
||||
pending: None,
|
||||
last_snapshot: None,
|
||||
tab_ids: Vec::new(),
|
||||
next_tab: 0,
|
||||
last_tabs: Vec::new(),
|
||||
render_cache: crate::snapshot::RenderCache::default(),
|
||||
layout: crate::layout::LayoutRuntime::default(),
|
||||
mounts: crate::mount::MountTable::default(),
|
||||
published_version: 0,
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{layout::Size, ui_bridge::UiKind};
|
||||
#[test]
|
||||
fn independent_view_geometry_and_shared_vm_reads_do_not_add_roots() {
|
||||
let mut vm = Vm::new().unwrap();
|
||||
let mut left = Presentation::new(vm.new_object().unwrap(), vm.new_dict().unwrap());
|
||||
let mut right = Presentation::new(vm.new_object().unwrap(), vm.new_dict().unwrap());
|
||||
left.layout.viewport = Some(Size {
|
||||
width: 100.0,
|
||||
height: 80.0,
|
||||
});
|
||||
right.layout.viewport = Some(Size {
|
||||
width: 200.0,
|
||||
height: 160.0,
|
||||
});
|
||||
let root = UiNode {
|
||||
block_id: "shared".into(),
|
||||
protocol_key: "rect".into(),
|
||||
slots: Vec::new(),
|
||||
interactive: false,
|
||||
kind: UiKind::Rect {
|
||||
width: 500.0,
|
||||
height: 500.0,
|
||||
radius: 0.0,
|
||||
color: "#237A45".into(),
|
||||
},
|
||||
};
|
||||
let left_frame = left.layout.frame(&root).unwrap();
|
||||
let right_frame = right.layout.frame(&root).unwrap();
|
||||
assert_eq!(left_frame.mounts[0].width, 100.0);
|
||||
assert_eq!(right_frame.mounts[0].width, 200.0);
|
||||
left.layout.clear_occurrences();
|
||||
let new_left = left.layout.frame(&root).unwrap();
|
||||
let same_right = right.layout.frame(&root).unwrap();
|
||||
assert_ne!(new_left.mounts[0].id, left_frame.mounts[0].id);
|
||||
assert_eq!(same_right.mounts[0].id, right_frame.mounts[0].id);
|
||||
let shared = vm.new_object().unwrap();
|
||||
let version = vm.change_version(shared).unwrap();
|
||||
left.paint_reads.insert(shared, version);
|
||||
right.layout_reads.insert(shared, version);
|
||||
vm.set_attr(shared, "value", endor_core::Value::Bool(true))
|
||||
.unwrap();
|
||||
let changes = vm.take_changes();
|
||||
left.observe_changes(&vm, &changes);
|
||||
right.observe_changes(&vm, &changes);
|
||||
assert!(left.force_frame && right.force_frame);
|
||||
let weak = vm.downgrade(shared).unwrap();
|
||||
vm.release(shared).unwrap();
|
||||
vm.collect_cycles();
|
||||
assert!(vm.upgrade(weak).unwrap().is_none());
|
||||
}
|
||||
}
|
||||
+75
-85
@@ -169,25 +169,26 @@ pub enum UiKind {
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Session {
|
||||
desktop: ObjectRef,
|
||||
tabs: ObjectRef,
|
||||
active: Option<ObjectRef>,
|
||||
pending: Option<Option<ObjectRef>>,
|
||||
// Weak visual-object registry belongs to the VM, not a particular window.
|
||||
nodes: Vec<WeakObjectRef>,
|
||||
last_snapshot: Option<Arc<UiNode>>,
|
||||
tab_ids: Vec<(WeakObjectRef, u64)>,
|
||||
next_tab: u64,
|
||||
last_tabs: Vec<crate::tabs::Tab>,
|
||||
render_cache: crate::snapshot::RenderCache,
|
||||
layout: crate::layout::LayoutRuntime,
|
||||
mounts: crate::mount::MountTable,
|
||||
published_version: u64,
|
||||
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,
|
||||
presentations: std::collections::BTreeMap<u64, crate::presentation::Presentation>,
|
||||
current: u64,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for Session {
|
||||
type Target = crate::presentation::Presentation;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.presentations
|
||||
.get(&self.current)
|
||||
.expect("selected presentation")
|
||||
}
|
||||
}
|
||||
impl std::ops::DerefMut for Session {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.presentations
|
||||
.get_mut(&self.current)
|
||||
.expect("selected presentation")
|
||||
}
|
||||
}
|
||||
type Shared = Arc<Mutex<Session>>;
|
||||
|
||||
@@ -560,30 +561,9 @@ impl NativeCallable for Function {
|
||||
affected.insert(block);
|
||||
}
|
||||
}
|
||||
if reason != "paint" {
|
||||
session.measure_cache.invalidate(&affected);
|
||||
for block in &affected {
|
||||
session.layout.invalidate(&block.to_string());
|
||||
}
|
||||
for presentation in session.presentations.values_mut() {
|
||||
presentation.invalidate(cx, &affected, &reason)?;
|
||||
}
|
||||
if reason == "content" {
|
||||
session
|
||||
.render_cache
|
||||
.invalidate_objects(affected.iter().copied());
|
||||
}
|
||||
let mut visible = false;
|
||||
for weak in session.mounts.active.values() {
|
||||
if let Some(mount) = cx.upgrade(*weak)?
|
||||
&& affected.contains(
|
||||
&cx.store()
|
||||
.payload::<crate::mount::Mount>(mount, "Mount")?
|
||||
.block,
|
||||
)
|
||||
{
|
||||
visible = true;
|
||||
}
|
||||
}
|
||||
session.force_frame |= visible;
|
||||
return Ok(NativeResult::Return(Value::Nil));
|
||||
}
|
||||
if matches!(self.operation, Mounts) {
|
||||
@@ -593,21 +573,23 @@ impl NativeCallable for Function {
|
||||
.lock()
|
||||
.map_err(|_| invalid("UI session poisoned"))?;
|
||||
let mut positions = Vec::new();
|
||||
for (id, weak) in &session.mounts.active {
|
||||
if let Some(object) = cx.upgrade(*weak)?
|
||||
&& cx
|
||||
.store()
|
||||
.payload::<crate::mount::Mount>(object, "Mount")?
|
||||
.block
|
||||
== owner
|
||||
{
|
||||
positions.push((*id, object));
|
||||
for (window, presentation) in &session.presentations {
|
||||
for (id, weak) in &presentation.mounts.active {
|
||||
if let Some(object) = cx.upgrade(*weak)?
|
||||
&& cx
|
||||
.store()
|
||||
.payload::<crate::mount::Mount>(object, "Mount")?
|
||||
.block
|
||||
== owner
|
||||
{
|
||||
positions.push((*window, *id, object));
|
||||
}
|
||||
}
|
||||
}
|
||||
positions.sort_unstable_by_key(|(id, _)| *id);
|
||||
positions.sort_unstable_by_key(|(window, id, _)| (*window, *id));
|
||||
let set = crate::mount::collection(
|
||||
cx,
|
||||
positions.into_iter().map(|(_, object)| object).collect(),
|
||||
positions.into_iter().map(|(_, _, object)| object).collect(),
|
||||
session.desktop,
|
||||
)?;
|
||||
return Ok(NativeResult::Return(Value::Object(set)));
|
||||
@@ -1081,7 +1063,10 @@ pub struct UiBridge {
|
||||
session: Shared,
|
||||
}
|
||||
|
||||
fn project_tabs(vm: &Vm, state: &mut Session) -> Result<Vec<crate::tabs::Tab>> {
|
||||
fn project_tabs(
|
||||
vm: &Vm,
|
||||
state: &mut crate::presentation::Presentation,
|
||||
) -> Result<Vec<crate::tabs::Tab>> {
|
||||
let window = object(Some(&vm.get_attr(state.desktop, "window")?))?;
|
||||
let pages = crate::window::pages(vm.object_store(), window)?;
|
||||
let active = state.pending.unwrap_or(state.active);
|
||||
@@ -1236,6 +1221,15 @@ impl UiBridge {
|
||||
input
|
||||
.validate()
|
||||
.map_err(|message| anyhow::anyhow!(message))?;
|
||||
if self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?
|
||||
.current
|
||||
!= input.window
|
||||
{
|
||||
bail!("event belongs to another window");
|
||||
}
|
||||
if matches!(input.kind.as_str(), "tab-activate" | "tab-close") {
|
||||
return self.dispatch_tab(vm, input);
|
||||
}
|
||||
@@ -1327,7 +1321,9 @@ impl UiBridge {
|
||||
}
|
||||
}
|
||||
state.nodes = live;
|
||||
state.render_cache.prune(vm.object_store());
|
||||
for presentation in state.presentations.values_mut() {
|
||||
presentation.render_cache.prune(vm.object_store());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn discard_pending(&self, vm: &mut Vm) -> Result<()> {
|
||||
@@ -1335,10 +1331,15 @@ impl UiBridge {
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
state.pending = None;
|
||||
vm.set_attr(state.desktop, "pending", Value::Nil)?;
|
||||
if state.active.is_some_and(|v| vm.object(v).is_err()) {
|
||||
state.active = None;
|
||||
for presentation in state.presentations.values_mut() {
|
||||
presentation.pending = None;
|
||||
vm.set_attr(presentation.desktop, "pending", Value::Nil)?;
|
||||
if presentation
|
||||
.active
|
||||
.is_some_and(|page| vm.object(page).is_err())
|
||||
{
|
||||
presentation.active = None;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1349,15 +1350,11 @@ impl UiBridge {
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
let active = state.pending.unwrap_or(state.active);
|
||||
if state
|
||||
.paint_reads
|
||||
.iter()
|
||||
.chain(state.layout_reads.iter())
|
||||
.any(|(object, version)| vm.change_version(*object).ok() != Some(*version))
|
||||
{
|
||||
state.force_frame = true;
|
||||
// One VM change drain feeds every presentation before selecting a root.
|
||||
// Otherwise a window refreshed first could consume another window's work.
|
||||
for presentation in state.presentations.values_mut() {
|
||||
presentation.observe_changes(vm, &changes);
|
||||
}
|
||||
state.render_cache.invalidate(changes);
|
||||
let root = active
|
||||
.map(|v| state.render_cache.snapshot(vm.object_store(), v))
|
||||
.transpose()?;
|
||||
@@ -1500,6 +1497,7 @@ impl UiBridge {
|
||||
.checked_add(1)
|
||||
.ok_or_else(|| anyhow::anyhow!("layout version exhausted"))?;
|
||||
crate::document::Frame {
|
||||
window: state.current,
|
||||
layout_version: state.layout.version,
|
||||
tabs: project_tabs(vm, &mut state)?,
|
||||
..crate::document::Frame::default()
|
||||
@@ -1556,6 +1554,11 @@ impl UiBridge {
|
||||
// Native layout may replace the structural Frame; attach chrome only
|
||||
// after either layout path has produced the final page geometry.
|
||||
frame.tabs = tabs;
|
||||
frame.window = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?
|
||||
.current;
|
||||
// Capture versions before lifecycle hooks can change a dependency.
|
||||
let reads = reads
|
||||
.into_iter()
|
||||
@@ -1623,25 +1626,12 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
let ui = vm.new_object()?;
|
||||
roots.push(ui);
|
||||
let session = Arc::new(Mutex::new(Session {
|
||||
desktop,
|
||||
tabs,
|
||||
active: None,
|
||||
pending: None,
|
||||
nodes: vec![],
|
||||
last_snapshot: None,
|
||||
tab_ids: Vec::new(),
|
||||
next_tab: 0,
|
||||
last_tabs: Vec::new(),
|
||||
render_cache: crate::snapshot::RenderCache::default(),
|
||||
layout: crate::layout::LayoutRuntime::default(),
|
||||
mounts: crate::mount::MountTable::default(),
|
||||
published_version: 0,
|
||||
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,
|
||||
nodes: Vec::new(),
|
||||
presentations: std::collections::BTreeMap::from([(
|
||||
crate::window::MAIN_WINDOW,
|
||||
crate::presentation::Presentation::new(desktop, tabs),
|
||||
)]),
|
||||
current: crate::window::MAIN_WINDOW,
|
||||
}));
|
||||
for (name, operation) in [
|
||||
("isInstance", Operation::IsInstance),
|
||||
|
||||
Reference in New Issue
Block a user