aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ports/libmlservo/src/lib.rs42
-rw-r--r--support/magicleap/Servo2D/code/src/Servo2D.cpp16
2 files changed, 23 insertions, 35 deletions
diff --git a/ports/libmlservo/src/lib.rs b/ports/libmlservo/src/lib.rs
index 109279c7ee2..3f55a31480f 100644
--- a/ports/libmlservo/src/lib.rs
+++ b/ports/libmlservo/src/lib.rs
@@ -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);
true
}
diff --git a/support/magicleap/Servo2D/code/src/Servo2D.cpp b/support/magicleap/Servo2D/code/src/Servo2D.cpp
index 3d6c0ca905e..b694bc1680f 100644
--- a/support/magicleap/Servo2D/code/src/Servo2D.cpp
+++ b/support/magicleap/Servo2D/code/src/Servo2D.cpp
@@ -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;
}