diff options
| author | 2012-06-07 11:35:35 -0700 | |
|---|---|---|
| committer | 2012-06-07 13:14:57 -0700 | |
| commit | d5e2937933c67d379fa2cf9e00b349acfd38872e (patch) | |
| tree | 20a2a5d21e1fd71f2f974c41b6e1e131d9c40eb5 | |
| parent | 4c38fe369fee76b8d4fca5a7b0b8d81a96f0219f (diff) | |
Eliminate gap between finalize() and destroy()
Bug: 6569073
Only nativeDestroy and nativeStopGL need to be called on the UI thread,
so split up destroyImpl into 3 functions, and only have the native
destroy be pushed to the UI thread if necessary. Also make the work that
is delayed be static without references to the finalizing WebView to allow
it to be fully deleted immediately after finalization.
Change-Id: I4e424051e69df0bc409af95ca3f3d2b9e58a6b75
| -rw-r--r-- | core/java/android/webkit/WebViewClassic.java | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/core/java/android/webkit/WebViewClassic.java b/core/java/android/webkit/WebViewClassic.java index d1da53be517e..10c211f02d41 100644 --- a/core/java/android/webkit/WebViewClassic.java +++ b/core/java/android/webkit/WebViewClassic.java @@ -2065,31 +2065,31 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc */ @Override public void destroy() { - destroyImpl(); - } - - private void destroyImpl() { - ViewRootImpl viewRoot = mWebView.getViewRootImpl(); - if (viewRoot != null) { + if (mWebView.getViewRootImpl() != null) { Log.e(LOGTAG, "Error: WebView.destroy() called while still attached!"); } + ensureFunctorDetached(); + destroyJava(); + destroyNative(); + } + private void ensureFunctorDetached() { if (mWebView.isHardwareAccelerated()) { int drawGLFunction = nativeGetDrawGLFunction(mNativeClass); + ViewRootImpl viewRoot = mWebView.getViewRootImpl(); if (drawGLFunction != 0 && viewRoot != null) { - // functor should have been detached in onDetachedFromWindow, do - // additionally here for safety viewRoot.detachFunctor(drawGLFunction); } } + } + private void destroyJava() { mCallbackProxy.blockMessages(); clearHelpers(); if (mListBoxDialog != null) { mListBoxDialog.dismiss(); mListBoxDialog = null; } - if (mNativeClass != 0) nativeStopGL(); if (mWebViewCore != null) { // Tell WebViewCore to destroy itself synchronized (this) { @@ -2100,12 +2100,36 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc // Remove any pending messages that might not be serviced yet. mPrivateHandler.removeCallbacksAndMessages(null); } - if (mNativeClass != 0) { - nativeDestroy(); - mNativeClass = 0; + } + + private void destroyNative() { + if (mNativeClass == 0) return; + int nptr = mNativeClass; + mNativeClass = 0; + if (Thread.currentThread() == mPrivateHandler.getLooper().getThread()) { + // We are on the main thread and can safely delete + nativeDestroy(nptr); + } else { + mPrivateHandler.post(new DestroyNativeRunnable(nptr)); } } + private static class DestroyNativeRunnable implements Runnable { + + private int mNativePtr; + + public DestroyNativeRunnable(int nativePtr) { + mNativePtr = nativePtr; + } + + @Override + public void run() { + // nativeDestroy also does a stopGL() + nativeDestroy(mNativePtr); + } + + } + /** * See {@link WebView#enablePlatformNotifications()} */ @@ -4099,14 +4123,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc @Override protected void finalize() throws Throwable { try { - if (mNativeClass != 0) { - mPrivateHandler.post(new Runnable() { - @Override - public void run() { - destroy(); - } - }); - } + destroy(); } finally { super.finalize(); } @@ -5313,13 +5330,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc updateHwAccelerated(); - if (mWebView.isHardwareAccelerated()) { - int drawGLFunction = nativeGetDrawGLFunction(mNativeClass); - ViewRootImpl viewRoot = mWebView.getViewRootImpl(); - if (drawGLFunction != 0 && viewRoot != null) { - viewRoot.detachFunctor(drawGLFunction); - } - } + ensureFunctorDetached(); } @Override @@ -8507,7 +8518,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc private native void nativeCreate(int ptr, String drawableDir, boolean isHighEndGfx); private native void nativeDebugDump(); - private native void nativeDestroy(); + private static native void nativeDestroy(int ptr); private native void nativeDraw(Canvas canvas, RectF visibleRect, int color, int extra); @@ -8526,7 +8537,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc private native int nativeGetBaseLayer(int nativeInstance); private native void nativeCopyBaseContentToPicture(Picture pict); private native boolean nativeHasContent(); - private native void nativeStopGL(); + private native void nativeStopGL(int ptr); private native void nativeDiscardAllTextures(); private native void nativeTileProfilingStart(); private native float nativeTileProfilingStop(); |