Fix servoshell can't respond when there's no minibrowser (#30598)

* Fix servoshell can't respond when there's no minibrowser

* Remove external_field and update documentation

* Update documentation

* Fix crash when handling ReadyToPresent if it's headless mode

* Fix some wpt tests got timedout
This commit is contained in:
Ngo Iok Ui (Wu Yu Wei) 2023-11-11 15:45:27 +09:00 committed by GitHub
parent d8e93fa408
commit 44d79269f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 43 deletions

View file

@ -240,10 +240,6 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
/// most up to date rendering.
waiting_on_pending_frame: bool,
/// Whether to send a ReadyToPresent message to the constellation after rendering a new frame,
/// allowing external code to draw to the framebuffer and decide when to present the frame.
external_present: bool,
/// Waiting for external code to call present.
waiting_on_present: bool,
}
@ -410,7 +406,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
exit_after_load,
convert_mouse_to_touch,
waiting_on_pending_frame: false,
external_present: false,
waiting_on_present: false,
}
}
@ -1858,17 +1853,14 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
_ => None,
};
// Perform the page flip. This will likely block for a while.
if self.external_present {
self.waiting_on_present = true;
let msg = ConstellationMsg::ReadyToPresent(
self.root_content_pipeline.top_level_browsing_context_id,
);
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending event to constellation failed ({:?}).", e);
}
} else {
self.present();
// Nottify embedder that servo is ready to present.
// Embedder should call `present` to tell compositor to continue rendering.
self.waiting_on_present = true;
let msg = ConstellationMsg::ReadyToPresent(
self.root_content_pipeline.top_level_browsing_context_id,
);
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending event to constellation failed ({:?}).", e);
}
self.composition_request = CompositionRequest::NoCompositingNecessary;
@ -1904,13 +1896,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
let gl = &self.webrender_gl;
self.assert_gl_framebuffer_complete();
if !self.external_present {
// Make framebuffer fully transparent.
gl.clear_color(0.0, 0.0, 0.0, 0.0);
gl.clear(gleam::gl::COLOR_BUFFER_BIT);
self.assert_gl_framebuffer_complete();
}
// Set the viewport background based on prefs.
let viewport = self.embedder_coordinates.get_flipped_viewport();
gl.scissor(
@ -2109,8 +2094,4 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
None => eprintln!("Unable to locate path to save captures"),
}
}
pub fn set_external_present(&mut self, value: bool) {
self.external_present = value;
}
}

View file

@ -761,10 +761,6 @@ where
self.compositor.deinit();
}
pub fn set_external_present(&mut self, value: bool) {
self.compositor.set_external_present(value)
}
pub fn present(&mut self) {
self.compositor.present();
}

View file

@ -41,8 +41,15 @@ pub struct App {
/// Action to be taken by the caller of [`App::handle_events`].
enum PumpResult {
/// The caller should shut down Servo and its related context.
Shutdown,
/// A new frame is ready to present. The caller can paint other things themselves during this
/// period, but has to call [`Servo::present`] to perform page flip and tell Servo compositor
/// to continue rendering.
ReadyToPresent,
/// The size has changed. The caller can paint other things themselves during this
/// period, but has to call [`Servo::present`] to perform page flip and tell Servo compositor
/// to continue rendering.
Resize,
}
@ -117,10 +124,6 @@ impl App {
// frame, set this to false, so we can avoid an unnecessary recomposite.
let mut need_recomposite = true;
// If we have a minibrowser, ask the compositor to notify us when a new frame
// is ready to present, so that we can paint the minibrowser then present.
let external_present = app.minibrowser.is_some();
let t_start = Instant::now();
let mut t = t_start;
let ev_waker = events_loop.create_event_loop_waker();
@ -175,7 +178,6 @@ impl App {
let servo_data = Servo::new(embedder, window.clone(), user_agent.clone());
let mut servo = servo_data.servo;
servo.set_external_present(external_present);
servo.handle_events(vec![EmbedderEvent::NewBrowser(
initial_url.to_owned(),
@ -209,9 +211,7 @@ impl App {
minibrowser.update(window.winit_window().unwrap(), "RedrawRequested");
minibrowser.paint(window.winit_window().unwrap());
}
if external_present {
app.servo.as_mut().unwrap().present();
}
app.servo.as_mut().unwrap().present();
// By default, the next RedrawRequested event will need to recomposite.
need_recomposite = true;
@ -296,7 +296,12 @@ impl App {
trace!("PumpResult::ReadyToPresent");
// Request a winit redraw event, so we can paint the minibrowser and present.
window.winit_window().unwrap().request_redraw();
// Otherwise, it's in headless mode and we present directly.
if let Some(window) = window.winit_window() {
window.request_redraw();
} else {
app.servo.as_mut().unwrap().present();
}
// We dont need the compositor to paint to this frame during the redraw event.
// TODO(servo#30331) broken on macOS?
@ -314,9 +319,7 @@ impl App {
minibrowser.update(window.winit_window().unwrap(), "PumpResult::Resize");
minibrowser.paint(window.winit_window().unwrap());
}
if external_present {
app.servo.as_mut().unwrap().present();
}
app.servo.as_mut().unwrap().present();
},
None => {},
}