Bug 1236654 - Properly shut down GLController on nsWindow closing; r=snorp

When nsWindow closes, notify GLController to shut down. To ensure any
pending calls on the UI thread are processed first, post a Runnable to
the UI thread that disposes the GLController on the UI thread.
This commit is contained in:
Jim Chen 2016-01-06 21:33:18 -05:00
parent e2aca4db00
commit 17cdf6a53d
4 changed files with 40 additions and 5 deletions

View File

@ -293,6 +293,20 @@ public class GLController extends JNIObject {
}
}
@WrapForJNI
private void destroy() {
// The nsWindow has been closed. First mark our compositor as destroyed.
mCompositorCreated = false;
// Then clear out any pending calls on the UI thread by disposing on the UI thread.
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
GLController.this.disposeNative();
}
});
}
public static class GLControllerException extends RuntimeException {
public static final long serialVersionUID = 1L;

View File

@ -1253,6 +1253,14 @@ auto GLController::CreateEGLSurface() const -> mozilla::jni::Object::LocalRef
return mozilla::jni::Method<CreateEGLSurface_t>::Call(this, nullptr);
}
constexpr char GLController::Destroy_t::name[];
constexpr char GLController::Destroy_t::signature[];
auto GLController::Destroy() const -> void
{
return mozilla::jni::Method<Destroy_t>::Call(this, nullptr);
}
constexpr char GLController::DisposeNative_t::name[];
constexpr char GLController::DisposeNative_t::signature[];

View File

@ -3384,6 +3384,23 @@ public:
auto CreateEGLSurface() const -> mozilla::jni::Object::LocalRef;
public:
struct Destroy_t {
typedef GLController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "destroy";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
auto Destroy() const -> void;
public:
struct DisposeNative_t {
typedef GLController Owner;

View File

@ -470,11 +470,7 @@ public:
~GLControllerSupport()
{
GLController::GlobalRef glController(mozilla::Move(mGLController));
nsAppShell::PostEvent([glController] {
GLControllerSupport::DisposeNative(GLController::LocalRef(
jni::GetGeckoThreadEnv(), glController));
});
mGLController->Destroy();
}
void Reattach(const GLController::LocalRef& aInstance)