@@ -102,10 +102,11 @@ use std::thread;
102102use std:: time:: Duration ;
103103use style:: animation:: Animation ;
104104use style:: context:: { QuirksMode , RegisteredSpeculativePainter , RegisteredSpeculativePainters } ;
105- use style:: context:: { SharedStyleContext , StyleSystemOptions , ThreadLocalStyleContextCreationInfo } ;
105+ use style:: context:: { SharedStyleContext , ThreadLocalStyleContextCreationInfo } ;
106106use style:: dom:: { ShowSubtree , ShowSubtreeDataAndPrimaryValues , TElement , TNode } ;
107107use style:: driver;
108108use style:: error_reporting:: RustLogReporter ;
109+ use style:: global_style_data:: { GLOBAL_STYLE_DATA , STYLE_THREAD_POOL } ;
109110use style:: invalidation:: element:: restyle_hints:: RestyleHint ;
110111use style:: logical_geometry:: LogicalPoint ;
111112use style:: media_queries:: { Device , MediaList , MediaType } ;
@@ -178,9 +179,6 @@ pub struct LayoutThread {
178179 /// Is this the first reflow in this LayoutThread?
179180 first_reflow : Cell < bool > ,
180181
181- /// The workers that we use for parallel operation.
182- parallel_traversal : Option < rayon:: ThreadPool > ,
183-
184182 /// Flag to indicate whether to use parallel operations
185183 parallel_flag : bool ,
186184
@@ -238,10 +236,6 @@ pub struct LayoutThread {
238236 /// only be a test-mode timer during testing for animations.
239237 timer : Timer ,
240238
241- // Number of layout threads. This is copied from `servo_config::opts`, but we'd
242- // rather limit the dependency on that module here.
243- layout_threads : usize ,
244-
245239 /// Paint time metrics.
246240 paint_time_metrics : PaintTimeMetrics ,
247241
@@ -270,7 +264,6 @@ impl LayoutThreadFactory for LayoutThread {
270264 content_process_shutdown_chan : Option < IpcSender < ( ) > > ,
271265 webrender_api_sender : webrender_api:: RenderApiSender ,
272266 webrender_document : webrender_api:: DocumentId ,
273- layout_threads : usize ,
274267 paint_time_metrics : PaintTimeMetrics ,
275268 ) {
276269 thread:: Builder :: new ( )
@@ -308,7 +301,6 @@ impl LayoutThreadFactory for LayoutThread {
308301 mem_profiler_chan. clone ( ) ,
309302 webrender_api_sender,
310303 webrender_document,
311- layout_threads,
312304 paint_time_metrics,
313305 ) ;
314306
@@ -470,7 +462,6 @@ impl LayoutThread {
470462 mem_profiler_chan : profile_mem:: ProfilerChan ,
471463 webrender_api_sender : webrender_api:: RenderApiSender ,
472464 webrender_document : webrender_api:: DocumentId ,
473- layout_threads : usize ,
474465 paint_time_metrics : PaintTimeMetrics ,
475466 ) -> LayoutThread {
476467 // The device pixel ratio is incorrect (it does not have the hidpi value),
@@ -481,17 +472,6 @@ impl LayoutThread {
481472 TypedScale :: new ( opts:: get ( ) . device_pixels_per_px . unwrap_or ( 1.0 ) ) ,
482473 ) ;
483474
484- let workers = rayon:: ThreadPoolBuilder :: new ( )
485- . num_threads ( layout_threads)
486- . start_handler ( |_| thread_state:: initialize_layout_worker_thread ( ) )
487- . build ( ) ;
488- let parallel_traversal = if layout_threads > 1 {
489- Some ( workers. expect ( "ThreadPool creation failed" ) )
490- } else {
491- None
492- } ;
493- debug ! ( "Possible layout Threads: {}" , layout_threads) ;
494-
495475 // Create the channel on which new animations can be sent.
496476 let ( new_animations_sender, new_animations_receiver) = unbounded ( ) ;
497477
@@ -521,7 +501,6 @@ impl LayoutThread {
521501 first_reflow : Cell :: new ( true ) ,
522502 font_cache_receiver : font_cache_receiver,
523503 font_cache_sender : ipc_font_cache_sender,
524- parallel_traversal : parallel_traversal,
525504 parallel_flag : true ,
526505 generation : Cell :: new ( 0 ) ,
527506 new_animations_sender : new_animations_sender,
@@ -563,7 +542,6 @@ impl LayoutThread {
563542 } else {
564543 Timer :: new ( )
565544 } ,
566- layout_threads : layout_threads,
567545 paint_time_metrics : paint_time_metrics,
568546 layout_query_waiting_time : Histogram :: new ( ) ,
569547 }
@@ -596,8 +574,8 @@ impl LayoutThread {
596574 id : self . id ,
597575 style_context : SharedStyleContext {
598576 stylist : & self . stylist ,
599- options : StyleSystemOptions :: default ( ) ,
600- guards : guards ,
577+ options : GLOBAL_STYLE_DATA . options . clone ( ) ,
578+ guards,
601579 visited_styles_enabled : false ,
602580 running_animations : self . running_animations . clone ( ) ,
603581 expired_animations : self . expired_animations . clone ( ) ,
@@ -881,7 +859,6 @@ impl LayoutThread {
881859 info. content_process_shutdown_chan ,
882860 self . webrender_api . clone_sender ( ) ,
883861 self . webrender_document ,
884- info. layout_threads ,
885862 info. paint_time_metrics ,
886863 ) ;
887864 }
@@ -924,8 +901,6 @@ impl LayoutThread {
924901 ) ;
925902
926903 self . root_flow . borrow_mut ( ) . take ( ) ;
927- // Drop the rayon threadpool if present.
928- let _ = self . parallel_traversal . take ( ) ;
929904 self . background_hang_monitor . unregister ( ) ;
930905 }
931906
@@ -1166,7 +1141,7 @@ impl LayoutThread {
11661141
11671142 // Parallelize if there's more than 750 objects based on rzambre's suggestion
11681143 // https://github.com/servo/servo/issues/10110
1169- self . parallel_flag = self . layout_threads > 1 && data. dom_count > 750 ;
1144+ self . parallel_flag = data. dom_count > 750 ;
11701145 debug ! ( "layout: received layout request for: {}" , self . url) ;
11711146 debug ! ( "Number of objects in DOM: {}" , data. dom_count) ;
11721147 debug ! ( "layout: parallel? {}" , self . parallel_flag) ;
@@ -1373,10 +1348,13 @@ impl LayoutThread {
13731348 // Create a layout context for use throughout the following passes.
13741349 let mut layout_context = self . build_layout_context ( guards. clone ( ) , true , & map) ;
13751350
1376- let thread_pool = if self . parallel_flag {
1377- self . parallel_traversal . as_ref ( )
1351+ let ( thread_pool, num_threads) = if self . parallel_flag {
1352+ (
1353+ STYLE_THREAD_POOL . style_thread_pool . as_ref ( ) ,
1354+ STYLE_THREAD_POOL . num_threads ,
1355+ )
13781356 } else {
1379- None
1357+ ( None , 1 )
13801358 } ;
13811359
13821360 let traversal = RecalcStyleAndConstructFlows :: new ( layout_context) ;
@@ -1404,14 +1382,14 @@ impl LayoutThread {
14041382 } ,
14051383 ) ;
14061384 // TODO(pcwalton): Measure energy usage of text shaping, perhaps?
1407- let text_shaping_time = ( font :: get_and_reset_text_shaping_performance_counter ( ) as u64 ) /
1408- ( self . layout_threads as u64 ) ;
1385+ let text_shaping_time =
1386+ font :: get_and_reset_text_shaping_performance_counter ( ) / num_threads ;
14091387 profile_time:: send_profile_data (
14101388 profile_time:: ProfilerCategory :: LayoutTextShaping ,
14111389 self . profiler_metadata ( ) ,
14121390 & self . time_profiler_chan ,
14131391 0 ,
1414- text_shaping_time,
1392+ text_shaping_time as u64 ,
14151393 0 ,
14161394 0 ,
14171395 ) ;
@@ -1742,12 +1720,16 @@ impl LayoutThread {
17421720 || {
17431721 let profiler_metadata = self . profiler_metadata ( ) ;
17441722
1745- if let ( true , Some ( traversal) ) =
1746- ( self . parallel_flag , self . parallel_traversal . as_ref ( ) )
1747- {
1723+ let thread_pool = if self . parallel_flag {
1724+ STYLE_THREAD_POOL . style_thread_pool . as_ref ( )
1725+ } else {
1726+ None
1727+ } ;
1728+
1729+ if let Some ( pool) = thread_pool {
17481730 // Parallel mode.
17491731 LayoutThread :: solve_constraints_parallel (
1750- traversal ,
1732+ pool ,
17511733 FlowRef :: deref_mut ( root_flow) ,
17521734 profiler_metadata,
17531735 self . time_profiler_chan . clone ( ) ,
@@ -1913,7 +1895,8 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
19131895 ) ) ) )
19141896 }
19151897
1916- let shared_lock = SharedRwLock :: new ( ) ;
1898+ let shared_lock = & GLOBAL_STYLE_DATA . shared_lock ;
1899+
19171900 // FIXME: presentational-hints.css should be at author origin with zero specificity.
19181901 // (Does it make a difference?)
19191902 let mut user_or_user_agent_stylesheets = vec ! [
@@ -1958,7 +1941,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
19581941 ) ?;
19591942
19601943 Ok ( UserAgentStylesheets {
1961- shared_lock : shared_lock,
1944+ shared_lock : shared_lock. clone ( ) ,
19621945 user_or_user_agent_stylesheets : user_or_user_agent_stylesheets,
19631946 quirks_mode_stylesheet : quirks_mode_stylesheet,
19641947 } )
0 commit comments