Merge pull request #256 from linebender/peniko-updates

Update for peniko changes and pin git rev
This commit is contained in:
Chad Brokaw 2023-01-17 13:01:11 -05:00 committed by GitHub
commit 3933c159a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 66 additions and 4295 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target /target
Cargo.lock

4245
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -25,8 +25,8 @@ futures-intrusive = "0.5.0"
parking_lot = "0.12" parking_lot = "0.12"
bytemuck = { version = "1.12.1", features = ["derive"] } bytemuck = { version = "1.12.1", features = ["derive"] }
smallvec = "1.8.0" smallvec = "1.8.0"
moscato = { git = "https://github.com/dfrg/pinot" } moscato = { git = "https://github.com/dfrg/pinot", rev = "59db153" }
peniko = { git = "https://github.com/linebender/peniko" } peniko = { git = "https://github.com/linebender/peniko", rev = "8cb710f" }
[features] [features]
hot_reload = [] hot_reload = []

View file

@ -1,5 +1,5 @@
use vello::kurbo::{Affine, Point, Rect}; 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 vello::{Renderer, Scene, SceneBuilder, SceneFragment};
use bevy::{ 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) { fn render_brush_transform(sb: &mut SceneBuilder, i: usize) {
let th = (std::f64::consts::PI / 180.0) * (i as f64); 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::RED,
Color::GREEN, Color::GREEN,
Color::BLUE, Color::BLUE,

View file

@ -225,7 +225,8 @@ pub fn render_blend_grid(sb: &mut SceneBuilder) {
fn render_blend_square(sb: &mut SceneBuilder, blend: BlendMode, transform: Affine) { 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 // 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 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); sb.fill(Fill::NonZero, transform, &linear, None, &rect);
const GRADIENTS: &[(f64, f64, Color)] = &[ const GRADIENTS: &[(f64, f64, Color)] = &[
(150., 0., Color::rgb8(255, 240, 64)), (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 { for (x, y, c) in GRADIENTS {
let mut color2 = c.clone(); let mut color2 = c.clone();
color2.a = 0; 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); sb.fill(Fill::NonZero, transform, &radial, None, &rect);
} }
const COLORS: &[Color] = &[ 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); sb.push_layer(Mix::Normal, 1.0, transform, &rect);
for (i, c) in COLORS.iter().enumerate() { 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); sb.push_layer(blend, 1.0, transform, &rect);
// squash the ellipse // squash the ellipse
let a = transform let a = transform
@ -364,7 +365,7 @@ pub fn render_anim_frame(sb: &mut SceneBuilder, text: &mut SimpleText, i: usize)
#[allow(unused)] #[allow(unused)]
pub fn render_brush_transform(sb: &mut SceneBuilder, i: usize) { pub fn render_brush_transform(sb: &mut SceneBuilder, i: usize) {
let th = (std::f64::consts::PI / 180.0) * (i as f64); 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::RED,
Color::GREEN, Color::GREEN,
Color::BLUE, Color::BLUE,

View file

@ -19,7 +19,7 @@ use super::{
DrawColor, DrawLinearGradient, DrawRadialGradient, DrawTag, PathEncoder, PathTag, Transform, 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. /// Encoded data streams for a scene.
#[derive(Default)] #[derive(Default)]
@ -159,33 +159,45 @@ impl Encoding {
}; };
self.encode_color(DrawColor::new(color)); self.encode_color(DrawColor::new(color));
} }
BrushRef::LinearGradient(gradient) => { BrushRef::Gradient(gradient) => match gradient.kind {
self.encode_linear_gradient( GradientKind::Linear { start, end } => {
DrawLinearGradient { self.encode_linear_gradient(
index: 0, DrawLinearGradient {
p0: point_to_f32(gradient.start), index: 0,
p1: point_to_f32(gradient.end), p0: point_to_f32(start),
}, p1: point_to_f32(end),
gradient.stops.iter().copied(), },
alpha, gradient.stops.iter().copied(),
gradient.extend, alpha,
); gradient.extend,
);
}
GradientKind::Radial {
start_center,
start_radius,
end_center,
end_radius,
} => {
self.encode_radial_gradient(
DrawRadialGradient {
index: 0,
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,
);
}
GradientKind::Sweep { .. } => {
todo!("sweep gradients aren't supported yet!")
}
},
BrushRef::Image(_) => {
todo!("images aren't supported yet!")
} }
BrushRef::RadialGradient(gradient) => {
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,
},
gradient.stops.iter().copied(),
alpha,
gradient.extend,
);
}
BrushRef::SweepGradient(_gradient) => todo!("sweep gradients aren't done yet!"),
} }
} }

View file

@ -266,7 +266,7 @@ fn convert_point(point: moscato::Point) -> peniko::kurbo::Point {
} }
fn convert_brush(brush: &moscato::Brush) -> peniko::Brush { fn convert_brush(brush: &moscato::Brush) -> peniko::Brush {
use peniko::{LinearGradient, RadialGradient}; use peniko::Gradient;
match brush { match brush {
moscato::Brush::Solid(color) => Brush::Solid(Color { moscato::Brush::Solid(color) => Brush::Solid(Color {
r: color.r, r: color.r,
@ -274,20 +274,22 @@ fn convert_brush(brush: &moscato::Brush) -> peniko::Brush {
b: color.b, b: color.b,
a: color.a, a: color.a,
}), }),
moscato::Brush::LinearGradient(grad) => Brush::LinearGradient(LinearGradient { moscato::Brush::LinearGradient(grad) => Brush::Gradient(
start: convert_point(grad.start), Gradient::new_linear(convert_point(grad.start), convert_point(grad.end))
end: convert_point(grad.end), .with_stops(convert_stops(&grad.stops).as_slice())
stops: convert_stops(&grad.stops), .with_extend(convert_extend(grad.extend)),
extend: convert_extend(grad.extend), ),
}),
moscato::Brush::RadialGradient(grad) => Brush::RadialGradient(RadialGradient { moscato::Brush::RadialGradient(grad) => Brush::Gradient(
start_center: convert_point(grad.center0), Gradient::new_two_point_radial(
end_center: convert_point(grad.center1), convert_point(grad.center0),
start_radius: grad.radius0, grad.radius0,
end_radius: grad.radius1, convert_point(grad.center1),
stops: convert_stops(&grad.stops), grad.radius1,
extend: convert_extend(grad.extend), )
}), .with_stops(convert_stops(&grad.stops).as_slice())
.with_extend(convert_extend(grad.extend)),
),
} }
} }