Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

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

  • Loading branch information
asajeffrey committed Oct 29, 2018
commit 0124baa82f1bd5119cf6398af2e97b4ddf444e9a
@@ -7,6 +7,11 @@ extern crate egl;
extern crate servo;
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 servo::BrowserId;
use servo::Servo;
@@ -36,10 +41,6 @@ use std::os::raw::c_void;
use std::path::PathBuf;
use std::rc::Rc;

type EGLContext = *const c_void;
type EGLSurface = *const c_void;
type EGLDisplay = *const c_void;

type ServoInstance = *mut c_void;

#[repr(u32)]
@@ -58,9 +59,9 @@ pub struct MLLogger(extern "C" fn (MLLogLevel, *const c_char));
const LOG_LEVEL: log::LevelFilter = log::LevelFilter::Info;

#[no_mangle]
pub unsafe extern "C" fn init_servo(_ctxt: EGLContext,
_surf: EGLSurface,
_disp: EGLDisplay,
pub unsafe extern "C" fn init_servo(ctxt: EGLContext,
surf: EGLSurface,
disp: EGLDisplay,
logger: MLLogger,
url: *const c_char,
width: u32,
@@ -77,7 +78,15 @@ pub unsafe extern "C" fn init_servo(_ctxt: EGLContext,
});

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");
let mut servo = Box::new(Servo::new(window));
@@ -110,28 +119,23 @@ pub unsafe extern "C" fn discard_servo(servo: ServoInstance) {
}

struct WindowInstance {
ctxt: EGLContext,
surf: EGLSurface,
disp: EGLDisplay,
gl: Rc<Gl>,
width: u32,
height: u32,
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 {
fn present(&self) {
SwapBuffers(self.disp, self.surf);
}

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);

This comment has been minimized.

@jdm

jdm Oct 29, 2018

Member

Shouldn't this be using the w and h arguments instead?

This comment has been minimized.

@asajeffrey

asajeffrey Oct 29, 2018

Author Member

Don't know. On sample runs they agree, except on the very first call where _w and _h are zero. I think the GL viewport has to agree with the viewport reported by get_coordinates() which uses self.x and self.y.

This comment has been minimized.

@paulrouget

paulrouget Oct 30, 2018

Contributor

The very first call is just to make sure we call make_current early: #16903 - but we could call prepare_for_composite with the right coordinates though. At that point, we have access to the size of the viewport:

let coordinates = window.get_coordinates();

Edit: Submitted a PR to remove the parameters #22048

true
}

@@ -113,8 +113,6 @@ int Servo2D::init() {
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
servo_ = init_servo(ctx, surf, dpy, logger, "https://servo.org", VIEWPORT_H, VIEWPORT_W, HIDPI);
@@ -124,9 +122,6 @@ int Servo2D::init() {
return 1;
}

// Flush GL
glFlush();
eglSwapBuffers(dpy, surf);
return 0;
}

@@ -173,20 +168,9 @@ void Servo2D::instanceInitialScenes() {
}

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
heartbeat_servo(servo_);

// Flush GL
glFlush();
eglSwapBuffers(dpy, surf);

// Return true for your app to continue running, false to terminate the app.
return true;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.