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

Factored out file loading on render tick for winit bin #162

Merged
merged 1 commit into from
Apr 5, 2022
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
8 changes: 6 additions & 2 deletions piet-gpu/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use clap::{App, Arg};

use piet_gpu_hal::{BufferUsage, Error, Instance, InstanceFlags, Session};

use piet_gpu::{test_scenes, PietGpuRenderContext, Renderer};
use piet_gpu::{test_scenes, PicoSvg, PietGpuRenderContext, Renderer};

const WIDTH: usize = 2048;
const HEIGHT: usize = 1536;
Expand Down Expand Up @@ -243,7 +243,11 @@ fn main() -> Result<(), Error> {
if matches.is_present("flip") {
scale = -scale;
}
test_scenes::render_svg(&mut ctx, input, scale);
let xml_str = std::fs::read_to_string(input).unwrap();
let start = std::time::Instant::now();
let svg = PicoSvg::load(&xml_str, scale).unwrap();
println!("parsing time: {:?}", start.elapsed());
test_scenes::render_svg(&mut ctx, &svg);
} else {
test_scenes::render_scene(&mut ctx);
}
Expand Down
32 changes: 22 additions & 10 deletions piet-gpu/bin/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use piet::kurbo::Point;
use piet::{RenderContext, Text, TextAttribute, TextLayoutBuilder};
use piet_gpu_hal::{CmdBuf, Error, ImageLayout, Instance, Session, SubmittedCmdBuf};

use piet_gpu::{test_scenes, PietGpuRenderContext, Renderer};
use piet_gpu::{test_scenes, PicoSvg, PietGpuRenderContext, Renderer};

use clap::{App, Arg};

Expand All @@ -29,6 +29,25 @@ fn main() -> Result<(), Error> {
)
.get_matches();

// Collect SVG if input
let svg = match matches.value_of("INPUT") {
Some(file) => {
let mut scale = matches
.value_of("scale")
.map(|scale| scale.parse().unwrap())
.unwrap_or(8.0);
if matches.is_present("flip") {
scale = -scale;
}
let xml_str = std::fs::read_to_string(file).unwrap();
let start = std::time::Instant::now();
let svg = PicoSvg::load(&xml_str, scale).unwrap();
println!("parsing time: {:?}", start.elapsed());
Some(svg)
}
None => None,
};

let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_inner_size(winit::dpi::LogicalSize {
Expand Down Expand Up @@ -106,15 +125,8 @@ fn main() -> Result<(), Error> {
}

let mut ctx = PietGpuRenderContext::new();
if let Some(input) = matches.value_of("INPUT") {
let mut scale = matches
.value_of("scale")
.map(|scale| scale.parse().unwrap())
.unwrap_or(8.0);
if matches.is_present("flip") {
scale = -scale;
}
test_scenes::render_svg(&mut ctx, input, scale);
if let Some(svg) = &svg {
test_scenes::render_svg(&mut ctx, svg);
} else {
use piet_gpu::{Blend, BlendMode::*, CompositionMode::*};
let blends = [
Expand Down
2 changes: 1 addition & 1 deletion piet-gpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use piet_gpu_hal::{
ImageLayout, Pipeline, QueryPool, Session,
};

use pico_svg::PicoSvg;
pub use pico_svg::PicoSvg;
use stages::{ClipBinding, ElementBinding, ElementCode};

use crate::stages::{ClipCode, Config, ElementStage};
Expand Down
7 changes: 1 addition & 6 deletions piet-gpu/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ pub fn render_blend_test(rc: &mut PietGpuRenderContext, i: usize, blend: Blend)
rc.restore().unwrap();
}

pub fn render_svg(rc: &mut impl RenderContext, filename: &str, scale: f64) {
let xml_str = std::fs::read_to_string(filename).unwrap();
let start = std::time::Instant::now();
let svg = PicoSvg::load(&xml_str, scale).unwrap();
println!("parsing time: {:?}", start.elapsed());

pub fn render_svg(rc: &mut impl RenderContext, svg: &PicoSvg) {
let start = std::time::Instant::now();
svg.render(rc);
println!("flattening and encoding time: {:?}", start.elapsed());
Expand Down