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

shutdown synchronously #22239

Merged
merged 1 commit into from Nov 23, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -12,6 +12,8 @@

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 @@
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 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 void suspend(boolean suspended) {
void inGLThread(Runnable f);

void inUIThread(Runnable f);

void finalizeShutdown();
}

public interface GfxCallbacks {
@@ -184,7 +207,7 @@ public void suspend(boolean suspended) {
}

public void wakeup() {
if (!mSuspended) {
if (!mSuspended && !mShuttingDown) {
mRunCallback.inGLThread(() -> mJNI.performUpdates());
}
}
@@ -200,7 +223,7 @@ public void makeCurrent() {
}

public void onShutdownComplete() {
mRunCallback.finalizeShutdown();
mShutdownComplete = true;
}

public void onAnimatingChanged(boolean animating) {
@@ -70,7 +70,9 @@ public void runLoop() {

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 void inUIThread(Runnable r) {
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 ServoView(Context context, AttributeSet attrs) {
init(context);
}

protected void onDetachedFromWindow() {
mServo.requestShutdown();
public void onDetachedFromWindow() {
mServo.shutdown();
mServo = null;
super.onDetachedFromWindow();
}

@@ -140,11 +141,6 @@ public void animationStateChanged(boolean animating) {
public void makeCurrent() {
}

public void finalizeShutdown() {
// shutdown has been requested and completed.
mServo.deinit();
}

public void inGLThread(Runnable f) {
queueEvent(f);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.