Skip to content
Permalink
Browse files

Implement WindowMethods for Android

  • Loading branch information...
ferjm committed May 20, 2019
1 parent e0a5abf commit 08d812ec0ed9e2f3d0a287ba5c7e0b926ae0f89a

Some generated files are not rendered by default. Learn more.

@@ -9,6 +9,7 @@ publish = false
[dependencies]
libservo = { path = "../../../components/servo" }
log = "0.4"
servo-media = { git = "https://github.com/servo/media" }

[target.'cfg(not(target_os = "macos"))'.dependencies]
libc = "0.2"
@@ -18,6 +18,7 @@ pub mod egl {
pub type khronos_uint64_t = libc::uint64_t;
pub type khronos_ssize_t = libc::c_long;
pub type EGLint = libc::int32_t;
pub type EGLContext = *const libc::c_void;
pub type EGLNativeDisplayType = *const libc::c_void;
pub type EGLNativePixmapType = *const libc::c_void;
pub type NativeDisplayType = EGLNativeDisplayType;
@@ -26,20 +27,31 @@ pub mod egl {

include!(concat!(env!("OUT_DIR"), "/egl_bindings.rs"));

pub fn init() -> Result<crate::gl_glue::ServoGl, &'static str> {
pub struct EGLInitResult {
pub gl_wrapper: crate::gl_glue::ServoGl,
pub gl_context: EGLContext,
pub display: EGLNativeDisplayType,
}

#[cfg(target_os = "android")]
pub fn init() -> Result<EGLInitResult, &'static str> {
info!("Loading EGL...");
unsafe {
let egl = Egl;
let d = egl.GetCurrentDisplay();
egl.SwapInterval(d, 1);
let display = egl.GetCurrentDisplay();
egl.SwapInterval(display, 1);
let egl = GlesFns::load_with(|addr| {
let addr = CString::new(addr.as_bytes()).unwrap();
let addr = addr.as_ptr();
let egl = Egl;
egl.GetProcAddress(addr) as *const c_void
});
info!("EGL loaded");
Ok(egl)
Ok(EGLInitResult {
gl_wrapper: egl,
gl_context: Egl.GetCurrentContext(),
display,
})
}
}
}
@@ -25,7 +25,7 @@ use servo::servo_url::ServoUrl;
use servo::webrender_api::{DevicePixel, FramebufferPixel, ScrollLocation};
use servo::webvr::{VRExternalShmemPtr, VRMainThreadHeartbeat, VRService, VRServiceManager};
use servo::{self, gl, BrowserId, Servo};

use servo_media::player::context as MediaPlayerContext;
use std::cell::RefCell;
use std::mem;
use std::os::raw::c_void;
@@ -48,6 +48,8 @@ pub struct InitOptions {
pub density: f32,
pub vr_init: VRInitOptions,
pub enable_subpixel_text_antialiasing: bool,
pub gl_context_pointer: Option<*const c_void>,
pub native_display_pointer: Option<*const c_void>,
}

pub enum VRInitOptions {
@@ -187,6 +189,8 @@ pub fn init(
host_callbacks: callbacks,
coordinates: RefCell::new(init_opts.coordinates),
density: init_opts.density,
gl_context_pointer: init_opts.gl_context_pointer,
native_display_pointer: init_opts.native_display_pointer,
});

let embedder_callbacks = Box::new(ServoEmbedderCallbacks {
@@ -583,6 +587,8 @@ struct ServoWindowCallbacks {
host_callbacks: Box<dyn HostTrait>,
coordinates: RefCell<Coordinates>,
density: f32,
gl_context_pointer: Option<*const libc::c_void>,
native_display_pointer: Option<*const libc::c_void>,
}

impl EmbedderMethods for ServoEmbedderCallbacks {
@@ -643,6 +649,24 @@ impl WindowMethods for ServoWindowCallbacks {
hidpi_factor: TypedScale::new(self.density),
}
}

fn get_gl_context(&self) -> MediaPlayerContext::GlContext {
match self.gl_context_pointer {
Some(context) => MediaPlayerContext::GlContext::Egl(context as usize),
None => MediaPlayerContext::GlContext::Unknown,
}
}

fn get_native_display(&self) -> MediaPlayerContext::NativeDisplay {
match self.native_display_pointer {
Some(display) => MediaPlayerContext::NativeDisplay::Egl(display as usize),
None => MediaPlayerContext::NativeDisplay::Unknown,
}
}

fn get_gl_api(&self) -> MediaPlayerContext::GlApi {
MediaPlayerContext::GlApi::Gles2
}
}

struct ResourceReaderInstance;
@@ -52,7 +52,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_init(
opts: JObject,
callbacks_obj: JObject,
) {
let (opts, log, log_str) = match get_options(&env, opts) {
let (mut opts, log, log_str) = match get_options(&env, opts) {
Ok((opts, log, log_str)) => (opts, log, log_str),
Err(err) => {
throw(&env, &err);
@@ -104,9 +104,11 @@ pub fn Java_org_mozilla_servoview_JNIServo_init(
let wakeup = Box::new(WakeupCallback::new(callbacks_ref.clone(), &env));
let callbacks = Box::new(HostCallbacks::new(callbacks_ref, &env));

if let Err(err) =
gl_glue::egl::init().and_then(|gl| simpleservo::init(opts, gl, wakeup, callbacks))
{
if let Err(err) = gl_glue::egl::init().and_then(|egl_init| {
opts.gl_context_pointer = Some(egl_init.gl_context);
opts.native_display_pointer = Some(egl_init.display);
simpleservo::init(opts, egl_init.gl_wrapper, wakeup, callbacks)
}) {
throw(&env, err)
};
}
@@ -726,6 +728,8 @@ fn get_options(env: &JNIEnv, opts: JObject) -> Result<(InitOptions, bool, Option
} else {
VRInitOptions::VRExternal(vr_pointer)
},
gl_context_pointer: None,
native_display_pointer: None,
};
Ok((opts, log, log_str))
}

0 comments on commit 08d812e

Please sign in to comment.
You can’t perform that action at this time.