Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Introduce ServoSurface #21234

Merged
merged 3 commits into from Aug 1, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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.
@@ -353,6 +356,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();
@@ -214,10 +214,12 @@ def package(self, release=False, dev=False, android=None, debug=False, debugger=
if flavor is not None:
flavor_name = flavor.title()

task_name = "assemble" + flavor_name + build_type + build_mode
variant = ":assemble" + flavor_name + build_type + build_mode
apk_task_name = ":servoapp" + variant
aar_task_name = ":servoview" + variant
try:
with cd(path.join("support", "android", "apk")):
subprocess.check_call(["./gradlew", "--no-daemon", task_name], env=env)
subprocess.check_call(["./gradlew", "--no-daemon", apk_task_name, aar_task_name], env=env)
except subprocess.CalledProcessError as e:
print("Packaging Android exited with return value %d" % e.returncode)
return e.returncode
@@ -1,4 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import org.apache.tools.ant.taskdefs.condition.Os

buildscript {
repositories {
jcenter()
@@ -17,6 +18,68 @@ allprojects {
}
google()
}
}

// Utility methods
String getTargetDir(boolean debug, String arch) {
def basePath = project.rootDir.getParentFile().getParentFile().getParentFile().absolutePath
return basePath + '/target/' + getSubTargetDir(debug, arch)
}

String getSubTargetDir(boolean debug, String arch) {
return getRustTarget(arch) + '/' + (debug ? 'debug' : 'release')
}

String getJniLibsPath(boolean debug, String arch) {
return getTargetDir(debug, arch) + '/apk/jniLibs'
}

static String getRustTarget(String arch) {
switch (arch.toLowerCase()) {
case 'arm' : return 'arm-linux-androideabi'
case 'armv7' : return 'armv7-linux-androideabi'
case 'arm64' : return 'aarch64-linux-android'
case 'x86' : return 'i686-linux-android'
default: throw new GradleException("Invalid target architecture " + arch)
}
}

buildDir = rootDir.absolutePath + "/../../../target/gradle"
static String getNDKAbi(String arch) {
switch (arch.toLowerCase()) {
case 'arm' : return 'armeabi'
case 'armv7' : return 'armeabi-v7a'
case 'arm64' : return 'arm64-v8a'
case 'x86' : return 'x86'
default: throw new GradleException("Invalid target architecture " + arch)
}
}

String getNdkDir() {
// Read environment variable used in rust build system
String ndkDir = System.getenv('ANDROID_NDK')
if (ndkDir == null) {
ndkDir = System.getenv('ANDROID_NDK_HOME')
}
if (ndkDir == null) {
ndkDir = System.getenv('ANDROID_NDK_ROOT')
}
if (ndkDir == null) {
// Fallback to ndkDir in local.properties
def rootDir = project.rootDir
def localProperties = new File(rootDir, "local.properties")
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}

ndkDir = properties.getProperty('ndk.dir')
}

def cmd = Os.isFamily(Os.FAMILY_WINDOWS) ? 'ndk-build.cmd' : 'ndk-build'
def ndkbuild = new File(ndkDir + '/' + cmd)
if (!ndkbuild.exists()) {
throw new GradleException("Please set a valid NDK_HOME environment variable" +
"or ndk.dir path in local.properties file");
}
return ndkbuild.absolutePath
}
@@ -17,6 +17,6 @@ MY_LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_PATH:= $(SERVO_TARGET_DIR)
LOCAL_MODULE := servo
LOCAL_MODULE := servojni
LOCAL_SRC_FILES := libsimpleservo.so
include $(PREBUILT_SHARED_LIBRARY)
@@ -1,4 +1,4 @@
NDK_TOOLCHAIN_VERSION := 4.9
APP_MODULES := c++_shared servo
APP_MODULES := c++_shared servojni
APP_PLATFORM := android-18
APP_STL:= c++_shared
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.