compositing: Keep the event loop awake when scrolling.

This commit is contained in:
Patrick Walton 2015-04-10 10:24:28 -07:00
parent 9e3e361b84
commit b4b3cbccf7
3 changed files with 24 additions and 6 deletions

View file

@ -82,6 +82,8 @@ pub struct IOCompositor<Window: WindowMethods> {
/// The device pixel ratio for this window.
hidpi_factor: ScaleFactor<ScreenPx, DevicePixel, f32>,
channel_to_self: Box<CompositorProxy + Send>,
/// A handle to the scrolling timer.
scrolling_timer: ScrollingTimerProxy,
@ -206,6 +208,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}),
window_size: window_size,
hidpi_factor: hidpi_factor,
channel_to_self: sender.clone_compositor_proxy(),
scrolling_timer: ScrollingTimerProxy::new(sender),
composition_request: CompositionRequest::NoCompositingNecessary,
pending_scroll_events: Vec::new(),
@ -360,6 +363,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
}
(Msg::RecompositeAfterScroll, ShutdownState::NotShuttingDown) => {
self.composition_request =
CompositionRequest::CompositeNow(CompositingReason::ContinueScroll)
}
(Msg::KeyEvent(key, state, modified), ShutdownState::NotShuttingDown) => {
if state == KeyState::Pressed {
self.window.handle_key(key, modified);
@ -755,11 +763,9 @@ impl<Window: WindowMethods> IOCompositor<Window> {
layer_id: LayerId,
point: Point2D<f32>) {
if self.move_layer(pipeline_id, layer_id, Point2D::from_untyped(&point)) {
if self.send_buffer_requests_for_all_layers() {
self.start_scrolling_timer_if_necessary();
}
self.perform_updates_after_scroll()
} else {
self.fragment_point = Some(point);
self.fragment_point = Some(point)
}
}
@ -899,8 +905,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
layer.handle_scroll_event(delta, cursor);
}
self.start_scrolling_timer_if_necessary();
self.send_buffer_requests_for_all_layers();
self.perform_updates_after_scroll();
}
if had_scroll_events {
@ -908,6 +913,16 @@ impl<Window: WindowMethods> IOCompositor<Window> {
}
}
/// Performs buffer requests and starts the scrolling timer or schedules a recomposite as
/// necessary.
fn perform_updates_after_scroll(&mut self) {
if self.send_buffer_requests_for_all_layers() {
self.start_scrolling_timer_if_necessary();
} else {
self.channel_to_self.send(Msg::RecompositeAfterScroll);
}
}
/// If there are any animations running, dispatches appropriate messages to the constellation.
fn process_animations(&mut self) {
for (pipeline_id, pipeline_details) in self.pipeline_details.iter() {

View file

@ -212,6 +212,7 @@ pub enum Msg {
/// Indicates that the scrolling timeout with the given starting timestamp has happened and a
/// composite should happen. (See the `scrolling` module.)
ScrollTimeout(u64),
RecompositeAfterScroll,
/// Sends an unconsumed key event back to the compositor.
KeyEvent(Key, KeyState, KeyModifiers),
/// Changes the cursor.
@ -240,6 +241,7 @@ impl Debug for Msg {
Msg::SetFrameTree(..) => write!(f, "SetFrameTree"),
Msg::LoadComplete => write!(f, "LoadComplete"),
Msg::ScrollTimeout(..) => write!(f, "ScrollTimeout"),
Msg::RecompositeAfterScroll => write!(f, "RecompositeAfterScroll"),
Msg::KeyEvent(..) => write!(f, "KeyEvent"),
Msg::SetCursor(..) => write!(f, "SetCursor"),
Msg::PaintTaskExited(..) => write!(f, "PaintTaskExited"),

View file

@ -103,6 +103,7 @@ impl CompositorEventListener for NullCompositor {
Msg::LoadComplete |
Msg::PaintMsgDiscarded(..) |
Msg::ScrollTimeout(..) |
Msg::RecompositeAfterScroll |
Msg::ChangePageTitle(..) |
Msg::ChangePageUrl(..) |
Msg::KeyEvent(..) |