mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Implement WindowMethods for Android
This commit is contained in:
parent
e0a5abf7df
commit
08d812ec0e
5 changed files with 51 additions and 9 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4404,6 +4404,7 @@ dependencies = [
|
|||
"libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libservo 0.0.1",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"servo-media 0.1.0 (git+https://github.com/servo/media)",
|
||||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
|
|
@ -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,12 +27,19 @@ 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();
|
||||
|
@ -39,7 +47,11 @@ pub mod 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))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue