Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
444 changes: 104 additions & 340 deletions Cargo.lock

Large diffs are not rendered by default.

39 changes: 26 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ homepage = "https://github.com/dioxuslabs/anyrender"
repository = "https://github.com/dioxuslabs/anyrender"
categories = ["gui"]
edition = "2024"
rust-version = "1.92.0"
rust-version = "1.88.0"

[workspace.dependencies]
# AnyRender dependencies (in-repo)
Expand All @@ -42,23 +42,39 @@ serde = "1.0.228"
serde_json = "1.0"
zip = { version = "2.1", default-features = false, features = ["deflate"] }
sha2 = "0.10"
skera = "=0.1.0" # pin because of breaking changes in past patch releases
skera = "=0.1.0" # pin because of breaking changes in past patch releases
read-fonts = "0.37"
ttf2woff2 = "0.11"
wuff = "0.2"

# Linebender
color = "0.3"

linebender_resource_handle = "0.1"
peniko = "0.6"
kurbo = "0.13"
vello = { version = "0.8", features = [ "wgpu" ] }
vello_cpu = { version = "0.0.7", default-features = false, features = ["std", "text", "u8_pipeline"] }
vello_hybrid = { version = "0.0.7" }
vello_common = { version = "0.0.7" }
# glifo = { version = "0.0.0" }color = "0.3"
# vello = { version = "0.8", features = ["wgpu"] }
# vello_cpu = { version = "0.0.7", default-features = false, features = [
# "std",
# "text",
# "u8_pipeline",
# ] }
# vello_hybrid = { version = "0.0.7" }
# vello_common = { version = "0.0.7" }
glifo = { git = "https://github.com/linebender/vello", rev = "3e1aba3ffa1286012119052cb4bc7250e1b61a4b" }
vello = { git = "https://github.com/linebender/vello", rev = "3e1aba3ffa1286012119052cb4bc7250e1b61a4b", features = [
"wgpu",
] }
vello_cpu = { git = "https://github.com/linebender/vello", rev = "3e1aba3ffa1286012119052cb4bc7250e1b61a4b", default-features = false, features = [
"std",
"text",
"u8_pipeline",
] }
vello_hybrid = { git = "https://github.com/linebender/vello", rev = "3e1aba3ffa1286012119052cb4bc7250e1b61a4b" }
vello_common = { git = "https://github.com/linebender/vello", rev = "3e1aba3ffa1286012119052cb4bc7250e1b61a4b" }

# Rendering
wgpu = "28"
wgpu = "29"
raw-window-handle = "0.6.0"
softbuffer = "0.4"
pixels = "0.17"
Expand All @@ -79,8 +95,5 @@ wasm-bindgen-futures = "0.4"
# Dev-dependencies
winit = { version = "0.30.2", features = ["rwh_06"] }

# [patch.crates-io]
# vello = { path = "../vello/vello" }
# vello_cpu = { path = "../vello/sparse_strips/vello_cpu" }
# vello_hybrid = { path = "../vello/sparse_strips/vello_hybrid" }
# vello_common = { path = "../vello/sparse_strips/vello_common" }
[patch.crates-io]
kurbo = { git = "https://github.com/linebender/kurbo", rev = "6836244" }
4 changes: 3 additions & 1 deletion crates/anyrender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,13 @@ pub trait PaintScene: RenderContext {
font_size: f32,
hint: bool,
normalized_coords: &'a [NormalizedCoord],
embolden: kurbo::Vec2,
style: impl Into<StyleRef<'a>>,
brush: impl Into<PaintRef<'a>>,
brush_alpha: f32,
transform: Affine,
glyph_transform: Option<Affine>,
glyphs: impl Iterator<Item = Glyph>,
glyphs: impl Iterator<Item = Glyph> + Clone,
);

