Bug 1236654 - Properly shut down GLController on nsWindow closing; r=snorp
authorJim Chen <nchen@mozilla.com>
Wed, 06 Jan 2016 21:33:18 -0500
changeset 278910 4b8f5864223f3bddb6d998bb4275ee17312ffbbc
parent 278909 a7af5278a65735cbb9982a723c39889fccf1c367
child 278911 d0a231612fd057dfc86c21da07434d459eb0ce2d
push id29860
push usercbook@mozilla.com
push dateThu, 07 Jan 2016 10:51:20 +0000
treeherdermozilla-central@e0bcd16e1d4b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1236654
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
mobile/android/base/java/org/mozilla/gecko/gfx/GLController.java
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
widget/android/nsWindow.cpp
--- a/mobile/android/base/java/org/mozilla/gecko/gfx/GLController.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gfx/GLController.java
@@ -288,16 +288,30 @@ public class GLController extends JNIObj
     }
 
     /* package */ void invalidateAndScheduleComposite() {
         if (mCompositorCreated) {
             syncInvalidateAndScheduleComposite();
         }
     }
 
+    @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;
 
         GLControllerException(String e) {
             super(e);
         }
     }
 }
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -1248,16 +1248,24 @@ constexpr char GLController::CreateCompo
 constexpr char GLController::CreateEGLSurface_t::name[];
 constexpr char GLController::CreateEGLSurface_t::signature[];
 
 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[];
 
 constexpr char GLController::PauseCompositor_t::name[];
 constexpr char GLController::PauseCompositor_t::signature[];
 
 constexpr char GLController::SetLayerClient_t::name[];
 constexpr char GLController::SetLayerClient_t::signature[];
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -3380,16 +3380,33 @@ public:
         static const bool isMultithreaded = true;
         static const mozilla::jni::ExceptionMode exceptionMode =
                 mozilla::jni::ExceptionMode::ABORT;
     };
 
     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;
         typedef void ReturnType;
         typedef void SetterType;
         typedef mozilla::jni::Args<> Args;
         static constexpr char name[] = "disposeNative";
         static constexpr char signature[] =
                 "()V";
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -465,21 +465,17 @@ public:
         , mGLController(aInstance)
         , mCompositorPaused(true)
     {
         Reattach(aInstance);
     }
 
     ~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)
     {
         Base::AttachNative(aInstance, this);
     }
 
     const GeckoLayerClient::Ref& GetLayerClient() const