Auto merge of #22044 - asajeffrey:magicleap-less-egl-buffer-swapping, r=jdm

Reduce the amount of EGL buffer swapping the ML port is doing

<!-- Please describe your changes on the following line: -->

At the moment, we're swapping the EGL buffers every heartbeat, which produces a lot of flickering. We should only swap the buffers when needed.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes do not require tests because we have no way to test on ML

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22044)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-10-30 09:57:56 -04:00 committed by GitHub
commit 4ead81717a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 35 deletions

View file

@ -7,6 +7,11 @@ extern crate egl;
extern crate servo; extern crate servo;
extern crate smallvec; extern crate smallvec;
use egl::egl::EGLContext;
use egl::egl::EGLDisplay;
use egl::egl::EGLSurface;
use egl::egl::MakeCurrent;
use egl::egl::SwapBuffers;
use egl::eglext::eglGetProcAddress; use egl::eglext::eglGetProcAddress;
use servo::BrowserId; use servo::BrowserId;
use servo::Servo; use servo::Servo;
@ -40,10 +45,6 @@ use std::os::raw::c_void;
use std::path::PathBuf; use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
type EGLContext = *const c_void;
type EGLSurface = *const c_void;
type EGLDisplay = *const c_void;
type ServoInstance = *mut c_void; type ServoInstance = *mut c_void;
#[repr(u32)] #[repr(u32)]
@ -62,9 +63,9 @@ pub struct MLLogger(extern "C" fn (MLLogLevel, *const c_char));
const LOG_LEVEL: log::LevelFilter = log::LevelFilter::Info; const LOG_LEVEL: log::LevelFilter = log::LevelFilter::Info;
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn init_servo(_ctxt: EGLContext, pub unsafe extern "C" fn init_servo(ctxt: EGLContext,
_surf: EGLSurface, surf: EGLSurface,
_disp: EGLDisplay, disp: EGLDisplay,
logger: MLLogger, logger: MLLogger,
url: *const c_char, url: *const c_char,
width: u32, width: u32,
@ -81,7 +82,15 @@ pub unsafe extern "C" fn init_servo(_ctxt: EGLContext,
}); });
info!("OpenGL version {}", gl.get_string(gl::VERSION)); info!("OpenGL version {}", gl.get_string(gl::VERSION));
let window = Rc::new(WindowInstance::new(gl, width, height, hidpi)); let window = Rc::new(WindowInstance {
ctxt: ctxt,
surf: surf,
disp: disp,
gl: gl,
width: width,
height: height,
hidpi: hidpi,
});
info!("Starting servo"); info!("Starting servo");
let mut servo = Box::new(Servo::new(window)); let mut servo = Box::new(Servo::new(window));
@ -169,28 +178,23 @@ pub unsafe extern "C" fn discard_servo(servo: ServoInstance) {
} }
struct WindowInstance { struct WindowInstance {
ctxt: EGLContext,
surf: EGLSurface,
disp: EGLDisplay,
gl: Rc<Gl>, gl: Rc<Gl>,
width: u32, width: u32,
height: u32, height: u32,
hidpi: f32, hidpi: f32,
} }
impl WindowInstance {
fn new(gl: Rc<Gl>, width: u32, height: u32, hidpi: f32) -> WindowInstance {
WindowInstance {
gl: gl,
width: width,
height: height,
hidpi: hidpi,
}
}
}
impl WindowMethods for WindowInstance { impl WindowMethods for WindowInstance {
fn present(&self) { fn present(&self) {
SwapBuffers(self.disp, self.surf);
} }
fn prepare_for_composite(&self, _w: Length<u32, DevicePixel>, _h: Length<u32, DevicePixel>) -> bool { fn prepare_for_composite(&self, _w: Length<u32, DevicePixel>, _h: Length<u32, DevicePixel>) -> bool {
MakeCurrent(self.disp, self.surf, self.surf, self.ctxt);
self.gl.viewport(0, 0, self.width as i32, self.height as i32);
true true
} }

View file

@ -116,8 +116,6 @@ int Servo2D::init() {
EGLContext ctx = plane_->getEGLContext(); EGLContext ctx = plane_->getEGLContext();
EGLSurface surf = plane_->getEGLSurface(); EGLSurface surf = plane_->getEGLSurface();
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglMakeCurrent(dpy, surf, surf, ctx);
glViewport(0, 0, VIEWPORT_W, VIEWPORT_H);
// Hook into servo // Hook into servo
servo_ = init_servo(ctx, surf, dpy, logger, "https://servo.org/", VIEWPORT_H, VIEWPORT_W, HIDPI); servo_ = init_servo(ctx, surf, dpy, logger, "https://servo.org/", VIEWPORT_H, VIEWPORT_W, HIDPI);
@ -127,9 +125,6 @@ int Servo2D::init() {
return 1; return 1;
} }
// Flush GL
glFlush();
eglSwapBuffers(dpy, surf);
return 0; return 0;
} }
@ -176,20 +171,9 @@ void Servo2D::instanceInitialScenes() {
} }
bool Servo2D::updateLoop(float fDelta) { bool Servo2D::updateLoop(float fDelta) {
// Get the EGL context, surface and display.
EGLContext ctx = plane_->getEGLContext();
EGLSurface surf = plane_->getEGLSurface();
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglMakeCurrent(dpy, surf, surf, ctx);
glViewport(0, 0, VIEWPORT_W, VIEWPORT_H);
// Hook into servo // Hook into servo
heartbeat_servo(servo_); heartbeat_servo(servo_);
// Flush GL
glFlush();
eglSwapBuffers(dpy, surf);
// Return true for your app to continue running, false to terminate the app. // Return true for your app to continue running, false to terminate the app.
return true; return true;
} }