aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_thread
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-07-20 13:38:31 -0500
committerGitHub <noreply@github.com>2016-07-20 13:38:31 -0500
commit14aeccc33ab44d706df86fbce67339218efe710c (patch)
tree623b24534550a56755d440d48f5a89cff6171ded /components/layout_thread
parent46db988b906fbec0286fa07387bb34e76a5b3a94 (diff)
parent0b67b218d0c8dc48a5301227802296aff98af6d7 (diff)
downloadservo-14aeccc33ab44d706df86fbce67339218efe710c.tar.gz
servo-14aeccc33ab44d706df86fbce67339218efe710c.zip
Auto merge of #12392 - emilio:test-animations, r=SimonSapin
style: Add support to test animations programatically. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #12120 <!-- Either: --> - [x] There are tests for these changes OR <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> r? @SimonSapin for the style changes, @Ms2ger or @jdm for the dom and test changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12392) <!-- Reviewable:end -->
Diffstat (limited to 'components/layout_thread')
-rw-r--r--components/layout_thread/lib.rs42
1 files changed, 34 insertions, 8 deletions
diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs
index 7fc12535ff7..592a6cda6a4 100644
--- a/components/layout_thread/lib.rs
+++ b/components/layout_thread/lib.rs
@@ -110,11 +110,13 @@ use style::refcell::RefCell;
use style::selector_matching::Stylist;
use style::servo_selector_impl::USER_OR_USER_AGENT_STYLESHEETS;
use style::stylesheets::{Stylesheet, CSSRuleIteratorExt};
+use style::timer::Timer;
use style::workqueue::WorkQueue;
use url::Url;
use util::geometry::MAX_RECT;
use util::ipc::OptionalIpcSender;
use util::opts;
+use util::prefs::PREFS;
use util::thread;
use util::thread_state;
@@ -226,6 +228,10 @@ pub struct LayoutThread {
// Webrender interface, if enabled.
webrender_api: Option<webrender_traits::RenderApi>,
+
+ /// The timer object to control the timing of the animations. This should
+ /// only be a test-mode timer during testing for animations.
+ timer: Timer,
}
impl LayoutThreadFactory for LayoutThread {
@@ -459,13 +465,20 @@ impl LayoutThread {
offset_parent_response: OffsetParentResponse::empty(),
margin_style_response: MarginStyleResponse::empty(),
stacking_context_scroll_offsets: HashMap::new(),
- })),
- error_reporter: CSSErrorReporter {
- pipelineid: id,
- script_chan: Arc::new(Mutex::new(script_chan)),
- },
- webrender_image_cache:
- Arc::new(RwLock::new(HashMap::with_hasher(Default::default()))),
+ })),
+ error_reporter: CSSErrorReporter {
+ pipelineid: id,
+ script_chan: Arc::new(Mutex::new(script_chan)),
+ },
+ webrender_image_cache:
+ Arc::new(RwLock::new(HashMap::with_hasher(Default::default()))),
+ timer:
+ if PREFS.get("layout.animations.test.enabled")
+ .as_boolean().unwrap_or(false) {
+ Timer::test_mode()
+ } else {
+ Timer::new()
+ },
}
}
@@ -501,6 +514,7 @@ impl LayoutThread {
expired_animations: self.expired_animations.clone(),
error_reporter: self.error_reporter.clone(),
local_context_creation_data: Mutex::new(local_style_context_creation_data),
+ timer: self.timer.clone(),
},
image_cache_thread: self.image_cache_thread.clone(),
image_cache_sender: Mutex::new(self.image_cache_sender.clone()),
@@ -653,6 +667,9 @@ impl LayoutThread {
let _rw_data = possibly_locked_rw_data.lock();
sender.send(self.epoch).unwrap();
},
+ Msg::AdvanceClockMs(how_many) => {
+ self.handle_advance_clock_ms(how_many, possibly_locked_rw_data);
+ }
Msg::GetWebFontLoadState(sender) => {
let _rw_data = possibly_locked_rw_data.lock();
let outstanding_web_fonts = self.outstanding_web_fonts.load(Ordering::SeqCst);
@@ -795,6 +812,14 @@ impl LayoutThread {
possibly_locked_rw_data.block(rw_data);
}
+ /// Advances the animation clock of the document.
+ fn handle_advance_clock_ms<'a, 'b>(&mut self,
+ how_many_ms: i32,
+ possibly_locked_rw_data: &mut RwData<'a, 'b>) {
+ self.timer.increment(how_many_ms as f64 / 1000.0);
+ self.tick_all_animations(possibly_locked_rw_data);
+ }
+
/// Sets quirks mode for the document, causing the quirks mode stylesheet to be used.
fn handle_set_quirks_mode<'a, 'b>(&self, possibly_locked_rw_data: &mut RwData<'a, 'b>) {
let mut rw_data = possibly_locked_rw_data.lock();
@@ -1350,7 +1375,8 @@ impl LayoutThread {
&mut *self.running_animations.write().unwrap(),
&mut *self.expired_animations.write().unwrap(),
&self.new_animations_receiver,
- self.id);
+ self.id,
+ &self.timer);
profile(time::ProfilerCategory::LayoutRestyleDamagePropagation,
self.profiler_metadata(),