Skip to content

Commit

Permalink
Update Peniko to 0.2.0 (#693)
Browse files Browse the repository at this point in the history
This updates Peniko to
[0.2.0](https://github.com/linebender/peniko/releases/tag/v0.2.0).

The main impact this would have on users is being able to set `alpha` on
images, but that is currently broken because of #692.

This also updates to Kurbo
[0.11.1](https://github.com/linebender/kurbo/releases/tag/v0.11.1),
which of note includes linebender/kurbo#353
  • Loading branch information
DJMcNab committed Sep 20, 2024
1 parent 620d256 commit 3bf5428
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 36 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This release has an [MSRV][] of 1.75.

### Fixed

## Removed
### Removed

- Breaking: `Pipelines` API from `vello_shaders` ([#612] by [@DJMcNab])

Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ vello_encoding = { version = "0.2.0", path = "vello_encoding" }
vello_shaders = { version = "0.2.0", path = "vello_shaders" }
bytemuck = { version = "1.16.0", features = ["derive"] }
skrifa = "0.19.3"
peniko = "0.1.1"
peniko = "0.2.0"
futures-intrusive = "0.5.0"
raw-window-handle = "0.6.2"
smallvec = "1.13.2"
Expand Down
24 changes: 6 additions & 18 deletions vello/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl<'a> DrawGlyphs<'a> {
resources.patches.push(Patch::GlyphRun { index });
self.scene
.encoding
.encode_brush(self.brush.clone(), self.brush_alpha);
.encode_brush(self.brush, self.brush_alpha);
// Glyph run resolve step affects transform and style state in a way
// that is opaque to the current encoding.
// See <https://github.com/linebender/vello/issues/424>
Expand Down Expand Up @@ -574,6 +574,7 @@ impl<'a> DrawGlyphs<'a> {
)
}
};
let image = image.multiply_alpha(self.brush_alpha);
// Split into multiple statements because rustfmt breaks
let transform =
run_transform.then_translate(Vec2::new(glyph.x.into(), glyph.y.into()));
Expand Down Expand Up @@ -625,7 +626,7 @@ impl<'a> DrawGlyphs<'a> {
clip_box: DEFAULT_CLIP_RECT,
clip_depth: 0,
location,
foreground_brush: self.brush.clone(),
foreground_brush: self.brush,
},
)
.unwrap();
Expand Down Expand Up @@ -903,8 +904,8 @@ fn conv_brush(
palette_index,
alpha,
} => color_index(cpal, palette_index)
.map(|it| Brush::Solid(it.with_alpha_factor(alpha)))
.unwrap_or(apply_alpha(foreground_brush.to_owned(), alpha)),
.map(|it| Brush::Solid(it.multiply_alpha(alpha)))
.unwrap_or(foreground_brush.to_owned().multiply_alpha(alpha)),

skrifa::color::Brush::LinearGradient {
p0,
Expand Down Expand Up @@ -942,19 +943,6 @@ fn conv_brush(
}
}

fn apply_alpha(mut brush: Brush, alpha: f32) -> Brush {
match &mut brush {
Brush::Solid(color) => *color = color.with_alpha_factor(alpha),
Brush::Gradient(grad) => grad
.stops
.iter_mut()
.for_each(|it| it.color = it.color.with_alpha_factor(alpha)),
// Cannot apply an alpha factor to
Brush::Image(_) => {}
}
brush
}

fn color_index(cpal: &'_ Cpal<'_>, palette_index: u16) -> Option<Color> {
// The "application determined" foreground colour should be used
// This will be handled by the caller
Expand Down Expand Up @@ -1013,7 +1001,7 @@ impl ColorStopsSource for ColorStopsConverter<'_> {
BrushRef::Image(_) => Color::BLACK,
},
};
let color = color.with_alpha_factor(item.alpha);
let color = color.multiply_alpha(item.alpha);
vec.push(ColorStop {
color,
offset: item.offset,
Expand Down
9 changes: 5 additions & 4 deletions vello_encoding/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,13 @@ impl Encoding {
}

/// Encodes a brush with an optional alpha modifier.
#[allow(unused_variables)]
pub fn encode_brush<'b>(&mut self, brush: impl Into<BrushRef<'b>>, alpha: f32) {
#[cfg(feature = "full")]
use super::math::point_to_f32;
match brush.into() {
BrushRef::Solid(color) => {
let color = if alpha != 1.0 {
color.with_alpha_factor(alpha)
color.multiply_alpha(alpha)
} else {
color
};
Expand Down Expand Up @@ -418,9 +417,11 @@ impl Encoding {

/// Encodes an image brush.
#[cfg(feature = "full")]
pub fn encode_image(&mut self, image: &Image, _alpha: f32) {
pub fn encode_image(&mut self, image: &Image, alpha: f32) {
let _alpha = alpha * f32::from(image.alpha);
// TODO: feed the alpha multiplier through the full pipeline for consistency
// with other brushes?
// Tracked in https://github.com/linebender/vello/issues/692
self.resources.patches.push(Patch::Image {
image: image.clone(),
draw_data_offset: self.draw_data.len(),
Expand Down Expand Up @@ -500,7 +501,7 @@ impl Encoding {
if alpha != 1.0 {
self.resources
.color_stops
.extend(color_stops.map(|stop| stop.with_alpha_factor(alpha)));
.extend(color_stops.map(|stop| stop.multiply_alpha(alpha)));
} else {
self.resources.color_stops.extend(color_stops);
}
Expand Down
4 changes: 2 additions & 2 deletions vello_tests/snapshots/stroke_styles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vello_tests/snapshots/stroke_styles_non_uniform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions vello_tests/snapshots/stroke_styles_skew.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3bf5428

Please sign in to comment.