diff --git a/.serena/memories/render-wasm/ffi-rendering-subtleties.md b/.serena/memories/render-wasm/ffi-rendering-subtleties.md index a9006d5996..dadbae5c2d 100644 --- a/.serena/memories/render-wasm/ffi-rendering-subtleties.md +++ b/.serena/memories/render-wasm/ffi-rendering-subtleties.md @@ -19,6 +19,10 @@ - Raster `Fill::Image`: skip `save_layer` unless the shape has an image filter; plain Rect/Frame (no corners) also skip the container clip (`draw_image_fill` in fills.rs). +- `can_render_directly` paints onto Current (no Fills/Strokes blit) for plain geometry and + for stroke-free text (SrcOver, no blur/shadows). Multi-style text is fine: span styles + live in Paragraph `TextStyle`s. Text skips the `nested_fills` guard (fills are on spans). + `draw_text` only `save_layer`s when stroke-group opacity is set; plain fill paint is direct. - Plain text fill paint reuses `TextContent.layout` paragraphs when `has_usable_paint_layout` (paragraphs present + version match; during interactive transforms rotation/move skips width check via diff --git a/render-wasm/src/render.rs b/render-wasm/src/render.rs index 40af6e2e2f..0842f92db9 100644 --- a/render-wasm/src/render.rs +++ b/render-wasm/src/render.rs @@ -1443,6 +1443,17 @@ impl RenderState { // Stroke-only (fills_none) can go direct: empty fills are a no-op and // strokes paint into Current. Large files need mid-walk GPU drains so // release builds do not backlog a huge ops buffer in one Partial. + // + // Plain text (no strokes / effects) also paints into Current: span styles + // live in Skia Paragraph TextStyles, so multi-style text is fine. + // Text skips the nested_fills guard because fills are on spans, not + // shape.fills. Strokes stay layered (masking needs save_layers). + let is_direct_geometry = matches!( + shape.shape_type, + Type::Rect(_) | Type::Circle | Type::Path(_) | Type::Bool(_) | Type::Frame(_) + ) && !(shape.fills.is_empty() && has_nested_fills); + let is_direct_text = + matches!(shape.shape_type, Type::Text(_)) && !shape.has_visible_strokes(); let can_render_directly = apply_to_current_surface && offset.is_none() && parent_shadows.is_none() @@ -1453,11 +1464,7 @@ impl RenderState { && shape.background_blur.is_none() && !has_inherited_blur && !shadows_need_layered - && matches!( - shape.shape_type, - Type::Rect(_) | Type::Circle | Type::Path(_) | Type::Bool(_) | Type::Frame(_) - ) - && !(shape.fills.is_empty() && has_nested_fills) + && (is_direct_geometry || is_direct_text) && target_surface != SurfaceId::Export; if can_render_directly { @@ -1486,21 +1493,50 @@ impl RenderState { }); } - fills::render(self, shape, &shape.fills, antialias, target_surface, None)?; + if let Type::Text(stored_text_content) = &shape.shape_type { + self.tile_atlas_flushed = true; - // Clipped frames draw strokes in render_shape_exit over children. - let skip_strokes = matches!(shape.shape_type, Type::Frame(_)) && shape.clip_content; - if !skip_strokes { - // Pass strokes in natural order; stroke merging handles top-most ordering internally. - let visible_strokes: Vec<&Stroke> = shape.visible_strokes().collect(); - strokes::render( - self, + if !text::try_paint_from_layout_cache( + Some(self), + None, shape, - &visible_strokes, Some(target_surface), - antialias, - outset, - )?; + text_layout_cache_rotation_only, + )? { + let rebound_text_content = + stored_text_content.paint_content_for_selrect(shape.selrect()); + let text_content = rebound_text_content.as_ref(); + let mut paragraph_builders = + text_content.paragraph_builder_group_from_text(None); + text::render( + Some(self), + None, + shape, + &mut paragraph_builders, + Some(target_surface), + None, + None, + None, + None, + )?; + } + } else { + fills::render(self, shape, &shape.fills, antialias, target_surface, None)?; + + // Clipped frames draw strokes in render_shape_exit over children. + let skip_strokes = matches!(shape.shape_type, Type::Frame(_)) && shape.clip_content; + if !skip_strokes { + // Pass strokes in natural order; stroke merging handles top-most ordering internally. + let visible_strokes: Vec<&Stroke> = shape.visible_strokes().collect(); + strokes::render( + self, + shape, + &visible_strokes, + Some(target_surface), + antialias, + outset, + )?; + } } self.surfaces.apply_mut(target_surface as u32, |s| { diff --git a/render-wasm/src/render/text.rs b/render-wasm/src/render/text.rs index e611f95d86..ce95dde278 100644 --- a/render-wasm/src/render/text.rs +++ b/render-wasm/src/render/text.rs @@ -466,6 +466,8 @@ fn render_text_on_canvas( ) { let layer_bounds = shape.layer_bounds(); + // Layer stack is managed here (blur / shadow / inset). `draw_text` is + // self-contained and only opens a layer when stroke-group opacity needs it. if let Some(blur_filter) = blur { let mut blur_paint = Paint::default(); blur_paint.set_image_filter(blur_filter.clone()); @@ -872,8 +874,6 @@ pub fn render_emoji_overlay( if blur.is_some() { canvas.restore(); } - - canvas.restore(); } fn draw_text( @@ -883,20 +883,22 @@ fn draw_text( layer_opacity: Option, overlay_emoji: bool, ) { - let layer_bounds = shape.layer_bounds(); - + // Multi-style spans are already encoded in each ParagraphBuilder's + // TextStyles; paragraph.paint handles them without an isolation layer. + // Only open a save_layer when stroke-group opacity must composite as one. if let Some(opacity) = layer_opacity { + let layer_bounds = shape.layer_bounds(); let mut opacity_paint = Paint::default(); opacity_paint.set_alpha_f(opacity); let layer_rec = SaveLayerRec::default() .bounds(&layer_bounds) .paint(&opacity_paint); canvas.save_layer(&layer_rec); + paint_text_with_emoji_overlay(canvas, shape, paragraph_builder_groups, overlay_emoji); + canvas.restore(); } else { - canvas.save_layer(&SaveLayerRec::default().bounds(&layer_bounds)); + paint_text_with_emoji_overlay(canvas, shape, paragraph_builder_groups, overlay_emoji); } - - paint_text_with_emoji_overlay(canvas, shape, paragraph_builder_groups, overlay_emoji); } /// Renders a text stroke masked to the glyph shape.