mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add transparent padding around ServoSurface
This commit is contained in:
parent
40d599e39f
commit
8f2390fdff
10 changed files with 186 additions and 74 deletions
|
@ -30,7 +30,7 @@ public class JNIServo {
|
|||
|
||||
public native void performUpdates();
|
||||
|
||||
public native void resize(int width, int height);
|
||||
public native void resize(ServoCoordinates coords);
|
||||
|
||||
public native void reload();
|
||||
|
||||
|
@ -69,8 +69,7 @@ public class JNIServo {
|
|||
public static class ServoOptions {
|
||||
public String args;
|
||||
public String url;
|
||||
public int width = 0;
|
||||
public int height = 0;
|
||||
public ServoCoordinates coordinates;
|
||||
public float density = 1;
|
||||
public boolean enableSubpixelTextAntialiasing = true;
|
||||
public long VRExternalContext = 0;
|
||||
|
@ -78,6 +77,15 @@ public class JNIServo {
|
|||
public boolean enableLogs = false;
|
||||
}
|
||||
|
||||
public static class ServoCoordinates {
|
||||
public int x = 0;
|
||||
public int y = 0;
|
||||
public int width = 0;
|
||||
public int height = 0;
|
||||
public int fb_width = 0;
|
||||
public int fb_height = 0;
|
||||
}
|
||||
|
||||
public interface Callbacks {
|
||||
void wakeup();
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.concurrent.Callable;
|
|||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import org.freedesktop.gstreamer.GStreamer;
|
||||
import org.mozilla.servoview.JNIServo.ServoCoordinates;
|
||||
import org.mozilla.servoview.JNIServo.ServoOptions;
|
||||
|
||||
public class Servo {
|
||||
|
@ -91,8 +92,8 @@ public class Servo {
|
|||
mRunCallback.inGLThread(() -> mJNI.setBatchMode(mode));
|
||||
}
|
||||
|
||||
public void resize(int width, int height) {
|
||||
mRunCallback.inGLThread(() -> mJNI.resize(width, height));
|
||||
public void resize(ServoCoordinates coords) {
|
||||
mRunCallback.inGLThread(() -> mJNI.resize(coords));
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
|
|
|
@ -18,6 +18,7 @@ import android.os.Looper;
|
|||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
|
||||
import org.mozilla.servoview.JNIServo.ServoCoordinates;
|
||||
import org.mozilla.servoview.JNIServo.ServoOptions;
|
||||
import org.mozilla.servoview.Servo.Client;
|
||||
import org.mozilla.servoview.Servo.GfxCallbacks;
|
||||
|
@ -34,6 +35,7 @@ public class ServoSurface {
|
|||
private final Handler mMainLooperHandler;
|
||||
private Handler mGLLooperHandler;
|
||||
private Surface mASurface;
|
||||
private int mPadding;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private long mVRExternalContext;
|
||||
|
@ -44,7 +46,8 @@ public class ServoSurface {
|
|||
private String mInitialUri;
|
||||
private Activity mActivity;
|
||||
|
||||
public ServoSurface(Surface surface, int width, int height) {
|
||||
public ServoSurface(Surface surface, int width, int height, int padding) {
|
||||
mPadding = padding;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
mASurface = surface;
|
||||
|
@ -136,7 +139,18 @@ public class ServoSurface {
|
|||
}
|
||||
|
||||
public void onSurfaceResized(int width, int height) {
|
||||
mServo.resize(width, height);
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
|
||||
ServoCoordinates coords = new ServoCoordinates();
|
||||
coords.x = mPadding;
|
||||
coords.y = mPadding;
|
||||
coords.width = width - 2 * mPadding;
|
||||
coords.height = height - 2 * mPadding;
|
||||
coords.fb_width = width;
|
||||
coords.fb_height = height;
|
||||
|
||||
mServo.resize(coords);
|
||||
}
|
||||
|
||||
static class GLSurface implements GfxCallbacks {
|
||||
|
@ -261,10 +275,17 @@ public class ServoSurface {
|
|||
mGLLooperHandler = new Handler();
|
||||
|
||||
inUIThread(() -> {
|
||||
ServoCoordinates coords = new ServoCoordinates();
|
||||
coords.x = mPadding;
|
||||
coords.y = mPadding;
|
||||
coords.width = mWidth - 2 * mPadding;
|
||||
coords.height = mHeight - 2 * mPadding;
|
||||
coords.fb_width = mWidth;
|
||||
coords.fb_height = mHeight;
|
||||
|
||||
ServoOptions options = new ServoOptions();
|
||||
options.coordinates = coords;
|
||||
options.args = mServoArgs;
|
||||
options.width = mWidth;
|
||||
options.height = mHeight;
|
||||
options.density = 1;
|
||||
options.url = mInitialUri;
|
||||
options.logStr = mServoLog;
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.view.MotionEvent;
|
|||
import android.view.ScaleGestureDetector;
|
||||
import android.widget.OverScroller;
|
||||
|
||||
import org.mozilla.servoview.JNIServo.ServoCoordinates;
|
||||
import org.mozilla.servoview.JNIServo.ServoOptions;
|
||||
import org.mozilla.servoview.Servo.Client;
|
||||
import org.mozilla.servoview.Servo.GfxCallbacks;
|
||||
|
@ -112,7 +113,13 @@ public class ServoView extends GLSurfaceView
|
|||
|
||||
public void onSurfaceInvalidated(int width, int height) {
|
||||
if (mServo != null) {
|
||||
mServo.resize(width, height);
|
||||
ServoCoordinates coords = new ServoCoordinates();
|
||||
coords.width = width;
|
||||
coords.height = height;
|
||||
coords.fb_width = width;
|
||||
coords.fb_height = height;
|
||||
|
||||
mServo.resize(coords);
|
||||
mServo.refresh();
|
||||
}
|
||||
}
|
||||
|
@ -150,12 +157,18 @@ public class ServoView extends GLSurfaceView
|
|||
}
|
||||
|
||||
public void onGLReady() {
|
||||
ServoCoordinates coords = new ServoCoordinates();
|
||||
coords.width = getWidth();
|
||||
coords.height = getHeight();
|
||||
coords.fb_width = getWidth();
|
||||
coords.fb_height = getHeight();
|
||||
|
||||
ServoOptions options = new ServoOptions();
|
||||
options.args = mServoArgs;
|
||||
options.width = getWidth();
|
||||
options.height = getHeight();
|
||||
options.coordinates = coords;
|
||||
options.enableLogs = true;
|
||||
options.enableSubpixelTextAntialiasing = true;
|
||||
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
options.density = metrics.density;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue