diff options
author | Glenn Watson <github@intuitionlibrary.com> | 2017-06-19 11:48:07 +1000 |
---|---|---|
committer | Glenn Watson <github@intuitionlibrary.com> | 2017-06-20 08:47:14 +1000 |
commit | c8255922a98996c5aea7eff8eb837682d883aa63 (patch) | |
tree | 984890059e8cdc11cc5dd0658b2785ca53ebf80c /components/compositing/compositor.rs | |
parent | 5f10a25ead8bae973ed9d5f6104f84b8dc1b8a16 (diff) | |
download | servo-c8255922a98996c5aea7eff8eb837682d883aa63.tar.gz servo-c8255922a98996c5aea7eff8eb837682d883aa63.zip |
Improve decisions in compositor over when to draw a frame.
This patch fixes a couple of issues in the compositor:
1) Remove the delayed composition code. Previously, this would schedule
a composite for 12ms in the future. This doesn't really make any sense
with WR. There's no point in doing a composite unless WR has provided
a new frame to be drawn. This fixes issues in several benchmarks where
we were doing multiple composite / renders per rAF, which is a waste
of CPU time. This *does* make the framerate slower in some cases (such
as a slow rAF callback) but it's more correct - otherwise we were just
compositing the same frame multiple times for no real benefit.
2) Inform the window of the current animation state of the compositor.
Specifically, if an animation (or rAF) is currently active, the
window system switches to use event polling, and does not block on
the OS-level event loop. In the case of active animation, we just
assume that we want to be running as the vsync interval and not
blocking. This means the compositor thread only sleeps on vsync
during animation, which reduces OS scheduling and results in much
smoother animation.
Diffstat (limited to 'components/compositing/compositor.rs')
-rw-r--r-- | components/compositing/compositor.rs | 48 |
1 files changed, 7 insertions, 41 deletions
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index cb2abb781fa..f6f1a02fcc5 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -6,7 +6,6 @@ use CompositionPipeline; use SendableFrameTree; use compositor_thread::{CompositorProxy, CompositorReceiver}; use compositor_thread::{InitialCompositorState, Msg, RenderListener}; -use delayed_composition::DelayedCompositionTimerProxy; use euclid::{Point2D, TypedPoint2D, TypedVector2D, TypedRect, ScaleFactor, TypedSize2D}; use gfx_traits::Epoch; use gleam::gl; @@ -131,9 +130,6 @@ pub struct IOCompositor<Window: WindowMethods> { channel_to_self: CompositorProxy, - /// A handle to the delayed composition timer. - delayed_composition_timer: DelayedCompositionTimerProxy, - /// The type of composition to perform composite_target: CompositeTarget, @@ -207,7 +203,6 @@ struct ScrollZoomEvent { #[derive(PartialEq, Debug)] enum CompositionRequest { NoCompositingNecessary, - DelayedComposite(u64), CompositeNow(CompositingReason), } @@ -363,7 +358,6 @@ impl<Window: WindowMethods> IOCompositor<Window> { scale: ScaleFactor::new(1.0), scale_factor: scale_factor, channel_to_self: state.sender.clone_compositor_proxy(), - delayed_composition_timer: DelayedCompositionTimerProxy::new(state.sender), composition_request: CompositionRequest::NoCompositingNecessary, touch_handler: TouchHandler::new(), pending_scroll_zoom_events: Vec::new(), @@ -437,8 +431,6 @@ impl<Window: WindowMethods> IOCompositor<Window> { let _ = receiver.recv(); } - self.delayed_composition_timer.shutdown(); - self.shutdown_state = ShutdownState::FinishedShuttingDown; } @@ -524,16 +516,6 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - (Msg::DelayedCompositionTimeout(timestamp), ShutdownState::NotShuttingDown) => { - if let CompositionRequest::DelayedComposite(this_timestamp) = - self.composition_request { - if timestamp == this_timestamp { - self.composition_request = CompositionRequest::CompositeNow( - CompositingReason::DelayedCompositeTimeout) - } - } - } - (Msg::Recomposite(reason), ShutdownState::NotShuttingDown) => { self.composition_request = CompositionRequest::CompositeNow(reason) } @@ -753,18 +735,6 @@ impl<Window: WindowMethods> IOCompositor<Window> { } } - fn schedule_delayed_composite_if_necessary(&mut self) { - match self.composition_request { - CompositionRequest::CompositeNow(_) => return, - CompositionRequest::DelayedComposite(_) | - CompositionRequest::NoCompositingNecessary => {} - } - - let timestamp = precise_time_ns(); - self.delayed_composition_timer.schedule_composite(timestamp); - self.composition_request = CompositionRequest::DelayedComposite(timestamp); - } - fn scroll_fragment_to_point(&mut self, id: ClipId, point: Point2D<f32>) { self.webrender_api.scroll_node_with_id(LayoutPoint::from_untyped(&point), id, ScrollClamping::ToContentBounds); @@ -1235,13 +1205,18 @@ impl<Window: WindowMethods> IOCompositor<Window> { pipeline_ids.push(*pipeline_id); } } + let animation_state = if pipeline_ids.is_empty() { + windowing::AnimationState::Idle + } else { + windowing::AnimationState::Animating + }; + self.window.set_animation_state(animation_state); for pipeline_id in &pipeline_ids { self.tick_animations_for_pipeline(*pipeline_id) } } fn tick_animations_for_pipeline(&mut self, pipeline_id: PipelineId) { - self.schedule_delayed_composite_if_necessary(); let animation_callbacks_running = self.pipeline_details(pipeline_id).animation_callbacks_running; if animation_callbacks_running { let msg = ConstellationMsg::TickAnimation(pipeline_id, AnimationTickType::Script); @@ -1635,14 +1610,6 @@ impl<Window: WindowMethods> IOCompositor<Window> { _ => compositor_messages.push(msg), } } - if found_recomposite_msg { - compositor_messages.retain(|msg| { - match *msg { - Msg::DelayedCompositionTimeout(_) => false, - _ => true, - } - }) - } for msg in compositor_messages { if !self.handle_browser_message(msg) { break @@ -1664,8 +1631,7 @@ impl<Window: WindowMethods> IOCompositor<Window> { } match self.composition_request { - CompositionRequest::NoCompositingNecessary | - CompositionRequest::DelayedComposite(_) => {} + CompositionRequest::NoCompositingNecessary => {} CompositionRequest::CompositeNow(_) => { self.composite() } |