From 883df2ebc3ba565f758001a47ad83f7eaa8af58d Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Fri, 19 Apr 2024 19:18:41 -0400 Subject: [PATCH 01/17] refactor: rename vello_svg to demo_svg, update docs --- ARCHITECTURE.md | 2 +- Cargo.lock | 18 +++--- Cargo.toml | 2 +- README.md | 60 +++++++++---------- examples/scenes/Cargo.toml | 2 +- examples/scenes/src/svg.rs | 6 +- .../{vello_svg => demo_svg}/Cargo.toml | 2 +- .../{vello_svg => demo_svg}/src/lib.rs | 0 8 files changed, 46 insertions(+), 46 deletions(-) rename integrations/{vello_svg => demo_svg}/Cargo.toml (94%) rename integrations/{vello_svg => demo_svg}/src/lib.rs (100%) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 4d28da71..7decd9a6 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -38,7 +38,7 @@ The repository is structured as such: - `tests/` - Helper code for writing tests; current has a single smoke test and not much else. - `doc/` - Various documents detailing the vision for Vello as it was developed. This directory should probably be refactored away; adding to it not recommended. - `examples/` - Example projects using Vello. Each example is its own crate, with its own dependencies. The simplest example is the `shapes` one. -- `integrations/vello_svg` - An SVG rendered based on Vello and usvg. Used in examples. May be moved to `crates/` in the future. +- `integrations/demo_svg` - An SVG rendered based on Vello and usvg. Used in examples. May be moved to `crates/` in the future. - `shader/` - This is where the magic happens. WGSL shaders that define the compute operations (often variations of prefix sum) that Vello does to render a scene. - `shared/` - Shared types, functions and constants included in other shaders through non-standard `#import` preprocessor directives (see "Shader templating"). - `src/` - Code for the main `vello` crate. diff --git a/Cargo.lock b/Cargo.lock index 528d6909..fd0656f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1455,6 +1455,14 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" +[[package]] +name = "demo_svg" +version = "0.0.0" +dependencies = [ + "usvg", + "vello", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -3266,6 +3274,7 @@ dependencies = [ "anyhow", "byte-unit", "clap", + "demo_svg", "getrandom", "image", "inquire", @@ -3273,7 +3282,6 @@ dependencies = [ "rand", "ureq", "vello", - "vello_svg", ] [[package]] @@ -4035,14 +4043,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "vello_svg" -version = "0.0.0" -dependencies = [ - "usvg", - "vello", -] - [[package]] name = "vello_tests" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index a88304ef..647f4ed3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ members = [ "crates/shaders", "crates/tests", - "integrations/vello_svg", + "integrations/demo_svg", "examples/headless", "examples/with_winit", diff --git a/README.md b/README.md index 98d0126a..eb51be20 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,16 @@ # Vello -**An experimental GPU compute-centric 2D renderer** +**An experimental GPU compute-centric 2D renderer.** [![Linebender Zulip](https://img.shields.io/badge/Linebender-%23gpu-blue?logo=Zulip)](https://xi.zulipchat.com/#narrow/stream/197075-gpu) [![dependency status](https://deps.rs/repo/github/linebender/vello/status.svg)](https://deps.rs/repo/github/linebender/vello) [![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](#license) [![wgpu version](https://img.shields.io/badge/wgpu-v0.19.3-orange.svg)](https://crates.io/crates/wgpu) - - - + +[![Crates.io](https://img.shields.io/crates/v/vello.svg)](https://crates.io/crates/vello) +[![Docs](https://docs.rs/vello/badge.svg)](https://docs.rs/vello) +[![Build status](https://github.com/linebender/vello/workflows/CI/badge.svg)](https://github.com/linebenvello/actions) --> @@ -18,6 +19,7 @@ Vello is an experimental 2D graphics rendering engine written in Rust, with a fo It can draw large 2D scenes with interactive or near-interactive performance, using [`wgpu`] for GPU access. Quickstart to run an example program: + ```shell cargo run -p with_winit ``` @@ -45,7 +47,6 @@ Vello avoids this by using prefix-sum algorithms to parallelize work that usuall This means that Vello needs a GPU with support for compute shaders to run. - ## Getting started Vello is meant to be integrated deep in UI render stacks. @@ -108,23 +109,19 @@ surface_texture.present(); See the [`examples/`](https://github.com/linebender/vello/tree/main/examples) folder to see how that code integrates with frameworks like winit and bevy. - ## Performance We've observed 177 fps for the paris-30k test scene on an M1 Max, at a resolution of 1600 pixels square, which is excellent performance and represents something of a best case for the engine. More formal benchmarks are on their way. - ## Integrations ### SVG -This repository also includes [`vello_svg`](./integrations/vello_svg/), which supports converting a [`usvg`](https://crates.io/crates/usvg) `Tree` into a Vello scene. - -This is currently incomplete; see its crate level documentation for more information. +A separate integration for rendering SVG files is available through the [`vello_svg`](https://github.com/linebender/vello_svg) crate. -This is used in the [winit](#winit) example for the SVG rendering. +This repository also includes a [`demo_svg`](./integrations/demo_svg/) integration, which only supports the minimal subset of SVG features needed for vello examples. This is used in the [winit](#winit) example for the SVG rendering. ### Lottie @@ -139,12 +136,12 @@ Examples must be selected using the `--package` (or `-p`) Cargo flag. ### Winit Our [winit] example ([examples/with_winit](https://github.com/linebender/vello/tree/main/examples/with_winit)) demonstrates rendering to a [winit] window. -By default, this renders the [GhostScript Tiger] as well as all SVG files you add in the [examples/assets/downloads/](https://github.com/linebender/vello/tree/main/examples/assets/downloads) directory using [`vello_svg`](#svg). +By default, this renders the [GhostScript Tiger] as well as all SVG files you add in the [examples/assets/downloads/](https://github.com/linebender/vello/tree/main/examples/assets/downloads) directory using [`demo_svg`](#svg). A custom list of SVG file paths (and directories to render all SVG files from) can be provided as arguments instead. It also includes a collection of test scenes showing the capabilities of `vello`, which can be shown with `--test-scenes`. ```shell -cargo run -p with_winit +cargo run -p with_winit ``` Some default test scenes can be downloaded from Wikimedia Commons using the `download` subcommand. @@ -165,11 +162,11 @@ This currently draws to a [`wgpu`] `Texture` using `vello`, then uses that textu cargo run -p with_bevy ``` -There is also a separate community integration for rendering lottie and SVG files through [`bevy_vello`](https://github.com/vectorgameexperts/bevy_vello). +There is also a separate community integration for rendering raw scenes or Lottie and SVG files through [`bevy_vello`](https://github.com/loopystudios/bevy_vello). ## Platforms -We aim to target all environments which can support WebGPU with the [default limits](https://www.w3.org/TR/webgpu/#limits). +We aim to target all environments which can support WebGPU with the [default limits](https://www.w3.org/TR/webgpu/#limits). We defer to [`wgpu`] for this support. Other platforms are more tricky, and may require special building/running procedures. @@ -198,31 +195,33 @@ There is also a web demo [available here](https://linebender.github.io/vello) on The [`with_winit`](#winit) example supports running on Android, using [cargo apk](https://crates.io/crates/cargo-apk). -``` +```shell cargo apk run -p with_winit ``` -> [!TIP] -> cargo apk doesn't support running in release mode without configuration. +> [!TIP] +> cargo apk doesn't support running in release mode without configuration. > See [their crates page docs](https://crates.io/crates/cargo-apk) (around `package.metadata.android.signing.`). -> +> > See also [cargo-apk#16](https://github.com/rust-mobile/cargo-apk/issues/16). > To run in release mode, you must add the following to `examples/with_winit/Cargo.toml` (changing `$HOME` to your home directory): -``` +```toml [package.metadata.android.signing.release] path = "$HOME/.android/debug.keystore" keystore_password = "android" ``` -> [!NOTE] -> As `cargo apk` does not allow passing command line arguments or environment variables to the app when ran, these can be embedded into the +> [!NOTE] +> As `cargo apk` does not allow passing command line arguments or environment variables to the app when ran, these can be embedded into the > program at compile time (currently for Android only) > `with_winit` currently supports the environment variables: -> - `VELLO_STATIC_LOG`, which is equivalent to `RUST_LOG` -> - `VELLO_STATIC_ARGS`, which is equivalent to passing in command line arguments +> +> - `VELLO_STATIC_LOG`, which is equivalent to `RUST_LOG` +> - `VELLO_STATIC_ARGS`, which is equivalent to passing in command line arguments For example (with unix shell environment variable syntax): + ```sh VELLO_STATIC_LOG="vello=trace" VELLO_STATIC_ARGS="--test-scenes" cargo apk run -p with_winit --lib ``` @@ -244,6 +243,7 @@ If you encounter a compilation issue due to a dependency and don't want to upgra # Use the problematic dependency's name and version cargo update -p package_name --precise 0.1.1 ``` + ## Community @@ -258,7 +258,7 @@ licensed as noted in the "License" section, without any additional terms or cond ## History -Vello was previously known as `piet-gpu`. +Vello was previously known as `piet-gpu`. This prior incarnation used a custom cross-API hardware abstraction layer, called `piet-gpu-hal`, instead of [`wgpu`]. An archive of this version can be found in the branches [`custom-hal-archive-with-shaders`] and [`custom-hal-archive`]. @@ -273,11 +273,11 @@ Many of these items are out-of-date or completed, but it still may provide some Vello takes inspiration from many other rendering projects, including: -* [Pathfinder](https://github.com/servo/pathfinder) -* [Spinel](https://fuchsia.googlesource.com/fuchsia/+/refs/heads/master/src/graphics/lib/compute/spinel/) -* [Forma](https://github.com/google/forma) -* [Massively Parallel Vector Graphics](https://w3.impa.br/~diego/projects/GanEtAl14/) -* [Random-access rendering of general vector graphics](https://hhoppe.com/proj/ravg/) +- [Pathfinder](https://github.com/servo/pathfinder) +- [Spinel](https://fuchsia.googlesource.com/fuchsia/+/refs/heads/master/src/graphics/lib/compute/spinel/) +- [Forma](https://github.com/google/forma) +- [Massively Parallel Vector Graphics](https://w3.impa.br/~diego/projects/GanEtAl14/) +- [Random-access rendering of general vector graphics](https://hhoppe.com/proj/ravg/) ## License diff --git a/examples/scenes/Cargo.toml b/examples/scenes/Cargo.toml index d9be6ea4..79450f11 100644 --- a/examples/scenes/Cargo.toml +++ b/examples/scenes/Cargo.toml @@ -11,7 +11,7 @@ workspace = true [dependencies] vello = { path = "../../" } -vello_svg = { path = "../../integrations/vello_svg" } +demo_svg = { path = "../../integrations/demo_svg" } anyhow = { workspace = true } clap = { workspace = true, features = ["derive"] } image = "0.24.9" diff --git a/examples/scenes/src/svg.rs b/examples/scenes/src/svg.rs index f14d3e9d..49fbc11f 100644 --- a/examples/scenes/src/svg.rs +++ b/examples/scenes/src/svg.rs @@ -5,11 +5,11 @@ use std::fs::read_dir; use std::path::{Path, PathBuf}; use anyhow::{Ok, Result}; +use demo_svg::usvg; +use demo_svg::usvg::TreeParsing; use instant::Instant; use vello::kurbo::Vec2; use vello::Scene; -use vello_svg::usvg; -use vello_svg::usvg::TreeParsing; use crate::{ExampleScene, SceneParams, SceneSet}; @@ -99,7 +99,7 @@ pub fn svg_function_of>( eprintln!("Parsed svg {name} in {:?}", start.elapsed()); let start = Instant::now(); let mut new_scene = Scene::new(); - vello_svg::render_tree(&mut new_scene, &svg); + demo_svg::render_tree(&mut new_scene, &svg); let resolution = Vec2::new(svg.size.width() as f64, svg.size.height() as f64); eprintln!("Encoded svg {name} in {:?}", start.elapsed()); (new_scene, resolution) diff --git a/integrations/vello_svg/Cargo.toml b/integrations/demo_svg/Cargo.toml similarity index 94% rename from integrations/vello_svg/Cargo.toml rename to integrations/demo_svg/Cargo.toml index 9693712f..ea651415 100644 --- a/integrations/vello_svg/Cargo.toml +++ b/integrations/demo_svg/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "vello_svg" +name = "demo_svg" description = "Render a usvg document to a Vello scene" categories = ["rendering", "graphics"] keywords = ["2d", "vector-graphics", "vello"] diff --git a/integrations/vello_svg/src/lib.rs b/integrations/demo_svg/src/lib.rs similarity index 100% rename from integrations/vello_svg/src/lib.rs rename to integrations/demo_svg/src/lib.rs From 4dfd3abf72229ec780dc28e307634b8e6fc40fe1 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Fri, 19 Apr 2024 19:20:14 -0400 Subject: [PATCH 02/17] docs: add changelog --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..cc811f88 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog + + + +## Unreleased + +## 0.1 (2024-03-04) + +- Initial release From f60f7c900d0722ae742ab0cd41c317850d205f68 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Fri, 19 Apr 2024 19:27:15 -0400 Subject: [PATCH 03/17] docs: update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc811f88..0205c2aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe ## Unreleased +### changed + +- [#547](https://github.com/linebender/vello/pull/547) - `RenderContext::new()` no longer returns a `Result` by [@waywardmonkeys](https://github.com/waywardmonkeys) + ## 0.1 (2024-03-04) - Initial release From 3dc82bca25713d0f8949d92ff7d1c0eefac7432f Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Fri, 19 Apr 2024 19:34:13 -0400 Subject: [PATCH 04/17] fix(docs): remove trailing HTML escape --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb51be20..fec3d3e6 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![Crates.io](https://img.shields.io/crates/v/vello.svg)](https://crates.io/crates/vello) [![Docs](https://docs.rs/vello/badge.svg)](https://docs.rs/vello) -[![Build status](https://github.com/linebender/vello/workflows/CI/badge.svg)](https://github.com/linebenvello/actions) --> +[![Build status](https://github.com/linebender/vello/workflows/CI/badge.svg)](https://github.com/linebenvello/actions) From 5f2b69b5d8a5debb5f281bc417235c5196c4051d Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Fri, 19 Apr 2024 19:35:07 -0400 Subject: [PATCH 05/17] fix: grammar --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fec3d3e6..862795a8 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ More formal benchmarks are on their way. A separate integration for rendering SVG files is available through the [`vello_svg`](https://github.com/linebender/vello_svg) crate. -This repository also includes a [`demo_svg`](./integrations/demo_svg/) integration, which only supports the minimal subset of SVG features needed for vello examples. This is used in the [winit](#winit) example for the SVG rendering. +This repository also includes the [`demo_svg`](./integrations/demo_svg/) integration, which supports a minimal subset of SVG features needed for vello examples. This is used in the [winit](#winit) example for the SVG rendering. ### Lottie From 859d6976134708597893e952bda02211c05422d0 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Sat, 20 Apr 2024 07:01:41 -0400 Subject: [PATCH 06/17] Update CHANGELOG.md Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0205c2aa..a61bdd2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe ## Unreleased -### changed +### Changed - [#547](https://github.com/linebender/vello/pull/547) - `RenderContext::new()` no longer returns a `Result` by [@waywardmonkeys](https://github.com/waywardmonkeys) From 1af373931bbc625d56f289145d68c62ac0a003ff Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Sat, 20 Apr 2024 07:16:24 -0400 Subject: [PATCH 07/17] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 862795a8..c96605e3 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,8 @@ More formal benchmarks are on their way. A separate integration for rendering SVG files is available through the [`vello_svg`](https://github.com/linebender/vello_svg) crate. -This repository also includes the [`demo_svg`](./integrations/demo_svg/) integration, which supports a minimal subset of SVG features needed for vello examples. This is used in the [winit](#winit) example for the SVG rendering. +This repository also includes the [`demo_svg`](./integrations/demo_svg/) integration, which supports a minimal subset of SVG features needed for vello examples. +This is used in the [winit](#winit) example for the SVG rendering. ### Lottie From b73f70682b8a73f88954ff3098a30d28d8f8797e Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Mon, 22 Apr 2024 15:27:28 -0400 Subject: [PATCH 08/17] Update Cargo.lock --- Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1b266aa6..a08d381d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3194,7 +3194,6 @@ dependencies = [ "anyhow", "byte-unit", "clap", - "demo_svg", "getrandom", "image", "inquire", From c427b6fef7fb869e87f766c7ab51c68f8c4dc8c2 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Mon, 22 Apr 2024 15:28:16 -0400 Subject: [PATCH 09/17] Delete integrations/demo_svg/Cargo.toml --- integrations/demo_svg/Cargo.toml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 integrations/demo_svg/Cargo.toml diff --git a/integrations/demo_svg/Cargo.toml b/integrations/demo_svg/Cargo.toml deleted file mode 100644 index ea651415..00000000 --- a/integrations/demo_svg/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "demo_svg" -description = "Render a usvg document to a Vello scene" -categories = ["rendering", "graphics"] -keywords = ["2d", "vector-graphics", "vello"] -edition.workspace = true -license.workspace = true -repository.workspace = true -publish = false - -[lints] -workspace = true - -[dependencies] -vello = { path = "../../" } -usvg = "0.37.0" From a6ce52f978ac4f4f3c71729c79de71e68e6720eb Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Mon, 22 Apr 2024 15:28:27 -0400 Subject: [PATCH 10/17] Delete integrations/demo_svg/src/lib.rs --- integrations/demo_svg/src/lib.rs | 301 ------------------------------- 1 file changed, 301 deletions(-) delete mode 100644 integrations/demo_svg/src/lib.rs diff --git a/integrations/demo_svg/src/lib.rs b/integrations/demo_svg/src/lib.rs deleted file mode 100644 index 2a00055a..00000000 --- a/integrations/demo_svg/src/lib.rs +++ /dev/null @@ -1,301 +0,0 @@ -// Copyright 2023 the Vello Authors -// SPDX-License-Identifier: Apache-2.0 OR MIT - -//! Append a [`usvg::Tree`] to a Vello [`Scene`] -//! -//! This currently lacks support for a [number of important](crate#unsupported-features) SVG features. -//! This is because this integration was developed for examples, which only need to support enough SVG -//! to demonstrate Vello. -//! -//! However, this is also intended to be the preferred integration between Vello and [usvg], so [consider -//! contributing](https://github.com/linebender/vello) if you need a feature which is missing. -//! -//! [`render_tree_with`] is the primary entry point function, which supports choosing the behaviour -//! when [unsupported features](crate#unsupported-features) are detected. In a future release where there are -//! no unsupported features, this may be phased out -//! -//! [`render_tree`] is a convenience wrapper around [`render_tree_with`] which renders an indicator around not -//! yet supported features -//! -//! This crate also re-exports [`usvg`], to make handling dependency versions easier -//! -//! # Unsupported features -//! -//! Missing features include: -//! - embedded images -//! - text -//! - group opacity -//! - mix-blend-modes -//! - clipping -//! - masking -//! - filter effects -//! - group background -//! - path visibility -//! - path paint order -//! - path shape-rendering -//! - patterns - -use std::convert::Infallible; -use usvg::NodeExt; -use vello::kurbo::{Affine, BezPath, Point, Rect, Stroke}; -use vello::peniko::{Brush, Color, Fill}; -use vello::Scene; - -/// Re-export vello. -pub use vello; - -/// Re-export usvg. -pub use usvg; - -/// Append a [`usvg::Tree`] into a Vello [`Scene`], with default error handling -/// This will draw a red box over (some) unsupported elements -/// -/// Calls [`render_tree_with`] with an error handler implementing the above. -/// -/// See the [module level documentation](crate#unsupported-features) for a list of some unsupported svg features -pub fn render_tree(scene: &mut Scene, svg: &usvg::Tree) { - render_tree_with(scene, svg, default_error_handler).unwrap_or_else(|e| match e {}); -} - -/// Append a [`usvg::Tree`] into a Vello [`Scene`]. -/// -/// Calls [`render_tree_with`] with [`default_error_handler`]. -/// This will draw a red box over unsupported element types. -/// -/// See the [module level documentation](crate#unsupported-features) for a list of some unsupported svg features -pub fn render_tree_with Result<(), E>, E>( - scene: &mut Scene, - svg: &usvg::Tree, - mut on_err: F, -) -> Result<(), E> { - for elt in svg.root.descendants() { - let transform = { - let usvg::Transform { - sx, - kx, - ky, - sy, - tx, - ty, - } = elt.abs_transform(); - Affine::new([sx, kx, ky, sy, tx, ty].map(f64::from)) - }; - match &*elt.borrow() { - usvg::NodeKind::Group(_) => {} - usvg::NodeKind::Path(path) => { - let mut local_path = BezPath::new(); - // The semantics of SVG paths don't line up with `BezPath`; we - // must manually track initial points - let mut just_closed = false; - let mut most_recent_initial = (0., 0.); - for elt in path.data.segments() { - match elt { - usvg::tiny_skia_path::PathSegment::MoveTo(p) => { - if std::mem::take(&mut just_closed) { - local_path.move_to(most_recent_initial); - } - most_recent_initial = (p.x.into(), p.y.into()); - local_path.move_to(most_recent_initial); - } - usvg::tiny_skia_path::PathSegment::LineTo(p) => { - if std::mem::take(&mut just_closed) { - local_path.move_to(most_recent_initial); - } - local_path.line_to(Point::new(p.x as f64, p.y as f64)); - } - usvg::tiny_skia_path::PathSegment::QuadTo(p1, p2) => { - if std::mem::take(&mut just_closed) { - local_path.move_to(most_recent_initial); - } - local_path.quad_to( - Point::new(p1.x as f64, p1.y as f64), - Point::new(p2.x as f64, p2.y as f64), - ); - } - usvg::tiny_skia_path::PathSegment::CubicTo(p1, p2, p3) => { - if std::mem::take(&mut just_closed) { - local_path.move_to(most_recent_initial); - } - local_path.curve_to( - Point::new(p1.x as f64, p1.y as f64), - Point::new(p2.x as f64, p2.y as f64), - Point::new(p3.x as f64, p3.y as f64), - ); - } - usvg::tiny_skia_path::PathSegment::Close => { - just_closed = true; - local_path.close_path(); - } - } - } - - // FIXME: let path.paint_order determine the fill/stroke order. - - if let Some(fill) = &path.fill { - if let Some((brush, brush_transform)) = - paint_to_brush(&fill.paint, fill.opacity) - { - scene.fill( - match fill.rule { - usvg::FillRule::NonZero => Fill::NonZero, - usvg::FillRule::EvenOdd => Fill::EvenOdd, - }, - transform, - &brush, - Some(brush_transform), - &local_path, - ); - } else { - on_err(scene, &elt)?; - } - } - if let Some(stroke) = &path.stroke { - if let Some((brush, brush_transform)) = - paint_to_brush(&stroke.paint, stroke.opacity) - { - let mut conv_stroke = Stroke::new(stroke.width.get() as f64) - .with_caps(match stroke.linecap { - usvg::LineCap::Butt => vello::kurbo::Cap::Butt, - usvg::LineCap::Round => vello::kurbo::Cap::Round, - usvg::LineCap::Square => vello::kurbo::Cap::Square, - }) - .with_join(match stroke.linejoin { - usvg::LineJoin::Miter | usvg::LineJoin::MiterClip => { - vello::kurbo::Join::Miter - } - usvg::LineJoin::Round => vello::kurbo::Join::Round, - usvg::LineJoin::Bevel => vello::kurbo::Join::Bevel, - }) - .with_miter_limit(stroke.miterlimit.get() as f64); - if let Some(dash_array) = stroke.dasharray.as_ref() { - conv_stroke = conv_stroke.with_dashes( - stroke.dashoffset as f64, - dash_array.iter().map(|x| *x as f64), - ); - } - scene.stroke( - &conv_stroke, - transform, - &brush, - Some(brush_transform), - &local_path, - ); - } else { - on_err(scene, &elt)?; - } - } - } - usvg::NodeKind::Image(_) => { - on_err(scene, &elt)?; - } - usvg::NodeKind::Text(_) => { - on_err(scene, &elt)?; - } - } - } - Ok(()) -} - -/// Error handler function for [`render_tree_with`] which draws a transparent red box -/// instead of unsupported SVG features -pub fn default_error_handler(scene: &mut Scene, node: &usvg::Node) -> Result<(), Infallible> { - if let Some(bb) = node.calculate_bbox() { - let rect = Rect { - x0: bb.left() as f64, - y0: bb.top() as f64, - x1: bb.right() as f64, - y1: bb.bottom() as f64, - }; - scene.fill( - Fill::NonZero, - Affine::IDENTITY, - Color::RED.with_alpha_factor(0.5), - None, - &rect, - ); - } - Ok(()) -} - -fn paint_to_brush(paint: &usvg::Paint, opacity: usvg::Opacity) -> Option<(Brush, Affine)> { - match paint { - usvg::Paint::Color(color) => Some(( - Brush::Solid(Color::rgba8( - color.red, - color.green, - color.blue, - opacity.to_u8(), - )), - Affine::IDENTITY, - )), - usvg::Paint::LinearGradient(gr) => { - let stops: Vec = gr - .stops - .iter() - .map(|stop| { - let mut cstop = vello::peniko::ColorStop::default(); - cstop.color.r = stop.color.red; - cstop.color.g = stop.color.green; - cstop.color.b = stop.color.blue; - cstop.color.a = (stop.opacity * opacity).to_u8(); - cstop.offset = stop.offset.get(); - cstop - }) - .collect(); - let start = Point::new(gr.x1 as f64, gr.y1 as f64); - let end = Point::new(gr.x2 as f64, gr.y2 as f64); - let arr = [ - gr.transform.sx, - gr.transform.ky, - gr.transform.kx, - gr.transform.sy, - gr.transform.tx, - gr.transform.ty, - ] - .map(f64::from); - let transform = Affine::new(arr); - let gradient = - vello::peniko::Gradient::new_linear(start, end).with_stops(stops.as_slice()); - Some((Brush::Gradient(gradient), transform)) - } - usvg::Paint::RadialGradient(gr) => { - let stops: Vec = gr - .stops - .iter() - .map(|stop| { - let mut cstop = vello::peniko::ColorStop::default(); - cstop.color.r = stop.color.red; - cstop.color.g = stop.color.green; - cstop.color.b = stop.color.blue; - cstop.color.a = (stop.opacity * opacity).to_u8(); - cstop.offset = stop.offset.get(); - cstop - }) - .collect(); - - let start_center = Point::new(gr.cx as f64, gr.cy as f64); - let end_center = Point::new(gr.fx as f64, gr.fy as f64); - let start_radius = 0_f32; - let end_radius = gr.r.get(); - let arr = [ - gr.transform.sx, - gr.transform.ky, - gr.transform.kx, - gr.transform.sy, - gr.transform.tx, - gr.transform.ty, - ] - .map(f64::from); - let transform = Affine::new(arr); - let gradient = vello::peniko::Gradient::new_two_point_radial( - start_center, - start_radius, - end_center, - end_radius, - ) - .with_stops(stops.as_slice()); - Some((Brush::Gradient(gradient), transform)) - } - usvg::Paint::Pattern(_) => None, - } -} From 4d91b2cf47f9c69f95b6dc8a375be64724c37003 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Tue, 23 Apr 2024 09:02:51 -0400 Subject: [PATCH 11/17] Update README.md Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 46b45838..c324dba6 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![Crates.io](https://img.shields.io/crates/v/vello.svg)](https://crates.io/crates/vello) [![Docs](https://docs.rs/vello/badge.svg)](https://docs.rs/vello) -[![Build status](https://github.com/linebender/vello/workflows/CI/badge.svg)](https://github.com/linebenvello/actions) +[![Build status](https://github.com/linebender/vello/workflows/CI/badge.svg)](https://github.com/linebender/vello/actions) From 2bb2ac3efcb4f92cc1d8df10a737cd0319b98a29 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Tue, 23 Apr 2024 09:03:11 -0400 Subject: [PATCH 12/17] Update README.md Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c324dba6..63e5c01e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Vello -**An experimental GPU compute-centric 2D renderer.** +**An experimental GPU compute-centric 2D renderer** [![Linebender Zulip](https://img.shields.io/badge/Linebender-%23gpu-blue?logo=Zulip)](https://xi.zulipchat.com/#narrow/stream/197075-gpu) [![dependency status](https://deps.rs/repo/github/linebender/vello/status.svg)](https://deps.rs/repo/github/linebender/vello) From aa4c1ccaabd7f745ea5d6604195a7993bd8e9e64 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Tue, 23 Apr 2024 10:04:17 -0400 Subject: [PATCH 13/17] fix: outdated docs --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 63e5c01e..7237edac 100644 --- a/README.md +++ b/README.md @@ -121,10 +121,6 @@ More formal benchmarks are on their way. A separate integration for rendering SVG files is available through the [`vello_svg`](https://github.com/linebender/vello_svg) crate. -This repository also includes the [`demo_svg`](./integrations/demo_svg/) integration, which supports a minimal subset of SVG features needed for vello examples. -This is used in the [winit](#winit) example for the SVG rendering. - - ### Lottie A separate integration for playing Lottie animations is available through the [`velato`](https://github.com/linebender/velato) crate. From 9f7b8885109277231bd25ab7d232d3b247bc1586 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Tue, 23 Apr 2024 10:05:04 -0400 Subject: [PATCH 14/17] fix: attribute linebender --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7237edac..044580c6 100644 --- a/README.md +++ b/README.md @@ -119,11 +119,11 @@ More formal benchmarks are on their way. ### SVG -A separate integration for rendering SVG files is available through the [`vello_svg`](https://github.com/linebender/vello_svg) crate. +A separate Linebender integration for rendering SVG files is available through the [`vello_svg`](https://github.com/linebender/vello_svg) crate. ### Lottie -A separate integration for playing Lottie animations is available through the [`velato`](https://github.com/linebender/velato) crate. +A separate Linebender integration for playing Lottie animations is available through the [`velato`](https://github.com/linebender/velato) crate. ## Examples From 4888de09acf9cac9ef94832a97cb853bf1e90f1f Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Tue, 23 Apr 2024 10:12:14 -0400 Subject: [PATCH 15/17] docs: update changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a61bdd2a..3d10b18e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,20 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe ## Unreleased +### Added + +- [#435](https://github.com/linebender/vello/pull/435) - Sweet gradients by [@dfrg](https://github.com/drfg) +- [#537](https://github.com/linebender/vello/pull/537) - Restore glyph hinting support by [@dfrg](https://github.com/drfg) + ### Changed - [#547](https://github.com/linebender/vello/pull/547) - `RenderContext::new()` no longer returns a `Result` by [@waywardmonkeys](https://github.com/waywardmonkeys) +### Fixed + +- [#521](https://github.com/linebender/vello/pull/521) - Rework robustness of cubic params by [@raphlinus](https://github.com/raphlinus) +- [#526](https://github.com/linebender/vello/pull/526) - Increase ~64k draw object limit by [@raphlinus](https://github.com/raphlinus) + ## 0.1 (2024-03-04) - Initial release From 7718aaf6e50fc1bdbe4d9f6408a79598c30660c0 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Tue, 23 Apr 2024 10:21:20 -0400 Subject: [PATCH 16/17] Update CHANGELOG.md Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d10b18e..4506aee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe ### Added -- [#435](https://github.com/linebender/vello/pull/435) - Sweet gradients by [@dfrg](https://github.com/drfg) +- [#435](https://github.com/linebender/vello/pull/435) - Sweep gradients by [@dfrg](https://github.com/drfg) - [#537](https://github.com/linebender/vello/pull/537) - Restore glyph hinting support by [@dfrg](https://github.com/drfg) ### Changed From be07cc45b9d3568c94610f09647eb189251b4422 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Tue, 23 Apr 2024 10:26:05 -0400 Subject: [PATCH 17/17] fix: docs --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4506aee1..75b1ff99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe ### Added - [#435](https://github.com/linebender/vello/pull/435) - Sweep gradients by [@dfrg](https://github.com/drfg) -- [#537](https://github.com/linebender/vello/pull/537) - Restore glyph hinting support by [@dfrg](https://github.com/drfg) +- [#544](https://github.com/linebender/vello/pull/544) - Restore glyph hinting support by [@dfrg](https://github.com/drfg) ### Changed @@ -21,8 +21,10 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe ### Fixed -- [#521](https://github.com/linebender/vello/pull/521) - Rework robustness of cubic params by [@raphlinus](https://github.com/raphlinus) -- [#526](https://github.com/linebender/vello/pull/526) - Increase ~64k draw object limit by [@raphlinus](https://github.com/raphlinus) +- [#496](https://github.com/linebender/vello/pull/496) - Performance optimizations for stroke-heavy scenes by [@raphlinus](https://github.com/raphlinus) +- [#521](https://github.com/linebender/vello/pull/521) - Increase robustness of cubic params by [@raphlinus](https://github.com/raphlinus) +- [#526](https://github.com/linebender/vello/pull/526) - Increases ~64k draw object limit by [@raphlinus](https://github.com/raphlinus) +- [#537](https://github.com/linebender/vello/pull/537) - Increase robustness of GPU shaders by [@raphlinus](https://github.com/raphlinus) ## 0.1 (2024-03-04)