Allow the Window to customize rayon's thread builder

This commit is contained in:
Alan Jeffrey 2019-03-28 14:34:24 -05:00
parent 224c8e85b9
commit 52fa494d48
2 changed files with 17 additions and 6 deletions

View File

@ -118,6 +118,12 @@ impl<W> DemoApp<W> where W: Window {
let view_box_size = view_box_size(options.mode, &window_size, false);
// Set up Rayon.
let mut thread_pool_builder = ThreadPoolBuilder::new();
thread_pool_builder = options.customize_rayon(thread_pool_builder);
thread_pool_builder = window.customize_rayon(thread_pool_builder);
thread_pool_builder.build_global().unwrap();
let built_svg = load_scene(resources, &options.input_path);
let message = get_svg_building_message(&built_svg);
let scene_view_box = built_svg.scene.view_box;
@ -761,14 +767,14 @@ impl Options {
Some(path) => SVGPath::Path(PathBuf::from(path)),
};
// Set up Rayon.
let mut thread_pool_builder = ThreadPoolBuilder::new();
if let Some(jobs) = jobs {
Options { jobs, mode, input_path }
}
fn customize_rayon(&self, mut thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder {
if let Some(jobs) = self.jobs {
thread_pool_builder = thread_pool_builder.num_threads(jobs);
}
thread_pool_builder.build_global().unwrap();
Options { jobs, mode, input_path }
thread_pool_builder
}
}

View File

@ -14,6 +14,7 @@ use pathfinder_geometry::basic::point::Point2DI32;
use pathfinder_geometry::distortion::BarrelDistortionCoefficients;
use pathfinder_gl::GLVersion;
use pathfinder_gpu::resources::ResourceLoader;
use rayon::ThreadPoolBuilder;
use std::path::PathBuf;
pub trait Window {
@ -26,6 +27,10 @@ pub trait Window {
fn present_open_svg_dialog(&mut self);
fn run_save_dialog(&self, extension: &str) -> Result<PathBuf, ()>;
fn customize_rayon(&self, thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder {
thread_pool_builder
}
#[inline]
fn barrel_distortion_coefficients(&self) -> BarrelDistortionCoefficients {
BarrelDistortionCoefficients::default()