mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Make JNI code more robust
This commit is contained in:
parent
021a24d5bb
commit
e0ce73abb2
7 changed files with 248 additions and 150 deletions
|
@ -20,13 +20,7 @@ public class JNIServo {
|
|||
|
||||
public native String version();
|
||||
|
||||
public native void init(Activity activity,
|
||||
String args,
|
||||
String url,
|
||||
String logstr,
|
||||
Callbacks callbacks,
|
||||
int width, int height, float density,
|
||||
boolean log);
|
||||
public native void init(Activity activity, ServoOptions options, Callbacks callbacks);
|
||||
|
||||
public native void setBatchMode(boolean mode);
|
||||
|
||||
|
@ -60,6 +54,16 @@ public class JNIServo {
|
|||
|
||||
public native void click(int x, int y);
|
||||
|
||||
public static class ServoOptions {
|
||||
public String args;
|
||||
public String url;
|
||||
public int width = 0;
|
||||
public int height = 0;
|
||||
public float density = 1;
|
||||
public String logStr;
|
||||
public boolean enableLogs = false;
|
||||
}
|
||||
|
||||
public interface Callbacks {
|
||||
void wakeup();
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
|
||||
import org.freedesktop.gstreamer.GStreamer;
|
||||
import org.mozilla.servoview.JNIServo.ServoOptions;
|
||||
|
||||
public class Servo {
|
||||
private static final String LOGTAG = "Servo";
|
||||
|
@ -23,15 +24,11 @@ public class Servo {
|
|||
private boolean mSuspended;
|
||||
|
||||
public Servo(
|
||||
ServoOptions options,
|
||||
RunCallback runCallback,
|
||||
GfxCallbacks gfxcb,
|
||||
Client client,
|
||||
Activity activity,
|
||||
String args,
|
||||
String url,
|
||||
String logstr,
|
||||
int width, int height,
|
||||
float density, boolean log) {
|
||||
Activity activity) {
|
||||
|
||||
mRunCallback = runCallback;
|
||||
|
||||
|
@ -40,7 +37,7 @@ public class Servo {
|
|||
Callbacks cbs = new Callbacks(client, gfxcb);
|
||||
|
||||
mRunCallback.inGLThread(() -> {
|
||||
mJNI.init(activity, args, url, logstr, cbs, width, height, density, log);
|
||||
mJNI.init(activity, options, cbs);
|
||||
});
|
||||
|
||||
try {
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.os.Message;
|
|||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
|
||||
import org.mozilla.servoview.JNIServo.ServoOptions;
|
||||
import org.mozilla.servoview.Servo.Client;
|
||||
import org.mozilla.servoview.Servo.GfxCallbacks;
|
||||
import org.mozilla.servoview.Servo.RunCallback;
|
||||
|
@ -37,9 +38,9 @@ public class ServoSurface {
|
|||
private int mHeight;
|
||||
private Servo mServo;
|
||||
private Client mClient = null;
|
||||
private String mServoArgs = "";
|
||||
private String mServoLog = "";
|
||||
private String mInitialUri = null;
|
||||
private String mServoArgs;
|
||||
private String mServoLog;
|
||||
private String mInitialUri;
|
||||
private Activity mActivity;
|
||||
|
||||
public ServoSurface(Surface surface, int width, int height) {
|
||||
|
@ -55,8 +56,8 @@ public class ServoSurface {
|
|||
}
|
||||
|
||||
public void setServoArgs(String args, String log) {
|
||||
mServoArgs = args != null ? args : "";
|
||||
mServoLog = log != null ? log : "";
|
||||
mServoArgs = args;
|
||||
mServoLog = log;
|
||||
}
|
||||
|
||||
public void setActivity(Activity activity) {
|
||||
|
@ -204,9 +205,16 @@ public class ServoSurface {
|
|||
};
|
||||
|
||||
inUIThread(() -> {
|
||||
final boolean showLogs = true;
|
||||
String uri = mInitialUri == null ? null : mInitialUri;
|
||||
mServo = new Servo(this, surface, mClient, mActivity, mServoArgs, uri, mServoLog, mWidth, mHeight, 1, showLogs);
|
||||
ServoOptions options = new ServoOptions();
|
||||
options.args = mServoArgs;
|
||||
options.width = mWidth;
|
||||
options.height = mHeight;
|
||||
options.density = 1;
|
||||
options.url = mInitialUri == null ? null : mInitialUri;
|
||||
options.logStr = mServoLog;
|
||||
options.enableLogs = true;
|
||||
|
||||
mServo = new Servo(options, this, surface, mClient, mActivity);
|
||||
});
|
||||
|
||||
Looper.loop();
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.view.MotionEvent;
|
|||
import android.view.ScaleGestureDetector;
|
||||
import android.widget.OverScroller;
|
||||
|
||||
import org.mozilla.servoview.JNIServo.ServoOptions;
|
||||
import org.mozilla.servoview.Servo.Client;
|
||||
import org.mozilla.servoview.Servo.GfxCallbacks;
|
||||
import org.mozilla.servoview.Servo.RunCallback;
|
||||
|
@ -41,8 +42,8 @@ public class ServoView extends GLSurfaceView
|
|||
private Client mClient = null;
|
||||
private Uri mInitialUri = null;
|
||||
private boolean mAnimating;
|
||||
private String mServoArgs = "";
|
||||
private String mServoLog = "";
|
||||
private String mServoArgs;
|
||||
private String mServoLog;
|
||||
private GestureDetector mGestureDetector;
|
||||
private ScaleGestureDetector mScaleGestureDetector;
|
||||
|
||||
|
@ -75,8 +76,8 @@ public class ServoView extends GLSurfaceView
|
|||
}
|
||||
|
||||
public void setServoArgs(String args, String log) {
|
||||
mServoArgs = args != null ? args : "";
|
||||
mServoLog = log != null ? log : "";
|
||||
mServoArgs = args;
|
||||
mServoLog = log;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
|
@ -135,16 +136,19 @@ public class ServoView extends GLSurfaceView
|
|||
}
|
||||
|
||||
public void onGLReady() {
|
||||
final boolean showLogs = true;
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
ServoOptions options = new ServoOptions();
|
||||
options.args = mServoArgs;
|
||||
options.width = getWidth();
|
||||
options.height = getHeight();
|
||||
options.enableLogs = true;
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
float density = metrics.density;
|
||||
|
||||
options.density = metrics.density;
|
||||
inGLThread(() -> {
|
||||
String uri = mInitialUri == null ? null : mInitialUri.toString();
|
||||
mServo = new Servo(this, this, mClient, mActivity, mServoArgs, uri, mServoLog, width, height, density, showLogs);
|
||||
options.url = uri;
|
||||
options.logStr = mServoLog;
|
||||
mServo = new Servo(options, this, this, mClient, mActivity);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue