Auto merge of #27766 - jdm:embedding-blit, r=asajeffrey

Embedding support for offscreen-rendering

The current embedding API assumes it should render directly to a native widget at all times. These changes expose an option to render to an offscreen surface when starting the engine, as well as a new WebrenderSurfman API for temporarily acquiring  the surface corresponding to the front buffer so it can be used for blitting purposes.

Demonstrated to work in https://github.com/jdm/servo-embedding-example.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
This commit is contained in:
bors-servo 2020-11-15 17:33:40 -05:00 committed by GitHub
commit c7f4eba3db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 9 deletions

View file

@ -162,6 +162,23 @@ impl WebrenderSurfman {
})
}
/// Invoke a closure with the surface associated with the current front buffer.
/// This can be used to create a surfman::SurfaceTexture to blit elsewhere.
pub fn with_front_buffer<F: FnMut(&Device, Surface) -> Surface>(&self, mut f: F) {
let ref mut device = self.0.device.borrow_mut();
let ref mut context = self.0.context.borrow_mut();
let surface = device
.unbind_surface_from_context(context)
.unwrap()
.unwrap();
let surface = f(device, surface);
device.bind_surface_to_context(context, surface).unwrap();
}
pub fn device(&self) -> std::cell::Ref<Device> {
self.0.device.borrow()
}
pub fn connection(&self) -> Connection {
let ref device = self.0.device.borrow();
device.connection()