diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 8ea0e4634e5..57835d37930 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -240,10 +240,6 @@ pub struct IOCompositor { /// 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 IOCompositor { exit_after_load, convert_mouse_to_touch, waiting_on_pending_frame: false, - external_present: false, waiting_on_present: false, } } @@ -1858,17 +1853,14 @@ impl IOCompositor { _ => 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 IOCompositor { 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 IOCompositor { None => eprintln!("Unable to locate path to save captures"), } } - - pub fn set_external_present(&mut self, value: bool) { - self.external_present = value; - } } diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 1eb9a62306b..265fb63766a 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -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(); } diff --git a/ports/servoshell/app.rs b/ports/servoshell/app.rs index fbd7d5bc313..2419ab5b4c8 100644 --- a/ports/servoshell/app.rs +++ b/ports/servoshell/app.rs @@ -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 don’t 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 => {}, }