From e182d29441779b1c17aac66587fbc3729bc04675 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 19 Jul 2016 22:12:07 +0200 Subject: [PATCH] Hoist retrieval of layout_threads from opts into Constellation --- components/constellation/pipeline.rs | 4 +++- components/layout_thread/lib.rs | 24 ++++++++++++------- components/layout_traits/lib.rs | 3 ++- components/script/script_thread.rs | 2 ++ components/script_layout_interface/message.rs | 1 + components/script_traits/lib.rs | 2 ++ 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs index dd2a665f6ac..eb9ee6c7e34 100644 --- a/components/constellation/pipeline.rs +++ b/components/constellation/pipeline.rs @@ -160,6 +160,7 @@ impl Pipeline { pipeline_port: pipeline_port, layout_to_constellation_chan: state.layout_to_constellation_chan.clone(), content_process_shutdown_chan: layout_content_process_shutdown_chan.clone(), + layout_threads: opts::get().layout_threads, }; if let Err(e) = script_chan.send(ConstellationControlMsg::AttachLayout(new_layout_info)) { @@ -470,7 +471,8 @@ impl UnprivilegedPipelineContent { self.time_profiler_chan, self.mem_profiler_chan, self.layout_content_process_shutdown_chan, - self.webrender_api_sender); + self.webrender_api_sender, + opts::get().layout_threads); if wait_for_completion { let _ = self.script_content_process_shutdown_port.recv(); diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 9d576e3bd02..ed7a8f1b3e7 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -232,6 +232,10 @@ pub struct LayoutThread { /// The timer object to control the timing of the animations. This should /// only be a test-mode timer during testing for animations. timer: Timer, + + // Number of layout threads. This is copied from `util::opts`, but we'd + // rather limit the dependency on that module here. + layout_threads: usize, } impl LayoutThreadFactory for LayoutThread { @@ -251,7 +255,8 @@ impl LayoutThreadFactory for LayoutThread { time_profiler_chan: time::ProfilerChan, mem_profiler_chan: mem::ProfilerChan, content_process_shutdown_chan: IpcSender<()>, - webrender_api_sender: Option) { + webrender_api_sender: Option, + layout_threads: usize) { thread::spawn_named(format!("LayoutThread {:?}", id), move || { thread_state::initialize(thread_state::LAYOUT); @@ -270,7 +275,8 @@ impl LayoutThreadFactory for LayoutThread { font_cache_thread, time_profiler_chan, mem_profiler_chan.clone(), - webrender_api_sender); + webrender_api_sender, + layout_threads); let reporter_name = format!("layout-reporter-{}", id); mem_profiler_chan.run_with_memory_reporting(|| { @@ -381,14 +387,14 @@ impl LayoutThread { font_cache_thread: FontCacheThread, time_profiler_chan: time::ProfilerChan, mem_profiler_chan: mem::ProfilerChan, - webrender_api_sender: Option) + webrender_api_sender: Option, + layout_threads: usize) -> LayoutThread { let device = Device::new( MediaType::Screen, opts::get().initial_window_size.as_f32() * ScaleFactor::new(1.0)); - let parallel_traversal = if opts::get().layout_threads != 1 { - Some(WorkQueue::new("LayoutWorker", thread_state::LAYOUT, - opts::get().layout_threads)) + let parallel_traversal = if layout_threads != 1 { + Some(WorkQueue::new("LayoutWorker", thread_state::LAYOUT, layout_threads)) } else { None }; @@ -479,6 +485,7 @@ impl LayoutThread { } else { Timer::new() }, + layout_threads: layout_threads, } } @@ -754,7 +761,8 @@ impl LayoutThread { self.time_profiler_chan.clone(), self.mem_profiler_chan.clone(), info.content_process_shutdown_chan, - self.webrender_api.as_ref().map(|wr| wr.clone_sender())); + self.webrender_api.as_ref().map(|wr| wr.clone_sender()), + info.layout_threads); } /// Enters a quiescent state in which no new messages will be processed until an `ExitNow` is @@ -1158,7 +1166,7 @@ impl LayoutThread { // TODO(pcwalton): Measure energy usage of text shaping, perhaps? let text_shaping_time = (font::get_and_reset_text_shaping_performance_counter() as u64) / - (opts::get().layout_threads as u64); + (self.layout_threads as u64); time::send_profile_data(time::ProfilerCategory::LayoutTextShaping, self.profiler_metadata(), self.time_profiler_chan.clone(), diff --git a/components/layout_traits/lib.rs b/components/layout_traits/lib.rs index 1b6c621d755..5f9fc0d472b 100644 --- a/components/layout_traits/lib.rs +++ b/components/layout_traits/lib.rs @@ -48,5 +48,6 @@ pub trait LayoutThreadFactory { time_profiler_chan: time::ProfilerChan, mem_profiler_chan: mem::ProfilerChan, content_process_shutdown_chan: IpcSender<()>, - webrender_api_sender: Option); + webrender_api_sender: Option, + layout_threads: usize); } diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index cf0cebf5a65..1ec367e9b75 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1142,6 +1142,7 @@ impl ScriptThread { pipeline_port, layout_to_constellation_chan, content_process_shutdown_chan, + layout_threads, } = new_layout_info; let layout_pair = channel(); @@ -1158,6 +1159,7 @@ impl ScriptThread { script_chan: self.control_chan.clone(), image_cache_thread: self.image_cache_thread.clone(), content_process_shutdown_chan: content_process_shutdown_chan, + layout_threads: layout_threads, }; let context = self.root_browsing_context(); diff --git a/components/script_layout_interface/message.rs b/components/script_layout_interface/message.rs index 4fbed81429d..b46703e778e 100644 --- a/components/script_layout_interface/message.rs +++ b/components/script_layout_interface/message.rs @@ -149,4 +149,5 @@ pub struct NewLayoutThreadInfo { pub image_cache_thread: ImageCacheThread, pub paint_chan: OptionalOpaqueIpcSender, pub content_process_shutdown_chan: IpcSender<()>, + pub layout_threads: usize, } diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index 7731e16743d..8269ca318ed 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -146,6 +146,8 @@ pub struct NewLayoutInfo { pub layout_to_constellation_chan: IpcSender, /// A shutdown channel so that layout can tell the content process to shut down when it's done. pub content_process_shutdown_chan: IpcSender<()>, + /// Number of threads to use for layout. + pub layout_threads: usize, } /// Messages sent from the constellation or layout to the script thread.