Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 com.android.webview.chromium; | 5 package com.android.webview.chromium; |
| 6 | 6 |
| 7 import android.graphics.Canvas; | 7 import android.graphics.Canvas; |
| 8 import android.os.Build; | 8 import android.os.Build; |
| 9 import android.view.View; | 9 import android.view.View; |
| 10 | 10 |
| 11 import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; | 11 import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; |
| 12 | 12 |
| 13 import org.chromium.android_webview.AwContents; | 13 import org.chromium.android_webview.AwContents; |
| 14 import org.chromium.content.common.CleanupReference; | |
| 15 | 14 |
| 16 /** | 15 /** |
| 17 * Simple Java abstraction and wrapper for the native DrawGLFunctor flow. | 16 * Simple Java abstraction and wrapper for the native DrawGLFunctor flow. |
| 18 * An instance of this class can be constructed, bound to a single view context (i.e. AwContennts) | 17 * An instance of this class can be constructed, bound to a single view context (i.e. AwContennts) |
| 19 * and then drawn and detached from the view tree any number of times (using req uestDrawGL and | 18 * and then drawn and detached from the view tree any number of times (using req uestDrawGL and |
| 20 * detach respectively). | 19 * detach respectively). |
| 21 */ | 20 */ |
| 22 class DrawGLFunctor implements AwContents.NativeDrawGLFunctor { | 21 class DrawGLFunctor implements AwContents.NativeDrawGLFunctor { |
| 23 private static final String TAG = DrawGLFunctor.class.getSimpleName(); | 22 private static final String TAG = DrawGLFunctor.class.getSimpleName(); |
| 24 | 23 |
| 25 // Pointer to native side instance | 24 // Pointer to native side instance |
| 26 private final CleanupReference mCleanupReference; | |
| 27 private final DestroyRunnable mDestroyRunnable; | 25 private final DestroyRunnable mDestroyRunnable; |
| 28 private final WebViewDelegate mWebViewDelegate; | 26 private final WebViewDelegate mWebViewDelegate; |
| 29 | 27 |
| 30 public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) { | 28 public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) { |
| 31 mDestroyRunnable = new DestroyRunnable(nativeCreateGLFunctor(viewContext )); | 29 mDestroyRunnable = new DestroyRunnable(nativeCreateGLFunctor(viewContext )); |
| 32 mCleanupReference = new CleanupReference(this, mDestroyRunnable); | |
| 33 mWebViewDelegate = webViewDelegate; | 30 mWebViewDelegate = webViewDelegate; |
| 34 } | 31 } |
| 35 | 32 |
| 36 @Override | 33 @Override |
| 37 public void detach(View containerView) { | 34 public void detach(View containerView) { |
| 38 mWebViewDelegate.detachDrawGlFunctor(containerView, mDestroyRunnable.mNa tiveDrawGLFunctor); | 35 mWebViewDelegate.detachDrawGlFunctor(containerView, mDestroyRunnable.mNa tiveDrawGLFunctor); |
| 39 } | 36 } |
| 40 | 37 |
| 41 private static final boolean sSupportFunctorReleasedCallback = | 38 private static final boolean sSupportFunctorReleasedCallback = |
| 42 (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) || "N".equals(Build. VERSION.CODENAME); | 39 (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) || "N".equals(Build. VERSION.CODENAME); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 65 mWebViewDelegate.invokeDrawGlFunctor( | 62 mWebViewDelegate.invokeDrawGlFunctor( |
| 66 containerView, mDestroyRunnable.mNativeDrawGLFunctor, waitForCom pletion); | 63 containerView, mDestroyRunnable.mNativeDrawGLFunctor, waitForCom pletion); |
| 67 return true; | 64 return true; |
| 68 } | 65 } |
| 69 | 66 |
| 70 @Override | 67 @Override |
| 71 public boolean supportsDrawGLFunctorReleasedCallback() { | 68 public boolean supportsDrawGLFunctorReleasedCallback() { |
| 72 return sSupportFunctorReleasedCallback; | 69 return sSupportFunctorReleasedCallback; |
| 73 } | 70 } |
| 74 | 71 |
| 72 @Override | |
| 73 public Runnable getDestroyRunnable() { | |
| 74 return mDestroyRunnable; | |
|
boliu
2016/04/27 17:08:46
Assert everywhere mNativeDrawGLFunctor is used tha
| |
| 75 } | |
| 76 | |
| 75 public static void setChromiumAwDrawGLFunction(long functionPointer) { | 77 public static void setChromiumAwDrawGLFunction(long functionPointer) { |
| 76 nativeSetChromiumAwDrawGLFunction(functionPointer); | 78 nativeSetChromiumAwDrawGLFunction(functionPointer); |
| 77 } | 79 } |
| 78 | 80 |
| 79 // Holds the core resources of the class, everything required to correctly c leanup. | 81 // Holds the core resources of the class, everything required to correctly c leanup. |
| 80 // IMPORTANT: this class must not hold any reference back to the outer DrawG LFunctor | 82 // IMPORTANT: this class must not hold any reference back to the outer DrawG LFunctor |
| 81 // instance, as that will defeat GC of that object. | 83 // instance, as that will defeat GC of that object. |
| 82 private static final class DestroyRunnable implements Runnable { | 84 private static final class DestroyRunnable implements Runnable { |
| 83 private long mNativeDrawGLFunctor; | 85 private long mNativeDrawGLFunctor; |
| 84 DestroyRunnable(long nativeDrawGLFunctor) { | 86 DestroyRunnable(long nativeDrawGLFunctor) { |
| 85 mNativeDrawGLFunctor = nativeDrawGLFunctor; | 87 mNativeDrawGLFunctor = nativeDrawGLFunctor; |
| 86 assert mNativeDrawGLFunctor != 0; | 88 assert mNativeDrawGLFunctor != 0; |
| 87 } | 89 } |
| 88 | 90 |
| 89 // Called when the outer DrawGLFunctor instance has been GC'ed, i.e this is its finalizer. | 91 // Called when the outer DrawGLFunctor instance has been GC'ed, i.e this is its finalizer. |
| 90 @Override | 92 @Override |
| 91 public void run() { | 93 public void run() { |
| 92 assert mNativeDrawGLFunctor != 0; | 94 assert mNativeDrawGLFunctor != 0; |
| 93 nativeDestroyGLFunctor(mNativeDrawGLFunctor); | 95 nativeDestroyGLFunctor(mNativeDrawGLFunctor); |
| 94 mNativeDrawGLFunctor = 0; | 96 mNativeDrawGLFunctor = 0; |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 | 99 |
| 98 private static native long nativeCreateGLFunctor(long viewContext); | 100 private static native long nativeCreateGLFunctor(long viewContext); |
| 99 private static native void nativeDestroyGLFunctor(long functor); | 101 private static native void nativeDestroyGLFunctor(long functor); |
| 100 private static native void nativeSetChromiumAwDrawGLFunction(long functionPo inter); | 102 private static native void nativeSetChromiumAwDrawGLFunction(long functionPo inter); |
| 101 } | 103 } |
| OLD | NEW |