Chromium Code Reviews| Index: android_webview/java/src/org/chromium/android_webview/AwContents.java |
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java |
| index 164f6dbe612b52972f739ad6a050fdfcdbf6d3eb..be804cda178b141c33c0769a5ac79b65e2f27a83 100644 |
| --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java |
| +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java |
| @@ -256,8 +256,11 @@ public class AwContents implements SmartClipProvider, |
| private long mNativeAwContents; |
| private final AwBrowserContext mBrowserContext; |
| + // mContainerView and mCurrentFunctor form a pair that needs to stay in sync. |
| private ViewGroup mContainerView; |
| - private AwGLFunctor mAwGLFunctor; |
| + private AwGLFunctor mCurrentFunctor; |
| + private AwGLFunctor mInitialFunctor; |
| + private AwGLFunctor mFullScreenFunctor; // Only non-null when in fullscreen mode. |
| private final Context mContext; |
| private final int mAppTargetSdkVersion; |
| private ContentViewCore mContentViewCore; |
| @@ -351,19 +354,18 @@ public class AwContents implements SmartClipProvider, |
| private static String sCurrentLocale = ""; |
| - private static final class DestroyRunnable implements Runnable { |
| + private static final class AwContentsDestroyRunnable implements Runnable { |
| private final long mNativeAwContents; |
| // Hold onto a reference to the window (via its wrapper), so that it is not destroyed |
| // until we are done here. |
| private final WindowAndroidWrapper mWindowAndroid; |
| - private final Object mAwGLFunctorNativeLifetimeObject; |
| - private DestroyRunnable(long nativeAwContents, WindowAndroidWrapper windowAndroid, |
| - AwGLFunctor awGLFunctor) { |
| + private AwContentsDestroyRunnable( |
| + long nativeAwContents, WindowAndroidWrapper windowAndroid) { |
| mNativeAwContents = nativeAwContents; |
| mWindowAndroid = windowAndroid; |
| - mAwGLFunctorNativeLifetimeObject = awGLFunctor.getNativeLifetimeObject(); |
| } |
| + |
| @Override |
| public void run() { |
| nativeDestroy(mNativeAwContents); |
| @@ -427,6 +429,7 @@ public class AwContents implements SmartClipProvider, |
| // Reference to the active mNativeAwContents pointer while it is active use |
| // (ie before it is destroyed). |
| private CleanupReference mCleanupReference; |
| + private AwContentsDestroyRunnable mAwContentsDestroyRunnable; |
|
boliu
2016/05/10 15:18:20
again, don't need this anymore
Tobias Sargeant
2016/05/13 13:23:57
Removed.
|
| //-------------------------------------------------------------------------------------------- |
| private class IoThreadClientImpl extends AwContentsIoThreadClient { |
| @@ -679,7 +682,10 @@ public class AwContents implements SmartClipProvider, |
| @Override |
| public void run() { |
| if (level >= TRIM_MEMORY_MODERATE) { |
| - mAwGLFunctor.deleteHardwareRenderer(); |
| + mInitialFunctor.deleteHardwareRenderer(); |
| + if (mFullScreenFunctor != null) { |
| + mFullScreenFunctor.deleteHardwareRenderer(); |
| + } |
| } |
| nativeTrimMemory(mNativeAwContents, level, visible); |
| } |
| @@ -743,6 +749,8 @@ public class AwContents implements SmartClipProvider, |
| mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| mInternalAccessAdapter = internalAccessAdapter; |
| mNativeDrawGLFunctorFactory = nativeDrawGLFunctorFactory; |
| + mInitialFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, mContainerView); |
| + mCurrentFunctor = mInitialFunctor; |
| mContentsClient = contentsClient; |
| mAwViewMethods = new AwViewMethodsImpl(); |
| mFullScreenTransitionsState = new FullScreenTransitionsState( |
| @@ -838,12 +846,13 @@ public class AwContents implements SmartClipProvider, |
| if (wasInitialContainerViewFocused) { |
| fullScreenView.requestFocus(); |
| } |
| + mFullScreenFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, fullScreenView); |
| mFullScreenTransitionsState.enterFullScreen(fullScreenView, wasInitialContainerViewFocused); |
| mAwViewMethods = new NullAwViewMethods(this, mInternalAccessAdapter, mContainerView); |
| // Associate this AwContents with the FullScreenView. |
| setInternalAccessAdapter(fullScreenView.getInternalAccessAdapter()); |
| - setContainerView(fullScreenView); |
| + setContainerView(fullScreenView, mFullScreenFunctor); |
| return fullScreenView; |
| } |
| @@ -884,13 +893,15 @@ public class AwContents implements SmartClipProvider, |
| // Re-associate this AwContents with the WebView. |
| setInternalAccessAdapter(mFullScreenTransitionsState.getInitialInternalAccessDelegate()); |
| - setContainerView(initialContainerView); |
| + setContainerView(initialContainerView, mInitialFunctor); |
| // Return focus to the WebView. |
| if (mFullScreenTransitionsState.wasInitialContainerViewFocused()) { |
| mContainerView.requestFocus(); |
| } |
| mFullScreenTransitionsState.exitFullScreen(); |
| + // Drop AwContents last reference to this functor. AwGLFunctor is responsible for cleanup. |
| + mFullScreenFunctor = null; |
| } |
| private void setInternalAccessAdapter(InternalAccessDelegate internalAccessAdapter) { |
| @@ -898,11 +909,13 @@ public class AwContents implements SmartClipProvider, |
| mContentViewCore.setContainerViewInternals(mInternalAccessAdapter); |
| } |
| - private void setContainerView(ViewGroup newContainerView) { |
| + private void setContainerView(ViewGroup newContainerView, AwGLFunctor currentFunctor) { |
| // setWillNotDraw(false) is required since WebView draws it's own contents using it's |
| // container view. If this is ever not the case we should remove this, as it removes |
| // Android's gatherTransparentRegion optimization for the view. |
| mContainerView = newContainerView; |
| + mCurrentFunctor = currentFunctor; |
| + updateNativeAwGLFunctor(); |
| mContainerView.setWillNotDraw(false); |
| mContentViewCore.setContainerView(mContainerView); |
| @@ -994,6 +1007,11 @@ public class AwContents implements SmartClipProvider, |
| } |
| } |
| + private void updateNativeAwGLFunctor() { |
| + nativeSetAwGLFunctor(mNativeAwContents, |
| + mCurrentFunctor != null ? mCurrentFunctor.getNativeAwGLFunctor() : 0); |
| + } |
| + |
| /* Common initialization routine for adopting a native AwContents instance into this |
| * java instance. |
| * |
| @@ -1011,6 +1029,8 @@ public class AwContents implements SmartClipProvider, |
| assert mNativeAwContents == 0 && mCleanupReference == null && mContentViewCore == null; |
| mNativeAwContents = newAwContentsPtr; |
| + nativeSetAwGLFunctor(mNativeAwContents, mInitialFunctor.getNativeAwGLFunctor()); |
| + updateNativeAwGLFunctor(); |
| // TODO(joth): when the native and java counterparts of AwBrowserContext are hooked up to |
| // each other, we should update |mBrowserContext| according to the newly received native |
| // WebContent's browser context. |
| @@ -1021,8 +1041,6 @@ public class AwContents implements SmartClipProvider, |
| mContentViewCore = createAndInitializeContentViewCore(mContainerView, mContext, |
| mInternalAccessAdapter, webContents, new AwGestureStateListener(), |
| mContentViewClient, mZoomControls, mWindowAndroid.getWindowAndroid()); |
| - mAwGLFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, mContainerView); |
| - nativeSetAwGLFunctor(mNativeAwContents, mAwGLFunctor.getNativeAwGLFunctor()); |
| nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mContentsClientBridge, |
| mIoThreadClient, mInterceptNavigationDelegate); |
| mWebContents = mContentViewCore.getWebContents(); |
| @@ -1034,8 +1052,9 @@ public class AwContents implements SmartClipProvider, |
| // The native side object has been bound to this java instance, so now is the time to |
| // bind all the native->java relationships. |
| - mCleanupReference = new CleanupReference( |
| - this, new DestroyRunnable(mNativeAwContents, mWindowAndroid, mAwGLFunctor)); |
| + mAwContentsDestroyRunnable = |
| + new AwContentsDestroyRunnable(mNativeAwContents, mWindowAndroid); |
| + mCleanupReference = new CleanupReference(this, mAwContentsDestroyRunnable); |
| } |
| private void installWebContentsObserver() { |
| @@ -1141,7 +1160,6 @@ public class AwContents implements SmartClipProvider, |
| // hardware resources. |
| if (mIsAttachedToWindow) { |
| Log.w(TAG, "WebView.destroy() called while WebView is still attached to window."); |
| - mAwGLFunctor.deleteHardwareRenderer(); |
| nativeOnDetachedFromWindow(mNativeAwContents); |
| } |
| mIsDestroyed = true; |
| @@ -1269,13 +1287,6 @@ public class AwContents implements SmartClipProvider, |
| return nativeGetNativeInstanceCount(); |
| } |
| - public long getAwDrawGLViewContext() { |
| - // Only called during early construction, so client should not have had a chance to |
| - // call destroy yet. |
| - assert !isDestroyed(NO_WARN); |
| - return mAwGLFunctor.getAwDrawGLViewContext(); |
| - } |
| - |
| // This is only to avoid heap allocations inside getGlobalVisibleRect. It should treated |
| // as a local variable in the function and not used anywhere else. |
| private static final Rect sLocalGlobalVisibleRect = new Rect(); |
| @@ -2966,7 +2977,7 @@ public class AwContents implements SmartClipProvider, |
| canvas.isHardwareAccelerated(), scrollX, scrollY, globalVisibleRect.left, |
| globalVisibleRect.top, globalVisibleRect.right, globalVisibleRect.bottom); |
| if (did_draw && canvas.isHardwareAccelerated() && !FORCE_AUXILIARY_BITMAP_RENDERING) { |
| - did_draw = mAwGLFunctor.requestDrawGLForCanvas(canvas); |
| + did_draw = mCurrentFunctor.requestDrawGL(canvas); |
| } |
| if (did_draw) { |
| int scrollXDiff = mContainerView.getScrollX() - scrollX; |
| @@ -3134,7 +3145,6 @@ public class AwContents implements SmartClipProvider, |
| } |
| mIsAttachedToWindow = false; |
| hideAutofillPopup(); |
| - mAwGLFunctor.deleteHardwareRenderer(); |
| nativeOnDetachedFromWindow(mNativeAwContents); |
| mContentViewCore.onDetachedFromWindow(); |