mirror of
https://github.com/penpot/penpot.git
synced 2025-05-25 19:36:12 +02:00
♻️ Add ShapeStrokes surface
This commit is contained in:
parent
5ebfc603e6
commit
2cf179ccf6
6 changed files with 132 additions and 83 deletions
|
@ -154,24 +154,23 @@ impl RenderState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset_canvas(&mut self) {
|
pub fn reset_canvas(&mut self) {
|
||||||
self.surfaces.canvas(SurfaceId::Shape).restore_to_count(1);
|
self.surfaces.canvas(SurfaceId::Fills).restore_to_count(1);
|
||||||
|
self.surfaces.canvas(SurfaceId::Strokes).restore_to_count(1);
|
||||||
self.surfaces.canvas(SurfaceId::Current).restore_to_count(1);
|
self.surfaces.canvas(SurfaceId::Current).restore_to_count(1);
|
||||||
self.surfaces
|
|
||||||
.canvas(SurfaceId::Shape)
|
self.surfaces.apply_mut(
|
||||||
.clear(self.background_color)
|
&[
|
||||||
.reset_matrix();
|
SurfaceId::Fills,
|
||||||
self.surfaces
|
SurfaceId::Strokes,
|
||||||
.canvas(SurfaceId::Current)
|
SurfaceId::Current,
|
||||||
.clear(self.background_color)
|
SurfaceId::Shadow,
|
||||||
.reset_matrix();
|
SurfaceId::Overlay,
|
||||||
self.surfaces
|
],
|
||||||
.canvas(SurfaceId::Shadow)
|
|s| {
|
||||||
.clear(self.background_color)
|
s.canvas().clear(self.background_color).reset_matrix();
|
||||||
.reset_matrix();
|
},
|
||||||
self.surfaces
|
);
|
||||||
.canvas(SurfaceId::Overlay)
|
|
||||||
.clear(self.background_color)
|
|
||||||
.reset_matrix();
|
|
||||||
self.surfaces
|
self.surfaces
|
||||||
.canvas(SurfaceId::Debug)
|
.canvas(SurfaceId::Debug)
|
||||||
.clear(skia::Color::TRANSPARENT)
|
.clear(skia::Color::TRANSPARENT)
|
||||||
|
@ -179,15 +178,28 @@ impl RenderState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_render_to_final_canvas(&mut self) {
|
pub fn apply_render_to_final_canvas(&mut self) {
|
||||||
self.surfaces
|
self.surfaces.draw_into(
|
||||||
.draw_into(SurfaceId::Current, SurfaceId::Target, None);
|
SurfaceId::Current,
|
||||||
|
SurfaceId::Target,
|
||||||
|
Some(&skia::Paint::default()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_drawing_to_render_canvas(&mut self) {
|
pub fn apply_drawing_to_render_canvas(&mut self) {
|
||||||
self.surfaces
|
self.surfaces
|
||||||
.flush_and_submit(&mut self.gpu_state, SurfaceId::Shape);
|
.flush_and_submit(&mut self.gpu_state, SurfaceId::Fills);
|
||||||
|
self.surfaces.draw_into(
|
||||||
|
SurfaceId::Fills,
|
||||||
|
SurfaceId::Current,
|
||||||
|
Some(&skia::Paint::default()),
|
||||||
|
);
|
||||||
self.surfaces
|
self.surfaces
|
||||||
.draw_into(SurfaceId::Shape, SurfaceId::Current, None);
|
.flush_and_submit(&mut self.gpu_state, SurfaceId::Strokes);
|
||||||
|
self.surfaces.draw_into(
|
||||||
|
SurfaceId::Strokes,
|
||||||
|
SurfaceId::Current,
|
||||||
|
Some(&skia::Paint::default()),
|
||||||
|
);
|
||||||
|
|
||||||
self.surfaces
|
self.surfaces
|
||||||
.flush_and_submit(&mut self.gpu_state, SurfaceId::Current);
|
.flush_and_submit(&mut self.gpu_state, SurfaceId::Current);
|
||||||
|
@ -196,17 +208,17 @@ impl RenderState {
|
||||||
self.surfaces
|
self.surfaces
|
||||||
.draw_into(SurfaceId::Overlay, SurfaceId::Current, None);
|
.draw_into(SurfaceId::Overlay, SurfaceId::Current, None);
|
||||||
|
|
||||||
self.surfaces
|
self.surfaces.apply_mut(
|
||||||
.canvas(SurfaceId::Shadow)
|
&[
|
||||||
.clear(skia::Color::TRANSPARENT);
|
SurfaceId::Shadow,
|
||||||
|
SurfaceId::Overlay,
|
||||||
self.surfaces
|
SurfaceId::Fills,
|
||||||
.canvas(SurfaceId::Overlay)
|
SurfaceId::Strokes,
|
||||||
.clear(skia::Color::TRANSPARENT);
|
],
|
||||||
|
|s| {
|
||||||
self.surfaces
|
s.canvas().clear(skia::Color::TRANSPARENT);
|
||||||
.canvas(SurfaceId::Shape)
|
},
|
||||||
.clear(skia::Color::TRANSPARENT);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invalidate_cache_if_needed(&mut self) {
|
pub fn invalidate_cache_if_needed(&mut self) {
|
||||||
|
@ -221,22 +233,27 @@ impl RenderState {
|
||||||
modifiers: Option<&Matrix>,
|
modifiers: Option<&Matrix>,
|
||||||
clip_bounds: Option<(Rect, Option<Corners>, Matrix)>,
|
clip_bounds: Option<(Rect, Option<Corners>, Matrix)>,
|
||||||
) {
|
) {
|
||||||
self.surfaces.canvas(SurfaceId::Shape).save();
|
let surface_ids = &[SurfaceId::Fills, SurfaceId::Strokes];
|
||||||
|
self.surfaces.apply_mut(surface_ids, |s| {
|
||||||
|
s.canvas().save();
|
||||||
|
});
|
||||||
|
|
||||||
|
// set clipping
|
||||||
if let Some((bounds, corners, transform)) = clip_bounds {
|
if let Some((bounds, corners, transform)) = clip_bounds {
|
||||||
self.surfaces.canvas(SurfaceId::Shape).concat(&transform);
|
self.surfaces
|
||||||
|
.apply_mut(&[SurfaceId::Fills, SurfaceId::Strokes], |s| {
|
||||||
|
s.canvas().concat(&transform);
|
||||||
|
});
|
||||||
|
|
||||||
if let Some(corners) = corners {
|
if let Some(corners) = corners {
|
||||||
let rrect = RRect::new_rect_radii(bounds, &corners);
|
let rrect = RRect::new_rect_radii(bounds, &corners);
|
||||||
self.surfaces.canvas(SurfaceId::Shape).clip_rrect(
|
self.surfaces.apply_mut(surface_ids, |s| {
|
||||||
rrect,
|
s.canvas().clip_rrect(rrect, skia::ClipOp::Intersect, true);
|
||||||
skia::ClipOp::Intersect,
|
});
|
||||||
true,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
self.surfaces.canvas(SurfaceId::Shape).clip_rect(
|
self.surfaces.apply_mut(surface_ids, |s| {
|
||||||
bounds,
|
s.canvas().clip_rect(bounds, skia::ClipOp::Intersect, true);
|
||||||
skia::ClipOp::Intersect,
|
});
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.options.is_debug_visible() {
|
if self.options.is_debug_visible() {
|
||||||
|
@ -245,13 +262,14 @@ impl RenderState {
|
||||||
paint.set_color(skia::Color::from_argb(255, 255, 0, 0));
|
paint.set_color(skia::Color::from_argb(255, 255, 0, 0));
|
||||||
paint.set_stroke_width(4.);
|
paint.set_stroke_width(4.);
|
||||||
self.surfaces
|
self.surfaces
|
||||||
.canvas(SurfaceId::Shape)
|
.canvas(SurfaceId::Fills)
|
||||||
.draw_rect(bounds, &paint);
|
.draw_rect(bounds, &paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.surfaces
|
self.surfaces.apply_mut(surface_ids, |s| {
|
||||||
.canvas(SurfaceId::Shape)
|
s.canvas()
|
||||||
.concat(&transform.invert().unwrap_or(Matrix::default()));
|
.concat(&transform.invert().unwrap_or(Matrix::default()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone so we don't change the value in the global state
|
// Clone so we don't change the value in the global state
|
||||||
|
@ -262,7 +280,6 @@ impl RenderState {
|
||||||
}
|
}
|
||||||
|
|
||||||
let center = shape.center();
|
let center = shape.center();
|
||||||
|
|
||||||
let mut matrix = shape.transform;
|
let mut matrix = shape.transform;
|
||||||
matrix.post_translate(center);
|
matrix.post_translate(center);
|
||||||
matrix.pre_translate(-center);
|
matrix.pre_translate(-center);
|
||||||
|
@ -270,17 +287,17 @@ impl RenderState {
|
||||||
match &shape.shape_type {
|
match &shape.shape_type {
|
||||||
Type::SVGRaw(sr) => {
|
Type::SVGRaw(sr) => {
|
||||||
if let Some(modifiers) = modifiers {
|
if let Some(modifiers) = modifiers {
|
||||||
self.surfaces.canvas(SurfaceId::Shape).concat(&modifiers);
|
self.surfaces.canvas(SurfaceId::Fills).concat(&modifiers);
|
||||||
}
|
}
|
||||||
self.surfaces.canvas(SurfaceId::Shape).concat(&matrix);
|
self.surfaces.canvas(SurfaceId::Fills).concat(&matrix);
|
||||||
if let Some(svg) = shape.svg.as_ref() {
|
if let Some(svg) = shape.svg.as_ref() {
|
||||||
svg.render(self.surfaces.canvas(SurfaceId::Shape))
|
svg.render(self.surfaces.canvas(SurfaceId::Fills))
|
||||||
} else {
|
} else {
|
||||||
let font_manager = skia::FontMgr::from(self.font_provider.clone());
|
let font_manager = skia::FontMgr::from(self.font_provider.clone());
|
||||||
let dom_result = skia::svg::Dom::from_str(sr.content.to_string(), font_manager);
|
let dom_result = skia::svg::Dom::from_str(sr.content.to_string(), font_manager);
|
||||||
match dom_result {
|
match dom_result {
|
||||||
Ok(dom) => {
|
Ok(dom) => {
|
||||||
dom.render(self.surfaces.canvas(SurfaceId::Shape));
|
dom.render(self.surfaces.canvas(SurfaceId::Fills));
|
||||||
shape.set_svg(dom);
|
shape.set_svg(dom);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -290,7 +307,10 @@ impl RenderState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.surfaces.canvas(SurfaceId::Shape).concat(&matrix);
|
self.surfaces
|
||||||
|
.apply_mut(&[SurfaceId::Fills, SurfaceId::Strokes], |s| {
|
||||||
|
s.canvas().concat(&matrix);
|
||||||
|
});
|
||||||
|
|
||||||
for fill in shape.fills().rev() {
|
for fill in shape.fills().rev() {
|
||||||
fills::render(self, &shape, fill);
|
fills::render(self, &shape, fill);
|
||||||
|
@ -319,7 +339,10 @@ impl RenderState {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.apply_drawing_to_render_canvas();
|
self.apply_drawing_to_render_canvas();
|
||||||
self.surfaces.canvas(SurfaceId::Shape).restore();
|
self.surfaces
|
||||||
|
.apply_mut(&[SurfaceId::Fills, SurfaceId::Strokes], |s| {
|
||||||
|
s.canvas().restore();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_render_loop(
|
pub fn start_render_loop(
|
||||||
|
@ -328,20 +351,23 @@ impl RenderState {
|
||||||
modifiers: &HashMap<Uuid, Matrix>,
|
modifiers: &HashMap<Uuid, Matrix>,
|
||||||
timestamp: i32,
|
timestamp: i32,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
let surface_ids = &[SurfaceId::Fills, SurfaceId::Strokes];
|
||||||
|
|
||||||
if self.render_in_progress {
|
if self.render_in_progress {
|
||||||
if let Some(frame_id) = self.render_request_id {
|
if let Some(frame_id) = self.render_request_id {
|
||||||
self.cancel_animation_frame(frame_id);
|
self.cancel_animation_frame(frame_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.reset_canvas();
|
self.reset_canvas();
|
||||||
self.surfaces.canvas(SurfaceId::Shape).scale((
|
self.surfaces.apply_mut(surface_ids, |s| {
|
||||||
self.viewbox.zoom * self.options.dpr(),
|
s.canvas().scale((
|
||||||
self.viewbox.zoom * self.options.dpr(),
|
self.viewbox.zoom * self.options.dpr(),
|
||||||
));
|
self.viewbox.zoom * self.options.dpr(),
|
||||||
self.surfaces
|
));
|
||||||
.canvas(SurfaceId::Shape)
|
s.canvas()
|
||||||
.translate((self.viewbox.pan_x, self.viewbox.pan_y));
|
.translate((self.viewbox.pan_x, self.viewbox.pan_y));
|
||||||
//
|
});
|
||||||
|
|
||||||
self.pending_nodes = vec![NodeRenderState {
|
self.pending_nodes = vec![NodeRenderState {
|
||||||
id: Uuid::nil(),
|
id: Uuid::nil(),
|
||||||
visited_children: false,
|
visited_children: false,
|
||||||
|
@ -430,7 +456,8 @@ impl RenderState {
|
||||||
let image = &cached.image;
|
let image = &cached.image;
|
||||||
let paint = skia::Paint::default();
|
let paint = skia::Paint::default();
|
||||||
self.surfaces.canvas(SurfaceId::Target).save();
|
self.surfaces.canvas(SurfaceId::Target).save();
|
||||||
self.surfaces.canvas(SurfaceId::Shape).save();
|
self.surfaces.canvas(SurfaceId::Fills).save();
|
||||||
|
self.surfaces.canvas(SurfaceId::Strokes).save();
|
||||||
|
|
||||||
let navigate_zoom = self.viewbox.zoom / cached.viewbox.zoom;
|
let navigate_zoom = self.viewbox.zoom / cached.viewbox.zoom;
|
||||||
let navigate_x = cached.viewbox.zoom * (self.viewbox.pan_x - cached.viewbox.pan_x);
|
let navigate_x = cached.viewbox.zoom * (self.viewbox.pan_x - cached.viewbox.pan_x);
|
||||||
|
@ -451,7 +478,8 @@ impl RenderState {
|
||||||
.draw_image(image, (0, 0), Some(&paint));
|
.draw_image(image, (0, 0), Some(&paint));
|
||||||
|
|
||||||
self.surfaces.canvas(SurfaceId::Target).restore();
|
self.surfaces.canvas(SurfaceId::Target).restore();
|
||||||
self.surfaces.canvas(SurfaceId::Shape).restore();
|
self.surfaces.canvas(SurfaceId::Fills).restore();
|
||||||
|
self.surfaces.canvas(SurfaceId::Strokes).restore();
|
||||||
|
|
||||||
self.flush();
|
self.flush();
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,9 @@ pub fn render_debug_shape(render_state: &mut RenderState, element: &Shape, inter
|
||||||
|
|
||||||
pub fn render(render_state: &mut RenderState) {
|
pub fn render(render_state: &mut RenderState) {
|
||||||
render_debug_view(render_state);
|
render_debug_view(render_state);
|
||||||
render_state
|
render_state.surfaces.draw_into(
|
||||||
.surfaces
|
SurfaceId::Debug,
|
||||||
.draw_into(SurfaceId::Debug, SurfaceId::Current, None);
|
SurfaceId::Current,
|
||||||
|
Some(&skia::Paint::default()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn draw_image_fill_in_container(
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = image_fill.size();
|
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 container = &shape.selrect;
|
||||||
let path_transform = shape.to_path_transform();
|
let path_transform = shape.to_path_transform();
|
||||||
let paint = fill.to_paint(container);
|
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.
|
* This SHOULD be the only public function in this module.
|
||||||
*/
|
*/
|
||||||
pub fn render(render_state: &mut RenderState, shape: &Shape, fill: &Fill) {
|
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 selrect = shape.selrect;
|
||||||
let path_transform = shape.to_path_transform();
|
let path_transform = shape.to_path_transform();
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,16 @@ pub fn render_drop_shadow(render_state: &mut RenderState, shadow: &Shadow, scale
|
||||||
let shadow_paint = shadow.to_paint(scale);
|
let shadow_paint = shadow.to_paint(scale);
|
||||||
render_state
|
render_state
|
||||||
.surfaces
|
.surfaces
|
||||||
.draw_into(SurfaceId::Shape, SurfaceId::Shadow, Some(&shadow_paint));
|
.draw_into(SurfaceId::Fills, SurfaceId::Shadow, Some(&shadow_paint));
|
||||||
|
|
||||||
render_state
|
render_state
|
||||||
.surfaces
|
.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
|
render_state
|
||||||
.surfaces
|
.surfaces
|
||||||
|
@ -24,7 +29,7 @@ pub fn render_inner_shadow(render_state: &mut RenderState, shadow: &Shadow, scal
|
||||||
|
|
||||||
render_state
|
render_state
|
||||||
.surfaces
|
.surfaces
|
||||||
.draw_into(SurfaceId::Shape, SurfaceId::Shadow, Some(&shadow_paint)); // , ShadowPaint
|
.draw_into(SurfaceId::Fills, SurfaceId::Shadow, Some(&shadow_paint));
|
||||||
|
|
||||||
render_state
|
render_state
|
||||||
.surfaces
|
.surfaces
|
||||||
|
|
|
@ -330,7 +330,7 @@ fn draw_image_stroke_in_container(
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = image_fill.size();
|
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 container = &shape.selrect;
|
||||||
let path_transform = shape.to_path_transform();
|
let path_transform = shape.to_path_transform();
|
||||||
let svg_attrs = &shape.svg_attrs;
|
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.
|
* This SHOULD be the only public function in this module.
|
||||||
*/
|
*/
|
||||||
pub fn render(render_state: &mut RenderState, shape: &Shape, stroke: &Stroke) {
|
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 dpr_scale = render_state.viewbox.zoom * render_state.options.dpr();
|
||||||
let selrect = shape.selrect;
|
let selrect = shape.selrect;
|
||||||
let path_transform = shape.to_path_transform();
|
let path_transform = shape.to_path_transform();
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use super::gpu_state::GpuState;
|
use super::gpu_state::GpuState;
|
||||||
use skia_safe as skia;
|
use skia_safe as skia;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub enum SurfaceId {
|
pub enum SurfaceId {
|
||||||
Target,
|
Target,
|
||||||
Current,
|
Current,
|
||||||
Shape,
|
Fills,
|
||||||
|
Strokes,
|
||||||
Shadow,
|
Shadow,
|
||||||
Overlay,
|
Overlay,
|
||||||
Debug,
|
Debug,
|
||||||
|
@ -15,8 +17,10 @@ pub struct Surfaces {
|
||||||
target: skia::Surface,
|
target: skia::Surface,
|
||||||
// keeps the current render
|
// keeps the current render
|
||||||
current: skia::Surface,
|
current: skia::Surface,
|
||||||
// keeps the current shape
|
// keeps the current shape's fills
|
||||||
shape: skia::Surface,
|
shape_fills: skia::Surface,
|
||||||
|
// keeps the current shape's strokes
|
||||||
|
shape_strokes: skia::Surface,
|
||||||
// used for rendering shadows
|
// used for rendering shadows
|
||||||
shadow: skia::Surface,
|
shadow: skia::Surface,
|
||||||
// for drawing the things that are over shadows.
|
// 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 current = target.new_surface_with_dimensions((width, height)).unwrap();
|
||||||
let shadow = 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 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();
|
let debug = target.new_surface_with_dimensions((width, height)).unwrap();
|
||||||
|
|
||||||
Surfaces {
|
Surfaces {
|
||||||
|
@ -45,7 +50,8 @@ impl Surfaces {
|
||||||
current,
|
current,
|
||||||
shadow,
|
shadow,
|
||||||
overlay,
|
overlay,
|
||||||
shape,
|
shape_fills,
|
||||||
|
shape_strokes,
|
||||||
debug,
|
debug,
|
||||||
sampling_options,
|
sampling_options,
|
||||||
}
|
}
|
||||||
|
@ -76,13 +82,21 @@ impl Surfaces {
|
||||||
.draw(self.canvas(to), (0.0, 0.0), sampling_options, paint);
|
.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 {
|
fn get_mut(&mut self, id: SurfaceId) -> &mut skia::Surface {
|
||||||
match id {
|
match id {
|
||||||
SurfaceId::Target => &mut self.target,
|
SurfaceId::Target => &mut self.target,
|
||||||
SurfaceId::Current => &mut self.current,
|
SurfaceId::Current => &mut self.current,
|
||||||
SurfaceId::Shadow => &mut self.shadow,
|
SurfaceId::Shadow => &mut self.shadow,
|
||||||
SurfaceId::Overlay => &mut self.overlay,
|
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,
|
SurfaceId::Debug => &mut self.debug,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +107,7 @@ impl Surfaces {
|
||||||
self.current = self.target.new_surface_with_dimensions(dim).unwrap();
|
self.current = self.target.new_surface_with_dimensions(dim).unwrap();
|
||||||
self.overlay = 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.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();
|
self.debug = self.target.new_surface_with_dimensions(dim).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue