Skip to content

Commit

Permalink
Update to Vello 0.3, Peniko 0.2 (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys authored Dec 18, 2024
1 parent 6fb9579 commit 5e0269e
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 64 deletions.
146 changes: 111 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ vello = ["dep:vello"]
[dependencies]
hashbrown = "0.15.1"
keyframe = { version = "1.1.1", default-features = false, features = ["mint_types"] }
kurbo = { version = "0.11", default-features = false }
peniko = { version = "0.1.1", default-features = false }
vello = { version = "0.2.0", default-features = false, optional = true }
kurbo = { version = "0.11.1", default-features = false }
peniko = { version = "0.2.0", default-features = false }
vello = { version = "0.3.0", default-features = false, optional = true }

[lints]
rust.unsafe_code = "forbid"
Expand Down
2 changes: 1 addition & 1 deletion src/animated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl Brush {
/// Evaluates the animation at the specified time.
pub fn evaluate(&self, alpha: f64, frame: f64) -> fixed::Brush {
match self {
Self::Solid(value) => value.evaluate(frame).with_alpha_factor(alpha as f32).into(),
Self::Solid(value) => value.evaluate(frame).multiply_alpha(alpha as f32).into(),
Self::Gradient(value) => value.evaluate(frame),
}
}
Expand Down
23 changes: 0 additions & 23 deletions src/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,3 @@ impl Repeater {
* Affine::translate((-self.anchor_point.x, -self.anchor_point.y))
}
}

// TODO: probably move this to peniko. The better option is to add an alpha
// parameter to the draw methods in vello. This is already handled at the
// encoding level.
pub(crate) fn brush_with_alpha(brush: &Brush, alpha: f64) -> Brush {
if alpha == 1.0 {
brush.clone()
} else {
match brush {
Brush::Solid(color) => color.with_alpha_factor(alpha as f32).into(),
Brush::Gradient(gradient) => Brush::Gradient(peniko::Gradient {
kind: gradient.kind,
extend: gradient.extend,
stops: gradient
.stops
.iter()
.map(|stop| stop.with_alpha_factor(alpha as f32))
.collect(),
}),
_ => unreachable!(),
}
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Brush {
if alpha == 1.0 {
ValueRef::Borrowed(value)
} else {
ValueRef::Owned(fixed::brush_with_alpha(value, alpha))
ValueRef::Owned(value.clone().multiply_alpha(alpha as f32))
}
}
Self::Animated(value) => ValueRef::Owned(value.evaluate(alpha, frame)),
Expand Down
2 changes: 1 addition & 1 deletion src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl Batch {
for draw in self.draws.iter().rev() {
// Some nastiness to avoid cloning the brush if unnecessary
let modified_brush = if draw.alpha != 1.0 {
Some(fixed::brush_with_alpha(&draw.brush, draw.alpha))
Some(draw.brush.clone().multiply_alpha(draw.alpha as f32))
} else {
None
};
Expand Down

0 comments on commit 5e0269e

Please sign in to comment.