aboutsummaryrefslogtreecommitdiffstats
path: root/components/compositing/compositor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/compositing/compositor.rs')
-rw-r--r--components/compositing/compositor.rs47
1 files changed, 41 insertions, 6 deletions
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs
index 67cecd6a4a0..8eed1ed3f66 100644
--- a/components/compositing/compositor.rs
+++ b/components/compositing/compositor.rs
@@ -230,6 +230,13 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
/// taken before the render is complete will not reflect the
/// 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,
}
#[derive(Clone, Copy)]
@@ -382,6 +389,8 @@ 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,
}
}
@@ -1525,6 +1534,12 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
target: CompositeTarget,
rect: Option<Rect<f32, CSSPixel>>,
) -> Result<Option<Image>, UnableToComposite> {
+ if self.waiting_on_present {
+ return Err(UnableToComposite::NotReadyToPaintImage(
+ NotReadyToPaint::WaitingOnConstellation,
+ ));
+ }
+
let size = self.embedder_coordinates.framebuffer.to_u32();
if let Err(err) = self.webrender_surfman.make_gl_context_current() {
@@ -1703,8 +1718,15 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
};
// Perform the page flip. This will likely block for a while.
- if let Err(err) = self.webrender_surfman.present() {
- warn!("Failed to present surface: {:?}", err);
+ if self.external_present {
+ self.waiting_on_present = true;
+ let msg =
+ ConstellationMsg::ReadyToPresent(self.root_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();
}
self.composition_request = CompositionRequest::NoCompositingNecessary;
@@ -1715,6 +1737,13 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
Ok(rv)
}
+ pub fn present(&mut self) {
+ if let Err(err) = self.webrender_surfman.present() {
+ warn!("Failed to present surface: {:?}", err);
+ }
+ self.waiting_on_present = false;
+ }
+
fn composite_if_necessary(&mut self, reason: CompositingReason) {
if self.composition_request == CompositionRequest::NoCompositingNecessary {
if self.is_running_problem_test {
@@ -1733,10 +1762,12 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
let gl = &self.webrender_gl;
self.assert_gl_framebuffer_complete();
- // 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();
+ 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();
+ }
// Make the viewport white.
let viewport = self.embedder_coordinates.get_flipped_viewport();
@@ -1919,6 +1950,10 @@ 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;
+ }
}
/// Why we performed a composite. This is used for debugging.