@@ -110,11 +110,13 @@ use style::refcell::RefCell;
110110use style:: selector_matching:: Stylist ;
111111use style:: servo_selector_impl:: USER_OR_USER_AGENT_STYLESHEETS ;
112112use style:: stylesheets:: { Stylesheet , CSSRuleIteratorExt } ;
113+ use style:: timer:: Timer ;
113114use style:: workqueue:: WorkQueue ;
114115use url:: Url ;
115116use util:: geometry:: MAX_RECT ;
116117use util:: ipc:: OptionalIpcSender ;
117118use util:: opts;
119+ use util:: prefs:: PREFS ;
118120use util:: thread;
119121use util:: thread_state;
120122
@@ -226,6 +228,10 @@ pub struct LayoutThread {
226228
227229 // Webrender interface, if enabled.
228230 webrender_api : Option < webrender_traits:: RenderApi > ,
231+
232+ /// The timer object to control the timing of the animations. This should
233+ /// only be a test-mode timer during testing for animations.
234+ timer : Timer ,
229235}
230236
231237impl LayoutThreadFactory for LayoutThread {
@@ -459,13 +465,20 @@ impl LayoutThread {
459465 offset_parent_response : OffsetParentResponse :: empty ( ) ,
460466 margin_style_response : MarginStyleResponse :: empty ( ) ,
461467 stacking_context_scroll_offsets : HashMap :: new ( ) ,
462- } ) ) ,
463- error_reporter : CSSErrorReporter {
464- pipelineid : id,
465- script_chan : Arc :: new ( Mutex :: new ( script_chan) ) ,
466- } ,
467- webrender_image_cache :
468- Arc :: new ( RwLock :: new ( HashMap :: with_hasher ( Default :: default ( ) ) ) ) ,
468+ } ) ) ,
469+ error_reporter : CSSErrorReporter {
470+ pipelineid : id,
471+ script_chan : Arc :: new ( Mutex :: new ( script_chan) ) ,
472+ } ,
473+ webrender_image_cache :
474+ Arc :: new ( RwLock :: new ( HashMap :: with_hasher ( Default :: default ( ) ) ) ) ,
475+ timer :
476+ if PREFS . get ( "layout.animations.test.enabled" )
477+ . as_boolean ( ) . unwrap_or ( false ) {
478+ Timer :: test_mode ( )
479+ } else {
480+ Timer :: new ( )
481+ } ,
469482 }
470483 }
471484
@@ -501,6 +514,7 @@ impl LayoutThread {
501514 expired_animations : self . expired_animations . clone ( ) ,
502515 error_reporter : self . error_reporter . clone ( ) ,
503516 local_context_creation_data : Mutex :: new ( local_style_context_creation_data) ,
517+ timer : self . timer . clone ( ) ,
504518 } ,
505519 image_cache_thread : self . image_cache_thread . clone ( ) ,
506520 image_cache_sender : Mutex :: new ( self . image_cache_sender . clone ( ) ) ,
@@ -653,6 +667,9 @@ impl LayoutThread {
653667 let _rw_data = possibly_locked_rw_data. lock ( ) ;
654668 sender. send ( self . epoch ) . unwrap ( ) ;
655669 } ,
670+ Msg :: AdvanceClockMs ( how_many) => {
671+ self . handle_advance_clock_ms ( how_many, possibly_locked_rw_data) ;
672+ }
656673 Msg :: GetWebFontLoadState ( sender) => {
657674 let _rw_data = possibly_locked_rw_data. lock ( ) ;
658675 let outstanding_web_fonts = self . outstanding_web_fonts . load ( Ordering :: SeqCst ) ;
@@ -795,6 +812,14 @@ impl LayoutThread {
795812 possibly_locked_rw_data. block ( rw_data) ;
796813 }
797814
815+ /// Advances the animation clock of the document.
816+ fn handle_advance_clock_ms < ' a , ' b > ( & mut self ,
817+ how_many_ms : i32 ,
818+ possibly_locked_rw_data : & mut RwData < ' a , ' b > ) {
819+ self . timer . increment ( how_many_ms as f64 / 1000.0 ) ;
820+ self . tick_all_animations ( possibly_locked_rw_data) ;
821+ }
822+
798823 /// Sets quirks mode for the document, causing the quirks mode stylesheet to be used.
799824 fn handle_set_quirks_mode < ' a , ' b > ( & self , possibly_locked_rw_data : & mut RwData < ' a , ' b > ) {
800825 let mut rw_data = possibly_locked_rw_data. lock ( ) ;
@@ -1350,7 +1375,8 @@ impl LayoutThread {
13501375 & mut * self . running_animations . write ( ) . unwrap ( ) ,
13511376 & mut * self . expired_animations . write ( ) . unwrap ( ) ,
13521377 & self . new_animations_receiver ,
1353- self . id ) ;
1378+ self . id ,
1379+ & self . timer ) ;
13541380
13551381 profile ( time:: ProfilerCategory :: LayoutRestyleDamagePropagation ,
13561382 self . profiler_metadata ( ) ,
0 commit comments