/// Draw a rounded rectangle blurred with a gaussian filter.
Expand Down Expand Up @@ -294,6 +295,7 @@ pub trait PaintScene: RenderContext {
cmd.font_size,
cmd.hint,
&cmd.normalized_coords,
cmd.embolden,
&cmd.style,
match cmd.brush {
Paint::Solid(alpha_color) => Paint::Solid(alpha_color),
Expand Down
1 change: 1 addition & 0 deletions crates/anyrender/src/null_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl PaintScene for NullScenePainter {
_font_size: f32,
_hint: bool,
_normalized_coords: &'a [crate::NormalizedCoord],
_embolden: kurbo::Vec2,
_style: impl Into<peniko::StyleRef<'a>>,
_brush: impl Into<crate::PaintRef<'a>>,
_brush_alpha: f32,
Expand Down
4 changes: 4 additions & 0 deletions crates/anyrender/src/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ pub struct GlyphRunCommand<Font = FontData, Brush = Paint> {
pub font_size: f32,
pub hint: bool,
pub normalized_coords: Vec<NormalizedCoord>,
#[cfg_attr(feature = "serde", serde(default = "Default::default"))]
pub embolden: kurbo::Vec2,
pub style: Style,
pub brush: Brush,
pub brush_alpha: f32,
Expand Down Expand Up @@ -244,6 +246,7 @@ impl PaintScene for Scene {
font_size: f32,
hint: bool,
normalized_coords: &'a [NormalizedCoord],
embolden: kurbo::Vec2,
style: impl Into<StyleRef<'a>>,
paint_ref: impl Into<PaintRef<'a>>,
brush_alpha: f32,
Expand All @@ -257,6 +260,7 @@ impl PaintScene for Scene {
font_size,
hint,
normalized_coords: normalized_coords.to_vec(),
embolden,
style: style.into().to_owned(),
brush,
brush_alpha,
Expand Down
2 changes: 2 additions & 0 deletions crates/anyrender_serialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl ResourceCollector {
font_size: glyph_run.font_size,
hint: glyph_run.hint,
normalized_coords: glyph_run.normalized_coords.clone(),
embolden: glyph_run.embolden,
style: glyph_run.style.clone(),
brush,
brush_alpha: glyph_run.brush_alpha,
Expand Down Expand Up @@ -308,6 +309,7 @@ impl ResourceReconstructor {
font_size: glyph_run.font_size,
hint: glyph_run.hint,
normalized_coords: glyph_run.normalized_coords.clone(),
embolden: glyph_run.embolden,
style: glyph_run.style.clone(),
brush,
brush_alpha: glyph_run.brush_alpha,
Expand Down
1 change: 1 addition & 0 deletions crates/anyrender_skia/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ impl PaintScene for SkiaScenePainter<'_> {
font_size: f32,
hint: bool,
normalized_coords: &'a [anyrender::NormalizedCoord],
_embolden: kurbo::Vec2,
style: impl Into<peniko::StyleRef<'a>>,
brush: impl Into<anyrender::PaintRef<'a>>,
brush_alpha: f32,
Expand Down
4 changes: 4 additions & 0 deletions crates/anyrender_vello/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl PaintScene for VelloScenePainter<'_, '_> {
font_size: f32,
hint: bool,
normalized_coords: &'a [NormalizedCoord],
embolden: kurbo::Vec2,
style: impl Into<StyleRef<'a>>,
paint: impl Into<PaintRef<'a>>,
brush_alpha: f32,
Expand All @@ -150,6 +151,9 @@ impl PaintScene for VelloScenePainter<'_, '_> {
.font_size(font_size)
.hint(hint)
.normalized_coords(normalized_coords)
.font_embolden(vello::FontEmbolden::new(kurbo::Diagonal2::new(
embolden.x, embolden.y,
)))
.brush(paint.into())
.brush_alpha(brush_alpha)
.transform(transform)
Expand Down
23 changes: 8 additions & 15 deletions crates/anyrender_vello/src/window_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use vello::{
AaConfig, AaSupport, RenderParams, Renderer as VelloRenderer, RendererOptions,
Scene as VelloScene,
};
use wgpu::{Features, Limits, PresentMode, SurfaceError, Texture, TextureFormat, TextureUsages};
use wgpu::{Features, Limits, PresentMode, Texture, TextureFormat, TextureUsages};
use wgpu_context::{
DeviceHandle, SurfaceRenderer, SurfaceRendererConfiguration, TextureConfiguration, WGPUContext,
};
Expand Down Expand Up @@ -305,19 +305,12 @@ impl WindowRenderer for VelloWindowRenderer {
});
timer.record_time("cmd");

match render_surface.ensure_current_surface_texture() {
Ok(_) => {}
Err(SurfaceError::Timeout | SurfaceError::Lost | SurfaceError::Outdated) => {
render_surface.clear_surface_texture();
return;
}
Err(SurfaceError::OutOfMemory) => panic!("Out of memory"),
Err(SurfaceError::Other) => panic!("Unknown error getting surface"),
let Ok(texture_view) = render_surface.target_texture_view() else {
// Skip frame in case of error trying to get current surface texture
render_surface.clear_surface_texture();
return;
};

let texture_view = render_surface
.target_texture_view()
.expect("handled errors from ensure_current_surface_texture above");
state
.renderer
.render_to_texture(
Expand All @@ -337,9 +330,9 @@ impl WindowRenderer for VelloWindowRenderer {

drop(texture_view);

render_surface
.maybe_blit_and_present()
.expect("handled errors from ensure_current_surface_texture above");
if render_surface.maybe_blit_and_present().is_err() {
return;
}
timer.record_time("present");

render_surface
Expand Down
24 changes: 14 additions & 10 deletions crates/anyrender_vello_cpu/src/image_renderer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::VelloCpuScenePainter;
use anyrender::{ImageRenderer, RenderContext as AnyRenderContext};
use debug_timer::debug_timer;
use vello_cpu::{RenderContext, RenderMode};
use vello_cpu::{RenderContext, RenderMode, Resources};

pub struct VelloCpuImageRenderer {
scene: VelloCpuScenePainter,
Expand All @@ -13,16 +13,19 @@ impl ImageRenderer for VelloCpuImageRenderer {

fn new(width: u32, height: u32) -> Self {
Self {
scene: VelloCpuScenePainter(RenderContext::new(width as u16, height as u16)),
scene: VelloCpuScenePainter {
render_ctx: RenderContext::new(width as u16, height as u16),
resources: Resources::new(),
},
}
}

fn resize(&mut self, width: u32, height: u32) {
self.scene.0 = RenderContext::new(width as u16, height as u16);
self.scene.render_ctx = RenderContext::new(width as u16, height as u16);
}

fn reset(&mut self) {
self.scene.0.reset();
self.scene.render_ctx.reset();
}

fn render<F: FnOnce(&mut Self::ScenePainter<'_>)>(&mut self, draw_fn: F, buffer: &mut [u8]) {
Expand All @@ -31,13 +34,14 @@ impl ImageRenderer for VelloCpuImageRenderer {
draw_fn(&mut self.scene);
timer.record_time("cmds");

self.scene.0.flush();
self.scene.render_ctx.flush();
timer.record_time("flush");

self.scene.0.render_to_buffer(
self.scene.render_ctx.render_to_buffer(
&mut self.scene.resources,
buffer,
self.scene.0.width(),
self.scene.0.height(),
self.scene.render_ctx.width(),
self.scene.render_ctx.height(),
RenderMode::OptimizeSpeed,
);
timer.record_time("render");
Expand All @@ -50,8 +54,8 @@ impl ImageRenderer for VelloCpuImageRenderer {
draw_fn: F,
buffer: &mut Vec<u8>,
) {
let width = self.scene.0.width();
let height = self.scene.0.height();
let width = self.scene.render_ctx.width();
let height = self.scene.render_ctx.height();
buffer.resize(width as usize * height as usize * 4, 0);
self.render(draw_fn, buffer);
}
Expand Down
Loading
Loading