From 369e134bedc4f50ac50ec299a13c49330e962f56 Mon Sep 17 00:00:00 2001 From: Aitor Moreno Date: Tue, 10 Jun 2025 12:46:17 +0200 Subject: [PATCH] :recycle: Refactor some minor perf issues --- render-wasm/src/render.rs | 66 +++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/render-wasm/src/render.rs b/render-wasm/src/render.rs index 0769c2926c..f6871eccae 100644 --- a/render-wasm/src/render.rs +++ b/render-wasm/src/render.rs @@ -49,6 +49,10 @@ pub struct NodeRenderState { } impl NodeRenderState { + pub fn is_root(&self) -> bool { + self.id.is_nil() + } + pub fn get_children_clip_bounds( &self, element: &Shape, @@ -610,6 +614,7 @@ impl RenderState { && performance::get_time() - timestamp > MAX_BLOCKING_TIME_MS } + #[inline] pub fn render_shape_enter(&mut self, element: &mut Shape, mask: bool) { // Masked groups needs two rendering passes, the first one rendering // the content and the second one rendering the mask so we need to do @@ -653,6 +658,7 @@ impl RenderState { .save_layer(&layer_rec); } + #[inline] pub fn render_shape_exit(&mut self, element: &mut Shape, visited_mask: bool) { if visited_mask { // Because masked groups needs two rendering passes (first drawing @@ -663,6 +669,33 @@ impl RenderState { self.surfaces.canvas(SurfaceId::Current).restore(); } } + } else { + // !visited_mask + if let Type::Group(group) = element.shape_type { + // When we're dealing with masked groups we need to + // do a separate extra step to draw the mask (the last + // element of a masked group) and blend (using + // the blend mode 'destination-in') the content + // of the group and the mask. + if group.masked { + self.pending_nodes.push(NodeRenderState { + id: element.id, + visited_children: true, + clip_bounds: None, + visited_mask: true, + mask: false, + }); + if let Some(&mask_id) = element.mask_id() { + self.pending_nodes.push(NodeRenderState { + id: mask_id, + visited_children: false, + clip_bounds: None, + visited_mask: false, + mask: true, + }); + } + } + } } if let Type::Group(_) = element.shape_type { self.nested_fills.pop(); @@ -738,38 +771,11 @@ impl RenderState { } if visited_children { - if !visited_mask { - if let Type::Group(group) = element.shape_type { - // When we're dealing with masked groups we need to - // do a separate extra step to draw the mask (the last - // element of a masked group) and blend (using - // the blend mode 'destination-in') the content - // of the group and the mask. - if group.masked { - self.pending_nodes.push(NodeRenderState { - id: node_id, - visited_children: true, - clip_bounds: None, - visited_mask: true, - mask: false, - }); - if let Some(&mask_id) = element.mask_id() { - self.pending_nodes.push(NodeRenderState { - id: mask_id, - visited_children: false, - clip_bounds: None, - visited_mask: false, - mask: true, - }); - } - } - } - } self.render_shape_exit(element, visited_mask); continue; } - if !node_render_state.id.is_nil() { + if !node_render_state.is_root() { let mut transformed_element: Cow = Cow::Borrowed(element); if let Some(modifier) = modifiers.get(&node_id) { @@ -790,14 +796,14 @@ impl RenderState { } self.render_shape_enter(element, mask); - if !node_render_state.id.is_nil() { + if !node_render_state.is_root() { self.render_shape( element, modifiers.get(&element.id), scale_content.get(&element.id), clip_bounds, ); - } else { + } else if visited_children { self.apply_drawing_to_render_canvas(Some(element)); }