mirror of
https://github.com/servo/servo.git
synced 2025-10-01 00:59:15 +01:00
Auto merge of #21234 - paulrouget:surface, r=MortimerGoro
Android: Introduce ServoSurface (WIP as it depends on 2 other PRs) Depends on #21199. Only last commit matters. r? @MortimerGoro Please look at ServoSurface.java. The rest is mostly some refactoring to share as much code as possible with ServoView. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21234) <!-- Reviewable:end -->
This commit is contained in:
commit
733552d997
9 changed files with 544 additions and 212 deletions
|
@ -39,6 +39,9 @@ pub trait HostTrait {
|
|||
/// Will be called from the thread used for the init call.
|
||||
/// Will be called when the GL buffer has been updated.
|
||||
fn flush(&self);
|
||||
/// Will be called before drawing.
|
||||
/// Time to make the targetted GL context current.
|
||||
fn make_current(&self);
|
||||
/// Page starts loading.
|
||||
/// "Reload button" should be disabled.
|
||||
/// "Stop button" should be enabled.
|
||||
|
@ -355,6 +358,7 @@ impl WindowMethods for ServoCallbacks {
|
|||
_height: Length<u32, DevicePixel>,
|
||||
) -> bool {
|
||||
debug!("WindowMethods::prepare_for_composite");
|
||||
self.host_callbacks.make_current();
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ fn call<F>(f: F) where F: Fn(&mut ServoGlue) -> Result<(), &'static str> {
|
|||
#[repr(C)]
|
||||
pub struct CHostCallbacks {
|
||||
pub flush: extern fn(),
|
||||
pub make_current: extern fn(),
|
||||
pub on_load_started: extern fn(),
|
||||
pub on_load_ended: extern fn(),
|
||||
pub on_title_changed: extern fn(title: *const c_char),
|
||||
|
@ -223,6 +224,11 @@ impl HostTrait for HostCallbacks {
|
|||
(self.0.flush)();
|
||||
}
|
||||
|
||||
fn make_current(&self) {
|
||||
debug!("make_current");
|
||||
(self.0.make_current)();
|
||||
}
|
||||
|
||||
fn on_load_started(&self) {
|
||||
debug!("on_load_ended");
|
||||
(self.0.on_load_started)();
|
||||
|
|
|
@ -36,21 +36,19 @@ where
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_version(env: JNIEnv, _class: JClass) -> jstring {
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_version(env: JNIEnv, _class: JClass) -> jstring {
|
||||
let v = api::servo_version();
|
||||
let output = env.new_string(v).expect("Couldn't create java string");
|
||||
output.into_inner()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_init(
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_init(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
activity: JObject,
|
||||
args: JString,
|
||||
url: JString,
|
||||
wakeup_obj: JObject,
|
||||
readfile_obj: JObject,
|
||||
callbacks_obj: JObject,
|
||||
width: jint,
|
||||
height: jint,
|
||||
|
@ -80,9 +78,11 @@ pub fn Java_com_mozilla_servoview_NativeServo_init(
|
|||
Some(env.get_string(url).expect("Couldn't get java string").into())
|
||||
};
|
||||
|
||||
let wakeup = Box::new(WakeupCallback::new(wakeup_obj, &env));
|
||||
let readfile = Box::new(ReadFileCallback::new(readfile_obj, &env));
|
||||
let callbacks = Box::new(HostCallbacks::new(callbacks_obj, &env));
|
||||
let callbacks_ref = env.new_global_ref(callbacks_obj).unwrap();
|
||||
|
||||
let wakeup = Box::new(WakeupCallback::new(callbacks_ref.clone(), &env));
|
||||
let readfile = Box::new(ReadFileCallback::new(callbacks_ref.clone(), &env));
|
||||
let callbacks = Box::new(HostCallbacks::new(callbacks_ref, &env));
|
||||
|
||||
gl_glue::egl::init().and_then(|gl| {
|
||||
api::init(
|
||||
|
@ -100,7 +100,7 @@ pub fn Java_com_mozilla_servoview_NativeServo_init(
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_setBatchMode(
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_setBatchMode(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
batch: jboolean,
|
||||
|
@ -110,7 +110,7 @@ pub fn Java_com_mozilla_servoview_NativeServo_setBatchMode(
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_resize(
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_resize(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
width: jint,
|
||||
|
@ -121,38 +121,38 @@ pub fn Java_com_mozilla_servoview_NativeServo_resize(
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_performUpdates(env: JNIEnv, _class: JClass) {
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_performUpdates(env: JNIEnv, _class: JClass) {
|
||||
debug!("performUpdates");
|
||||
call(env, |s| s.perform_updates());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_loadUri(env: JNIEnv, _class: JClass, url: JString) {
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_loadUri(env: JNIEnv, _class: JClass, url: JString) {
|
||||
debug!("loadUri");
|
||||
let url: String = env.get_string(url).unwrap().into();
|
||||
call(env, |s| s.load_uri(&url));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_reload(env: JNIEnv, _class: JClass) {
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_reload(env: JNIEnv, _class: JClass) {
|
||||
debug!("reload");
|
||||
call(env, |s| s.reload());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_goBack(env: JNIEnv, _class: JClass) {
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_goBack(env: JNIEnv, _class: JClass) {
|
||||
debug!("goBack");
|
||||
call(env, |s| s.go_back());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_goForward(env: JNIEnv, _class: JClass) {
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_goForward(env: JNIEnv, _class: JClass) {
|
||||
debug!("goForward");
|
||||
call(env, |s| s.go_forward());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_scrollStart(
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_scrollStart(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
dx: jint,
|
||||
|
@ -165,7 +165,7 @@ pub fn Java_com_mozilla_servoview_NativeServo_scrollStart(
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_scrollEnd(
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_scrollEnd(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
dx: jint,
|
||||
|
@ -179,7 +179,7 @@ pub fn Java_com_mozilla_servoview_NativeServo_scrollEnd(
|
|||
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_scroll(
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_scroll(
|
||||
env: JNIEnv,
|
||||
_: JClass,
|
||||
dx: jint,
|
||||
|
@ -192,7 +192,7 @@ pub fn Java_com_mozilla_servoview_NativeServo_scroll(
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_com_mozilla_servoview_NativeServo_click(env: JNIEnv, _: JClass, x: jint, y: jint) {
|
||||
pub fn Java_com_mozilla_servoview_JNIServo_click(env: JNIEnv, _: JClass, x: jint, y: jint) {
|
||||
debug!("click");
|
||||
call(env, |s| s.click(x as u32, y as u32));
|
||||
}
|
||||
|
@ -203,12 +203,9 @@ pub struct WakeupCallback {
|
|||
}
|
||||
|
||||
impl WakeupCallback {
|
||||
pub fn new(jobject: JObject, env: &JNIEnv) -> WakeupCallback {
|
||||
pub fn new(callback: GlobalRef, env: &JNIEnv) -> WakeupCallback {
|
||||
let jvm = Arc::new(env.get_java_vm().unwrap());
|
||||
WakeupCallback {
|
||||
callback: env.new_global_ref(jobject).unwrap(),
|
||||
jvm,
|
||||
}
|
||||
WakeupCallback { callback, jvm }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,9 +230,9 @@ pub struct ReadFileCallback {
|
|||
}
|
||||
|
||||
impl ReadFileCallback {
|
||||
pub fn new(jobject: JObject, env: &JNIEnv) -> ReadFileCallback {
|
||||
pub fn new(callback: GlobalRef, env: &JNIEnv) -> ReadFileCallback {
|
||||
let jvm = env.get_java_vm().unwrap();
|
||||
let callback = Mutex::new(env.new_global_ref(jobject).unwrap());
|
||||
let callback = Mutex::new(callback);
|
||||
ReadFileCallback { callback, jvm }
|
||||
}
|
||||
}
|
||||
|
@ -260,12 +257,9 @@ impl ReadFileTrait for ReadFileCallback {
|
|||
}
|
||||
|
||||
impl HostCallbacks {
|
||||
pub fn new(jobject: JObject, env: &JNIEnv) -> HostCallbacks {
|
||||
pub fn new(callbacks: GlobalRef, env: &JNIEnv) -> HostCallbacks {
|
||||
let jvm = env.get_java_vm().unwrap();
|
||||
HostCallbacks {
|
||||
callbacks: env.new_global_ref(jobject).unwrap(),
|
||||
jvm,
|
||||
}
|
||||
HostCallbacks { callbacks, jvm }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,6 +271,13 @@ impl HostTrait for HostCallbacks {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
fn make_current(&self) {
|
||||
debug!("make_current");
|
||||
let env = self.jvm.get_env().unwrap();
|
||||
env.call_method(self.callbacks.as_obj(), "makeCurrent", "()V", &[])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_load_started(&self) {
|
||||
debug!("on_load_started");
|
||||
let env = self.jvm.get_env().unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue