Skip to content

Commit acde7a5

Browse files
authored
Add push_clip_layer (#30)
* Add `push_clip_layer` Signed-off-by: sagudev <[email protected]> * add `transform: Affine` to `push_clip_layer` Signed-off-by: sagudev <[email protected]> --------- Signed-off-by: sagudev <[email protected]>
1 parent 1ecfe8d commit acde7a5

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

crates/anyrender/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ pub trait PaintScene {
9595
clip: &impl Shape,
9696
);
9797

98+
/// Pushes a new clip layer clipped by the specified shape.
99+
/// Every drawing command after this call will be clipped by the shape until the layer is popped.
100+
/// However, the transforms are not saved or modified by the layer stack.
101+
fn push_clip_layer(&mut self, transform: Affine, clip: &impl Shape);
102+
98103
/// Pops the current layer.
99104
fn pop_layer(&mut self);
100105

crates/anyrender/src/null_backend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ impl PaintScene for NullScenePainter {
9191
) {
9292
}
9393

94+
fn push_clip_layer(&mut self, _transform: kurbo::Affine, _clip: &impl kurbo::Shape) {}
95+
9496
fn pop_layer(&mut self) {}
9597

9698
fn stroke<'a>(

crates/anyrender_skia/src/scene.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ impl PaintScene for SkiaScenePainter<'_> {
394394
}
395395
}
396396

397+
fn push_clip_layer(&mut self, transform: kurbo::Affine, clip: &impl kurbo::Shape) {
398+
self.inner.save(); // we need to do two saves because of pop_layer
399+
400+
self.set_matrix(transform);
401+
self.clip(clip);
402+
self.inner.save();
403+
}
404+
397405
fn pop_layer(&mut self) {
398406
self.inner.restore();
399407
self.inner.restore();

crates/anyrender_vello/src/scene.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ impl PaintScene for VelloScenePainter<'_, '_> {
6060
self.inner.push_layer(blend, alpha, transform, clip);
6161
}
6262

63+
fn push_clip_layer(&mut self, transform: Affine, clip: &impl Shape) {
64+
self.inner.push_clip_layer(transform, clip);
65+
}
66+
6367
fn pop_layer(&mut self) {
6468
self.inner.pop_layer();
6569
}

crates/anyrender_vello_cpu/src/scene.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ impl PaintScene for VelloCpuScenePainter {
6363
);
6464
}
6565

66+
fn push_clip_layer(&mut self, transform: Affine, clip: &impl Shape) {
67+
self.0.set_transform(transform);
68+
self.0.push_clip_layer(&clip.into_path(DEFAULT_TOLERANCE));
69+
}
70+
6671
fn pop_layer(&mut self) {
6772
self.0.pop_layer();
6873
}

crates/anyrender_vello_hybrid/src/scene.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ impl PaintScene for VelloHybridScenePainter<'_> {
103103
);
104104
}
105105

106+
fn push_clip_layer(&mut self, transform: Affine, clip: &impl Shape) {
107+
self.scene.set_transform(transform);
108+
self.scene
109+
.push_clip_layer(&clip.into_path(DEFAULT_TOLERANCE));
110+
}
111+
106112
fn pop_layer(&mut self) {
107113
self.scene.pop_layer();
108114
}

0 commit comments

Comments
 (0)