mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
Instead, schedule a delayed composite after each frame of an animation. The previous code would cause jank, because the following sequence frequently occurred: 1. The page uses `requestAnimationFrame()` to request a frame. 2. The compositor receives the message, schedules a composite, dispatches the rAF message to the script thread, composites, and goes to sleep waiting for vblank (frame 1). 3. The script makes a change and sends it through the pipeline. Eventually it gets painted and is sent to the compositor, but the compositor is sleeping. 4. The compositor wakes up, sees the new painted content, page flips, and goes to sleep (frame 2). Repeat from step 1. The problem is that we have two composition frames, not just one. This halves Web apps' framerate! This commit fixes the problem by scheduling the composite in step 2 to 12 ms in the future. We already have this delayed-composition functionality in the form of the scrolling timer, which I repurposed and renamed to the "delayed composition timer" for this task. This change gives the page 12 ms to prepare the frame, which seems to usually be enough, especially with WebRender. Note that simply removing the scheduled composite after rAF is not the correct solution. If this is done, then pages that call rAF and don't modify the page won't receive future rAFs, since the compositor will be sleeping and won't be notified of vblank. Fixes a bunch of jank in browser.html. The remaining jank seems to be a problem with browser.html itself.
104 lines
3.2 KiB
Rust
104 lines
3.2 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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/. */
|
|
|
|
#![feature(box_syntax)]
|
|
#![feature(custom_derive)]
|
|
#![feature(plugin)]
|
|
#![feature(mpsc_select)]
|
|
#![feature(plugin)]
|
|
#![plugin(plugins)]
|
|
|
|
#![deny(unsafe_code)]
|
|
#![plugin(serde_macros)]
|
|
|
|
extern crate app_units;
|
|
|
|
extern crate azure;
|
|
extern crate canvas;
|
|
extern crate canvas_traits;
|
|
extern crate clipboard;
|
|
#[cfg(target_os = "macos")]
|
|
extern crate core_graphics;
|
|
#[cfg(target_os = "macos")]
|
|
extern crate core_text;
|
|
extern crate devtools_traits;
|
|
extern crate euclid;
|
|
#[cfg(not(target_os = "windows"))]
|
|
extern crate gaol;
|
|
extern crate gfx;
|
|
extern crate gfx_traits;
|
|
extern crate gleam;
|
|
extern crate image;
|
|
extern crate ipc_channel;
|
|
extern crate layers;
|
|
extern crate layout_traits;
|
|
#[macro_use]
|
|
extern crate log;
|
|
extern crate msg;
|
|
extern crate net_traits;
|
|
extern crate num;
|
|
extern crate offscreen_gl_context;
|
|
#[macro_use]
|
|
extern crate profile_traits;
|
|
extern crate script_traits;
|
|
extern crate serde;
|
|
extern crate style_traits;
|
|
extern crate time;
|
|
extern crate url;
|
|
#[macro_use]
|
|
extern crate util;
|
|
extern crate webrender;
|
|
extern crate webrender_traits;
|
|
|
|
pub use compositor_thread::{CompositorEventListener, CompositorProxy, CompositorThread};
|
|
pub use constellation::Constellation;
|
|
use euclid::size::{Size2D};
|
|
use gfx_traits::Epoch;
|
|
use ipc_channel::ipc::{IpcSender};
|
|
use msg::constellation_msg::{FrameId, Key, KeyState, KeyModifiers, LoadData};
|
|
use msg::constellation_msg::{NavigationDirection, PipelineId, SubpageId};
|
|
use msg::constellation_msg::{WebDriverCommandMsg, WindowSizeData};
|
|
use std::collections::HashMap;
|
|
use url::Url;
|
|
|
|
mod compositor;
|
|
mod compositor_layer;
|
|
pub mod compositor_thread;
|
|
pub mod constellation;
|
|
mod delayed_composition;
|
|
mod headless;
|
|
pub mod pipeline;
|
|
#[cfg(not(target_os = "windows"))]
|
|
pub mod sandboxing;
|
|
mod surface_map;
|
|
mod timer_scheduler;
|
|
mod touch;
|
|
pub mod windowing;
|
|
|
|
/// Messages from the compositor to the constellation.
|
|
#[derive(Deserialize, Serialize)]
|
|
pub enum CompositorMsg {
|
|
Exit,
|
|
FrameSize(PipelineId, Size2D<f32>),
|
|
/// Request that the constellation send the FrameId corresponding to the document
|
|
/// with the provided pipeline id
|
|
GetFrame(PipelineId, IpcSender<Option<FrameId>>),
|
|
/// Request that the constellation send the current pipeline id for the provided frame
|
|
/// id, or for the root frame if this is None, over a provided channel
|
|
GetPipeline(Option<FrameId>, IpcSender<Option<PipelineId>>),
|
|
/// Requests that the constellation inform the compositor of the title of the pipeline
|
|
/// immediately.
|
|
GetPipelineTitle(PipelineId),
|
|
InitLoadUrl(Url),
|
|
/// Query the constellation to see if the current compositor output is stable
|
|
IsReadyToSaveImage(HashMap<PipelineId, Epoch>),
|
|
KeyEvent(Key, KeyState, KeyModifiers),
|
|
LoadUrl(PipelineId, LoadData),
|
|
Navigate(Option<(PipelineId, SubpageId)>, NavigationDirection),
|
|
ResizedWindow(WindowSizeData),
|
|
/// Requests that the constellation instruct layout to begin a new tick of the animation.
|
|
TickAnimation(PipelineId),
|
|
/// Dispatch a webdriver command
|
|
WebDriverCommand(WebDriverCommandMsg),
|
|
}
|