Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix animation smoothness when using requestAnimationFrame. #9858

Merged
merged 1 commit into from Mar 4, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use AnimationTickType;
use CompositorMsg as ConstellationMsg;
use app_units::Au;
use compositor_layer::{CompositorData, CompositorLayer, RcCompositorLayer, WantsScrollEventsFlag};
@@ -1550,7 +1551,13 @@ impl<Window: WindowMethods> IOCompositor<Window> {

fn tick_animations_for_pipeline(&mut self, pipeline_id: PipelineId) {
self.schedule_delayed_composite_if_necessary();
self.constellation_chan.send(ConstellationMsg::TickAnimation(pipeline_id)).unwrap()
let animation_callbacks_running = self.pipeline_details(pipeline_id).animation_callbacks_running;
let animation_type = if animation_callbacks_running {
AnimationTickType::Script
} else {
AnimationTickType::Layout
};
self.constellation_chan.send(ConstellationMsg::TickAnimation(pipeline_id, animation_type)).unwrap()
}

fn constrain_viewport(&mut self, pipeline_id: PipelineId, constraints: ViewportConstraints) {
@@ -9,6 +9,7 @@
//! navigation context, each `Pipeline` encompassing a `ScriptThread`,
//! `LayoutThread`, and `PaintThread`.

use AnimationTickType;
use CompositorMsg as FromCompositorMsg;
use canvas::canvas_paint_thread::CanvasPaintThread;
use canvas::webgl_paint_thread::WebGLPaintThread;
@@ -585,8 +586,8 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
debug!("constellation got window resize message");
self.handle_resized_window_msg(new_size);
}
Request::Compositor(FromCompositorMsg::TickAnimation(pipeline_id)) => {
self.handle_tick_animation(pipeline_id)
Request::Compositor(FromCompositorMsg::TickAnimation(pipeline_id, tick_type)) => {
self.handle_tick_animation(pipeline_id, tick_type)
}
Request::Compositor(FromCompositorMsg::WebDriverCommand(command)) => {
debug!("constellation got webdriver command message");
@@ -912,12 +913,22 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>
animation_state))
}

fn handle_tick_animation(&mut self, pipeline_id: PipelineId) {
self.pipeline(pipeline_id)
.layout_chan
.0
.send(LayoutControlMsg::TickAnimations)
.unwrap();
fn handle_tick_animation(&mut self, pipeline_id: PipelineId, tick_type: AnimationTickType) {
match tick_type {
AnimationTickType::Script => {
self.pipeline(pipeline_id)
.script_chan
.send(ConstellationControlMsg::TickAllAnimations(pipeline_id))
.unwrap();
}
AnimationTickType::Layout => {
self.pipeline(pipeline_id)
.layout_chan
.0
.send(LayoutControlMsg::TickAnimations)
.unwrap();
}
}
}

fn handle_load_url_msg(&mut self, source_id: PipelineId, load_data: LoadData) {
@@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use AnimationTickType;
use CompositorMsg as ConstellationMsg;
use compositor_thread::{CompositorEventListener, CompositorReceiver};
use compositor_thread::{InitialCompositorState, Msg};
@@ -98,7 +99,7 @@ impl CompositorEventListener for NullCompositor {
AnimationState::NoAnimationsPresent |
AnimationState::NoAnimationCallbacksPresent => {}
AnimationState::AnimationCallbacksPresent => {
let msg = ConstellationMsg::TickAnimation(pipeline_id);
let msg = ConstellationMsg::TickAnimation(pipeline_id, AnimationTickType::Script);
self.constellation_chan.send(msg).unwrap()
}
}
@@ -76,6 +76,13 @@ mod timer_scheduler;
mod touch;
pub mod windowing;

/// Specifies whether the script or layout thread needs to be ticked for animation.
#[derive(Deserialize, Serialize)]
pub enum AnimationTickType {
Script,
Layout,
}

/// Messages from the compositor to the constellation.
#[derive(Deserialize, Serialize)]
pub enum CompositorMsg {
@@ -98,7 +105,7 @@ pub enum CompositorMsg {
Navigate(Option<(PipelineId, SubpageId)>, NavigationDirection),
ResizedWindow(WindowSizeData),
/// Requests that the constellation instruct layout to begin a new tick of the animation.
TickAnimation(PipelineId),
TickAnimation(PipelineId, AnimationTickType),
/// Dispatch a webdriver command
WebDriverCommand(WebDriverCommandMsg),
}
@@ -1202,10 +1202,6 @@ impl LayoutThread {
fn tick_all_animations<'a, 'b>(&mut self, possibly_locked_rw_data: &mut RwData<'a, 'b>) {
let mut rw_data = possibly_locked_rw_data.lock();
self.tick_animations(&mut rw_data);

self.script_chan
.send(ConstellationControlMsg::TickAllAnimations(self.id))
.unwrap();
}

pub fn tick_animations(&mut self, rw_data: &mut LayoutThreadData) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.