Run source measurement and arrangement in the frame pipeline
Verify Tessera GUI / verify (push) Failing after 7m30s
Verify Tessera GUI / verify (push) Failing after 7m30s
This commit is contained in:
+60
-34
@@ -107,6 +107,31 @@ fn measure_shape(shape: &Shape) -> Result<Size> {
|
||||
Ok(size)
|
||||
}
|
||||
|
||||
fn shape(node: &UiNode, children: Vec<Size>) -> Result<Shape> {
|
||||
Ok(match &node.kind {
|
||||
UiKind::Text { value, size, .. } => Shape::Text(value.clone(), *size),
|
||||
UiKind::Rect { width, height, .. } => Shape::Rect(*width, *height),
|
||||
UiKind::Spacer(size) => Shape::Rect(*size, *size),
|
||||
_ => {
|
||||
let (row, padding, gap) = container(node).context("unknown native visual protocol")?;
|
||||
Shape::Container(row, padding, gap, children)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn measure_native(node: &UiNode, children: Vec<Size>) -> Result<Size> {
|
||||
measure_shape(&shape(node, children)?)
|
||||
}
|
||||
|
||||
/// Private derived scratch space for one occurrence during layout. Contains no
|
||||
/// managed references; source code cannot mutate it through heap attributes.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Context {
|
||||
pub node: Option<std::sync::Arc<UiNode>>,
|
||||
pub children: Vec<Size>,
|
||||
pub bounds: Option<[f32; 4]>,
|
||||
}
|
||||
|
||||
pub fn paint_native(node: &UiNode, x: f32, y: f32, size: Size) -> Option<RenderCommand> {
|
||||
match &node.kind {
|
||||
UiKind::Text { value, size, color } => Some(RenderCommand::Text {
|
||||
@@ -170,12 +195,35 @@ impl LayoutRuntime {
|
||||
// Stage all cache/identity changes; a rejected frame leaves the last
|
||||
// valid occurrence registry intact and never publishes partial geometry.
|
||||
let mut next = self.clone();
|
||||
let frame = next.build(root)?;
|
||||
let frame = next.build(root, false)?;
|
||||
*self = next;
|
||||
Ok(frame)
|
||||
}
|
||||
|
||||
fn build(&mut self, root: &UiNode) -> Result<Frame> {
|
||||
/// Allocate stable occurrence identities without measuring or publishing geometry.
|
||||
pub fn structure(&mut self, root: &UiNode) -> Result<Frame> {
|
||||
let mut next = self.clone();
|
||||
let frame = next.build(root, true)?;
|
||||
*self = next;
|
||||
Ok(frame)
|
||||
}
|
||||
|
||||
pub fn measure_node(&mut self, node: &UiNode, children: Vec<Size>) -> Result<Size> {
|
||||
let shape = shape(node, children)?;
|
||||
if let Some((_, size)) = self
|
||||
.sizes
|
||||
.get(&node.block_id)
|
||||
.filter(|(old, _)| *old == shape)
|
||||
{
|
||||
return Ok(*size);
|
||||
}
|
||||
self.measured += 1;
|
||||
let size = measure_shape(&shape)?;
|
||||
self.sizes.insert(node.block_id.clone(), (shape, size));
|
||||
Ok(size)
|
||||
}
|
||||
|
||||
fn build(&mut self, root: &UiNode, structural: bool) -> Result<Frame> {
|
||||
self.measured = 0;
|
||||
self.arranged = 0;
|
||||
let mut items = Vec::<Item<'_>>::new();
|
||||
@@ -221,36 +269,11 @@ impl LayoutRuntime {
|
||||
}
|
||||
}
|
||||
let mut sizes = vec![Size::default(); items.len()];
|
||||
for (index, item) in items.iter().enumerate().rev() {
|
||||
let shape = match &item.node.kind {
|
||||
UiKind::Text { value, size, .. } => Shape::Text(value.clone(), *size),
|
||||
UiKind::Rect { width, height, .. } => Shape::Rect(*width, *height),
|
||||
UiKind::Spacer(size) => Shape::Rect(*size, *size),
|
||||
_ => {
|
||||
let (row, padding, gap) =
|
||||
container(item.node).context("unknown native visual protocol")?;
|
||||
Shape::Container(
|
||||
row,
|
||||
padding,
|
||||
gap,
|
||||
item.children.iter().map(|i| sizes[*i]).collect(),
|
||||
)
|
||||
}
|
||||
};
|
||||
let size = if let Some((old_shape, size)) = self
|
||||
.sizes
|
||||
.get(&item.node.block_id)
|
||||
.filter(|(old, _)| *old == shape)
|
||||
{
|
||||
let _ = old_shape;
|
||||
*size
|
||||
} else {
|
||||
self.measured += 1;
|
||||
let size = measure_shape(&shape)?;
|
||||
self.sizes.insert(item.node.block_id.clone(), (shape, size));
|
||||
size
|
||||
};
|
||||
sizes[index] = size;
|
||||
if !structural {
|
||||
for (index, item) in items.iter().enumerate().rev() {
|
||||
sizes[index] = self
|
||||
.measure_node(item.node, item.children.iter().map(|i| sizes[*i]).collect())?;
|
||||
}
|
||||
}
|
||||
let mut points = vec![(0.0_f32, 0.0_f32); items.len()];
|
||||
let mut mounts = Vec::with_capacity(items.len());
|
||||
@@ -262,7 +285,7 @@ impl LayoutRuntime {
|
||||
}
|
||||
}
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
self.arranged += 1;
|
||||
self.arranged += usize::from(!structural);
|
||||
let (x, y) = points[index];
|
||||
let size = sizes[index];
|
||||
bounded(x)?;
|
||||
@@ -281,9 +304,12 @@ impl LayoutRuntime {
|
||||
height: size.height,
|
||||
interactive: item.node.interactive,
|
||||
});
|
||||
if let Some(command) = paint_native(item.node, x, y, size) {
|
||||
if !structural && let Some(command) = paint_native(item.node, x, y, size) {
|
||||
commands.push(command);
|
||||
}
|
||||
if structural {
|
||||
continue;
|
||||
}
|
||||
let child_sizes: Vec<_> = item.children.iter().map(|child| sizes[*child]).collect();
|
||||
for (child, point) in
|
||||
item.children
|
||||
|
||||
Reference in New Issue
Block a user