Skip to content
Merged
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
6 changes: 6 additions & 0 deletions Cargo.lock

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

14 changes: 11 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,29 @@ clippy.wildcard_dependencies = "warn"
[workspace.dependencies]
# NOTE: Make sure to keep this in sync with the version badge in README.md
vello = { version = "0.6.0", default-features = false }
kurbo = { version = "0.12.0" }
peniko = { version = "0.5.0" }

[lints]
workspace = true

[dependencies]
vello = { workspace = true }
vello = { workspace = true, optional = true }
kurbo = { workspace = true }
peniko = { workspace = true }

# For the parser
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.145"
serde_repr = "0.1.20"

[dev-dependencies]
vello = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.56"

[features]
default = []
wgpu = ["vello/wgpu"]
default = ["vello"]
vello = ["dep:vello"]
wgpu = ["vello", "vello/wgpu"]
2 changes: 2 additions & 0 deletions examples/scenes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ workspace = true

[dependencies]
vello = { workspace = true }
kurbo = { workspace = true }
peniko = { workspace = true }
velato = { path = "../.." }
anyhow = "1"
clap = { version = "4.5.38", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions examples/scenes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ pub use lottie::{default_scene, scene_from_files};
pub use simple_text::RobotoText;
pub use test_scenes::test_scenes;

use kurbo::Vec2;
use peniko::{Color, color};
use vello::Scene;
use vello::kurbo::Vec2;
use vello::peniko::{Color, color};

pub struct SceneParams<'a> {
pub time: f64,
Expand Down
4 changes: 2 additions & 2 deletions examples/scenes/src/lottie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{ExampleScene, SceneSet};
#[cfg(not(target_arch = "wasm32"))]
use anyhow::{Ok, Result};
use instant::Instant;
use kurbo::{Affine, Vec2};
use std::sync::Arc;
#[cfg(not(target_arch = "wasm32"))]
use std::{
Expand All @@ -15,7 +16,6 @@ use std::{
};
use velato::Composition;
use vello::Scene;
use vello::kurbo::{Affine, Vec2};

#[cfg(not(target_arch = "wasm32"))]
pub fn scene_from_files(files: &[PathBuf]) -> Result<SceneSet> {
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn lottie_function_of<R: AsRef<str>>(
let frame = ((start.elapsed().as_secs_f64() * lottie.frame_rate)
% (lottie.frames.end - lottie.frames.start))
+ lottie.frames.start;
renderer.render(lottie, frame, Affine::IDENTITY, 1.0)
renderer.render_to_vello_scene(lottie, frame, Affine::IDENTITY, 1.0)
}
let started = Instant::now();
let mut renderer = velato::Renderer::new();
Expand Down
6 changes: 3 additions & 3 deletions examples/scenes/src/simple_text.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2022 the Velato Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use kurbo::Affine;
use peniko::{Blob, Brush, BrushRef, FontData, StyleRef};
use skrifa::MetadataProvider;
use skrifa::raw::FontRef;
use std::sync::Arc;
use vello::kurbo::Affine;
use vello::peniko::{Blob, Brush, BrushRef, FontData, StyleRef};
use vello::{Glyph, Scene};

// This is very much a hack to get things working.
Expand Down Expand Up @@ -113,7 +113,7 @@ impl RobotoText {
transform: Affine,
text: &str,
) {
use vello::peniko::{Color, Fill};
use peniko::{Color, Fill};
let brush = brush.unwrap_or(&Brush::Solid(Color::WHITE));
self.add_run(
scene,
Expand Down
2 changes: 1 addition & 1 deletion examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::{ExampleScene, SceneConfig, SceneParams, SceneSet};
use vello::kurbo::Affine;
use kurbo::Affine;
use vello::*;

macro_rules! scene {
Expand Down
2 changes: 2 additions & 0 deletions examples/with_winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ workspace = true

[dependencies]
vello = { workspace = true, features = ["wgpu"] }
kurbo = { workspace = true }
peniko = { workspace = true }
wgpu = { version = "26.0", features = ["vulkan", "metal", "dx12"] }
scenes = { path = "../scenes" }
anyhow = "1"
Expand Down
4 changes: 2 additions & 2 deletions examples/with_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ use std::sync::Arc;

use anyhow::Result;
use clap::{CommandFactory, Parser};
use kurbo::{Affine, Vec2};
use peniko::Color;
use scenes::{RobotoText, SceneParams, SceneSet};
use vello::kurbo::{Affine, Vec2};
use vello::low_level::BumpAllocators;
use vello::peniko::Color;
use vello::util::{RenderContext, RenderSurface};
use vello::{AaConfig, Renderer, RendererOptions, Scene, wgpu};

Expand Down
2 changes: 1 addition & 1 deletion examples/with_winit/src/multi_touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// Adapted from <https://github.com/emilk/egui/blob/212656f3fc6b931b21eaad401e5cec2b0da93baa/crates/egui/src/input_state/touch_state.rs>
use std::{collections::BTreeMap, fmt::Debug};

use vello::kurbo::{Point, Vec2};
use kurbo::{Point, Vec2};
use winit::event::{Touch, TouchPhase};

/// All you probably need to know about a multi-touch gesture.
Expand Down
4 changes: 2 additions & 2 deletions examples/with_winit/src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2023 the Velato Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use kurbo::{Affine, PathEl, Rect, Stroke};
use peniko::{Brush, Color, Fill};
use scenes::RobotoText;
use std::collections::VecDeque;
use vello::kurbo::{Affine, PathEl, Rect, Stroke};
use vello::low_level::BumpAllocators;
use vello::peniko::{Brush, Color, Fill};
use vello::{AaConfig, Scene};

const SLIDING_WINDOW_SIZE: usize = 100;
Expand Down
2 changes: 1 addition & 1 deletion src/import/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::defaults::FLOAT_VALUE_ONE_HUNDRED;
use crate::runtime::model::Layer;
use crate::schema::helpers::int_boolean::BoolInt;
use crate::{runtime, schema};
use vello::peniko::{self, BlendMode, Compose, Mix};
use peniko::{self, BlendMode, Compose, Mix};

pub struct LayerSetupParams {
pub layer_index: usize,
Expand Down
4 changes: 2 additions & 2 deletions src/import/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use crate::schema::animated_properties::split_vector::SplitVector;
use crate::schema::constants::gradient_type::GradientType;
use crate::schema::helpers::int_boolean::BoolInt;
use crate::{Composition, schema};
use kurbo::{Cap, Join, Point, Size, Vec2};
use peniko::{BlendMode, Color, Mix};
use std::collections::HashMap;
use vello::kurbo::{Cap, Join, Point, Size, Vec2};
use vello::peniko::{BlendMode, Color, Mix};

fn process_layers(
source_layers: &[schema::layers::AnyLayer],
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//! let frame = 0.0; // Arbitrary number chosen. Ensure it's a valid frame!
//! let transform = vello::kurbo::Affine::IDENTITY;
//! let alpha = 1.0;
//! let scene = renderer.render(&composition, frame, transform, alpha);
//! let scene = renderer.render_to_vello_scene(&composition, frame, transform, alpha);
//! ```
//!
//! # Unsupported features
Expand Down Expand Up @@ -91,6 +91,7 @@ mod error;
pub use error::Error;

// Re-export vello
#[cfg(feature = "vello")]
pub use vello;

pub use runtime::{Composition, Renderer, model};
pub use runtime::{Composition, RenderSink, Renderer, model};
5 changes: 4 additions & 1 deletion src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ use crate::schema::Animation;
use std::collections::HashMap;
use std::ops::Range;

#[cfg(feature = "vello")]
mod vello;

pub mod model;

pub use render::Renderer;
pub use render::{RenderSink, Renderer};

/// Model of a Lottie file.
#[derive(Clone, Default, Debug)]
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/model/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ Representations of fixed (non-animated) values.

use std::mem::swap;

use vello::kurbo::{self, Affine, Point, Vec2};
use vello::peniko;
use kurbo::{Affine, Point, Vec2};

/// Fixed affine transformation.
pub type Transform = kurbo::Affine;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2024 the Velato Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use kurbo::{Affine, PathEl, Point, Shape as _, Size, Vec2};
use peniko::{BlendMode, Color};
use std::ops::Range;
use vello::kurbo::{self, Affine, PathEl, Point, Shape as _, Size, Vec2};
use vello::peniko::{self, BlendMode, Color};

mod spline;
mod value;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/model/spline.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 the Velato Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use vello::kurbo::{PathEl, Point};
use kurbo::{PathEl, Point};

/// Helper trait for converting cubic splines to paths.
pub trait SplineToPath {
Expand Down
9 changes: 3 additions & 6 deletions src/runtime/model/value.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// Copyright 2024 the Velato Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use vello::{
kurbo::{
self, ParamCurve, Point,
common::{solve_cubic, solve_itp},
},
peniko,
use kurbo::{
ParamCurve, Point,
common::{solve_cubic, solve_itp},
};

/// Fixed or animated value.
Expand Down
55 changes: 30 additions & 25 deletions src/runtime/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@

use super::Composition;
use super::model::{Content, Draw, Geometry, GroupTransform, Layer, Shape, fixed};
use std::mem::swap;
use std::ops::Range;
use vello::kurbo::{
use kurbo::{
Affine, BezPath, CubicBez, Line, ParamCurve, ParamCurveArclen, PathEl, PathSeg, Point, QuadBez,
Rect,
};
use vello::peniko::{Fill, Mix};
use peniko::{Fill, Mix};
use std::mem::swap;
use std::ops::Range;

pub trait RenderSink {
fn push_layer(
&mut self,
blend: impl Into<peniko::BlendMode>,
alpha: f32,
transform: Affine,
shape: &impl kurbo::Shape,
);

fn push_clip_layer(&mut self, transform: Affine, shape: &impl kurbo::Shape);

fn pop_layer(&mut self);

fn draw(
&mut self,
stroke: Option<&fixed::Stroke>,
transform: Affine,
brush: &fixed::Brush,
shape: &impl kurbo::Shape,
);
}

/// Renders a composition into a scene.
#[derive(Debug, Default)]
Expand All @@ -24,27 +46,14 @@ impl Renderer {
Self::default()
}

/// Renders the animation at a given frame to a new scene.
pub fn render(
&mut self,
animation: &Composition,
frame: f64,
transform: Affine,
alpha: f64,
) -> vello::Scene {
let mut scene = vello::Scene::new();
self.append(animation, frame, transform, alpha, &mut scene);
scene
}

/// Renders and appends the animation at a given frame to the provided scene.
pub fn append(
&mut self,
animation: &Composition,
frame: f64,
transform: Affine,
alpha: f64,
scene: &mut vello::Scene,
scene: &mut impl RenderSink,
) {
self.batch.clear();
scene.push_clip_layer(
Expand Down Expand Up @@ -77,7 +86,7 @@ impl Renderer {
transform: Affine,
alpha: f64,
frame: f64,
scene: &mut vello::Scene,
scene: &mut impl RenderSink,
) {
if !layer.frames.contains(&frame) {
return;
Expand Down Expand Up @@ -447,7 +456,7 @@ impl Batch {
self.trim_elements.clear();
}

fn render(&self, scene: &mut vello::Scene) {
fn render(&self, scene: &mut impl RenderSink) {
// Process all draws in reverse
for draw in self.draws.iter().rev() {
// Some nastiness to avoid cloning the brush if unnecessary
Expand All @@ -460,11 +469,7 @@ impl Batch {
for geometry in self.geometries[draw.geometry.clone()].iter() {
let path = &self.elements[geometry.elements.clone()];
let transform = geometry.transform;
if let Some(stroke) = draw.stroke.as_ref() {
scene.stroke(stroke, transform, brush, None, &path);
} else {
scene.fill(Fill::NonZero, transform, brush, None, &path);
}
scene.draw(draw.stroke.as_ref(), transform, brush, &path);
}
}
}
Expand Down
Loading