| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.android_webview; | 5 package org.chromium.android_webview; |
| 6 | 6 |
| 7 import android.graphics.Canvas; | 7 import android.graphics.Canvas; |
| 8 import android.view.ViewGroup; | 8 import android.view.ViewGroup; |
| 9 | 9 |
| 10 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
| 11 import org.chromium.base.annotations.JNINamespace; | 11 import org.chromium.base.annotations.JNINamespace; |
| 12 import org.chromium.content.common.CleanupReference; |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * Manages state associated with the Android render thread and the draw functor | 15 * Manages state associated with the Android render thread and the draw functor |
| 15 * that the WebView uses to render its contents. AwGLFunctor is responsible for | 16 * that the WebView uses to render its contents. AwGLFunctor is responsible for |
| 16 * managing the lifetime of native RenderThreadManager and HardwareRenderer, | 17 * managing the lifetime of native RenderThreadManager and HardwareRenderer, |
| 17 * ensuring that they continue to exist while the functor remains attached to | 18 * ensuring that they continue to exist while the functor remains attached to |
| 18 * the render node hierarchy. | 19 * the render node hierarchy. |
| 19 */ | 20 */ |
| 20 @JNINamespace("android_webview") | 21 @JNINamespace("android_webview") |
| 21 class AwGLFunctor { | 22 class AwGLFunctor { |
| 22 private static final class DestroyRunnable implements Runnable { | 23 private static final class DestroyRunnable implements Runnable { |
| 23 private final long mNativeAwGLFunctor; | 24 private final long mNativeAwGLFunctor; |
| 24 | 25 |
| 25 private DestroyRunnable(long nativeAwGLFunctor) { | 26 private DestroyRunnable(long nativeAwGLFunctor) { |
| 26 mNativeAwGLFunctor = nativeAwGLFunctor; | 27 mNativeAwGLFunctor = nativeAwGLFunctor; |
| 27 } | 28 } |
| 28 @Override | 29 @Override |
| 29 public void run() { | 30 public void run() { |
| 30 nativeDestroy(mNativeAwGLFunctor); | 31 nativeDestroy(mNativeAwGLFunctor); |
| 31 } | 32 } |
| 32 } | 33 } |
| 33 | 34 |
| 34 private final long mNativeAwGLFunctor; | 35 private final long mNativeAwGLFunctor; |
| 35 private final DestroyRunnable mDestroyRunnable; | 36 private final DestroyRunnable mDestroyRunnable; |
| 37 private final CleanupReference mCleanupReference; |
| 36 private final AwContents.NativeGLDelegate mNativeGLDelegate; | 38 private final AwContents.NativeGLDelegate mNativeGLDelegate; |
| 37 private final ViewGroup mContainerView; | 39 private final ViewGroup mContainerView; |
| 38 private final Runnable mFunctorReleasedCallback; | 40 private final Runnable mFunctorReleasedCallback; |
| 39 | 41 |
| 40 public AwGLFunctor(AwContents.NativeGLDelegate nativeGLDelegate, ViewGroup c
ontainerView) { | 42 public AwGLFunctor(AwContents.NativeGLDelegate nativeGLDelegate, ViewGroup c
ontainerView) { |
| 41 mNativeAwGLFunctor = nativeCreate(this); | 43 mNativeAwGLFunctor = nativeCreate(this); |
| 42 mDestroyRunnable = new DestroyRunnable(mNativeAwGLFunctor); | 44 mDestroyRunnable = new DestroyRunnable(mNativeAwGLFunctor); |
| 45 mCleanupReference = new CleanupReference(mDestroyRunnable, mDestroyRunna
ble); |
| 43 mNativeGLDelegate = nativeGLDelegate; | 46 mNativeGLDelegate = nativeGLDelegate; |
| 44 mContainerView = containerView; | 47 mContainerView = containerView; |
| 45 if (mNativeGLDelegate.supportsDrawGLFunctorReleasedCallback()) { | 48 if (mNativeGLDelegate.supportsDrawGLFunctorReleasedCallback()) { |
| 46 mFunctorReleasedCallback = new Runnable() { | 49 mFunctorReleasedCallback = new Runnable() { |
| 47 @Override | 50 @Override |
| 48 public void run() { | 51 public void run() { |
| 49 // Deliberate no-op. This Runnable is holding a strong refer
ence back to the | 52 // Deliberate no-op. This Runnable is holding a strong refer
ence back to the |
| 50 // AwGLFunctor, which serves its purpose for now. | 53 // AwGLFunctor, which serves its purpose for now. |
| 51 } | 54 } |
| 52 }; | 55 }; |
| 53 } else { | 56 } else { |
| 54 mFunctorReleasedCallback = null; | 57 mFunctorReleasedCallback = null; |
| 55 } | 58 } |
| 56 } | 59 } |
| 57 | 60 |
| 58 public static long getAwDrawGLFunction() { | 61 public static long getAwDrawGLFunction() { |
| 59 return nativeGetAwDrawGLFunction(); | 62 return nativeGetAwDrawGLFunction(); |
| 60 } | 63 } |
| 61 | 64 |
| 62 public long getNativeAwGLFunctor() { | 65 public long getNativeAwGLFunctor() { |
| 63 return mNativeAwGLFunctor; | 66 return mNativeAwGLFunctor; |
| 64 } | 67 } |
| 65 | 68 |
| 66 public Runnable getDestroyRunnable() { | 69 public Object getNativeLifetimeObject() { |
| 67 return mDestroyRunnable; | 70 return mDestroyRunnable; |
| 68 } | 71 } |
| 69 | 72 |
| 70 public boolean requestDrawGLForCanvas(Canvas canvas) { | 73 public boolean requestDrawGLForCanvas(Canvas canvas) { |
| 71 return mNativeGLDelegate.requestDrawGL( | 74 return mNativeGLDelegate.requestDrawGL( |
| 72 canvas, false, mContainerView, mFunctorReleasedCallback); | 75 canvas, false, mContainerView, mFunctorReleasedCallback); |
| 73 } | 76 } |
| 74 | 77 |
| 75 @CalledByNative | 78 @CalledByNative |
| 76 private boolean requestDrawGL(boolean waitForCompletion) { | 79 private boolean requestDrawGL(boolean waitForCompletion) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 91 return nativeGetAwDrawGLViewContext(mNativeAwGLFunctor); | 94 return nativeGetAwDrawGLViewContext(mNativeAwGLFunctor); |
| 92 } | 95 } |
| 93 | 96 |
| 94 private native void nativeDeleteHardwareRenderer(long nativeAwGLFunctor); | 97 private native void nativeDeleteHardwareRenderer(long nativeAwGLFunctor); |
| 95 private native long nativeGetAwDrawGLViewContext(long nativeAwGLFunctor); | 98 private native long nativeGetAwDrawGLViewContext(long nativeAwGLFunctor); |
| 96 | 99 |
| 97 private static native long nativeGetAwDrawGLFunction(); | 100 private static native long nativeGetAwDrawGLFunction(); |
| 98 private static native void nativeDestroy(long nativeAwGLFunctor); | 101 private static native void nativeDestroy(long nativeAwGLFunctor); |
| 99 private static native long nativeCreate(AwGLFunctor javaProxy); | 102 private static native long nativeCreate(AwGLFunctor javaProxy); |
| 100 } | 103 } |
| OLD | NEW |