Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(690)

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwContents.java

Issue 1844343005: WIP - Control the lifetime of RenderThreadManager from Java. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 657f1f81078f37d1e287cf283edd36d3969ee06c..b9bc1172ad305d7c323033d7d0f87b24d9419a0b 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -4,6 +4,8 @@
package org.chromium.android_webview;
+import static android.content.ComponentCallbacks2.TRIM_MEMORY_MODERATE;
boliu 2016/04/07 18:14:03 Do you need this? Code that uses this is inside a
Tobias Sargeant 2016/04/07 21:07:35 Removed.
+
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ComponentCallbacks2;
@@ -220,6 +222,7 @@ public class AwContents implements SmartClipProvider,
private long mNativeAwContents;
private final AwBrowserContext mBrowserContext;
private ViewGroup mContainerView;
+ private AwGLFunctor mAwGLFunctor;
private final Context mContext;
private final int mAppTargetSdkVersion;
private ContentViewCore mContentViewCore;
@@ -318,10 +321,13 @@ public class AwContents implements SmartClipProvider,
// 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 AwGLFunctor mAwGLFunctor;
- private DestroyRunnable(long nativeAwContents, WindowAndroidWrapper windowAndroid) {
+ private DestroyRunnable(long nativeAwContents, WindowAndroidWrapper windowAndroid,
+ AwGLFunctor awGLFunctor) {
mNativeAwContents = nativeAwContents;
mWindowAndroid = windowAndroid;
+ mAwGLFunctor = awGLFunctor;
}
@Override
public void run() {
@@ -637,6 +643,9 @@ public class AwContents implements SmartClipProvider,
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
+ if (level >= TRIM_MEMORY_MODERATE) {
+ mAwGLFunctor.deleteHardwareRenderer();
+ }
nativeTrimMemory(mNativeAwContents, level, visible);
}
});
@@ -967,6 +976,9 @@ public class AwContents implements SmartClipProvider,
mContentViewCore = createAndInitializeContentViewCore(mContainerView, mContext,
mInternalAccessAdapter, webContents, new AwGestureStateListener(),
mContentViewClient, mZoomControls, mWindowAndroid.getWindowAndroid());
+ mAwGLFunctor = new AwGLFunctor(mNativeGLDelegate);
+ mAwGLFunctor.setAwContents(mIsAttachedToWindow ? this : null);
+ nativeSetAwGLFunctor(mNativeAwContents, mAwGLFunctor.getNativeAwGLFunctor());
nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mContentsClientBridge,
mIoThreadClient, mInterceptNavigationDelegate);
mWebContents = mContentViewCore.getWebContents();
@@ -978,8 +990,8 @@ 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));
+ mCleanupReference = new CleanupReference(
+ this, new DestroyRunnable(mNativeAwContents, mWindowAndroid, mAwGLFunctor));
}
private void installWebContentsObserver() {
@@ -1113,6 +1125,8 @@ public class AwContents implements SmartClipProvider,
mCleanupReference.cleanupNow();
mCleanupReference = null;
+ mAwGLFunctor.destroy();
+ mAwGLFunctor = null;
}
assert mContentViewCore == null;
@@ -1183,7 +1197,7 @@ public class AwContents implements SmartClipProvider,
}
public static long getAwDrawGLFunction() {
- return nativeGetAwDrawGLFunction();
+ return AwGLFunctor.getAwDrawGLFunction();
}
public static void setShouldDownloadFavicons() {
@@ -1216,10 +1230,7 @@ public class AwContents implements SmartClipProvider,
// Only called during early construction, so client should not have had a chance to
// call destroy yet.
assert !isDestroyed(NO_WARN);
-
- // Using the native pointer as the returned viewContext. This is matched by the
- // reinterpret_cast back to BrowserViewRenderer pointer in the native DrawGLFunction.
- return nativeGetAwDrawGLViewContext(mNativeAwContents);
+ return mAwGLFunctor.getAwDrawGLViewContext();
}
// This is only to avoid heap allocations inside getGlobalVisibleRect. It should treated
@@ -2694,8 +2705,7 @@ public class AwContents implements SmartClipProvider,
mPossiblyStaleHitTestData.imgSrc = imgSrc;
}
- @CalledByNative
- private boolean requestDrawGL(boolean waitForCompletion) {
+ boolean requestDrawGL(boolean waitForCompletion) {
boliu 2016/04/07 18:14:03 hmm, is it ok to set/unset mNativeGLDelegate + con
return mNativeGLDelegate.requestDrawGL(null, waitForCompletion, mContainerView);
}
@@ -2710,8 +2720,7 @@ public class AwContents implements SmartClipProvider,
// Call postInvalidateOnAnimation for invalidations. This is only used to synchronize
// draw functor destruction.
- @CalledByNative
- private void detachFunctorFromView() {
+ void detachFunctorFromView() {
mNativeGLDelegate.detachGLFunctor();
mContainerView.invalidate();
}
@@ -3070,6 +3079,7 @@ public class AwContents implements SmartClipProvider,
mContentViewCore.onAttachedToWindow();
nativeOnAttachedToWindow(mNativeAwContents, mContainerView.getWidth(),
mContainerView.getHeight());
+ mAwGLFunctor.setAwContents(AwContents.this);
updateHardwareAcceleratedFeaturesToggle();
postUpdateContentViewCoreVisibility();
@@ -3090,6 +3100,8 @@ public class AwContents implements SmartClipProvider,
}
mIsAttachedToWindow = false;
hideAutofillPopup();
+ mAwGLFunctor.deleteHardwareRenderer();
+ mAwGLFunctor.setAwContents(null);
nativeOnDetachedFromWindow(mNativeAwContents);
mContentViewCore.onDetachedFromWindow();
@@ -3222,7 +3234,6 @@ public class AwContents implements SmartClipProvider,
boolean forceAuxiliaryBitmapRendering);
private static native void nativeSetAwDrawSWFunctionTable(long functionTablePointer);
private static native void nativeSetAwDrawGLFunctionTable(long functionTablePointer);
- private static native long nativeGetAwDrawGLFunction();
private static native int nativeGetNativeInstanceCount();
private static native void nativeSetShouldDownloadFavicons();
private static native void nativeSetLocale(String locale);
@@ -3233,6 +3244,7 @@ public class AwContents implements SmartClipProvider,
AwContentsIoThreadClient ioThreadClient,
InterceptNavigationDelegate navigationInterceptionDelegate);
private native WebContents nativeGetWebContents(long nativeAwContents);
+ private native void nativeSetAwGLFunctor(long nativeAwContents, long nativeAwGLFunctor);
private native void nativeDocumentHasImages(long nativeAwContents, Message message);
private native void nativeGenerateMHTML(
@@ -3278,7 +3290,6 @@ public class AwContents implements SmartClipProvider,
private native void nativeFocusFirstNode(long nativeAwContents);
private native void nativeSetBackgroundColor(long nativeAwContents, int color);
- private native long nativeGetAwDrawGLViewContext(long nativeAwContents);
private native long nativeCapturePicture(long nativeAwContents, int width, int height);
private native void nativeEnableOnNewPicture(long nativeAwContents, boolean enabled);
private native void nativeInsertVisualStateCallback(

Powered by Google App Engine
This is Rietveld 408576698