Skip to content

Commit

Permalink
Responding to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed Oct 23, 2018
1 parent 9babe0f commit 5aa2dc5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ports/libmlservo/Cargo.toml
Expand Up @@ -13,7 +13,7 @@ bench = false

[dependencies]
libservo = { path = "../../components/servo" }
servo-egl = "0.2"
log = "0.4"
servo-egl = "0.2"
smallvec = "0.6"

33 changes: 22 additions & 11 deletions ports/libmlservo/src/lib.rs
Expand Up @@ -55,24 +55,29 @@ pub enum MLLogLevel {
#[repr(transparent)]
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,
logger: MLLogger,
url: *const c_char) -> ServoInstance
url: *const c_char,
width: u32,
height: u32,
hidpi: f32) -> ServoInstance
{
// Servo initialization goes here!
servo::embedder_traits::resources::set(Box::new(ResourceReaderInstance::new()));
let _ = log::set_boxed_logger(Box::new(logger));
log::set_max_level(log::LevelFilter::Info);
log::set_max_level(LOG_LEVEL);
let gl = GlesFns::load_with(|symbol| {
let cstr = CString::new(symbol).expect("Failed to convert GL symbol to a char*");
eglGetProcAddress(cstr.as_ptr() as _) as _
});

info!("OpenGL version {}", gl.get_string(gl::VERSION));
let window = Rc::new(WindowInstance::new(gl));
let window = Rc::new(WindowInstance::new(gl, width, height, hidpi));

info!("Starting servo");
let mut servo = Box::new(Servo::new(window));
Expand Down Expand Up @@ -106,12 +111,18 @@ pub unsafe extern "C" fn discard_servo(servo: ServoInstance) {

struct WindowInstance {
gl: Rc<Gl>,
width: u32,
height: u32,
hidpi: f32,
}

impl WindowInstance {
fn new(gl: Rc<Gl>) -> WindowInstance {
fn new(gl: Rc<Gl>, width: u32, height: u32, hidpi: f32) -> WindowInstance {
WindowInstance {
gl: gl,
width: width,
height: height,
hidpi: hidpi,
}
}
}
Expand All @@ -134,12 +145,12 @@ impl WindowMethods for WindowInstance {

fn get_coordinates(&self) -> EmbedderCoordinates {
EmbedderCoordinates {
hidpi_factor: TypedScale::new(1.0),
screen: TypedSize2D::new(500, 500),
screen_avail: TypedSize2D::new(500, 500),
window: (TypedSize2D::new(500, 500), TypedPoint2D::new(0, 0)),
framebuffer: TypedSize2D::new(500, 500),
viewport: TypedRect::new(TypedPoint2D::new(0, 0), TypedSize2D::new(500, 500)),
hidpi_factor: TypedScale::new(self.hidpi),
screen: TypedSize2D::new(self.width, self.height),
screen_avail: TypedSize2D::new(self.width, self.height),
window: (TypedSize2D::new(self.width, self.height), TypedPoint2D::new(0, 0)),
framebuffer: TypedSize2D::new(self.width, self.height),
viewport: TypedRect::new(TypedPoint2D::new(0, 0), TypedSize2D::new(self.width, self.height)),
}
}

Expand Down Expand Up @@ -201,7 +212,7 @@ impl ResourceReaderMethods for ResourceReaderInstance {

impl log::Log for MLLogger {
fn enabled(&self, metadata: &log::Metadata) -> bool {
metadata.level() <= log::Level::Info
metadata.level() <= LOG_LEVEL
}

fn log(&self, record: &log::Record) {
Expand Down
20 changes: 16 additions & 4 deletions support/magicleap/Servo2D/code/src/Servo2D.cpp
Expand Up @@ -13,6 +13,18 @@
#include <GLES/gl.h>
#include <string.h>

// The viewport dimensions (in px).
const unsigned int VIEWPORT_W = 500;
const unsigned int VIEWPORT_H = 500;

// The hidpi factor.
const float HIDPI = 1.0;

// The prism dimensions (in m).
const float PRISM_W = 0.5;
const float PRISM_H = 0.5;
const float PRISM_D = 0.5;

// A function which calls the ML logger, suitable for passing into Servo
typedef void (*MLLogger)(MLLogLevel lvl, char* msg);
void logger(MLLogLevel lvl, char* msg) {
Expand Down Expand Up @@ -41,7 +53,7 @@ Servo2D::~Servo2D() {

// The prism dimensions
const glm::vec3 Servo2D::getInitialPrismExtents() const {
return glm::vec3(0.5f, 0.5f, 0.5f);
return glm::vec3(PRISM_W, PRISM_H, PRISM_D);
}

// Create the prism for Servo
Expand All @@ -64,7 +76,7 @@ int Servo2D::init() {
lumin::ui::Cursor::SetScale(prism_, 0.03f);
instanceInitialScenes();

// Get the panar resource that holds the EGL context
// Get the planar resource that holds the EGL context
lumin::RootNode* root_node = prism_->getRootNode();
if (!root_node) {
ML_LOG(Error, "Servo2D Failed to get root node");
Expand Down Expand Up @@ -101,7 +113,7 @@ int Servo2D::init() {
EGLSurface surf = plane_->getEGLSurface();
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglMakeCurrent(dpy, surf, surf, ctx);
glViewport(0, 0, 500, 500);
glViewport(0, 0, VIEWPORT_W, VIEWPORT_H);

// Hook into servo
servo_ = init_servo(ctx, surf, dpy, logger, "https://servo.org");
Expand Down Expand Up @@ -165,7 +177,7 @@ bool Servo2D::updateLoop(float fDelta) {
EGLSurface surf = plane_->getEGLSurface();
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglMakeCurrent(dpy, surf, surf, ctx);
glViewport(0, 0, 500, 500);
glViewport(0, 0, VIEWPORT_W, VIEWPORT_H);

// Hook into servo
heartbeat_servo(servo_);
Expand Down

0 comments on commit 5aa2dc5

Please sign in to comment.