Commit f94c3312 authored by Bill Orr's avatar Bill Orr Committed by Commit Bot

Clean up native page onPreDrawListener when exiting VrShell

Currently the onPreDrawListener for native pages is called even after
VrShell exits. A fix is to unregister our onPreDrawListener during
VrShell shutdown.

VrShell destruction is ordered to remove VrShell from the view hierarchy,
then notify VrShell to do clean up.  Unfortunately removing VrShell
from the view hierarchy prevents cleaning up our onPreDrawListener, so
we need a new notification to clean up while still in the view
hierarchy.

The fix is to remove our OnPreDrawlistener in response to a new cleanup
method called while we are still hosted in the view.

BUG=743119

Change-Id: Ieacdfb6a08799d4347ea2b268070fd6543f6a2c7
Reviewed-on: https://chromium-review.googlesource.com/580107
Commit-Queue: Bill Orr <billorr@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488507}
parent 04a7c3fc
......@@ -64,4 +64,10 @@ public interface VrShell {
* Requests to exit VR.
*/
void requestToExitVr(@UiUnsupportedMode int reason);
/**
* Gives VrShell a chance to clean up any view-dependent state before removing
* VrShell from the view hierarchy.
*/
void onBeforeWindowDetached();
}
......@@ -1504,6 +1504,7 @@ public class VrShellDelegate
}
private void removeVrViews() {
mVrShell.onBeforeWindowDetached();
mActivity.onExitVr();
FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
decor.removeView(mVrShell.getContainer());
......
......@@ -93,6 +93,7 @@ public class VrShellImpl
private final TabModelSelectorObserver mTabModelSelectorObserver;
private final View.OnTouchListener mTouchListener;
private TabModelSelectorTabObserver mTabModelSelectorTabObserver;
private OnPreDrawListener mPredrawListener;
private long mNativeVrShell;
......@@ -311,7 +312,7 @@ public class VrShellImpl
mRenderToSurfaceLayout.setVisibility(View.VISIBLE);
// We need a pre-draw listener to invalidate the native page because scrolling usually
// doesn't trigger an onDraw call, so our texture won't get updated.
mRenderToSurfaceLayout.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
mPredrawListener = new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (mRenderToSurfaceLayout.isDirty()) {
......@@ -320,7 +321,8 @@ public class VrShellImpl
}
return true;
}
});
};
mRenderToSurfaceLayout.getViewTreeObserver().addOnPreDrawListener(mPredrawListener);
mRenderToSurfaceLayoutParent.addView(mRenderToSurfaceLayout);
addView(mRenderToSurfaceLayoutParent);
}
......@@ -554,6 +556,11 @@ public class VrShellImpl
}
}
@Override
public void onBeforeWindowDetached() {
mRenderToSurfaceLayout.getViewTreeObserver().removeOnPreDrawListener(mPredrawListener);
}
@Override
public void shutdown() {
reparentAllTabs(mActivity.getWindowAndroid());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment