Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SceneBuilder/Fragment #432

Merged
merged 6 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 5 deletions crates/encoding/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Encoding {
}

/// Clears the encoding.
pub fn reset(&mut self, is_fragment: bool) {
pub fn reset(&mut self) {
self.transforms.clear();
self.path_tags.clear();
self.path_data.clear();
Expand All @@ -79,10 +79,6 @@ impl Encoding {
self.flags = 0;
#[cfg(feature = "full")]
self.resources.reset();
if !is_fragment {
self.transforms.push(Transform::IDENTITY);
self.styles.push(Style::from_fill(Fill::NonZero));
}
}

/// Appends another encoding to this one with an optional transform.
Expand Down
2 changes: 1 addition & 1 deletion crates/encoding/src/glyph_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct GlyphCache {

impl GlyphCache {
pub fn clear(&mut self) {
self.encoding.reset(true);
self.encoding.reset();
self.glyphs.clear();
}

Expand Down
10 changes: 4 additions & 6 deletions examples/headless/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use vello::{
block_on_wgpu,
kurbo::{Affine, Vec2},
util::RenderContext,
RendererOptions, Scene, SceneBuilder, SceneFragment,
RendererOptions, Scene,
};
use wgpu::{
BufferDescriptor, BufferUsages, CommandEncoderDescriptor, Extent3d, ImageCopyBuffer,
Expand Down Expand Up @@ -94,8 +94,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> {
},
)
.or_else(|_| bail!("Got non-Send/Sync error from creating renderer"))?;
let mut fragment = SceneFragment::new();
let mut builder = SceneBuilder::for_fragment(&mut fragment);
let mut fragment = Scene::new();
let example_scene = &mut scenes.scenes[index];
let mut text = SimpleText::new();
let mut images = ImageCache::new();
Expand All @@ -110,7 +109,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> {
};
example_scene
.function
.render(&mut builder, &mut scene_params);
.render(&mut fragment, &mut scene_params);
let mut transform = Affine::IDENTITY;
let (width, height) = if let Some(resolution) = scene_params.resolution {
let ratio = resolution.x / resolution.y;
Expand Down Expand Up @@ -143,8 +142,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> {
antialiasing_method: vello::AaConfig::Area,
};
let mut scene = Scene::new();
let mut builder = SceneBuilder::for_scene(&mut scene);
builder.append(&fragment, Some(transform));
scene.append(&fragment, Some(transform));
let size = Extent3d {
width,
height,
Expand Down
8 changes: 4 additions & 4 deletions examples/scenes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use simple_text::SimpleText;
pub use svg::{default_scene, scene_from_files};
pub use test_scenes::test_scenes;

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

pub struct SceneParams<'a> {
pub time: f64,
Expand All @@ -43,11 +43,11 @@ pub struct ExampleScene {
}

pub trait TestScene {
fn render(&mut self, sb: &mut SceneBuilder, params: &mut SceneParams);
fn render(&mut self, sb: &mut Scene, params: &mut SceneParams);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sb here is short for SceneBuilder, which is of course no longer accurate

I'm not certain what we should change it to. Maybe scene would be fine?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, good catch. Renamed all of these (and occurrences of builder) to scene.

}

impl<F: FnMut(&mut SceneBuilder, &mut SceneParams)> TestScene for F {
fn render(&mut self, sb: &mut SceneBuilder, params: &mut SceneParams) {
impl<F: FnMut(&mut Scene, &mut SceneParams)> TestScene for F {
fn render(&mut self, sb: &mut Scene, params: &mut SceneParams) {
self(sb, params);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/scenes/src/mmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rand::{seq::SliceRandom, Rng};
use vello::peniko::Color;
use vello::{
kurbo::{Affine, BezPath, CubicBez, Line, ParamCurve, PathSeg, Point, QuadBez, Stroke},
SceneBuilder,
Scene,
};

use crate::{SceneParams, TestScene};
Expand Down Expand Up @@ -67,7 +67,7 @@ impl MMark {
}

impl TestScene for MMark {
fn render(&mut self, sb: &mut SceneBuilder, params: &mut SceneParams) {
fn render(&mut self, sb: &mut Scene, params: &mut SceneParams) {
let c = params.complexity;
let n = if c < 10 {
(c + 1) * 1000
Expand Down
8 changes: 4 additions & 4 deletions examples/scenes/src/simple_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use vello::{
kurbo::Affine,
peniko::{Blob, Brush, BrushRef, Font, StyleRef},
skrifa::{raw::FontRef, MetadataProvider},
SceneBuilder,
Scene,
};

// This is very much a hack to get things working.
Expand All @@ -46,7 +46,7 @@ impl SimpleText {
#[allow(clippy::too_many_arguments)]
pub fn add_run<'a>(
&mut self,
builder: &mut SceneBuilder,
builder: &mut Scene,
font: Option<&Font>,
size: f32,
brush: impl Into<BrushRef<'a>>,
Expand All @@ -71,7 +71,7 @@ impl SimpleText {
#[allow(clippy::too_many_arguments)]
pub fn add_var_run<'a>(
&mut self,
builder: &mut SceneBuilder,
builder: &mut Scene,
font: Option<&Font>,
size: f32,
variations: &[(&str, f32)],
Expand Down Expand Up @@ -129,7 +129,7 @@ impl SimpleText {

pub fn add(
&mut self,
builder: &mut SceneBuilder,
builder: &mut Scene,
font: Option<&Font>,
size: f32,
brush: Option<&Brush>,
Expand Down
11 changes: 5 additions & 6 deletions examples/scenes/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use anyhow::{Ok, Result};
use instant::Instant;
use vello::{kurbo::Vec2, SceneBuilder, SceneFragment};
use vello::{kurbo::Vec2, Scene};
use vello_svg::usvg;
use vello_svg::usvg::TreeParsing;

Expand Down Expand Up @@ -88,16 +88,15 @@ fn example_scene_of(file: PathBuf) -> ExampleScene {
pub fn svg_function_of<R: AsRef<str>>(
name: String,
contents: impl FnOnce() -> R + Send + 'static,
) -> impl FnMut(&mut SceneBuilder, &mut SceneParams) {
fn render_svg_contents(name: &str, contents: &str) -> (SceneFragment, Vec2) {
) -> impl FnMut(&mut Scene, &mut SceneParams) {
fn render_svg_contents(name: &str, contents: &str) -> (Scene, Vec2) {
let start = Instant::now();
let svg = usvg::Tree::from_str(contents, &usvg::Options::default())
.expect("failed to parse svg file");
eprintln!("Parsed svg {name} in {:?}", start.elapsed());
let start = Instant::now();
let mut new_scene = SceneFragment::new();
let mut builder = SceneBuilder::for_fragment(&mut new_scene);
vello_svg::render_tree(&mut builder, &svg);
let mut new_scene = Scene::new();
vello_svg::render_tree(&mut new_scene, &svg);
let resolution = Vec2::new(svg.size.width(), svg.size.height());
eprintln!("Encoded svg {name} in {:?}", start.elapsed());
(new_scene, resolution)
Expand Down
55 changes: 27 additions & 28 deletions examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn test_scenes() -> SceneSet {

// Scenes

fn funky_paths(sb: &mut SceneBuilder, _: &mut SceneParams) {
fn funky_paths(sb: &mut Scene, _: &mut SceneParams) {
use PathEl::*;
let missing_movetos = [
MoveTo((0., 0.).into()),
Expand Down Expand Up @@ -109,7 +109,7 @@ fn funky_paths(sb: &mut SceneBuilder, _: &mut SceneParams) {
);
}

fn stroke_styles(transform: Affine) -> impl FnMut(&mut SceneBuilder, &mut SceneParams) {
fn stroke_styles(transform: Affine) -> impl FnMut(&mut Scene, &mut SceneParams) {
use PathEl::*;
move |sb, params| {
let colors = [
Expand Down Expand Up @@ -280,7 +280,7 @@ fn stroke_styles(transform: Affine) -> impl FnMut(&mut SceneBuilder, &mut SceneP

// This test has been adapted from Skia's "trickycubicstrokes" GM slide which can be found at
// `github.com/google/skia/blob/0d4d11451c4f4e184305cbdbd67f6b3edfa4b0e3/gm/trickycubicstrokes.cpp`
fn tricky_strokes(sb: &mut SceneBuilder, _: &mut SceneParams) {
fn tricky_strokes(sb: &mut Scene, _: &mut SceneParams) {
use PathEl::*;
let colors = [
Color::rgb8(140, 181, 236),
Expand Down Expand Up @@ -368,7 +368,7 @@ fn tricky_strokes(sb: &mut SceneBuilder, _: &mut SceneParams) {
}
}

fn fill_types(sb: &mut SceneBuilder, params: &mut SceneParams) {
fn fill_types(sb: &mut Scene, params: &mut SceneParams) {
use PathEl::*;
let rect = Rect::from_origin_size(Point::new(0., 0.), (500., 500.));
let star = [
Expand Down Expand Up @@ -452,14 +452,14 @@ fn fill_types(sb: &mut SceneBuilder, params: &mut SceneParams) {
}
}

fn cardioid_and_friends(sb: &mut SceneBuilder, _: &mut SceneParams) {
fn cardioid_and_friends(sb: &mut Scene, _: &mut SceneParams) {
render_cardioid(sb);
render_clip_test(sb);
render_alpha_test(sb);
//render_tiger(sb, false);
}

fn longpathdash(cap: Cap) -> impl FnMut(&mut SceneBuilder, &mut SceneParams) {
fn longpathdash(cap: Cap) -> impl FnMut(&mut Scene, &mut SceneParams) {
use std::f64::consts::PI;
use PathEl::*;
move |sb, _| {
Expand Down Expand Up @@ -504,7 +504,7 @@ fn longpathdash(cap: Cap) -> impl FnMut(&mut SceneBuilder, &mut SceneParams) {
}
}

fn animated_text(sb: &mut SceneBuilder, params: &mut SceneParams) {
fn animated_text(sb: &mut Scene, params: &mut SceneParams) {
// Uses the static array address as a cache key for expedience. Real code
// should use a better strategy.
let piet_logo = params
Expand Down Expand Up @@ -621,7 +621,7 @@ fn animated_text(sb: &mut SceneBuilder, params: &mut SceneParams) {
);
}

fn brush_transform(sb: &mut SceneBuilder, params: &mut SceneParams) {
fn brush_transform(sb: &mut Scene, params: &mut SceneParams) {
let th = params.time;
let linear = Gradient::new_linear((0.0, 0.0), (0.0, 200.0)).with_stops([
Color::RED,
Expand Down Expand Up @@ -655,8 +655,8 @@ fn brush_transform(sb: &mut SceneBuilder, params: &mut SceneParams) {
);
}

fn gradient_extend(sb: &mut SceneBuilder, params: &mut SceneParams) {
fn square(sb: &mut SceneBuilder, is_radial: bool, transform: Affine, extend: Extend) {
fn gradient_extend(sb: &mut Scene, params: &mut SceneParams) {
fn square(sb: &mut Scene, is_radial: bool, transform: Affine, extend: Extend) {
let colors = [Color::RED, Color::rgb8(0, 255, 0), Color::BLUE];
let width = 300f64;
let height = 300f64;
Expand Down Expand Up @@ -703,9 +703,9 @@ fn gradient_extend(sb: &mut SceneBuilder, params: &mut SceneParams) {
}

#[allow(clippy::too_many_arguments)]
fn two_point_radial(sb: &mut SceneBuilder, _params: &mut SceneParams) {
fn two_point_radial(sb: &mut Scene, _params: &mut SceneParams) {
fn make(
sb: &mut SceneBuilder,
sb: &mut Scene,
x0: f64,
y0: f64,
r0: f32,
Expand Down Expand Up @@ -867,7 +867,7 @@ fn two_point_radial(sb: &mut SceneBuilder, _params: &mut SceneParams) {
}
}

fn blend_grid(sb: &mut SceneBuilder, _: &mut SceneParams) {
fn blend_grid(sb: &mut Scene, _: &mut SceneParams) {
const BLEND_MODES: &[Mix] = &[
Mix::Normal,
Mix::Multiply,
Expand Down Expand Up @@ -897,7 +897,7 @@ fn blend_grid(sb: &mut SceneBuilder, _: &mut SceneParams) {

// Support functions

fn render_cardioid(sb: &mut SceneBuilder) {
fn render_cardioid(sb: &mut Scene) {
let n = 601;
let dth = std::f64::consts::PI * 2.0 / (n as f64);
let center = Point::new(1024.0, 768.0);
Expand All @@ -924,7 +924,7 @@ fn render_cardioid(sb: &mut SceneBuilder) {
);
}

fn render_clip_test(sb: &mut SceneBuilder) {
fn render_clip_test(sb: &mut Scene) {
const N: usize = 16;
const X0: f64 = 50.0;
const Y0: f64 = 450.0;
Expand Down Expand Up @@ -958,7 +958,7 @@ fn render_clip_test(sb: &mut SceneBuilder) {
}
}

fn render_alpha_test(sb: &mut SceneBuilder) {
fn render_alpha_test(sb: &mut Scene) {
// Alpha compositing tests.
sb.fill(
Fill::NonZero,
Expand Down Expand Up @@ -990,7 +990,7 @@ fn render_alpha_test(sb: &mut SceneBuilder) {
sb.pop_layer();
}

fn render_blend_square(sb: &mut SceneBuilder, blend: BlendMode, transform: Affine) {
fn render_blend_square(sb: &mut Scene, blend: BlendMode, transform: Affine) {
// Inspired by https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode
let rect = Rect::from_origin_size(Point::new(0., 0.), (200., 200.));
let linear =
Expand Down Expand Up @@ -1034,14 +1034,13 @@ fn render_blend_square(sb: &mut SceneBuilder, blend: BlendMode, transform: Affin
sb.pop_layer();
}

fn blend_square(blend: BlendMode) -> SceneFragment {
let mut fragment = SceneFragment::default();
let mut sb = SceneBuilder::for_fragment(&mut fragment);
render_blend_square(&mut sb, blend, Affine::IDENTITY);
fn blend_square(blend: BlendMode) -> Scene {
let mut fragment = Scene::default();
render_blend_square(&mut fragment, blend, Affine::IDENTITY);
fragment
}

fn conflation_artifacts(sb: &mut SceneBuilder, _: &mut SceneParams) {
fn conflation_artifacts(sb: &mut Scene, _: &mut SceneParams) {
use PathEl::*;
const N: f64 = 50.0;
const S: f64 = 4.0;
Expand Down Expand Up @@ -1130,7 +1129,7 @@ fn conflation_artifacts(sb: &mut SceneBuilder, _: &mut SceneParams) {
);
}

fn labyrinth(sb: &mut SceneBuilder, _: &mut SceneParams) {
fn labyrinth(sb: &mut Scene, _: &mut SceneParams) {
use PathEl::*;

let rows: &[[u8; 12]] = &[
Expand Down Expand Up @@ -1207,7 +1206,7 @@ fn labyrinth(sb: &mut SceneBuilder, _: &mut SceneParams) {
);
}

fn robust_paths(sb: &mut SceneBuilder, _: &mut SceneParams) {
fn robust_paths(sb: &mut Scene, _: &mut SceneParams) {
let mut path = BezPath::new();
path.move_to((16.0, 16.0));
path.line_to((32.0, 16.0));
Expand Down Expand Up @@ -1284,7 +1283,7 @@ fn robust_paths(sb: &mut SceneBuilder, _: &mut SceneParams) {
);
}

fn base_color_test(sb: &mut SceneBuilder, params: &mut SceneParams) {
fn base_color_test(sb: &mut Scene, params: &mut SceneParams) {
// Cycle through the hue value every 5 seconds (t % 5) * 360/5
let color = Color::hlc((params.time % 5.0) * 72.0, 80.0, 80.0);
params.base_color = Some(color);
Expand All @@ -1299,7 +1298,7 @@ fn base_color_test(sb: &mut SceneBuilder, params: &mut SceneParams) {
);
}

fn clip_test(sb: &mut SceneBuilder, params: &mut SceneParams) {
fn clip_test(sb: &mut Scene, params: &mut SceneParams) {
let clip = {
const X0: f64 = 50.0;
const Y0: f64 = 0.0;
Expand Down Expand Up @@ -1404,7 +1403,7 @@ fn make_diamond(cx: f64, cy: f64) -> [PathEl; 5] {
]
}

fn splash_screen(sb: &mut SceneBuilder, params: &mut SceneParams) {
fn splash_screen(sb: &mut Scene, params: &mut SceneParams) {
let strings = [
"Vello test",
" Arrow keys: switch scenes",
Expand All @@ -1429,7 +1428,7 @@ fn splash_screen(sb: &mut SceneBuilder, params: &mut SceneParams) {
}
}

fn splash_with_tiger() -> impl FnMut(&mut SceneBuilder, &mut SceneParams) {
fn splash_with_tiger() -> impl FnMut(&mut Scene, &mut SceneParams) {
let contents = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../assets/Ghostscript_Tiger.svg"
Expand Down
Loading