From 72cf6e83b26d24af3c1b270f839911dfaddf2d46 Mon Sep 17 00:00:00 2001 From: boliu Date: Fri, 6 Feb 2015 09:12:34 -0800 Subject: [PATCH] aw: Make repeated detachGLFunctor work detachGLFunctor is called every time the webview is detached (ie when hardware acceleration is torn down and cleaned up). This can happen many times since webview can be attached and detached many times. However the implementation in the glue layer only does something on the first call. Also in general, it's a bad pattern for CleanupReference to have strong java refs. It's not necessary to call detachGLFunctor on gc; detach is enough. So move all that code out of the DestroyRunnable of the CleanupReference. This is a long standing bug since the first release of chromium webview. BUG= Review URL: https://codereview.chromium.org/872403006 Cr-Commit-Position: refs/heads/master@{#315051} --- .../android/webview/chromium/DrawGLFunctor.java | 30 ++++++++++------------ 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/android_webview/glue/java/src/com/android/webview/chromium/DrawGLFunctor.java b/android_webview/glue/java/src/com/android/webview/chromium/DrawGLFunctor.java index 34348b79a1a7..b12cb048e85e 100644 --- a/android_webview/glue/java/src/com/android/webview/chromium/DrawGLFunctor.java +++ b/android_webview/glue/java/src/com/android/webview/chromium/DrawGLFunctor.java @@ -24,10 +24,13 @@ class DrawGLFunctor { // Pointer to native side instance private CleanupReference mCleanupReference; private DestroyRunnable mDestroyRunnable; + private final long mNativeDrawGLFunctor; private WebViewDelegate mWebViewDelegate; + View mContainerView; public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) { - mDestroyRunnable = new DestroyRunnable(nativeCreateGLFunctor(viewContext), webViewDelegate); + mNativeDrawGLFunctor = nativeCreateGLFunctor(viewContext); + mDestroyRunnable = new DestroyRunnable(mNativeDrawGLFunctor); mCleanupReference = new CleanupReference(this, mDestroyRunnable); mWebViewDelegate = webViewDelegate; } @@ -39,11 +42,14 @@ class DrawGLFunctor { mCleanupReference = null; mDestroyRunnable = null; mWebViewDelegate = null; + mContainerView = null; } } public void detach() { - mDestroyRunnable.detachNativeFunctor(); + if (mWebViewDelegate != null && mContainerView != null) { + mWebViewDelegate.detachDrawGlFunctor(mContainerView, mNativeDrawGLFunctor); + } } public boolean requestDrawGL(Canvas canvas, View containerView, boolean waitForCompletion) { @@ -60,7 +66,7 @@ class DrawGLFunctor { return false; } - mDestroyRunnable.mContainerView = containerView; + mContainerView = containerView; if (canvas == null) { mWebViewDelegate.invokeDrawGlFunctor( @@ -80,29 +86,19 @@ class DrawGLFunctor { // IMPORTANT: this class must not hold any reference back to the outer DrawGLFunctor // instance, as that will defeat GC of that object. private static final class DestroyRunnable implements Runnable { - private WebViewDelegate mWebViewDelegate; - View mContainerView; - long mNativeDrawGLFunctor; - DestroyRunnable(long nativeDrawGLFunctor, WebViewDelegate webViewDelegate) { + private long mNativeDrawGLFunctor; + DestroyRunnable(long nativeDrawGLFunctor) { mNativeDrawGLFunctor = nativeDrawGLFunctor; - mWebViewDelegate = webViewDelegate; + assert mNativeDrawGLFunctor != 0; } // Called when the outer DrawGLFunctor instance has been GC'ed, i.e this is its finalizer. @Override public void run() { - detachNativeFunctor(); + assert mNativeDrawGLFunctor != 0; nativeDestroyGLFunctor(mNativeDrawGLFunctor); mNativeDrawGLFunctor = 0; } - - void detachNativeFunctor() { - if (mNativeDrawGLFunctor != 0 && mContainerView != null && mWebViewDelegate != null) { - mWebViewDelegate.detachDrawGlFunctor(mContainerView, mNativeDrawGLFunctor); - } - mContainerView = null; - mWebViewDelegate = null; - } } private static native long nativeCreateGLFunctor(long viewContext); -- 2.11.4.GIT