mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #22239 - paulrouget:shutdown2, r=jdm
shutdown synchronously --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22239) <!-- Reviewable:end -->
This commit is contained in:
commit
d7d9015518
3 changed files with 41 additions and 21 deletions
|
@ -12,6 +12,8 @@ import android.util.Log;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import org.freedesktop.gstreamer.GStreamer;
|
||||
import org.mozilla.servoview.JNIServo.ServoOptions;
|
||||
|
@ -21,6 +23,8 @@ public class Servo {
|
|||
private AssetManager mAssetMgr;
|
||||
private JNIServo mJNI = new JNIServo();
|
||||
private RunCallback mRunCallback;
|
||||
private boolean mShuttingDown;
|
||||
private boolean mShutdownComplete;
|
||||
private boolean mSuspended;
|
||||
|
||||
public Servo(
|
||||
|
@ -47,12 +51,33 @@ public class Servo {
|
|||
}
|
||||
}
|
||||
|
||||
public void requestShutdown() {
|
||||
mRunCallback.inGLThread(() -> mJNI.requestShutdown());
|
||||
}
|
||||
|
||||
public void deinit() {
|
||||
mRunCallback.inGLThread(() -> mJNI.deinit());
|
||||
public void shutdown() {
|
||||
mShuttingDown = true;
|
||||
FutureTask<Void> task = new FutureTask<Void>(new Callable<Void>() {
|
||||
public Void call() throws Exception {
|
||||
mJNI.requestShutdown();
|
||||
// Wait until Servo gets back to us to finalize shutdown.
|
||||
while (!mShutdownComplete) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (Exception e) {
|
||||
mShutdownComplete = true;
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
mJNI.performUpdates();
|
||||
}
|
||||
mJNI.deinit();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
mRunCallback.inGLThread(task);
|
||||
// Block until task is complete.
|
||||
try {
|
||||
task.get();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String version() {
|
||||
|
@ -161,8 +186,6 @@ public class Servo {
|
|||
void inGLThread(Runnable f);
|
||||
|
||||
void inUIThread(Runnable f);
|
||||
|
||||
void finalizeShutdown();
|
||||
}
|
||||
|
||||
public interface GfxCallbacks {
|
||||
|
@ -184,7 +207,7 @@ public class Servo {
|
|||
}
|
||||
|
||||
public void wakeup() {
|
||||
if (!mSuspended) {
|
||||
if (!mSuspended && !mShuttingDown) {
|
||||
mRunCallback.inGLThread(() -> mJNI.performUpdates());
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +223,7 @@ public class Servo {
|
|||
}
|
||||
|
||||
public void onShutdownComplete() {
|
||||
mRunCallback.finalizeShutdown();
|
||||
mShutdownComplete = true;
|
||||
}
|
||||
|
||||
public void onAnimatingChanged(boolean animating) {
|
||||
|
|
|
@ -70,7 +70,9 @@ public class ServoSurface {
|
|||
|
||||
public void shutdown() {
|
||||
Log.d(LOGTAG, "shutdown");
|
||||
mServo.requestShutdown();
|
||||
mServo.shutdown();
|
||||
mServo = null;
|
||||
mGLThread.shutdown();
|
||||
try {
|
||||
Log.d(LOGTAG, "Waiting for GL thread to shutdown");
|
||||
mGLThread.join();
|
||||
|
@ -228,9 +230,8 @@ public class ServoSurface {
|
|||
mMainLooperHandler.post(r);
|
||||
}
|
||||
|
||||
public void finalizeShutdown() {
|
||||
Log.d(LOGTAG, "finalizeShutdown");
|
||||
mServo.deinit();
|
||||
public void shutdown() {
|
||||
Log.d(LOGTAG, "GLThread::shutdown");
|
||||
mSurface.destroy();
|
||||
mGLLooperHandler.getLooper().quitSafely();
|
||||
}
|
||||
|
|
|
@ -69,8 +69,9 @@ public class ServoView extends GLSurfaceView
|
|||
init(context);
|
||||
}
|
||||
|
||||
protected void onDetachedFromWindow() {
|
||||
mServo.requestShutdown();
|
||||
public void onDetachedFromWindow() {
|
||||
mServo.shutdown();
|
||||
mServo = null;
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
|
@ -140,11 +141,6 @@ public class ServoView extends GLSurfaceView
|
|||
public void makeCurrent() {
|
||||
}
|
||||
|
||||
public void finalizeShutdown() {
|
||||
// shutdown has been requested and completed.
|
||||
mServo.deinit();
|
||||
}
|
||||
|
||||
public void inGLThread(Runnable f) {
|
||||
queueEvent(f);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue