Support shared-VM native windows and Page detachment
Verify Tessera GUI / verify (push) Failing after 7m35s

This commit is contained in:
2026-10-21 18:11:58 +08:00
parent f8173168fd
commit e3e46068eb
13 changed files with 993 additions and 145 deletions
+45 -11
View File
@@ -431,8 +431,14 @@ struct Worker {
}
impl Worker {
fn refresh_viewport(&mut self, namespace: &Arc<RwLock<NamespaceState>>, notify: &Notify) {
let (epoch, viewport) = match namespace.read() {
Ok(current) => (current.submission, current.viewport),
let (epoch, viewports) = match namespace.read() {
Ok(current) => {
let mut viewports = current.window_viewports.clone();
if let Some(viewport) = current.viewport {
viewports.insert(crate::window::MAIN_WINDOW, viewport);
}
(current.submission, viewports)
}
Err(_) => return,
};
let Some((owner, runtime)) = &mut self.repl else {
@@ -447,7 +453,7 @@ impl Worker {
}
let id = runtime.id;
let result = catch_unwind(AssertUnwindSafe(|| -> Result<_> {
let document = runtime.resize(viewport)?;
let document = runtime.resize_windows(&viewports)?;
Ok((document, runtime.take_window_commands()?))
}));
let mut current = match namespace.write() {
@@ -485,6 +491,9 @@ impl Worker {
"Runtime discarded after an internal viewport failure".into()
}
});
for view in document.windows.values_mut() {
view.frame.fault = document.frame.fault.clone();
}
(document, None)
}
};
@@ -523,6 +532,10 @@ impl Worker {
if let Ok(mut current) = namespace.write() {
current.document.frame.session = 0;
current.document.frame.focus = None;
for document in current.document.windows.values_mut() {
document.frame.session = 0;
document.frame.focus = None;
}
current.runtime_session = 0;
current.window_commands.clear();
}
@@ -539,7 +552,7 @@ impl Worker {
};
if !matches!(
input.kind.as_str(),
"click" | "focus" | "tab-activate" | "tab-close"
"click" | "focus" | "tab-activate" | "tab-close" | "tab-detach" | "window-close"
) {
return error_response(StatusCode(400), "unsupported event kind");
}
@@ -550,12 +563,24 @@ impl Worker {
Ok(current) => current,
Err(_) => return error_response(StatusCode(500), "namespace lock poisoned"),
};
let frame = &current.document.frame;
let frame = if input.window == crate::window::MAIN_WINDOW {
&current.document.frame
} else {
let Some(document) = current.document.windows.get(&input.window) else {
return error_response(StatusCode(409), "window is no longer active");
};
&document.frame
};
if frame.window != input.window
|| frame.session != input.session
|| frame.layout_version != input.layout_version
|| (input.kind != "window-close" && frame.layout_version != input.layout_version)
|| frame.fault.is_some()
|| if matches!(input.kind.as_str(), "tab-activate" | "tab-close") {
|| if input.kind == "window-close" {
false
} else if matches!(
input.kind.as_str(),
"tab-activate" | "tab-close" | "tab-detach"
) {
!frame.tabs.iter().any(|tab| tab.id == input.mount)
} else {
!frame
@@ -564,7 +589,9 @@ impl Worker {
.any(|mount| mount.id == input.mount && mount.interactive)
}
|| self.repl.as_ref().is_none_or(|(context, runtime)| {
*context != epoch || runtime.id != input.session
*context != epoch
|| runtime.id != input.session
|| (input.kind != "window-close" && !runtime.accepts_window(input.window))
})
{
return error_response(
@@ -642,7 +669,11 @@ impl Worker {
Ok(Err(error)) => {
if event.is_some() || faulted {
let mut document = current.document.clone();
document.frame.fault = Some(format!("{error:#}").chars().take(1024).collect());
let fault: String = format!("{error:#}").chars().take(1024).collect();
document.frame.fault = Some(fault.clone());
for view in document.windows.values_mut() {
view.frame.fault = Some(fault.clone());
}
let _ = current.commit(epoch, document);
drop(current);
notify();
@@ -653,6 +684,9 @@ impl Worker {
let mut document = current.document.clone();
document.frame.fault =
Some("Runtime discarded after an internal execution failure".into());
for view in document.windows.values_mut() {
view.frame.fault = document.frame.fault.clone();
}
current.runtime_session = 0;
current.window_commands.clear();
let _ = current.commit(epoch, document);
@@ -901,13 +935,13 @@ declarations, explicit first `self` parameters, positional field construction an
member assignment. Inherited methods bind the actual receiver; overridden methods
are dynamically selected through self. Concrete native visual subclasses reuse real native allocators; abstract bases remain unconstructible. Traits and annotation checking remain pending. Native Block/Page methods use the same type method tables and binding path.
Window is a host-provided managed resource: ui.window(), page.window(), page.open(window), window.pages()/id()/viewport(), resize(width,height), setTitle(text) and focus(). Requests project to the actual main native window only after successful input/candidate completion and carry the current runtime session. Resize is asynchronous and the reported viewport is authoritative; this host accepts 1..4096 logical dimensions with a native 720x480 minimum. Failed input/candidates discard pending requests and read-only rendering rejects window effects. Open Pages appear in native tab chrome, with page.title, click activation/close, Ctrl+Tab cycling and Cmd/Ctrl+W close when page keyboard focus is active. Overflow arrows reach additional pages. These operations call actual Page methods in the same VM; tab IDs are weak runtime projections and add no GC roots. The 36-logical-pixel bar reduces Page constraint height; window/ui viewport reports the full inner size and native pointer positions are translated into content coordinates. Additional windows, Window() construction and detach/move remain pending.
Window is a host-provided managed resource: ui.window(), page.window(), page.open(window), window.pages()/id()/viewport(), resize(width,height), setTitle(text) and focus(). Requests project to their actual native window only after successful input/candidate completion and carry the current runtime session. Resize is asynchronous and the reported viewport is authoritative; this host accepts 1..4096 logical dimensions with a native 720x480 minimum. Failed input/candidates discard pending requests and read-only rendering rejects window effects. Open Pages appear in native tab chrome, with page.title, click activation/close, Ctrl+Tab cycling and Cmd/Ctrl+W close when page keyboard focus is active. Overflow arrows reach additional pages. These operations call actual Page methods in the same VM; tab IDs are weak runtime projections and add no GC roots. The 36-logical-pixel bar reduces Page constraint height; window/ui viewport reports the full inner size and native pointer positions are translated into content coordinates. Window() now creates additional native windows in the same VM, up to 16 open resources. Page.open(window)/moveToWindow(window) preserve Page and business identity while replacing Mounts; detachToWindow() creates and returns a new Window. Dragging a tab away from its strip invokes the same method. Window.close()/secondary OS close remove Page roots, unmount, and retire the resource context; retained Pages can reopen in another live window, and closed Window resources reject viewport/resize/title/focus operations. Closing the primary OS shell exits the application. Secondary viewport inputs and frame publication use the same worker. Existing-window drag/drop, release-point placement and faulted-VM cleanup remain pending.
Source measure and arrange overrides execute bottom-up and top-down in one read-only VM layout call. Structural Mount links exist before first measurement; bounds queries reject premature geometry. Native base layout uses current occurrence child measurements, and Arrangement must assign every stable child slot exactly once. Layout dependencies changed by lifecycle hooks trigger another pass before publication. Page constraints now use the current logical window viewport. Column/Button propagate cross-axis width and Row propagates cross-axis height; desired sizes are clamped. ui.viewport() provides a managed snapshot whose private input participates in rendering dependencies. Native resize updates are coalesced on the same worker without adding source inputs. Source measurement caches use Mount/method/children/constraints and actual subcall object reads, including returned-result decoding; Mount-reading methods conservatively bypass caching. ui.stats() exposes sourceMeasureHits/sourceMeasureMisses outside read-only rendering. General constraint negotiation, wrapping and scrolling remain pending.
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. 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
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/tab-detach and the mount wire field carries the opaque tab ID from frame.tabs; point/press_point must be omitted. All spatial/tab actions validate session and layout_version before dispatch. Resource window-close uses mount=0 and no points; it validates the live window/session rather than its old layout version. 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.