Auto merge of #27425 - jdm:preserve-draw-buffer, r=asajeffrey

Support preserveDrawingBuffer

Depends on https://github.com/asajeffrey/surfman-chains/pull/9 and https://github.com/servo/webxr/pull/190.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #24604
- [x] There are tests for these changes
This commit is contained in:
bors-servo 2020-08-06 16:11:26 -04:00 committed by GitHub
commit 0573e9c60d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 21 deletions

View file

@ -40,7 +40,7 @@ style = { path = "../style" }
style_traits = { path = "../style_traits" }
# NOTE: the sm-angle feature only enables angle on windows, not other platforms!
surfman = { version = "0.3", features = ["sm-angle","sm-angle-default"] }
surfman-chains = "0.4"
surfman-chains = "0.5"
surfman-chains-api = "0.2"
time = { version = "0.1.0", optional = true }
webrender = { git = "https://github.com/servo/webrender" }

View file

@ -827,22 +827,30 @@ impl WebGLThread {
debug!("Swapping {:?}", context_id);
swap_chain
.swap_buffers(&mut self.device, &mut data.ctx)
.swap_buffers(
&mut self.device,
&mut data.ctx,
if data.attributes.preserve_drawing_buffer {
surfman_chains::PreserveBuffer::Yes(&*data.gl)
} else {
surfman_chains::PreserveBuffer::No
},
)
.unwrap();
debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR);
// TODO: if preserveDrawingBuffer is true, then blit the front buffer to the back buffer
// https://github.com/servo/servo/issues/24604
debug!("Clearing {:?}", context_id);
let alpha = data
.state
.requested_flags
.contains(ContextAttributeFlags::ALPHA);
let clear_color = [0.0, 0.0, 0.0, !alpha as i32 as f32];
swap_chain
.clear_surface(&mut self.device, &mut data.ctx, &*data.gl, clear_color)
.unwrap();
debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR);
if !data.attributes.preserve_drawing_buffer {
debug!("Clearing {:?}", context_id);
let alpha = data
.state
.requested_flags
.contains(ContextAttributeFlags::ALPHA);
let clear_color = [0.0, 0.0, 0.0, !alpha as i32 as f32];
swap_chain
.clear_surface(&mut self.device, &mut data.ctx, &*data.gl, clear_color)
.unwrap();
debug_assert_eq!(data.gl.get_error(), gl::NO_ERROR);
}
// Rebind framebuffers as appropriate.
debug!("Rebinding {:?}", context_id);

View file

@ -13,5 +13,5 @@ path = "lib.rs"
[dependencies]
euclid = "0.20"
surfman = "0.3"
surfman-chains = "0.4"
surfman-chains = "0.5"

View file

@ -147,7 +147,7 @@ impl WebrenderSurfman {
let ref mut device = self.0.device.borrow_mut();
let ref mut context = self.0.context.borrow_mut();
if let Some(ref swap_chain) = self.0.swap_chain {
return swap_chain.swap_buffers(device, context);
return swap_chain.swap_buffers(device, context, surfman_chains::PreserveBuffer::No);
}
let mut surface = device.unbind_surface_from_context(context)?.unwrap();
device.present_surface(context, &mut surface)?;