♻️ Add ShapeStrokes surface

This commit is contained in:
Belén Albeza 2025-02-21 14:08:59 +01:00
parent 5ebfc603e6
commit 2cf179ccf6
6 changed files with 132 additions and 83 deletions

View file

@ -64,7 +64,9 @@ pub fn render_debug_shape(render_state: &mut RenderState, element: &Shape, inter
pub fn render(render_state: &mut RenderState) {
render_debug_view(render_state);
render_state
.surfaces
.draw_into(SurfaceId::Debug, SurfaceId::Current, None);
render_state.surfaces.draw_into(
SurfaceId::Debug,
SurfaceId::Current,
Some(&skia::Paint::default()),
);
}

View file

@ -16,7 +16,7 @@ fn draw_image_fill_in_container(
}
let size = image_fill.size();
let canvas = render_state.surfaces.canvas(SurfaceId::Shape);
let canvas = render_state.surfaces.canvas(SurfaceId::Fills);
let container = &shape.selrect;
let path_transform = shape.to_path_transform();
let paint = fill.to_paint(container);
@ -96,7 +96,7 @@ fn draw_image_fill_in_container(
* This SHOULD be the only public function in this module.
*/
pub fn render(render_state: &mut RenderState, shape: &Shape, fill: &Fill) {
let canvas = render_state.surfaces.canvas(SurfaceId::Shape);
let canvas = render_state.surfaces.canvas(SurfaceId::Fills);
let selrect = shape.selrect;
let path_transform = shape.to_path_transform();

View file

@ -7,11 +7,16 @@ pub fn render_drop_shadow(render_state: &mut RenderState, shadow: &Shadow, scale
let shadow_paint = shadow.to_paint(scale);
render_state
.surfaces
.draw_into(SurfaceId::Shape, SurfaceId::Shadow, Some(&shadow_paint));
.draw_into(SurfaceId::Fills, SurfaceId::Shadow, Some(&shadow_paint));
render_state
.surfaces
.draw_into(SurfaceId::Shadow, SurfaceId::Current, None);
.draw_into(SurfaceId::Strokes, SurfaceId::Shadow, Some(&shadow_paint));
render_state.surfaces.draw_into(
SurfaceId::Shadow,
SurfaceId::Current,
Some(&skia::Paint::default()),
);
render_state
.surfaces
@ -24,7 +29,7 @@ pub fn render_inner_shadow(render_state: &mut RenderState, shadow: &Shadow, scal
render_state
.surfaces
.draw_into(SurfaceId::Shape, SurfaceId::Shadow, Some(&shadow_paint)); // , ShadowPaint
.draw_into(SurfaceId::Fills, SurfaceId::Shadow, Some(&shadow_paint));
render_state
.surfaces

View file

@ -330,7 +330,7 @@ fn draw_image_stroke_in_container(
}
let size = image_fill.size();
let canvas = render_state.surfaces.canvas(SurfaceId::Shape);
let canvas = render_state.surfaces.canvas(SurfaceId::Fills);
let container = &shape.selrect;
let path_transform = shape.to_path_transform();
let svg_attrs = &shape.svg_attrs;
@ -432,7 +432,7 @@ fn draw_image_stroke_in_container(
* This SHOULD be the only public function in this module.
*/
pub fn render(render_state: &mut RenderState, shape: &Shape, stroke: &Stroke) {
let canvas = render_state.surfaces.canvas(SurfaceId::Shape);
let canvas = render_state.surfaces.canvas(SurfaceId::Strokes);
let dpr_scale = render_state.viewbox.zoom * render_state.options.dpr();
let selrect = shape.selrect;
let path_transform = shape.to_path_transform();

View file

@ -1,10 +1,12 @@
use super::gpu_state::GpuState;
use skia_safe as skia;
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum SurfaceId {
Target,
Current,
Shape,
Fills,
Strokes,
Shadow,
Overlay,
Debug,
@ -15,8 +17,10 @@ pub struct Surfaces {
target: skia::Surface,
// keeps the current render
current: skia::Surface,
// keeps the current shape
shape: skia::Surface,
// keeps the current shape's fills
shape_fills: skia::Surface,
// keeps the current shape's strokes
shape_strokes: skia::Surface,
// used for rendering shadows
shadow: skia::Surface,
// for drawing the things that are over shadows.
@ -37,7 +41,8 @@ impl Surfaces {
let current = target.new_surface_with_dimensions((width, height)).unwrap();
let shadow = target.new_surface_with_dimensions((width, height)).unwrap();
let overlay = target.new_surface_with_dimensions((width, height)).unwrap();
let shape = target.new_surface_with_dimensions((width, height)).unwrap();
let shape_fills = target.new_surface_with_dimensions((width, height)).unwrap();
let shape_strokes = target.new_surface_with_dimensions((width, height)).unwrap();
let debug = target.new_surface_with_dimensions((width, height)).unwrap();
Surfaces {
@ -45,7 +50,8 @@ impl Surfaces {
current,
shadow,
overlay,
shape,
shape_fills,
shape_strokes,
debug,
sampling_options,
}
@ -76,13 +82,21 @@ impl Surfaces {
.draw(self.canvas(to), (0.0, 0.0), sampling_options, paint);
}
pub fn apply_mut(&mut self, ids: &[SurfaceId], mut f: impl FnMut(&mut skia::Surface) -> ()) {
for id in ids {
let surface = self.get_mut(*id);
f(surface);
}
}
fn get_mut(&mut self, id: SurfaceId) -> &mut skia::Surface {
match id {
SurfaceId::Target => &mut self.target,
SurfaceId::Current => &mut self.current,
SurfaceId::Shadow => &mut self.shadow,
SurfaceId::Overlay => &mut self.overlay,
SurfaceId::Shape => &mut self.shape,
SurfaceId::Fills => &mut self.shape_fills,
SurfaceId::Strokes => &mut self.shape_strokes,
SurfaceId::Debug => &mut self.debug,
}
}
@ -93,7 +107,7 @@ impl Surfaces {
self.current = self.target.new_surface_with_dimensions(dim).unwrap();
self.overlay = self.target.new_surface_with_dimensions(dim).unwrap();
self.shadow = self.target.new_surface_with_dimensions(dim).unwrap();
self.shape = self.target.new_surface_with_dimensions(dim).unwrap();
self.shape_fills = self.target.new_surface_with_dimensions(dim).unwrap();
self.debug = self.target.new_surface_with_dimensions(dim).unwrap();
}
}