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.content.common.CleanupReference; | 14 import org.chromium.content.common.CleanupReference; |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * Simple Java abstraction and wrapper for the native DrawGLFunctor flow. | 17 * Simple Java abstraction and wrapper for the native DrawGLFunctor flow. |
| 17 * An instance of this class can be constructed, bound to a single view context (i.e. AwContennts) | 18 * An instance of this class can be constructed, bound to a single view context (i.e. AwContennts) |
| 18 * and then drawn and detached from the view tree any number of times (using req uestDrawGL and | 19 * and then drawn and detached from the view tree any number of times (using req uestDrawGL and |
| 19 * detach respectively). | 20 * detach respectively). |
| 20 */ | 21 */ |
| 21 class DrawGLFunctor { | 22 class DrawGLFunctor implements AwContents.NativeDrawGLFunctor { |
| 22 private static final String TAG = DrawGLFunctor.class.getSimpleName(); | 23 private static final String TAG = DrawGLFunctor.class.getSimpleName(); |
| 23 | 24 |
| 24 // Pointer to native side instance | 25 // Pointer to native side instance |
| 25 private CleanupReference mCleanupReference; | 26 private final CleanupReference mCleanupReference; |
| 26 private DestroyRunnable mDestroyRunnable; | 27 private final DestroyRunnable mDestroyRunnable; |
| 27 private final long mNativeDrawGLFunctor; | 28 private final long mNativeDrawGLFunctor; |
|
boliu
2016/04/20 16:49:09
this looks unused
| |
| 28 private WebViewDelegate mWebViewDelegate; | 29 private final WebViewDelegate mWebViewDelegate; |
| 29 View mContainerView; | |
| 30 | 30 |
| 31 public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) { | 31 public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) { |
| 32 mNativeDrawGLFunctor = nativeCreateGLFunctor(viewContext); | 32 mNativeDrawGLFunctor = nativeCreateGLFunctor(viewContext); |
| 33 mDestroyRunnable = new DestroyRunnable(mNativeDrawGLFunctor); | 33 mDestroyRunnable = new DestroyRunnable(mNativeDrawGLFunctor); |
| 34 mCleanupReference = new CleanupReference(this, mDestroyRunnable); | 34 mCleanupReference = new CleanupReference(this, mDestroyRunnable); |
| 35 mWebViewDelegate = webViewDelegate; | 35 mWebViewDelegate = webViewDelegate; |
| 36 } | 36 } |
| 37 | 37 |
| 38 public void detach() { | 38 @Override |
| 39 if (mWebViewDelegate != null && mContainerView != null) { | 39 public void detach(View containerView) { |
| 40 mWebViewDelegate.detachDrawGlFunctor(mContainerView, mNativeDrawGLFu nctor); | 40 mWebViewDelegate.detachDrawGlFunctor(containerView, mNativeDrawGLFunctor ); |
| 41 } | |
| 42 } | 41 } |
| 43 | 42 |
| 44 private static final boolean sSupportFunctorReleasedCallback = | 43 private static final boolean sSupportFunctorReleasedCallback = (Build.VERSIO N.SDK_INT |
| 45 (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) || "N".equals(Build. VERSION.CODENAME); | 44 > Build.VERSION_CODES.M) || "N".equals(Build.VERSION.CODENAME); |
| 46 public boolean requestDrawGL(Canvas canvas, View containerView, boolean wait ForCompletion, | 45 |
| 47 Runnable releasedCallback) { | 46 @Override |
| 47 public boolean requestDrawGL(Canvas canvas, Runnable releasedCallback) { | |
| 48 assert canvas != null; | |
| 48 if (mDestroyRunnable.mNativeDrawGLFunctor == 0) { | 49 if (mDestroyRunnable.mNativeDrawGLFunctor == 0) { |
| 49 throw new RuntimeException("requested DrawGL on already destroyed Dr awGLFunctor"); | 50 throw new RuntimeException("requested DrawGL on already destroyed Dr awGLFunctor"); |
| 50 } | 51 } |
| 51 | 52 |
| 52 if (canvas != null && waitForCompletion) { | |
| 53 throw new IllegalArgumentException( | |
| 54 "requested a blocking DrawGL with a not null canvas."); | |
| 55 } | |
| 56 | |
| 57 if (!mWebViewDelegate.canInvokeDrawGlFunctor(containerView)) { | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 mContainerView = containerView; | |
| 62 | |
| 63 if (canvas == null) { | |
| 64 assert releasedCallback == null; | |
| 65 mWebViewDelegate.invokeDrawGlFunctor( | |
| 66 containerView, mDestroyRunnable.mNativeDrawGLFunctor, waitFo rCompletion); | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 70 if (sSupportFunctorReleasedCallback) { | 53 if (sSupportFunctorReleasedCallback) { |
| 71 assert releasedCallback != null; | 54 assert releasedCallback != null; |
| 72 mWebViewDelegate.callDrawGlFunction( | 55 mWebViewDelegate.callDrawGlFunction( |
| 73 canvas, mDestroyRunnable.mNativeDrawGLFunctor, releasedCallb ack); | 56 canvas, mDestroyRunnable.mNativeDrawGLFunctor, releasedCallb ack); |
| 74 } else { | 57 } else { |
| 75 assert releasedCallback == null; | 58 assert releasedCallback == null; |
| 76 mWebViewDelegate.callDrawGlFunction(canvas, mDestroyRunnable.mNative DrawGLFunctor); | 59 mWebViewDelegate.callDrawGlFunction(canvas, mDestroyRunnable.mNative DrawGLFunctor); |
| 77 } | 60 } |
| 78 return true; | 61 return true; |
| 79 } | 62 } |
| 80 | 63 |
| 81 public static boolean supportsDrawGLFunctorReleasedCallback() { | 64 @Override |
| 65 public boolean requestInvokeGL(View containerView, boolean waitForCompletion ) { | |
| 66 if (mDestroyRunnable.mNativeDrawGLFunctor == 0) { | |
|
boliu
2016/04/20 16:49:09
This can't ever happen. There is no explicit destr
| |
| 67 throw new RuntimeException("requested DrawGL on already destroyed Dr awGLFunctor"); | |
| 68 } | |
| 69 | |
| 70 if (!sSupportFunctorReleasedCallback | |
| 71 && !mWebViewDelegate.canInvokeDrawGlFunctor(containerView)) { | |
| 72 return false; | |
| 73 } | |
| 74 | |
| 75 mWebViewDelegate.invokeDrawGlFunctor( | |
| 76 containerView, mDestroyRunnable.mNativeDrawGLFunctor, waitForCom pletion); | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 @Override | |
| 81 public boolean supportsDrawGLFunctorReleasedCallback() { | |
| 82 return sSupportFunctorReleasedCallback; | 82 return sSupportFunctorReleasedCallback; |
| 83 } | 83 } |
| 84 | 84 |
| 85 public static void setChromiumAwDrawGLFunction(long functionPointer) { | 85 public static void setChromiumAwDrawGLFunction(long functionPointer) { |
| 86 nativeSetChromiumAwDrawGLFunction(functionPointer); | 86 nativeSetChromiumAwDrawGLFunction(functionPointer); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Holds the core resources of the class, everything required to correctly c leanup. | 89 // Holds the core resources of the class, everything required to correctly c leanup. |
| 90 // IMPORTANT: this class must not hold any reference back to the outer DrawG LFunctor | 90 // IMPORTANT: this class must not hold any reference back to the outer DrawG LFunctor |
| 91 // instance, as that will defeat GC of that object. | 91 // instance, as that will defeat GC of that object. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 102 assert mNativeDrawGLFunctor != 0; | 102 assert mNativeDrawGLFunctor != 0; |
| 103 nativeDestroyGLFunctor(mNativeDrawGLFunctor); | 103 nativeDestroyGLFunctor(mNativeDrawGLFunctor); |
| 104 mNativeDrawGLFunctor = 0; | 104 mNativeDrawGLFunctor = 0; |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 private static native long nativeCreateGLFunctor(long viewContext); | 108 private static native long nativeCreateGLFunctor(long viewContext); |
| 109 private static native void nativeDestroyGLFunctor(long functor); | 109 private static native void nativeDestroyGLFunctor(long functor); |
| 110 private static native void nativeSetChromiumAwDrawGLFunction(long functionPo inter); | 110 private static native void nativeSetChromiumAwDrawGLFunction(long functionPo inter); |
| 111 } | 111 } |
| OLD | NEW |