mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 20:31:29 +11:00
Update for peniko changes
This applies updates for the gradient API in peniko and pins the git dependency so prevent further breakage. Also removes Cargo.lock.
This commit is contained in:
parent
3902e65618
commit
516fd6c981
4245
Cargo.lock
generated
4245
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -26,7 +26,7 @@ parking_lot = "0.12"
|
|||
bytemuck = { version = "1.12.1", features = ["derive"] }
|
||||
smallvec = "1.8.0"
|
||||
moscato = { git = "https://github.com/dfrg/pinot" }
|
||||
peniko = { git = "https://github.com/linebender/peniko" }
|
||||
peniko = { git = "https://github.com/linebender/peniko", rev = "ba96b90" }
|
||||
|
||||
[features]
|
||||
hot_reload = []
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use vello::kurbo::{Affine, Point, Rect};
|
||||
use vello::peniko::{Color, Fill, LinearGradient, Stroke};
|
||||
use vello::peniko::{Color, Fill, Gradient, Stroke};
|
||||
use vello::{Renderer, Scene, SceneBuilder, SceneFragment};
|
||||
|
||||
use bevy::{
|
||||
|
@ -191,7 +191,7 @@ fn render_fragment(mut fragment: Query<&mut VelloFragment>, mut frame: Local<usi
|
|||
|
||||
fn render_brush_transform(sb: &mut SceneBuilder, i: usize) {
|
||||
let th = (std::f64::consts::PI / 180.0) * (i as f64);
|
||||
let linear = LinearGradient::new((0.0, 0.0), (0.0, 200.0)).stops([
|
||||
let linear = Gradient::new_linear((0.0, 0.0), (0.0, 200.0)).with_stops([
|
||||
Color::RED,
|
||||
Color::GREEN,
|
||||
Color::BLUE,
|
||||
|
|
|
@ -225,7 +225,8 @@ pub fn render_blend_grid(sb: &mut SceneBuilder) {
|
|||
fn render_blend_square(sb: &mut SceneBuilder, blend: BlendMode, transform: Affine) {
|
||||
// Inspired by https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode
|
||||
let rect = Rect::from_origin_size(Point::new(0., 0.), (200., 200.));
|
||||
let linear = LinearGradient::new((0.0, 0.0), (200.0, 0.0)).stops([Color::BLACK, Color::WHITE]);
|
||||
let linear =
|
||||
Gradient::new_linear((0.0, 0.0), (200.0, 0.0)).with_stops([Color::BLACK, Color::WHITE]);
|
||||
sb.fill(Fill::NonZero, transform, &linear, None, &rect);
|
||||
const GRADIENTS: &[(f64, f64, Color)] = &[
|
||||
(150., 0., Color::rgb8(255, 240, 64)),
|
||||
|
@ -235,7 +236,7 @@ fn render_blend_square(sb: &mut SceneBuilder, blend: BlendMode, transform: Affin
|
|||
for (x, y, c) in GRADIENTS {
|
||||
let mut color2 = c.clone();
|
||||
color2.a = 0;
|
||||
let radial = RadialGradient::new((*x, *y), 100.0).stops([*c, color2]);
|
||||
let radial = Gradient::new_radial((*x, *y), 100.0).with_stops([*c, color2]);
|
||||
sb.fill(Fill::NonZero, transform, &radial, None, &rect);
|
||||
}
|
||||
const COLORS: &[Color] = &[
|
||||
|
@ -245,7 +246,7 @@ fn render_blend_square(sb: &mut SceneBuilder, blend: BlendMode, transform: Affin
|
|||
];
|
||||
sb.push_layer(Mix::Normal, 1.0, transform, &rect);
|
||||
for (i, c) in COLORS.iter().enumerate() {
|
||||
let linear = LinearGradient::new((0.0, 0.0), (0.0, 200.0)).stops([Color::WHITE, *c]);
|
||||
let linear = Gradient::new_linear((0.0, 0.0), (0.0, 200.0)).with_stops([Color::WHITE, *c]);
|
||||
sb.push_layer(blend, 1.0, transform, &rect);
|
||||
// squash the ellipse
|
||||
let a = transform
|
||||
|
@ -364,7 +365,7 @@ pub fn render_anim_frame(sb: &mut SceneBuilder, text: &mut SimpleText, i: usize)
|
|||
#[allow(unused)]
|
||||
pub fn render_brush_transform(sb: &mut SceneBuilder, i: usize) {
|
||||
let th = (std::f64::consts::PI / 180.0) * (i as f64);
|
||||
let linear = LinearGradient::new((0.0, 0.0), (0.0, 200.0)).stops([
|
||||
let linear = Gradient::new_linear((0.0, 0.0), (0.0, 200.0)).with_stops([
|
||||
Color::RED,
|
||||
Color::GREEN,
|
||||
Color::BLUE,
|
||||
|
|
|
@ -19,7 +19,7 @@ use super::{
|
|||
DrawColor, DrawLinearGradient, DrawRadialGradient, DrawTag, PathEncoder, PathTag, Transform,
|
||||
};
|
||||
|
||||
use peniko::{kurbo::Shape, BlendMode, BrushRef, Color, ColorStop, Extend};
|
||||
use peniko::{kurbo::Shape, BlendMode, BrushRef, Color, ColorStop, Extend, GradientKind};
|
||||
|
||||
/// Encoded data streams for a scene.
|
||||
#[derive(Default)]
|
||||
|
@ -159,33 +159,45 @@ impl Encoding {
|
|||
};
|
||||
self.encode_color(DrawColor::new(color));
|
||||
}
|
||||
BrushRef::LinearGradient(gradient) => {
|
||||
BrushRef::Gradient(gradient) => match gradient.kind {
|
||||
GradientKind::Linear { start, end } => {
|
||||
self.encode_linear_gradient(
|
||||
DrawLinearGradient {
|
||||
index: 0,
|
||||
p0: point_to_f32(gradient.start),
|
||||
p1: point_to_f32(gradient.end),
|
||||
p0: point_to_f32(start),
|
||||
p1: point_to_f32(end),
|
||||
},
|
||||
gradient.stops.iter().copied(),
|
||||
alpha,
|
||||
gradient.extend,
|
||||
);
|
||||
}
|
||||
BrushRef::RadialGradient(gradient) => {
|
||||
GradientKind::Radial {
|
||||
start_center,
|
||||
start_radius,
|
||||
end_center,
|
||||
end_radius,
|
||||
} => {
|
||||
self.encode_radial_gradient(
|
||||
DrawRadialGradient {
|
||||
index: 0,
|
||||
p0: point_to_f32(gradient.start_center),
|
||||
p1: point_to_f32(gradient.end_center),
|
||||
r0: gradient.start_radius,
|
||||
r1: gradient.end_radius,
|
||||
p0: point_to_f32(start_center),
|
||||
p1: point_to_f32(end_center),
|
||||
r0: start_radius,
|
||||
r1: end_radius,
|
||||
},
|
||||
gradient.stops.iter().copied(),
|
||||
alpha,
|
||||
gradient.extend,
|
||||
);
|
||||
}
|
||||
BrushRef::SweepGradient(_gradient) => todo!("sweep gradients aren't done yet!"),
|
||||
GradientKind::Sweep { .. } => {
|
||||
todo!("sweep gradients aren't supported yet!")
|
||||
}
|
||||
},
|
||||
BrushRef::Image(_) => {
|
||||
todo!("images aren't supported yet!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
32
src/glyph.rs
32
src/glyph.rs
|
@ -266,7 +266,7 @@ fn convert_point(point: moscato::Point) -> peniko::kurbo::Point {
|
|||
}
|
||||
|
||||
fn convert_brush(brush: &moscato::Brush) -> peniko::Brush {
|
||||
use peniko::{LinearGradient, RadialGradient};
|
||||
use peniko::Gradient;
|
||||
match brush {
|
||||
moscato::Brush::Solid(color) => Brush::Solid(Color {
|
||||
r: color.r,
|
||||
|
@ -274,20 +274,22 @@ fn convert_brush(brush: &moscato::Brush) -> peniko::Brush {
|
|||
b: color.b,
|
||||
a: color.a,
|
||||
}),
|
||||
moscato::Brush::LinearGradient(grad) => Brush::LinearGradient(LinearGradient {
|
||||
start: convert_point(grad.start),
|
||||
end: convert_point(grad.end),
|
||||
stops: convert_stops(&grad.stops),
|
||||
extend: convert_extend(grad.extend),
|
||||
}),
|
||||
moscato::Brush::RadialGradient(grad) => Brush::RadialGradient(RadialGradient {
|
||||
start_center: convert_point(grad.center0),
|
||||
end_center: convert_point(grad.center1),
|
||||
start_radius: grad.radius0,
|
||||
end_radius: grad.radius1,
|
||||
stops: convert_stops(&grad.stops),
|
||||
extend: convert_extend(grad.extend),
|
||||
}),
|
||||
moscato::Brush::LinearGradient(grad) => Brush::Gradient(
|
||||
Gradient::new_linear(convert_point(grad.start), convert_point(grad.end))
|
||||
.with_stops(convert_stops(&grad.stops).as_slice())
|
||||
.with_extend(convert_extend(grad.extend)),
|
||||
),
|
||||
|
||||
moscato::Brush::RadialGradient(grad) => Brush::Gradient(
|
||||
Gradient::new_two_point_radial(
|
||||
convert_point(grad.center0),
|
||||
grad.radius0,
|
||||
convert_point(grad.center1),
|
||||
grad.radius1,
|
||||
)
|
||||
.with_stops(convert_stops(&grad.stops).as_slice())
|
||||
.with_extend(convert_extend(grad.extend)),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue