Skip to content

Commit

Permalink
Update vello and parley deps... (#165)
Browse files Browse the repository at this point in the history
* Update vello and parley deps...

... and everything else, apparently. This pushes the new font code changes through the ecosystem.

Brings everything into sync and should put us in a good place to start releasing.

This works as is but depends on a vello commit that is still under review: linebender/vello#425 should land first and this should be updated with the new git rev before merging.

* fmt :(

* update git revs
  • Loading branch information
dfrg authored Jan 26, 2024
1 parent ea45b9f commit d800c22
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 221 deletions.
386 changes: 220 additions & 166 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ taffy = ["dep:taffy"]
[dependencies]
xilem_core.workspace = true
taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "7781c70241f7f572130c13106f2a869a9cf80885", optional = true }
vello = { git = "https://github.com/linebender/vello", rev = "9d7c4f00d8db420337706771a37937e9025e089c" }
wgpu = "0.17.0"
parley = { git = "https://github.com/dfrg/parley", rev = "2371bf4b702ec91edee2d58ffb2d432539580e1e" }
tokio = { version = "1.21", features = ["full"] }
vello = { git = "https://github.com/linebender/vello", rev = "944ce63d8ff40d01f3dbbb7be096feaf6c3657fa" }
wgpu = "0.18.0"
parley = { git = "https://github.com/dfrg/parley", rev = "cf41c3ff25ae0c9c48e96b59bc4ee41571a279b9" }
tokio = { version = "1.35", features = ["full"] }
futures-task = "0.3"
bitflags = "2"
tracing = "0.1.37"
accesskit = "0.11"
accesskit = "0.12"
fnv = "1.0.7"

[dependencies.glazier]
git = "https://github.com/linebender/glazier"
rev = "19a01ba8a97f15bf499ac64e6ea9690d7390deb5"
rev = "ec7e0c5fafd5c106c4c67831bc829572958c671c"
default-features = false
features = ["accesskit"]

Expand Down
6 changes: 5 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ where
}

