From 9ea3c54b92de68850c4bb04276d82d54e1329a96 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 20 Mar 2025 10:21:03 +0100 Subject: [PATCH] :tada: Improve tile shapes iteration --- render-wasm/src/render.rs | 36 +++++++++++++++++++-------------- render-wasm/src/render/tiles.rs | 4 ---- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/render-wasm/src/render.rs b/render-wasm/src/render.rs index b2a82844f0..7bdd5ca2d1 100644 --- a/render-wasm/src/render.rs +++ b/render-wasm/src/render.rs @@ -668,7 +668,6 @@ impl RenderState { }); if element.is_recursive() { - // Fix this let children_clip_bounds = node_render_state .get_children_clip_bounds(element, modifiers.get(&element.id)); for child_id in element.children_ids().iter().rev() { @@ -712,17 +711,22 @@ impl RenderState { if let Some(next_tile) = self.pending_tiles.pop() { self.update_render_context(next_tile); if !self.surfaces.has_cached_tile_surface(next_tile) { - // If the tile is empty or it doesn't exists we don't do anything with it - if self.tiles.has_shapes_at(next_tile) { - // TODO: This should be more efficient, we should be able to know exactly what shapes tree - // are included for this tile - self.pending_nodes.push(NodeRenderState { - id: Uuid::nil(), - visited_children: false, - clip_bounds: None, - visited_mask: false, - mask: false, - }); + if let Some(ids) = self.tiles.get_shapes_at(next_tile) { + for id in ids { + let element = tree.get_mut(&id).ok_or( + "Error: Element with root_id {id} not found in the tree." + .to_string(), + )?; + if element.parent_id == Some(Uuid::nil()) { + self.pending_nodes.push(NodeRenderState { + id: *id, + visited_children: false, + clip_bounds: None, + visited_mask: false, + mask: false, + }); + } + } } } } else { @@ -772,10 +776,12 @@ impl RenderState { while let Some(shape_id) = nodes.pop() { if let Some(shape) = tree.get(&shape_id) { let mut shape = shape.clone(); - if let Some(modifier) = modifiers.get(&shape_id) { - shape.apply_transform(modifier); + if shape_id != Uuid::nil() { + if let Some(modifier) = modifiers.get(&shape_id) { + shape.apply_transform(modifier); + } + self.update_tile_for(&shape); } - self.update_tile_for(&shape); for child_id in shape.children_ids().iter() { nodes.push(*child_id); } diff --git a/render-wasm/src/render/tiles.rs b/render-wasm/src/render/tiles.rs index b0befba35e..9931c423a0 100644 --- a/render-wasm/src/render/tiles.rs +++ b/render-wasm/src/render/tiles.rs @@ -60,10 +60,6 @@ impl TileHashMap { } } - pub fn has_shapes_at(&mut self, tile: Tile) -> bool { - return self.grid.contains_key(&tile); - } - pub fn get_shapes_at(&mut self, tile: Tile) -> Option<&IndexSet> { return self.grid.get(&tile); }