Bug 1263808 - Guard against premature LayerView destruction. r=rbarker, a=ritu
authorJim Chen <nchen@mozilla.com>
Mon, 15 Aug 2016 14:05:00 -0400
changeset 347675 e1604afddd41b5757168a4fe1c9cdaa1ff7e8454
parent 347674 e6d0063c10d6ffcf56e2d1ae7ffb16116c845819
child 347676 0ccf48273f8e8a882a9776b467a6b3c6d6dc5bd0
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker, ritu
bugs1263808
milestone50.0a2
Bug 1263808 - Guard against premature LayerView destruction. r=rbarker, a=ritu It's possible for LayerView to be destroyed before it's finished initializing on the Gecko thread. In that case, we should not continue with normal destruction of NPZC. Checking isGeckoReady() in GeckoLayerClient accomplishes that. Also, guard against a case where LayerView.onSizeChanged is called after LayerView destruction and results in a NPE from mCompositor being null.
mobile/android/base/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
mobile/android/base/java/org/mozilla/gecko/gfx/NativePanZoomController.java
mobile/android/base/java/org/mozilla/gecko/gfx/PanZoomTarget.java
--- a/mobile/android/base/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
@@ -145,21 +145,22 @@ class GeckoLayerClient implements LayerV
         mView.setListener(this);
         mContentDocumentIsDisplayed = true;
     }
 
     public void setOverscrollHandler(final Overscroll listener) {
         mPanZoomController.setOverscrollHandler(listener);
     }
 
-    /** Attaches to root layer so that Gecko appears. */
-    /* package */ boolean isGeckoReady() {
+    @Override // PanZoomTarget
+    public boolean isGeckoReady() {
         return mGeckoIsReady;
     }
 
+    /** Attaches to root layer so that Gecko appears. */
     @WrapForJNI
     private void onGeckoReady() {
         mGeckoIsReady = true;
 
         mRootLayer = new VirtualLayer(new IntSize(mView.getWidth(), mView.getHeight()));
         mLayerRenderer = mView.getRenderer();
 
         sendResizeEventIfNecessary(true, null);
@@ -278,18 +279,21 @@ class GeckoLayerClient implements LayerV
             Log.d(LOGTAG, "Screen-size changed to " + mScreenSize);
         }
 
         if (windowSizeChanged) {
             Log.d(LOGTAG, "Window-size changed to " + mWindowSize);
         }
 
         if (mView != null) {
-            mView.getGLController().onSizeChanged(mWindowSize.width, mWindowSize.height,
-                                                  mScreenSize.width, mScreenSize.height);
+            final GLController glController = mView.getGLController();
+            if (glController != null) {
+                glController.onSizeChanged(mWindowSize.width, mWindowSize.height,
+                                           mScreenSize.width, mScreenSize.height);
+            }
         }
 
         String json = "";
         try {
             if (scrollChange != null) {
                 int id = ++sPaintSyncId;
                 if (id == 0) {
                     // never use 0 as that is the default value for "this is not
--- a/mobile/android/base/java/org/mozilla/gecko/gfx/NativePanZoomController.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gfx/NativePanZoomController.java
@@ -240,17 +240,17 @@ class NativePanZoomController extends JN
     public boolean getRedrawHint()
     {
         // FIXME implement this
         return true;
     }
 
     @Override @WrapForJNI(allowMultithread = true) // PanZoomController
     public void destroy() {
-        if (mDestroyed) {
+        if (mDestroyed || !mTarget.isGeckoReady()) {
             return;
         }
         mDestroyed = true;
         disposeNative();
     }
 
     @Override @WrapForJNI // JNIObject
     protected native void disposeNative();
--- a/mobile/android/base/java/org/mozilla/gecko/gfx/PanZoomTarget.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gfx/PanZoomTarget.java
@@ -18,16 +18,17 @@ public interface PanZoomTarget {
 
     public void setAnimationTarget(ImmutableViewportMetrics viewport);
     public void setViewportMetrics(ImmutableViewportMetrics viewport);
     public void scrollBy(float dx, float dy);
     public void panZoomStopped();
     /** This triggers an (asynchronous) viewport update/redraw. */
     public void forceRedraw(DisplayPortMetrics displayPort);
 
+    public boolean isGeckoReady();
     public boolean post(Runnable action);
     public void postRenderTask(RenderTask task);
     public void removeRenderTask(RenderTask task);
     public Object getLock();
     public PointF convertViewPointToLayerPoint(PointF viewPoint);
     public Matrix getMatrixForLayerRectToViewRect();
     public void setScrollingRootContent(boolean isRootContent);
 }