diff options
7 files changed, 69 insertions, 9 deletions
diff --git a/ports/libsimpleservo/src/api.rs b/ports/libsimpleservo/src/api.rs index 7cf986137f6..cdaa4a67cf2 100644 --- a/ports/libsimpleservo/src/api.rs +++ b/ports/libsimpleservo/src/api.rs @@ -208,6 +208,12 @@ impl ServoGlue { self.process_event(event) } + /// Redraw the page. + pub fn refresh(&mut self) -> Result<(), &'static str> { + info!("refresh"); + self.process_event(WindowEvent::Refresh) + } + /// Stop loading the page. pub fn stop(&mut self) -> Result<(), &'static str> { warn!("TODO can't stop won't stop"); diff --git a/ports/libsimpleservo/src/capi.rs b/ports/libsimpleservo/src/capi.rs index d4732f84270..3edadc81dd5 100644 --- a/ports/libsimpleservo/src/capi.rs +++ b/ports/libsimpleservo/src/capi.rs @@ -145,6 +145,12 @@ pub extern "C" fn stop() { } #[no_mangle] +pub extern "C" fn refresh() { + debug!("refresh"); + call(|s| s.refresh()); +} + +#[no_mangle] pub extern "C" fn go_back() { debug!("go_back"); call(|s| s.go_back()); diff --git a/ports/libsimpleservo/src/jniapi.rs b/ports/libsimpleservo/src/jniapi.rs index 6ef3a6464bf..2367b685d47 100644 --- a/ports/libsimpleservo/src/jniapi.rs +++ b/ports/libsimpleservo/src/jniapi.rs @@ -150,6 +150,12 @@ pub fn Java_com_mozilla_servoview_JNIServo_stop(env: JNIEnv, _class: JClass) { } #[no_mangle] +pub fn Java_com_mozilla_servoview_JNIServo_refresh(env: JNIEnv, _class: JClass) { + debug!("refresh"); + call(env, |s| s.refresh()); +} + +#[no_mangle] pub fn Java_com_mozilla_servoview_JNIServo_goBack(env: JNIEnv, _class: JClass) { debug!("goBack"); call(env, |s| s.go_back()); diff --git a/support/android/apk/servoapp/src/main/java/com/mozilla/servo/MainActivity.java b/support/android/apk/servoapp/src/main/java/com/mozilla/servo/MainActivity.java index 1d042151a3a..794e8ae5564 100644 --- a/support/android/apk/servoapp/src/main/java/com/mozilla/servo/MainActivity.java +++ b/support/android/apk/servoapp/src/main/java/com/mozilla/servo/MainActivity.java @@ -151,4 +151,15 @@ public class MainActivity extends Activity implements Servo.Client { mFwdButton.setEnabled(canGoForward); } + @Override + public void onPause() { + mServoView.onPause(); + super.onPause(); + } + @Override + public void onResume() { + mServoView.onResume(); + super.onResume(); + } + } diff --git a/support/android/apk/servoview/src/main/java/com/mozilla/servoview/JNIServo.java b/support/android/apk/servoview/src/main/java/com/mozilla/servoview/JNIServo.java index 13c62fe9372..aa8125038fa 100644 --- a/support/android/apk/servoview/src/main/java/com/mozilla/servoview/JNIServo.java +++ b/support/android/apk/servoview/src/main/java/com/mozilla/servoview/JNIServo.java @@ -35,6 +35,8 @@ public class JNIServo { public native void stop(); + public native void refresh(); + public native void goBack(); public native void goForward(); diff --git a/support/android/apk/servoview/src/main/java/com/mozilla/servoview/Servo.java b/support/android/apk/servoview/src/main/java/com/mozilla/servoview/Servo.java index 268669e5c45..e125d245d75 100644 --- a/support/android/apk/servoview/src/main/java/com/mozilla/servoview/Servo.java +++ b/support/android/apk/servoview/src/main/java/com/mozilla/servoview/Servo.java @@ -17,6 +17,7 @@ public class Servo { private AssetManager mAssetMgr; private JNIServo mJNI = new JNIServo(); private RunCallback mRunCallback; + private boolean mSuspended; public Servo( RunCallback runCallback, @@ -49,6 +50,10 @@ public class Servo { mRunCallback.inGLThread(() -> mJNI.resize(width, height)); } + public void refresh() { + mRunCallback.inGLThread(() -> mJNI.refresh()); + } + public void reload() { mRunCallback.inGLThread(() -> mJNI.reload()); } @@ -85,6 +90,10 @@ public class Servo { mRunCallback.inGLThread(() -> mJNI.click(x, y)); } + public void suspend(boolean suspended) { + mSuspended = suspended; + } + public interface Client { void onLoadStarted(); @@ -122,7 +131,9 @@ public class Servo { } public void wakeup() { - mRunCallback.inGLThread(() -> mJNI.performUpdates()); + if (!mSuspended) { + mRunCallback.inGLThread(() -> mJNI.performUpdates()); + } } public void flush() { diff --git a/support/android/apk/servoview/src/main/java/com/mozilla/servoview/ServoView.java b/support/android/apk/servoview/src/main/java/com/mozilla/servoview/ServoView.java index 7385b8a29e1..0424d84ebe0 100644 --- a/support/android/apk/servoview/src/main/java/com/mozilla/servoview/ServoView.java +++ b/support/android/apk/servoview/src/main/java/com/mozilla/servoview/ServoView.java @@ -54,6 +54,7 @@ public class ServoView extends GLSurfaceView setWillNotCacheDrawing(false); setEGLContextClientVersion(3); setEGLConfigChooser(8, 8, 8, 8, 24, 0); + setPreserveEGLContextOnPause(true); ServoGLRenderer mRenderer = new ServoGLRenderer(this); setRenderer(mRenderer); setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); @@ -80,9 +81,10 @@ public class ServoView extends GLSurfaceView mServo.stop(); } - public void onSurfaceResized(int width, int height) { + public void onSurfaceInvalidated(int width, int height) { if (mServo != null) { mServo.resize(width, height); + mServo.refresh(); } } @@ -143,7 +145,7 @@ public class ServoView extends GLSurfaceView if (mScroller.isFinished() && mFlinging) { mFlinging = false; - queueEvent(() -> mServo.scrollEnd(0, 0, mCurX, mCurY)); + inGLThread(() -> mServo.scrollEnd(0, 0, mCurX, mCurY)); if (!mAnimating) { // Not scrolling. Not animating. We don't need to schedule // another frame. @@ -164,7 +166,7 @@ public class ServoView extends GLSurfaceView mLastY = mCurY; if (dx != 0 || dy != 0) { - queueEvent(() -> mServo.scroll(dx, dy, mCurX, mCurY)); + inGLThread(() -> mServo.scroll(dx, dy, mCurX, mCurY)); } else { if (mAnimating) { requestRender(); @@ -205,7 +207,7 @@ public class ServoView extends GLSurfaceView mCurY = (int) e.getY(); mLastY = mCurY; mScroller.forceFinished(true); - queueEvent(() -> mServo.scrollStart(0, 0, mCurX, mCurY)); + inGLThread(() -> mServo.scrollStart(0, 0, mCurX, mCurY)); Choreographer.getInstance().postFrameCallback(this); return true; case (MotionEvent.ACTION_MOVE): @@ -215,7 +217,7 @@ public class ServoView extends GLSurfaceView case (MotionEvent.ACTION_UP): case (MotionEvent.ACTION_CANCEL): if (!mFlinging) { - queueEvent(() -> mServo.scrollEnd(0, 0, mCurX, mCurY)); + inGLThread(() -> mServo.scrollEnd(0, 0, mCurX, mCurY)); Choreographer.getInstance().removeFrameCallback(this); } return true; @@ -225,7 +227,7 @@ public class ServoView extends GLSurfaceView } public boolean onSingleTapUp(MotionEvent e) { - queueEvent(() -> mServo.click((int) e.getX(), (int) e.getY())); + inGLThread(() -> mServo.click((int) e.getX(), (int) e.getY())); return false; } @@ -239,6 +241,22 @@ public class ServoView extends GLSurfaceView public void onShowPress(MotionEvent e) { } + @Override + public void onPause() { + super.onPause(); + if (mServo != null) { + mServo.suspend(true); + } + } + + @Override + public void onResume() { + super.onResume(); + if (mServo != null) { + mServo.suspend(false); + } + } + static class ServoGLRenderer implements Renderer { private final ServoView mView; @@ -254,9 +272,9 @@ public class ServoView extends GLSurfaceView public void onDrawFrame(GL10 unused) { } - public void onSurfaceChanged(GL10 unused, int width, int height) { + public void onSurfaceChanged(GL10 gl, int width, int height) { GLES31.glViewport(0, 0, width, height); - mView.onSurfaceResized(width, height); + mView.onSurfaceInvalidated(width, height); } } } |