pub fn accessibility(&mut self) -> TreeUpdate {
let mut update = TreeUpdate::default();
let mut update = TreeUpdate {
nodes: vec![],
tree: None,
focus: accesskit::NodeId(0),
};
self.ensure_root();
let root_pod = self.root_pod.as_mut().unwrap();
let mut window_node_builder = accesskit::NodeBuilder::new(accesskit::Role::Window);
Expand Down
12 changes: 9 additions & 3 deletions src/app_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use vello::{
kurbo::{Affine, Size},
peniko::Color,
util::{RenderContext, RenderSurface},
RenderParams, Renderer, RendererOptions,
AaSupport, RenderParams, Renderer, RendererOptions,
};
use vello::{Scene, SceneBuilder};

Expand Down Expand Up @@ -230,15 +230,21 @@ where
let queue = &self.render_cx.devices[dev_id].queue;
let renderer_options = RendererOptions {
surface_format: Some(surface.format),
timestamp_period: queue.get_timestamp_period(),
use_cpu: false,
antialiasing_support: AaSupport {
area: true,
msaa8: false,
msaa16: false,
},
};
let render_params = RenderParams {
base_color: Color::BLACK,
width,
height,
antialiasing_method: vello::AaConfig::Area,
};
self.renderer
.get_or_insert_with(|| Renderer::new(device, &renderer_options).unwrap())
.get_or_insert_with(|| Renderer::new(device, renderer_options).unwrap())
.render_to_surface(device, queue, &self.scene, &surface_texture, &render_params)
.expect("failed to render to surface");
surface_texture.present();
Expand Down
2 changes: 1 addition & 1 deletion src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ impl Id {

impl From<Id> for accesskit::NodeId {
fn from(id: Id) -> accesskit::NodeId {
id.to_nonzero_raw().into()
accesskit::NodeId(id.to_nonzero_raw().into())
}
}
59 changes: 28 additions & 31 deletions src/text.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
use parley::Layout;
use vello::kurbo::Affine;
use vello::{
glyph::{fello::raw::FontRef, GlyphContext},
peniko::{Brush, Color},
*,
kurbo::Affine,
peniko::{Brush, Fill},
SceneBuilder,
};

#[derive(Clone, PartialEq, Debug)]
pub struct ParleyBrush(pub Brush);

impl Default for ParleyBrush {
fn default() -> ParleyBrush {
ParleyBrush(Brush::Solid(Color::rgb8(0, 0, 0)))
}
}

impl parley::style::Brush for ParleyBrush {}

pub fn render_text(builder: &mut SceneBuilder, transform: Affine, layout: &Layout<ParleyBrush>) {
let mut gcx = GlyphContext::new();
pub fn render_text(builder: &mut SceneBuilder, transform: Affine, layout: &Layout<Brush>) {
for line in layout.lines() {
for glyph_run in line.glyph_runs() {
let mut x = glyph_run.offset();
let y = glyph_run.baseline();
let run = glyph_run.run();
let font = run.font();
let font_size = run.font_size();
let font_ref = font.as_ref();
if let Ok(font_ref) = FontRef::from_index(font_ref.data, font.index()) {
let style = glyph_run.style();
let vars: [(&str, f32); 0] = [];
let mut gp = gcx.new_provider(&font_ref, None, font_size, false, vars);
for glyph in glyph_run.glyphs() {
if let Some(fragment) = gp.get(glyph.id, Some(&style.brush.0)) {
let font = vello::peniko::Font::new(font.data().0.clone(), font.index());
let style = glyph_run.style();
let coords = run
.normalized_coords()
.iter()
.map(|coord| vello::skrifa::instance::NormalizedCoord::from_bits(*coord))
.collect::<Vec<_>>();
builder
.draw_glyphs(&font)
.brush(&style.brush)
.transform(transform)
.font_size(font_size)
.normalized_coords(&coords)
.draw(
Fill::NonZero,
glyph_run.glyphs().map(|glyph| {
let gx = x + glyph.x;
let gy = y - glyph.y;
let xform = Affine::translate((gx as f64, gy as f64))
* Affine::scale_non_uniform(1.0, -1.0);
builder.append(&fragment, Some(transform * xform));
}
x += glyph.advance;
}
}
x += glyph.advance;
vello::glyph::Glyph {
id: glyph.id as _,
x: gx,
y: gy,
}
}),
);
}
}
}
8 changes: 4 additions & 4 deletions src/widget/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use vello::{
SceneBuilder,
};

use crate::{text::ParleyBrush, IdPath, Message};
use crate::{IdPath, Message};

use super::{
contexts::LifeCycleCx,
Expand All @@ -33,7 +33,7 @@ use super::{
pub struct Button {
id_path: IdPath,
label: String,
layout: Option<Layout<ParleyBrush>>,
layout: Option<Layout<Brush>>,
}

impl Button {
Expand Down Expand Up @@ -96,8 +96,8 @@ impl Widget for Button {
let mut lcx = parley::LayoutContext::new();
let mut layout_builder = lcx.ranged_builder(cx.font_cx(), &self.label, 1.0);

layout_builder.push_default(&parley::style::StyleProperty::Brush(ParleyBrush(
Brush::Solid(Color::rgb8(0xf0, 0xf0, 0xea)),
layout_builder.push_default(&parley::style::StyleProperty::Brush(Brush::Solid(
Color::rgb8(0xf0, 0xf0, 0xea),
)));
let mut layout = layout_builder.build();
// Question for Chad: is this needed?
Expand Down
6 changes: 3 additions & 3 deletions src/widget/piet_scene_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use vello::kurbo::{self, Affine, Rect, Shape};
use vello::peniko::{BrushRef, Color, ColorStopsSource, Fill, Gradient, Stroke};
use vello::kurbo::{self, Affine, Rect, Shape, Stroke};
use vello::peniko::{BrushRef, Color, ColorStopsSource, Fill, Gradient};
use vello::SceneBuilder;

#[derive(Debug, Clone, Copy)]
Expand All @@ -15,7 +15,7 @@ pub fn stroke<'b>(
stroke_width: f64,
) {
builder.stroke(
&Stroke::new(stroke_width as f32),
&Stroke::new(stroke_width),
Affine::IDENTITY,
brush,
None,
Expand Down
10 changes: 4 additions & 6 deletions src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ use vello::{
SceneBuilder,
};

use crate::text::ParleyBrush;

use super::{
contexts::LifeCycleCx, BoxConstraints, ChangeFlags, Event, EventCx, LayoutCx, LifeCycle,
PaintCx, UpdateCx, Widget,
};

pub struct TextWidget {
text: Cow<'static, str>,
layout: Option<Layout<ParleyBrush>>,
layout: Option<Layout<Brush>>,
}

impl TextWidget {
Expand All @@ -43,13 +41,13 @@ impl TextWidget {
ChangeFlags::LAYOUT | ChangeFlags::PAINT
}

fn get_layout_mut(&mut self, font_cx: &mut FontContext) -> &mut Layout<ParleyBrush> {
fn get_layout_mut(&mut self, font_cx: &mut FontContext) -> &mut Layout<Brush> {
// Ensure Parley layout is initialised
if self.layout.is_none() {
let mut lcx = parley::LayoutContext::new();
let mut layout_builder = lcx.ranged_builder(font_cx, &self.text, 1.0);
layout_builder.push_default(&parley::style::StyleProperty::Brush(ParleyBrush(
Brush::Solid(Color::rgb8(255, 255, 255)),
layout_builder.push_default(&parley::style::StyleProperty::Brush(Brush::Solid(
Color::rgb8(255, 255, 255),
)));
self.layout = Some(layout_builder.build());
}
Expand Down

0 comments on commit d800c22

Please sign in to comment.