Merge pull request #124 from asajeffrey/pf3-demo-customize-rayon

Allow the Window to customize rayon's thread builder
This commit is contained in:
Patrick Walton 2019-03-28 15:17:23 -07:00 committed by GitHub
commit a987bf0fc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
// Set up Rayon.
let mut thread_pool_builder = ThreadPoolBuilder::new();
thread_pool_builder = options.adjust_thread_pool_settings(thread_pool_builder);
thread_pool_builder = window.adjust_thread_pool_settings(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;
@ -753,14 +759,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 adjust_thread_pool_settings(&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

@ -15,6 +15,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 {
@ -28,6 +29,10 @@ pub trait Window {
fn present_open_svg_dialog(&mut self);
fn run_save_dialog(&self, extension: &str) -> Result<PathBuf, ()>;
fn adjust_thread_pool_settings(&self, thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder {
thread_pool_builder
}
#[inline]
fn barrel_distortion_coefficients(&self) -> BarrelDistortionCoefficients {
BarrelDistortionCoefficients::default()