Skip to content

Commit

Permalink
Version 0.3 (#18)
Browse files Browse the repository at this point in the history
## 0.3.0

### Added

- Added `vello_svg::Error`, which is returned by new functions that read
text into a `usvg::Tree`.
- Added `vello_svg::render`, which takes an svg string and renders to a
new vello scene.
- Added `vello_svg::append`, which takes an svg string and renders to a
provided vello scene.
- Added `vello_svg::append_with`, which takes an svg string and renders
to a provided vello scene with and error handler.
- Added `vello_svg::render_tree`, which takes a usvg::Tree and renders
to a provided vello scene with and error handler.

### Changed

- Updated to vello 0.2
- Renamed `render_tree` to `append_tree`
- Renamed `render_tree_with` to `append_tree_with` and removed the
`Result<(), E>` return type for the error handler.
  • Loading branch information
simbleau committed Jul 3, 2024
1 parent cf6fe55 commit b84f1e6
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 582 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe

## Unreleased

## 0.3.0

### Added

- Added `vello_svg::Error`, which is returned by new functions that read text into a `usvg::Tree`.
- Added `vello_svg::render`, which takes an svg string and renders to a new vello scene.
- Added `vello_svg::append`, which takes an svg string and renders to a provided vello scene.
- Added `vello_svg::append_with`, which takes an svg string and renders to a provided vello scene with and error handler.
- Added `vello_svg::render_tree`, which takes a usvg::Tree and renders to a provided vello scene with and error handler.

### Changed

- Updated to vello 0.2
- Updated to usvg 0.42
- Renamed `render_tree` to `append_tree`
- Renamed `render_tree_with` to `append_tree_with` and removed the `Result<(), E>` return type for the error handler.

### Removed

- All code and related profiling (`wgpu_profiler`) used in examples.

## 0.2.0

### Added
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ members = ["examples/with_winit", "examples/run_wasm", "examples/scenes"]

[workspace.package]
edition = "2021"
version = "0.2.0"
version = "0.3.0"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/linebender/vello_svg"

[workspace.dependencies]
# NOTE: Make sure to keep this in sync with the version badge in README.md
vello = { version = "0.1.0", default-features = false }
vello = { version = "0.2.0", default-features = false }

[package]
name = "vello_svg"
Expand All @@ -24,14 +24,14 @@ repository.workspace = true

[dependencies]
vello = { workspace = true }
usvg = "0.41.0"
thiserror = "1.0.61"
usvg = "0.42.0"
image = { version = "0.25.0", default-features = false, features = [
"png",
"jpeg",
"gif",
] }


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

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
[![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_svg/status.svg)](https://deps.rs/repo/github/linebender/vello_svg)
[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](#license)
[![vello version](https://img.shields.io/badge/vello-v0.1.0-purple.svg)](https://crates.io/crates/vello)

[![vello version](https://img.shields.io/badge/vello-v0.2.0-purple.svg)](https://crates.io/crates/vello)\
[![Crates.io](https://img.shields.io/crates/v/vello_svg.svg)](https://crates.io/crates/vello_svg)
[![Docs](https://docs.rs/vello_svg/badge.svg)](https://docs.rs/vello_svg)
[![Build status](https://github.com/linebender/vello_svg/workflows/CI/badge.svg)](https://github.com/linebender/vello_svg/actions)
Expand Down
2 changes: 1 addition & 1 deletion examples/run_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ repository.workspace = true
publish = false

[dependencies]
cargo-run-wasm = "0.3.2"
cargo-run-wasm = "0.4.0"
2 changes: 1 addition & 1 deletion examples/run_wasm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
/// ```

fn main() {
cargo_run_wasm::run_wasm_with_css("body { margin: 0px; }");
cargo_run_wasm::run_wasm_cli_with_css("body { margin: 0px; }");
}
8 changes: 3 additions & 5 deletions examples/scenes/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,14 @@ pub fn svg_function_of<R: AsRef<str>>(
) -> impl FnMut(&mut Scene, &mut SceneParams) {
fn render_svg_contents(name: &str, contents: &str) -> (Scene, Vec2) {
let start = Instant::now();
let fontdb = usvg::fontdb::Database::new();
let svg = usvg::Tree::from_str(contents, &usvg::Options::default(), &fontdb)
let svg = usvg::Tree::from_str(contents, &usvg::Options::default())
.unwrap_or_else(|e| panic!("failed to parse svg file {name}: {e}"));
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);
let scene = vello_svg::render_tree(&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)
(scene, resolution)
}
let mut cached_scene = None;
#[cfg(not(target_arch = "wasm32"))]
Expand Down
6 changes: 2 additions & 4 deletions examples/with_winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ name = "with_winit_bin"
path = "src/main.rs"

[dependencies]
vello = { workspace = true, features = ["buffer_labels", "wgpu", "wgpu-profiler"] }
vello = { workspace = true, features = ["buffer_labels", "wgpu"] }
scenes = { path = "../scenes" }
anyhow = "1"
clap = { version = "4.5.1", features = ["derive"] }
instant = { version = "0.1.12", features = ["wasm-bindgen"] }
pollster = "0.3"
wgpu-profiler = "0.16"
wgpu = "0.19.3"
winit = "0.29.12"
env_logger = "0.11.2"
log = "0.4.21"

[target.'cfg(not(any(target_arch = "wasm32", target_os = "android")))'.dependencies]
vello = { workspace = true, features = ["hot_reload", "wgpu", "wgpu-profiler"] }
vello = { workspace = true, features = ["hot_reload", "wgpu"] }
notify-debouncer-mini = "0.3"

[target.'cfg(target_os = "android")'.dependencies]
Expand Down
75 changes: 12 additions & 63 deletions examples/with_winit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 the Vello Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use instant::{Duration, Instant};
use instant::Instant;
use std::collections::HashSet;
use std::num::NonZeroUsize;
use std::sync::Arc;
Expand All @@ -12,7 +12,7 @@ use scenes::{RobotoText, SceneParams, SceneSet};
use vello::kurbo::{Affine, Vec2};
use vello::peniko::Color;
use vello::util::{RenderContext, RenderSurface};
use vello::{AaConfig, BumpAllocators, Renderer, RendererOptions, Scene};
use vello::{wgpu, AaConfig, BumpAllocators, Renderer, RendererOptions, Scene};

use winit::event_loop::{EventLoop, EventLoopBuilder};
use winit::window::Window;
Expand Down Expand Up @@ -83,7 +83,7 @@ fn run(
let mut render_state = {
renderers.resize_with(render_cx.devices.len(), || None);
let id = render_state.surface.dev_id;
let mut renderer = Renderer::new(
let renderer = Renderer::new(
&render_cx.devices[id].device,
RendererOptions {
surface_format: Some(render_state.surface.format),
Expand All @@ -95,14 +95,6 @@ fn run(
},
)
.expect("Could create renderer");
renderer
.profiler
.change_settings(wgpu_profiler::GpuProfilerSettings {
enable_timer_queries: false,
enable_debug_groups: false,
..Default::default()
})
.expect("Not setting max_num_pending_frames");
renderers[id] = Some(renderer);
Some(render_state)
};
Expand Down Expand Up @@ -145,9 +137,7 @@ fn run(
if let Some(set_scene) = args.scene {
scene_ix = set_scene;
}
let mut profile_stored = None;
let mut prev_scene_ix = scene_ix - 1;
let mut profile_taken = Instant::now();
let mut modifiers = ModifiersState::default();
event_loop
.run(move |event, event_loop| match event {
Expand Down Expand Up @@ -211,32 +201,6 @@ fn run(
aa_config_ix.saturating_add(1)
};
}
"p" => {
if let Some(renderer) = &renderers[render_state.surface.dev_id]
{
if let Some(profile_result) = &renderer
.profile_result
.as_ref()
.or(profile_stored.as_ref())
{
// There can be empty results if the required features aren't supported
if !profile_result.is_empty() {
let path = std::path::Path::new("trace.json");
match wgpu_profiler::chrometrace::write_chrometrace(
path,
profile_result,
) {
Ok(()) => {
println!("Wrote trace to path {path:?}");
}
Err(e) => {
eprintln!("Failed to write trace {e}")
}
}
}
}
}
}
"v" => {
vsync_on = !vsync_on;
render_cx.set_present_mode(
Expand Down Expand Up @@ -409,26 +373,6 @@ fn run(
vsync_on,
antialiasing_method,
);
if let Some(profiling_result) = renderers[render_state.surface.dev_id]
.as_mut()
.and_then(|it| it.profile_result.take())
{
if profile_stored.is_none()
|| profile_taken.elapsed() > Duration::from_secs(1)
{
profile_stored = Some(profiling_result);
profile_taken = Instant::now();
}
}
if let Some(profiling_result) = profile_stored.as_ref() {
stats::draw_gpu_profiling(
&mut scene,
scene_params.text,
width as f64,
height as f64,
profiling_result,
);
}
}
let surface_texture = render_state
.surface
Expand Down Expand Up @@ -534,7 +478,12 @@ fn run(
.take()
.unwrap_or_else(|| create_window(event_loop));
let size = window.inner_size();
let surface_future = render_cx.create_surface(window.clone(), size.width, size.height, wgpu::PresentMode::AutoVsync);
let surface_future = render_cx.create_surface(
window.clone(),
size.width,
size.height,
wgpu::PresentMode::AutoVsync,
);
// We need to block here, in case a Suspended event appeared
let surface =
pollster::block_on(surface_future).expect("Error creating surface");
Expand All @@ -550,7 +499,7 @@ fn run(
surface_format: Some(render_state.surface.format),
use_cpu,
antialiasing_support: vello::AaSupport::all(),
num_init_threads: NonZeroUsize::new(args.num_init_threads)
num_init_threads: NonZeroUsize::new(args.num_init_threads),
},
)
.expect("Could create renderer");
Expand Down Expand Up @@ -617,7 +566,7 @@ pub fn main() -> Result<()> {
if let Some(scenes) = scenes {
let event_loop = EventLoopBuilder::<UserEvent>::with_user_event().build()?;
#[allow(unused_mut)]
let mut render_cx = RenderContext::new().unwrap();
let mut render_cx = RenderContext::new();
#[cfg(not(target_arch = "wasm32"))]
{
#[cfg(not(target_os = "android"))]
Expand Down Expand Up @@ -701,7 +650,7 @@ fn android_main(app: AndroidApp) {
.select_scene_set(|| Args::command())
.unwrap()
.unwrap();
let render_cx = RenderContext::new().unwrap();
let render_cx = RenderContext::new();

run(event_loop, args, scenes, render_cx);
}
Loading

0 comments on commit b84f1e6

Please sign in to comment.