mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
libservo: Don't bounce ready-to-present frame notifications to the Constellation (#35369)
Instead of telling the Constellation to tell the embedder that new frames are ready, have the compositor tell the embedder directly. This should reduce frame latency. Now, after processing compositor updates, run any pending `WebView::new_frame_ready` delegate methods. This change also removes the `refresh` call from the Java interface as that was the only other place that the compositor was rendering the WebRender scene outside of event looping spinning. This `refresh` call was completely unused. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
8c46749740
commit
71bfd2d13f
11 changed files with 26 additions and 63 deletions
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::OnceCell;
|
||||
use std::collections::hash_set::Iter;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs::{create_dir_all, File};
|
||||
|
@ -212,8 +213,9 @@ pub struct IOCompositor {
|
|||
/// The number of frames pending to receive from WebRender.
|
||||
pending_frames: usize,
|
||||
|
||||
/// Waiting for external code to call present.
|
||||
waiting_on_present: bool,
|
||||
/// A list of [`WebViewId`]s of WebViews that have new frames ready that are waiting to
|
||||
/// be presented.
|
||||
webviews_waiting_on_present: FnvHashSet<WebViewId>,
|
||||
|
||||
/// The [`Instant`] of the last animation tick, used to avoid flooding the Constellation and
|
||||
/// ScriptThread with a deluge of animation ticks.
|
||||
|
@ -403,7 +405,7 @@ impl IOCompositor {
|
|||
exit_after_load,
|
||||
convert_mouse_to_touch,
|
||||
pending_frames: 0,
|
||||
waiting_on_present: false,
|
||||
webviews_waiting_on_present: Default::default(),
|
||||
last_animation_tick: Instant::now(),
|
||||
version_string,
|
||||
};
|
||||
|
@ -424,6 +426,10 @@ impl IOCompositor {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn webviews_waiting_on_present(&self) -> Iter<'_, WebViewId> {
|
||||
self.webviews_waiting_on_present.iter()
|
||||
}
|
||||
|
||||
fn update_cursor(&mut self, result: CompositorHitTestResult) {
|
||||
let cursor = match result.cursor {
|
||||
Some(cursor) if cursor != self.cursor => cursor,
|
||||
|
@ -1976,7 +1982,7 @@ impl IOCompositor {
|
|||
target: CompositeTarget,
|
||||
page_rect: Option<Rect<f32, CSSPixel>>,
|
||||
) -> Result<Option<Image>, UnableToComposite> {
|
||||
if self.waiting_on_present {
|
||||
if !self.webviews_waiting_on_present.is_empty() {
|
||||
debug!("tried to composite while waiting on present");
|
||||
return Err(UnableToComposite::NotReadyToPaintImage(
|
||||
NotReadyToPaint::WaitingOnConstellation,
|
||||
|
@ -2146,15 +2152,11 @@ impl IOCompositor {
|
|||
let _span =
|
||||
tracing::trace_span!("ConstellationMsg::ReadyToPresent", servo_profiling = true)
|
||||
.entered();
|
||||
|
||||
// Notify embedder that servo is ready to present.
|
||||
// Embedder should call `present` to tell compositor to continue rendering.
|
||||
self.waiting_on_present = true;
|
||||
let webview_ids = self.webviews.painting_order().map(|(&id, _)| id);
|
||||
let msg = ConstellationMsg::ReadyToPresent(webview_ids.collect());
|
||||
if let Err(e) = self.constellation_chan.send(msg) {
|
||||
warn!("Sending event to constellation failed ({:?}).", e);
|
||||
}
|
||||
|
||||
self.webviews_waiting_on_present
|
||||
.extend(self.webviews.painting_order().map(|(&id, _)| id));
|
||||
self.composition_request = CompositionRequest::NoCompositingNecessary;
|
||||
|
||||
self.process_animations(true);
|
||||
|
@ -2245,7 +2247,7 @@ impl IOCompositor {
|
|||
let _span =
|
||||
tracing::trace_span!("Compositor Present Surface", servo_profiling = true).entered();
|
||||
self.rendering_context.present();
|
||||
self.waiting_on_present = false;
|
||||
self.webviews_waiting_on_present.clear();
|
||||
}
|
||||
|
||||
fn composite_if_necessary(&mut self, reason: CompositingReason) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue