Merge pull request #162 from simbleau/issue-161

Factored out file loading on render tick for winit bin
diff --git a/piet-gpu/bin/cli.rs b/piet-gpu/bin/cli.rs
index 70023af..abe6ae1 100644
--- a/piet-gpu/bin/cli.rs
+++ b/piet-gpu/bin/cli.rs
@@ -6,7 +6,7 @@
 
 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;
@@ -243,7 +243,11 @@
             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);
         }
diff --git a/piet-gpu/bin/winit.rs b/piet-gpu/bin/winit.rs
index 3ca0742..b1db5e0 100644
--- a/piet-gpu/bin/winit.rs
+++ b/piet-gpu/bin/winit.rs
@@ -2,7 +2,7 @@
 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};
 
@@ -29,6 +29,25 @@
         )
         .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 {
@@ -106,15 +125,8 @@
                     }
 
                     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 = [
diff --git a/piet-gpu/src/lib.rs b/piet-gpu/src/lib.rs
index e12f824..249735a 100644
--- a/piet-gpu/src/lib.rs
+++ b/piet-gpu/src/lib.rs
@@ -21,7 +21,7 @@
     ImageLayout, Pipeline, QueryPool, Session,
 };
 
-use pico_svg::PicoSvg;
+pub use pico_svg::PicoSvg;
 use stages::{ClipBinding, ElementBinding, ElementCode};
 
 use crate::stages::{ClipCode, Config, ElementStage};
diff --git a/piet-gpu/src/test_scenes.rs b/piet-gpu/src/test_scenes.rs
index ee5839d..350b9dd 100644
--- a/piet-gpu/src/test_scenes.rs
+++ b/piet-gpu/src/test_scenes.rs
@@ -21,12 +21,7 @@
     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());