Skip to content

Commit f2d71ab

Browse files
committed
Add filter and backdrop to PaintScene and LayerCommand
Signed-off-by: Nico Burns <nico@nicoburns.com>
1 parent 6765bca commit f2d71ab

11 files changed

Lines changed: 49 additions & 6 deletions

File tree

crates/anyrender/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use recording::RenderCommand;
4444
use std::{any::Any, sync::Arc};
4545

4646
pub mod filters;
47+
pub use filters::Filter;
4748
pub mod wasm_send_sync;
4849
pub use wasm_send_sync::*;
4950
pub mod types;
@@ -192,6 +193,8 @@ pub trait PaintScene: RenderContext {
192193
alpha: f32,
193194
transform: Affine,
194195
clip: &impl Shape,
196+
filter: Option<Arc<Filter>>,
197+
backdrop_filter: Option<Arc<Filter>>,
195198
);
196199

197200
/// Pushes a new clip layer clipped by the specified shape.
@@ -260,6 +263,8 @@ pub trait PaintScene: RenderContext {
260263
cmd.alpha,
261264
scene_transform * cmd.transform,
262265
&cmd.clip,
266+
cmd.filter,
267+
cmd.backdrop_filter,
263268
),
264269
RenderCommand::PushClipLayer(cmd) => {
265270
self.push_clip_layer(scene_transform * cmd.transform, &cmd.clip)

crates/anyrender/src/null_backend.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A dummy implementation of the AnyRender traits while simply ignores all commands
22
3-
use crate::{ImageRenderer, PaintScene, RenderContext, WindowHandle, WindowRenderer};
3+
use crate::{Filter, ImageRenderer, PaintScene, RenderContext, WindowHandle, WindowRenderer};
44
use std::sync::Arc;
55

66
#[derive(Copy, Clone, Default)]
@@ -102,6 +102,8 @@ impl PaintScene for NullScenePainter {
102102
_alpha: f32,
103103
_transform: kurbo::Affine,
104104
_clip: &impl kurbo::Shape,
105+
_filter: Option<Arc<Filter>>,
106+
_backdrop_filter: Option<Arc<Filter>>,
105107
) {
106108
}
107109

crates/anyrender/src/recording.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::{Glyph, NormalizedCoord, Paint, PaintRef, PaintScene, RenderContext};
1+
use std::sync::Arc;
2+
3+
use crate::{Filter, Glyph, NormalizedCoord, Paint, PaintRef, PaintScene, RenderContext};
24
use kurbo::{Affine, BezPath, Rect, Shape, Stroke};
35
use peniko::{BlendMode, Color, Fill, FontData, Style, StyleRef};
46

@@ -58,6 +60,8 @@ pub struct LayerCommand {
5860
pub transform: Affine,
5961
#[cfg_attr(feature = "serde", serde(with = "svg_path"))]
6062
pub clip: BezPath, // TODO: more shape options
63+
pub filter: Option<Arc<Filter>>,
64+
pub backdrop_filter: Option<Arc<Filter>>,
6165
}
6266

6367
/// Pushes a new clip layer clipped by the specified shape.
@@ -178,6 +182,8 @@ impl PaintScene for Scene {
178182
alpha: f32,
179183
transform: Affine,
180184
clip: &impl Shape,
185+
filter: Option<Arc<Filter>>,
186+
backdrop_filter: Option<Arc<Filter>>,
181187
) {
182188
let blend = blend.into();
183189
let clip = clip.into_path(self.tolerance);
@@ -186,6 +192,8 @@ impl PaintScene for Scene {
186192
alpha,
187193
transform,
188194
clip,
195+
filter,
196+
backdrop_filter,
189197
};
190198
self.commands.push(RenderCommand::PushLayer(layer));
191199
}

crates/anyrender_serialize/tests/serialize.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ fn test_all_command_types_roundtrip() {
3030
0.75,
3131
Affine::translate((5.0, 5.0)),
3232
&Rect::new(0.0, 0.0, 500.0, 500.0),
33+
None,
34+
None,
3335
);
3436

3537
// Fill (NonZero)
@@ -85,6 +87,8 @@ fn test_all_command_types_roundtrip() {
8587
1.0,
8688
Affine::IDENTITY,
8789
&Rect::new(0.0, 0.0, 500.0, 500.0),
90+
None,
91+
None,
8892
);
8993
scene.fill(
9094
Fill::NonZero,

crates/anyrender_skia/src/scene.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use anyrender::{PaintScene, RenderContext};
1+
use std::sync::Arc;
2+
3+
use anyrender::{Filter, PaintScene, RenderContext};
24
use peniko::color::AlphaColor;
35
use skia_safe::{
46
BlurStyle, Canvas, Color, ColorSpace, Font, FontArguments, FontHinting, FontMgr, GlyphId,
@@ -411,6 +413,8 @@ impl PaintScene for SkiaScenePainter<'_> {
411413
alpha: f32,
412414
transform: kurbo::Affine,
413415
clip: &impl kurbo::Shape,
416+
_filter: Option<Arc<Filter>>,
417+
_backdrop_filter: Option<Arc<Filter>>,
414418
) {
415419
let blend: peniko::BlendMode = blend.into();
416420

crates/anyrender_svg/src/render.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub(crate) fn render_group<S: PaintScene, F: FnMut(&mut S, &usvg::Node)>(
3939
alpha,
4040
global_transform * transform,
4141
&local_path,
42+
None,
43+
None,
4244
);
4345

4446
true
@@ -60,6 +62,8 @@ pub(crate) fn render_group<S: PaintScene, F: FnMut(&mut S, &usvg::Node)>(
6062
alpha,
6163
global_transform * transform,
6264
&rect,
65+
None,
66+
None,
6367
);
6468

6569
true

crates/anyrender_vello/src/scene.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use anyrender::{NormalizedCoord, Paint, PaintRef, PaintScene, RenderContext, ResourceId};
1+
use std::sync::Arc;
2+
3+
use anyrender::{Filter, NormalizedCoord, Paint, PaintRef, PaintScene, RenderContext, ResourceId};
24
use kurbo::{Affine, Rect, Shape, Stroke};
35
use peniko::{BlendMode, BrushRef, Color, Fill, FontData, ImageBrush, ImageData, StyleRef};
46
use rustc_hash::FxHashMap;
@@ -70,6 +72,8 @@ impl PaintScene for VelloScenePainter<'_, '_> {
7072
alpha: f32,
7173
transform: Affine,
7274
clip: &impl Shape,
75+
_filter: Option<Arc<Filter>>,
76+
_backdrop_filter: Option<Arc<Filter>>,
7377
) {
7478
self.inner
7579
.push_layer(Fill::NonZero, blend, alpha, transform, clip);

crates/anyrender_vello_cpu/src/scene.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use anyrender::{NormalizedCoord, Paint, PaintRef, PaintScene, RenderContext};
1+
use std::sync::Arc;
2+
3+
use anyrender::{Filter, NormalizedCoord, Paint, PaintRef, PaintScene, RenderContext};
24
use glifo::FontEmbolden;
35
use kurbo::{Affine, Diagonal2, Rect, Shape, Stroke};
46
use peniko::{BlendMode, Color, Fill, FontData, ImageBrush, StyleRef};
@@ -63,6 +65,8 @@ impl PaintScene for VelloCpuScenePainter {
6365
alpha: f32,
6466
transform: Affine,
6567
clip: &impl Shape,
68+
_filter: Option<Arc<Filter>>,
69+
_backdrop_filter: Option<Arc<Filter>>,
6670
) {
6771
self.render_ctx.set_transform(transform);
6872
self.render_ctx.push_layer(

crates/anyrender_vello_hybrid/src/scene.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use anyrender::{NormalizedCoord, Paint, PaintRef, PaintScene, RenderContext, ResourceId};
1+
use std::sync::Arc;
2+
3+
use anyrender::{Filter, NormalizedCoord, Paint, PaintRef, PaintScene, RenderContext, ResourceId};
24
use glifo::FontEmbolden;
35
use kurbo::{Affine, Diagonal2, Rect, Shape, Stroke};
46
use peniko::{BlendMode, Color, Fill, FontData, ImageBrush, ImageData, StyleRef};
@@ -176,6 +178,8 @@ impl PaintScene for VelloHybridScenePainter<'_> {
176178
alpha: f32,
177179
transform: Affine,
178180
clip: &impl Shape,
181+
_filter: Option<Arc<Filter>>,
182+
_backdrop_filter: Option<Arc<Filter>>,
179183
) {
180184
self.scene.set_transform(transform);
181185
self.layer_stack.push(LayerKind::Layer);

crates/anyrender_vello_hybrid/src/webgl_scene.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ impl PaintScene for WebGlScenePainter<'_> {
107107
alpha: f32,
108108
transform: Affine,
109109
clip: &impl Shape,
110+
_filter: Option<Arc<Filter>>,
111+
_backdrop_filter: Option<Arc<Filter>>,
110112
) {
111113
self.scene.set_transform(transform);
112114
self.layer_stack.push(LayerKind::Layer);

0 commit comments

Comments
 (0)