From b4b3cbccf7d303491be8a55796df888562c8451d Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 10 Apr 2015 10:24:28 -0700 Subject: [PATCH] compositing: Keep the event loop awake when scrolling. --- components/compositing/compositor.rs | 27 ++++++++++++++++++----- components/compositing/compositor_task.rs | 2 ++ components/compositing/headless.rs | 1 + 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 3465cb1cecd..78f9f83c43d 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -82,6 +82,8 @@ pub struct IOCompositor { /// The device pixel ratio for this window. hidpi_factor: ScaleFactor, + channel_to_self: Box, + /// A handle to the scrolling timer. scrolling_timer: ScrollingTimerProxy, @@ -206,6 +208,7 @@ impl IOCompositor { }), 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 IOCompositor { } } + (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 IOCompositor { layer_id: LayerId, point: Point2D) { 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 IOCompositor { 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 IOCompositor { } } + /// 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() { diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs index c951f589965..7b08b2cb249 100644 --- a/components/compositing/compositor_task.rs +++ b/components/compositing/compositor_task.rs @@ -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"), diff --git a/components/compositing/headless.rs b/components/compositing/headless.rs index 72a5b0c961e..46f8351ba21 100644 --- a/components/compositing/headless.rs +++ b/components/compositing/headless.rs @@ -103,6 +103,7 @@ impl CompositorEventListener for NullCompositor { Msg::LoadComplete | Msg::PaintMsgDiscarded(..) | Msg::ScrollTimeout(..) | + Msg::RecompositeAfterScroll | Msg::ChangePageTitle(..) | Msg::ChangePageUrl(..) | Msg::KeyEvent(..) |