Commit 523d01b8 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

aw: Lazy allocate AwGLFunctor

Right now the lifetime of AwGLFunctor (and that of associated objects)
roughly matches the lifetime of AwContents. This is not necessary, and
we only need to ensure it's alive when functor is in use. This better
matches the APIthat the vulkan functor will have. It also has the up
side of converting CleanupReference usage to explicit destroy, which
is always nice.

Bug: 901554
Change-Id: Ib1126d1ddfeacc7b8c689aeb51bb897cf839b41c
Reviewed-on: https://chromium-review.googlesource.com/c/1320749Reviewed-by: default avatarTobias Sargeant <tobiasjs@chromium.org>
Reviewed-by: default avatarChris Blume <cblume@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606512}
parent c28b30e1
...@@ -22,20 +22,20 @@ class DrawGLFunctor implements AwContents.NativeDrawGLFunctor { ...@@ -22,20 +22,20 @@ class DrawGLFunctor implements AwContents.NativeDrawGLFunctor {
private static final String TAG = DrawGLFunctor.class.getSimpleName(); private static final String TAG = DrawGLFunctor.class.getSimpleName();
// Pointer to native side instance // Pointer to native side instance
private final DestroyRunnable mDestroyRunnable;
private final WebViewDelegate mWebViewDelegate; private final WebViewDelegate mWebViewDelegate;
private long mNativeDrawGLFunctor;
public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) { public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) {
mDestroyRunnable = new DestroyRunnable(nativeCreateGLFunctor(viewContext)); mNativeDrawGLFunctor = nativeCreateGLFunctor(viewContext);
mWebViewDelegate = webViewDelegate; mWebViewDelegate = webViewDelegate;
} }
@Override @Override
public void detach(View containerView) { public void detach(View containerView) {
if (mDestroyRunnable.mNativeDrawGLFunctor == 0) { if (mNativeDrawGLFunctor == 0) {
throw new RuntimeException("detach on already destroyed DrawGLFunctor"); throw new RuntimeException("detach on already destroyed DrawGLFunctor");
} }
mWebViewDelegate.detachDrawGlFunctor(containerView, mDestroyRunnable.mNativeDrawGLFunctor); mWebViewDelegate.detachDrawGlFunctor(containerView, mNativeDrawGLFunctor);
} }
private static final boolean sSupportFunctorReleasedCallback = private static final boolean sSupportFunctorReleasedCallback =
...@@ -43,24 +43,23 @@ class DrawGLFunctor implements AwContents.NativeDrawGLFunctor { ...@@ -43,24 +43,23 @@ class DrawGLFunctor implements AwContents.NativeDrawGLFunctor {
@Override @Override
public boolean requestDrawGL(Canvas canvas, Runnable releasedCallback) { public boolean requestDrawGL(Canvas canvas, Runnable releasedCallback) {
if (mDestroyRunnable.mNativeDrawGLFunctor == 0) { if (mNativeDrawGLFunctor == 0) {
throw new RuntimeException("requestDrawGL on already destroyed DrawGLFunctor"); throw new RuntimeException("requestDrawGL on already destroyed DrawGLFunctor");
} }
assert canvas != null; assert canvas != null;
if (sSupportFunctorReleasedCallback) { if (sSupportFunctorReleasedCallback) {
assert releasedCallback != null; assert releasedCallback != null;
mWebViewDelegate.callDrawGlFunction( mWebViewDelegate.callDrawGlFunction(canvas, mNativeDrawGLFunctor, releasedCallback);
canvas, mDestroyRunnable.mNativeDrawGLFunctor, releasedCallback);
} else { } else {
assert releasedCallback == null; assert releasedCallback == null;
mWebViewDelegate.callDrawGlFunction(canvas, mDestroyRunnable.mNativeDrawGLFunctor); mWebViewDelegate.callDrawGlFunction(canvas, mNativeDrawGLFunctor);
} }
return true; return true;
} }
@Override @Override
public boolean requestInvokeGL(View containerView, boolean waitForCompletion) { public boolean requestInvokeGL(View containerView, boolean waitForCompletion) {
if (mDestroyRunnable.mNativeDrawGLFunctor == 0) { if (mNativeDrawGLFunctor == 0) {
throw new RuntimeException("requestInvokeGL on already destroyed DrawGLFunctor"); throw new RuntimeException("requestInvokeGL on already destroyed DrawGLFunctor");
} }
if (!sSupportFunctorReleasedCallback if (!sSupportFunctorReleasedCallback
...@@ -69,7 +68,7 @@ class DrawGLFunctor implements AwContents.NativeDrawGLFunctor { ...@@ -69,7 +68,7 @@ class DrawGLFunctor implements AwContents.NativeDrawGLFunctor {
} }
mWebViewDelegate.invokeDrawGlFunctor( mWebViewDelegate.invokeDrawGlFunctor(
containerView, mDestroyRunnable.mNativeDrawGLFunctor, waitForCompletion); containerView, mNativeDrawGLFunctor, waitForCompletion);
return true; return true;
} }
...@@ -79,33 +78,16 @@ class DrawGLFunctor implements AwContents.NativeDrawGLFunctor { ...@@ -79,33 +78,16 @@ class DrawGLFunctor implements AwContents.NativeDrawGLFunctor {
} }
@Override @Override
public Runnable getDestroyRunnable() { public void destroy() {
return mDestroyRunnable; assert mNativeDrawGLFunctor != 0;
nativeDestroyGLFunctor(mNativeDrawGLFunctor);
mNativeDrawGLFunctor = 0;
} }
public static void setChromiumAwDrawGLFunction(long functionPointer) { public static void setChromiumAwDrawGLFunction(long functionPointer) {
nativeSetChromiumAwDrawGLFunction(functionPointer); nativeSetChromiumAwDrawGLFunction(functionPointer);
} }
// Holds the core resources of the class, everything required to correctly cleanup.
// 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 long mNativeDrawGLFunctor;
DestroyRunnable(long nativeDrawGLFunctor) {
mNativeDrawGLFunctor = nativeDrawGLFunctor;
assert mNativeDrawGLFunctor != 0;
}
// Called when the outer DrawGLFunctor instance has been GC'ed, i.e this is its finalizer.
@Override
public void run() {
assert mNativeDrawGLFunctor != 0;
nativeDestroyGLFunctor(mNativeDrawGLFunctor);
mNativeDrawGLFunctor = 0;
}
}
private static native long nativeCreateGLFunctor(long viewContext); private static native long nativeCreateGLFunctor(long viewContext);
private static native void nativeDestroyGLFunctor(long functor); private static native void nativeDestroyGLFunctor(long functor);
private static native void nativeSetChromiumAwDrawGLFunction(long functionPointer); private static native void nativeSetChromiumAwDrawGLFunction(long functionPointer);
......
...@@ -264,12 +264,10 @@ public class AwContents implements SmartClipProvider { ...@@ -264,12 +264,10 @@ public class AwContents implements SmartClipProvider {
void detach(View containerView); void detach(View containerView);
/** /**
* Get a Runnable that is used to destroy the native portion of the functor. After the * Destroy this functor instance and any native objects associated with it. No method is
* run method of this Runnable is called, no other methods should be called on the Java * called after destroy.
* object.
*/ */
Runnable getDestroyRunnable(); void destroy();
} }
/** /**
...@@ -306,11 +304,8 @@ public class AwContents implements SmartClipProvider { ...@@ -306,11 +304,8 @@ public class AwContents implements SmartClipProvider {
private long mNativeAwContents; private long mNativeAwContents;
private final AwBrowserContext mBrowserContext; private final AwBrowserContext mBrowserContext;
// mContainerView and mCurrentFunctor form a pair that needs to stay in sync.
private ViewGroup mContainerView; private ViewGroup mContainerView;
private AwGLFunctor mCurrentFunctor; private AwGLFunctor mDrawFunctor;
private AwGLFunctor mInitialFunctor;
private AwGLFunctor mFullScreenFunctor; // Only non-null when in fullscreen mode.
private final Context mContext; private final Context mContext;
private final int mAppTargetSdkVersion; private final int mAppTargetSdkVersion;
private AwViewAndroidDelegate mViewAndroidDelegate; private AwViewAndroidDelegate mViewAndroidDelegate;
...@@ -744,9 +739,8 @@ public class AwContents implements SmartClipProvider { ...@@ -744,9 +739,8 @@ public class AwContents implements SmartClipProvider {
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
if (isDestroyedOrNoOperation(NO_WARN)) return; if (isDestroyedOrNoOperation(NO_WARN)) return;
if (level >= TRIM_MEMORY_MODERATE) { if (level >= TRIM_MEMORY_MODERATE) {
mInitialFunctor.deleteHardwareRenderer(); if (mDrawFunctor != null) {
if (mFullScreenFunctor != null) { mDrawFunctor.deleteHardwareRenderer();
mFullScreenFunctor.deleteHardwareRenderer();
} }
} }
nativeTrimMemory(mNativeAwContents, level, visible); nativeTrimMemory(mNativeAwContents, level, visible);
...@@ -828,8 +822,6 @@ public class AwContents implements SmartClipProvider { ...@@ -828,8 +822,6 @@ public class AwContents implements SmartClipProvider {
mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
mInternalAccessAdapter = internalAccessAdapter; mInternalAccessAdapter = internalAccessAdapter;
mNativeDrawGLFunctorFactory = nativeDrawGLFunctorFactory; mNativeDrawGLFunctorFactory = nativeDrawGLFunctorFactory;
mInitialFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, mContainerView);
mCurrentFunctor = mInitialFunctor;
mContentsClient = contentsClient; mContentsClient = contentsClient;
mContentsClient.getCallbackHelper().setCancelCallbackPoller( mContentsClient.getCallbackHelper().setCancelCallbackPoller(
() -> AwContents.this.isDestroyedOrNoOperation(NO_WARN)); () -> AwContents.this.isDestroyedOrNoOperation(NO_WARN));
...@@ -938,13 +930,12 @@ public class AwContents implements SmartClipProvider { ...@@ -938,13 +930,12 @@ public class AwContents implements SmartClipProvider {
if (wasInitialContainerViewFocused) { if (wasInitialContainerViewFocused) {
fullScreenView.requestFocus(); fullScreenView.requestFocus();
} }
mFullScreenFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, fullScreenView);
mFullScreenTransitionsState.enterFullScreen(fullScreenView, wasInitialContainerViewFocused); mFullScreenTransitionsState.enterFullScreen(fullScreenView, wasInitialContainerViewFocused);
mAwViewMethods = new NullAwViewMethods(this, mInternalAccessAdapter, mContainerView); mAwViewMethods = new NullAwViewMethods(this, mInternalAccessAdapter, mContainerView);
// Associate this AwContents with the FullScreenView. // Associate this AwContents with the FullScreenView.
setInternalAccessAdapter(fullScreenView.getInternalAccessAdapter()); setInternalAccessAdapter(fullScreenView.getInternalAccessAdapter());
setContainerView(fullScreenView, mFullScreenFunctor); setContainerView(fullScreenView);
return fullScreenView; return fullScreenView;
} }
...@@ -985,15 +976,13 @@ public class AwContents implements SmartClipProvider { ...@@ -985,15 +976,13 @@ public class AwContents implements SmartClipProvider {
// Re-associate this AwContents with the WebView. // Re-associate this AwContents with the WebView.
setInternalAccessAdapter(mFullScreenTransitionsState.getInitialInternalAccessDelegate()); setInternalAccessAdapter(mFullScreenTransitionsState.getInitialInternalAccessDelegate());
setContainerView(initialContainerView, mInitialFunctor); setContainerView(initialContainerView);
// Return focus to the WebView. // Return focus to the WebView.
if (mFullScreenTransitionsState.wasInitialContainerViewFocused()) { if (mFullScreenTransitionsState.wasInitialContainerViewFocused()) {
mContainerView.requestFocus(); mContainerView.requestFocus();
} }
mFullScreenTransitionsState.exitFullScreen(); mFullScreenTransitionsState.exitFullScreen();
// Drop AwContents last reference to this functor. AwGLFunctor is responsible for cleanup.
mFullScreenFunctor = null;
} }
private void setInternalAccessAdapter(InternalAccessDelegate internalAccessAdapter) { private void setInternalAccessAdapter(InternalAccessDelegate internalAccessAdapter) {
...@@ -1001,15 +990,15 @@ public class AwContents implements SmartClipProvider { ...@@ -1001,15 +990,15 @@ public class AwContents implements SmartClipProvider {
mViewEventSink.setAccessDelegate(mInternalAccessAdapter); mViewEventSink.setAccessDelegate(mInternalAccessAdapter);
} }
private void setContainerView(ViewGroup newContainerView, AwGLFunctor currentFunctor) { private void setContainerView(ViewGroup newContainerView) {
// setWillNotDraw(false) is required since WebView draws it's own contents using it's // 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 // container view. If this is ever not the case we should remove this, as it removes
// Android's gatherTransparentRegion optimization for the view. // Android's gatherTransparentRegion optimization for the view.
mContainerView = newContainerView; mContainerView = newContainerView;
mCurrentFunctor = currentFunctor;
updateNativeAwGLFunctor();
mContainerView.setWillNotDraw(false); mContainerView.setWillNotDraw(false);
assert mDrawFunctor == null;
mViewAndroidDelegate.setContainerView(mContainerView); mViewAndroidDelegate.setContainerView(mContainerView);
if (mAwPdfExporter != null) { if (mAwPdfExporter != null) {
mAwPdfExporter.setContainerView(mContainerView); mAwPdfExporter.setContainerView(mContainerView);
...@@ -1118,9 +1107,18 @@ public class AwContents implements SmartClipProvider { ...@@ -1118,9 +1107,18 @@ public class AwContents implements SmartClipProvider {
} }
} }
private void setFunctor(AwGLFunctor functor) {
if (mDrawFunctor == functor) return;
AwGLFunctor oldFunctor = mDrawFunctor;
mDrawFunctor = functor;
updateNativeAwGLFunctor();
if (oldFunctor != null) oldFunctor.releasedByContents();
}
private void updateNativeAwGLFunctor() { private void updateNativeAwGLFunctor() {
nativeSetAwGLFunctor(mNativeAwContents, nativeSetAwGLFunctor(
mCurrentFunctor != null ? mCurrentFunctor.getNativeAwGLFunctor() : 0); mNativeAwContents, mDrawFunctor != null ? mDrawFunctor.getNativeAwGLFunctor() : 0);
} }
/* Common initialization routine for adopting a native AwContents instance into this /* Common initialization routine for adopting a native AwContents instance into this
...@@ -3279,6 +3277,7 @@ public class AwContents implements SmartClipProvider { ...@@ -3279,6 +3277,7 @@ public class AwContents implements SmartClipProvider {
// Only valid within software onDraw(). // Only valid within software onDraw().
private final Rect mClipBoundsTemporary = new Rect(); private final Rect mClipBoundsTemporary = new Rect();
@SuppressLint("DrawAllocation") // For new AwGLFunctor.
@Override @Override
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {
if (isDestroyedOrNoOperation(NO_WARN)) { if (isDestroyedOrNoOperation(NO_WARN)) {
...@@ -3294,6 +3293,10 @@ public class AwContents implements SmartClipProvider { ...@@ -3294,6 +3293,10 @@ public class AwContents implements SmartClipProvider {
return; return;
} }
if (canvas.isHardwareAccelerated() && mDrawFunctor == null) {
setFunctor(new AwGLFunctor(mNativeDrawGLFunctorFactory, mContainerView));
}
mScrollOffsetManager.syncScrollOffsetFromOnDraw(); mScrollOffsetManager.syncScrollOffsetFromOnDraw();
int scrollX = mContainerView.getScrollX(); int scrollX = mContainerView.getScrollX();
int scrollY = mContainerView.getScrollY(); int scrollY = mContainerView.getScrollY();
...@@ -3324,7 +3327,7 @@ public class AwContents implements SmartClipProvider { ...@@ -3324,7 +3327,7 @@ public class AwContents implements SmartClipProvider {
} }
if (did_draw && canvas.isHardwareAccelerated() if (did_draw && canvas.isHardwareAccelerated()
&& !ForceAuxiliaryBitmapRendering.sResult) { && !ForceAuxiliaryBitmapRendering.sResult) {
did_draw = mCurrentFunctor.requestDrawGL(canvas); did_draw = mDrawFunctor.requestDrawGL(canvas);
} }
if (did_draw) { if (did_draw) {
int scrollXDiff = mContainerView.getScrollX() - scrollX; int scrollXDiff = mContainerView.getScrollX() - scrollX;
...@@ -3488,7 +3491,6 @@ public class AwContents implements SmartClipProvider { ...@@ -3488,7 +3491,6 @@ public class AwContents implements SmartClipProvider {
mContainerView.getHeight()); mContainerView.getHeight());
updateHardwareAcceleratedFeaturesToggle(); updateHardwareAcceleratedFeaturesToggle();
postUpdateWebContentsVisibility(); postUpdateWebContentsVisibility();
mCurrentFunctor.onAttachedToWindow();
updateDefaultLocale(); updateDefaultLocale();
mSettings.updateAcceptLanguages(); mSettings.updateAcceptLanguages();
...@@ -3512,7 +3514,7 @@ public class AwContents implements SmartClipProvider { ...@@ -3512,7 +3514,7 @@ public class AwContents implements SmartClipProvider {
mViewEventSink.onDetachedFromWindow(); mViewEventSink.onDetachedFromWindow();
updateHardwareAcceleratedFeaturesToggle(); updateHardwareAcceleratedFeaturesToggle();
postUpdateWebContentsVisibility(); postUpdateWebContentsVisibility();
mCurrentFunctor.onDetachedFromWindow(); setFunctor(null);
if (mComponentCallbacks != null) { if (mComponentCallbacks != null) {
mContext.unregisterComponentCallbacks(mComponentCallbacks); mContext.unregisterComponentCallbacks(mComponentCallbacks);
......
...@@ -20,26 +20,7 @@ import org.chromium.base.annotations.JNINamespace; ...@@ -20,26 +20,7 @@ import org.chromium.base.annotations.JNINamespace;
*/ */
@JNINamespace("android_webview") @JNINamespace("android_webview")
public class AwGLFunctor { public class AwGLFunctor {
private static final class DestroyRunnable implements Runnable {
private final long mNativeAwGLFunctor;
private final Runnable mNativeDrawGLFunctorDestroyRunnable;
private DestroyRunnable(
long nativeAwGLFunctor, Runnable nativeDrawGLFunctorDestroyRunnable) {
mNativeAwGLFunctor = nativeAwGLFunctor;
mNativeDrawGLFunctorDestroyRunnable = nativeDrawGLFunctorDestroyRunnable;
}
@Override
public void run() {
mNativeDrawGLFunctorDestroyRunnable.run();
nativeDestroy(mNativeAwGLFunctor);
}
}
private final long mNativeAwGLFunctor; private final long mNativeAwGLFunctor;
// Same gc-life time as this, but does not reference any members like |mContainerView|.
private final Object mLifetimeObject;
private final CleanupReference mCleanupReference;
private final AwContents.NativeDrawGLFunctor mNativeDrawGLFunctor; private final AwContents.NativeDrawGLFunctor mNativeDrawGLFunctor;
private final ViewGroup mContainerView; private final ViewGroup mContainerView;
private final Runnable mFunctorReleasedCallback; private final Runnable mFunctorReleasedCallback;
...@@ -49,23 +30,19 @@ public class AwGLFunctor { ...@@ -49,23 +30,19 @@ public class AwGLFunctor {
public AwGLFunctor(AwContents.NativeDrawGLFunctorFactory nativeDrawGLFunctorFactory, public AwGLFunctor(AwContents.NativeDrawGLFunctorFactory nativeDrawGLFunctorFactory,
ViewGroup containerView) { ViewGroup containerView) {
mNativeAwGLFunctor = nativeCreate(this); mNativeAwGLFunctor = nativeCreate(this);
mNativeDrawGLFunctor = nativeDrawGLFunctorFactory.createFunctor(getAwDrawGLViewContext()); mNativeDrawGLFunctor = nativeDrawGLFunctorFactory.createFunctor(
mLifetimeObject = new Object(); nativeGetAwDrawGLViewContext(mNativeAwGLFunctor));
mCleanupReference = new CleanupReference(mLifetimeObject,
new DestroyRunnable(mNativeAwGLFunctor, mNativeDrawGLFunctor.getDestroyRunnable()));
mContainerView = containerView; mContainerView = containerView;
if (mNativeDrawGLFunctor.supportsDrawGLFunctorReleasedCallback()) { if (mNativeDrawGLFunctor.supportsDrawGLFunctorReleasedCallback()) {
mFunctorReleasedCallback = () -> removeReference(); mFunctorReleasedCallback = () -> removeReference();
} else { } else {
mFunctorReleasedCallback = null; mFunctorReleasedCallback = null;
} }
}
public void onAttachedToWindow() {
addReference(); addReference();
} }
public void onDetachedFromWindow() { public void releasedByContents() {
assert mRefCount > 0;
removeReference(); removeReference();
} }
...@@ -74,10 +51,12 @@ public class AwGLFunctor { ...@@ -74,10 +51,12 @@ public class AwGLFunctor {
} }
public long getNativeAwGLFunctor() { public long getNativeAwGLFunctor() {
assert mRefCount > 0;
return mNativeAwGLFunctor; return mNativeAwGLFunctor;
} }
public boolean requestDrawGL(Canvas canvas) { public boolean requestDrawGL(Canvas canvas) {
assert mRefCount > 0;
boolean success = mNativeDrawGLFunctor.requestDrawGL(canvas, mFunctorReleasedCallback); boolean success = mNativeDrawGLFunctor.requestDrawGL(canvas, mFunctorReleasedCallback);
if (success && mFunctorReleasedCallback != null) { if (success && mFunctorReleasedCallback != null) {
addReference(); addReference();
...@@ -90,11 +69,14 @@ public class AwGLFunctor { ...@@ -90,11 +69,14 @@ public class AwGLFunctor {
} }
private void removeReference() { private void removeReference() {
assert mRefCount > 0;
if (--mRefCount == 0) { if (--mRefCount == 0) {
// When |mRefCount| decreases to zero, the functor is neither attached to a view, nor // When |mRefCount| decreases to zero, the functor is neither attached to a view, nor
// referenced from the render tree, and so it is safe to delete the HardwareRenderer // referenced from the render tree, and so it is safe to delete the HardwareRenderer
// instance to free up resources because the current state will not be drawn again. // instance to free up resources because the current state will not be drawn again.
deleteHardwareRenderer(); nativeDeleteHardwareRenderer(mNativeAwGLFunctor);
mNativeDrawGLFunctor.destroy();
nativeDestroy(mNativeAwGLFunctor);
} }
} }
...@@ -110,13 +92,10 @@ public class AwGLFunctor { ...@@ -110,13 +92,10 @@ public class AwGLFunctor {
} }
public void deleteHardwareRenderer() { public void deleteHardwareRenderer() {
assert mRefCount > 0;
nativeDeleteHardwareRenderer(mNativeAwGLFunctor); nativeDeleteHardwareRenderer(mNativeAwGLFunctor);
} }
public long getAwDrawGLViewContext() {
return nativeGetAwDrawGLViewContext(mNativeAwGLFunctor);
}
/** /**
* Intended for test code. * Intended for test code.
* @return the number of native instances of this class. * @return the number of native instances of this class.
......
...@@ -443,22 +443,11 @@ public class AwTestContainerView extends FrameLayout { ...@@ -443,22 +443,11 @@ public class AwTestContainerView extends FrameLayout {
} }
} }
private static final class NativeDrawGLFunctorDestroyRunnable implements Runnable {
public long mContext;
NativeDrawGLFunctorDestroyRunnable(long context) {
mContext = context;
}
@Override
public void run() {
mContext = 0;
}
}
private class NativeDrawGLFunctor implements AwContents.NativeDrawGLFunctor { private class NativeDrawGLFunctor implements AwContents.NativeDrawGLFunctor {
private NativeDrawGLFunctorDestroyRunnable mDestroyRunnable; private long mContext;
NativeDrawGLFunctor(long context) { NativeDrawGLFunctor(long context) {
mDestroyRunnable = new NativeDrawGLFunctorDestroyRunnable(context); mContext = context;
} }
@Override @Override
...@@ -470,14 +459,14 @@ public class AwTestContainerView extends FrameLayout { ...@@ -470,14 +459,14 @@ public class AwTestContainerView extends FrameLayout {
public boolean requestDrawGL(Canvas canvas, Runnable releasedRunnable) { public boolean requestDrawGL(Canvas canvas, Runnable releasedRunnable) {
assert releasedRunnable == null; assert releasedRunnable == null;
if (!isBackedByHardwareView()) return false; if (!isBackedByHardwareView()) return false;
mHardwareView.requestRender(mDestroyRunnable.mContext, canvas, false); mHardwareView.requestRender(mContext, canvas, false);
return true; return true;
} }
@Override @Override
public boolean requestInvokeGL(View containerView, boolean waitForCompletion) { public boolean requestInvokeGL(View containerView, boolean waitForCompletion) {
if (!isBackedByHardwareView()) return false; if (!isBackedByHardwareView()) return false;
mHardwareView.requestRender(mDestroyRunnable.mContext, null, waitForCompletion); mHardwareView.requestRender(mContext, null, waitForCompletion);
return true; return true;
} }
...@@ -487,8 +476,8 @@ public class AwTestContainerView extends FrameLayout { ...@@ -487,8 +476,8 @@ public class AwTestContainerView extends FrameLayout {
} }
@Override @Override
public Runnable getDestroyRunnable() { public void destroy() {
return mDestroyRunnable; mContext = 0;
} }
} }
......
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