Skip to content

Commit

Permalink
Fix SVG export in the demo; update Cargo.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Jun 25, 2019
1 parent ff777f7 commit 4cdded7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
39 changes: 20 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions demo/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ features = ["release_max_level_warn"]
[dependencies.pathfinder_content]
path = "../../content"

[dependencies.pathfinder_export]
path = "../../export"

[dependencies.pathfinder_geometry]
path = "../../geometry"

Expand Down
6 changes: 4 additions & 2 deletions demo/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::device::{GroundProgram, GroundVertexArray};
use crate::ui::{DemoUIModel, DemoUIPresenter, ScreenshotInfo, ScreenshotType, UIAction};
use crate::window::{Event, Keycode, SVGPath, Window, WindowSize};
use clap::{App, Arg};
use pathfinder_export::{Export, FileFormat};
use pathfinder_geometry::vector::{Vector2F, Vector2I};
use pathfinder_geometry::rect::RectF;
use pathfinder_geometry::transform2d::Transform2DF;
Expand All @@ -38,7 +39,7 @@ use pathfinder_renderer::scene::Scene;
use pathfinder_svg::BuiltSVG;
use pathfinder_ui::{MousePosition, UIEvent};
use std::fs::File;
use std::io::{Read, Write};
use std::io::{BufWriter, Read};
use std::path::PathBuf;
use std::thread;
use std::time::Duration;
Expand Down Expand Up @@ -550,7 +551,8 @@ impl<W> DemoApp<W> where W: Window {
}
Some(ScreenshotInfo { kind: ScreenshotType::SVG, path }) => {
// FIXME(pcwalton): This won't work on Android.
File::create(path).unwrap().write_all(&mut self.scene_proxy.as_svg()).unwrap();
let mut writer = BufWriter::new(File::create(path).unwrap());
self.scene_proxy.copy_scene().export(&mut writer, FileFormat::SVG).unwrap();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions export/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum FileFormat {
pub trait Export {
fn export<W: Write>(&self, writer: &mut W, format: FileFormat) -> io::Result<()>;
}

impl Export for Scene {
fn export<W: Write>(&self, writer: &mut W, format: FileFormat) -> io::Result<()> {
match format {
Expand Down
11 changes: 10 additions & 1 deletion renderer/src/concurrent/scene_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ impl SceneProxy {
}
renderer.end_scene();
}

#[inline]
pub fn copy_scene(&self) -> Scene {
let (sender, receiver) = mpsc::channel();
self.sender.send(MainToWorkerMsg::CopyScene(sender)).unwrap();
receiver.recv().unwrap()
}
}

fn scene_thread<E>(mut scene: Scene,
Expand All @@ -98,6 +105,7 @@ fn scene_thread<E>(mut scene: Scene,
while let Ok(msg) = main_to_worker_receiver.recv() {
match msg {
MainToWorkerMsg::ReplaceScene(new_scene) => scene = new_scene,
MainToWorkerMsg::CopyScene(sender) => sender.send(scene.clone()).unwrap(),
MainToWorkerMsg::SetViewBox(new_view_box) => scene.set_view_box(new_view_box),
MainToWorkerMsg::Build(options, listener) => scene.build(options, listener, &executor)
}
Expand All @@ -106,8 +114,9 @@ fn scene_thread<E>(mut scene: Scene,

enum MainToWorkerMsg {
ReplaceScene(Scene),
CopyScene(Sender<Scene>),
SetViewBox(RectF),
Build(BuildOptions, Box<dyn RenderCommandListener>)
Build(BuildOptions, Box<dyn RenderCommandListener>),
}

pub struct RenderCommandStream {
Expand Down

0 comments on commit 4cdded7

Please sign in to comment.