mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Reduce the amount of EGL buffer swapping the ML port is doing
This commit is contained in:
parent
0ec0f705b6
commit
0124baa82f
2 changed files with 23 additions and 35 deletions
|
@ -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;
|
||||||
|
@ -36,10 +41,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)]
|
||||||
|
@ -58,9 +59,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,
|
||||||
|
@ -77,7 +78,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));
|
||||||
|
@ -110,28 +119,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,8 +113,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);
|
||||||
|
@ -124,9 +122,6 @@ int Servo2D::init() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush GL
|
|
||||||
glFlush();
|
|
||||||
eglSwapBuffers(dpy, surf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,20 +168,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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue