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 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Introduce ServoSurface

  • Loading branch information
paulrouget committed Aug 1, 2018
commit c36b16546e21fb6b8173c1008e6081ac86c07737
@@ -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 }
}
}

@@ -20,10 +20,11 @@
import android.widget.ProgressBar;

import com.mozilla.servoview.ServoView;
import com.mozilla.servoview.Servo;

import java.io.File;

public class MainActivity extends Activity implements ServoView.Client {
public class MainActivity extends Activity implements Servo.Client {

private static final String LOGTAG = "MainActivity";

@@ -49,10 +50,10 @@ protected void onCreate(Bundle savedInstanceState) {
mUrlField = findViewById(R.id.urlfield);
mProgressBar = findViewById(R.id.progressbar);

mServoView.setClient(this);
mBackButton.setEnabled(false);
mFwdButton.setEnabled(false);

mServoView.setClient(this);
mServoView.requestFocus();

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
@@ -66,9 +67,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

String args = getIntent().getStringExtra("servoargs");
if (args != null) {
mServoView.setServoArgs(args);
}
mServoView.setServoArgs(args);

setupUrlField();
}
@@ -105,18 +104,16 @@ private void loadUrlFromField() {
mServoView.loadUri(Uri.parse(uri));
}

// From activity_main.xml:
public void onReloadClicked(View v) {
mServoView.reload();
}

public void onBackClicked(View v) {
mServoView.goBack();
}

public void onForwardClicked(View v) {
mServoView.goForward();
}

public void onStopClicked(View v) {
mServoView.stop();
}
@@ -10,48 +10,65 @@
/**
* Maps /ports/libsimpleservo API
*/
public class NativeServo {
@SuppressWarnings("JniMissingFunction")
public class JNIServo {
JNIServo() {
System.loadLibrary("c++_shared");
System.loadLibrary("simpleservo");
}

public native String version();

public native void init(Activity activity,
String args,
String url,
WakeupCallback wakeup,
ReadFileCallback readfile,
ServoCallbacks callbacks,
Callbacks callbacks,
int width, int height, boolean log);

public native void setBatchMode(boolean mode);

public native void performUpdates();

public native void resize(int width, int height);

public native void reload();

public native void stop();

public native void goBack();

public native void goForward();

public native void loadUri(String uri);

public native void scrollStart(int dx, int dy, int x, int y);

public native void scroll(int dx, int dy, int x, int y);
public native void scrollEnd(int dx, int dy, int x, int y);
public native void click(int x, int y);

NativeServo() {
System.loadLibrary("c++_shared");
System.loadLibrary("simpleservo");
}
public native void scrollEnd(int dx, int dy, int x, int y);

public interface ReadFileCallback {
byte[] readfile(String file);
}
public native void click(int x, int y);

public interface WakeupCallback {
public interface Callbacks {
void wakeup();
}

public interface ServoCallbacks {
void flush();

void makeCurrent();

void onAnimatingChanged(boolean animating);

void onLoadStarted();

void onLoadEnded();

void onTitleChanged(String title);

void onUrlChanged(String url);

void onHistoryChanged(boolean canGoBack, boolean canGoForward);
void onAnimatingChanged(boolean animating);

byte[] readfile(String file);
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.