mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Fix rAF callbacks when in spurious mode.
This fixes another rAF bug, that is being exposed by the previous two commits. Previously, the fake timer callback would only be set if we were being called from a non-rAF event handler. Now, if we're in fake / spurious mode, unconditionally set the one shot timer. Otherwise, notify the compositor that animations are present if we're not currently in a rAF callback.
This commit is contained in:
parent
6c9e305442
commit
cbeb181c61
1 changed files with 22 additions and 21 deletions
|
@ -1538,28 +1538,29 @@ impl Document {
|
||||||
self.animation_frame_ident.set(ident);
|
self.animation_frame_ident.set(ident);
|
||||||
self.animation_frame_list.borrow_mut().push((ident, Some(callback)));
|
self.animation_frame_list.borrow_mut().push((ident, Some(callback)));
|
||||||
|
|
||||||
// No need to send a `ChangeRunningAnimationsState` if we're running animation callbacks:
|
|
||||||
// we're guaranteed to already be in the "animation callbacks present" state.
|
|
||||||
//
|
|
||||||
// This reduces CPU usage by avoiding needless thread wakeups in the common case of
|
|
||||||
// repeated rAF.
|
|
||||||
//
|
|
||||||
// TODO: Should tick animation only when document is visible
|
// TODO: Should tick animation only when document is visible
|
||||||
if !self.running_animation_callbacks.get() {
|
|
||||||
if !self.is_faking_animation_frames() {
|
// If we are running 'fake' animation frames, we unconditionally
|
||||||
let global_scope = self.window.upcast::<GlobalScope>();
|
// set up a one-shot timer for script to execute the rAF callbacks.
|
||||||
let event = ConstellationMsg::ChangeRunningAnimationsState(
|
if self.is_faking_animation_frames() {
|
||||||
global_scope.pipeline_id(),
|
let callback = FakeRequestAnimationFrameCallback {
|
||||||
AnimationState::AnimationCallbacksPresent);
|
document: Trusted::new(self),
|
||||||
global_scope.constellation_chan().send(event).unwrap();
|
};
|
||||||
} else {
|
self.global()
|
||||||
let callback = FakeRequestAnimationFrameCallback {
|
.schedule_callback(OneshotTimerCallback::FakeRequestAnimationFrame(callback),
|
||||||
document: Trusted::new(self),
|
MsDuration::new(FAKE_REQUEST_ANIMATION_FRAME_DELAY));
|
||||||
};
|
} else if !self.running_animation_callbacks.get() {
|
||||||
self.global()
|
// No need to send a `ChangeRunningAnimationsState` if we're running animation callbacks:
|
||||||
.schedule_callback(OneshotTimerCallback::FakeRequestAnimationFrame(callback),
|
// we're guaranteed to already be in the "animation callbacks present" state.
|
||||||
MsDuration::new(FAKE_REQUEST_ANIMATION_FRAME_DELAY));
|
//
|
||||||
}
|
// This reduces CPU usage by avoiding needless thread wakeups in the common case of
|
||||||
|
// repeated rAF.
|
||||||
|
|
||||||
|
let global_scope = self.window.upcast::<GlobalScope>();
|
||||||
|
let event = ConstellationMsg::ChangeRunningAnimationsState(
|
||||||
|
global_scope.pipeline_id(),
|
||||||
|
AnimationState::AnimationCallbacksPresent);
|
||||||
|
global_scope.constellation_chan().send(event).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
ident
|
ident
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue