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

Side by Side Diff: android_webview/glue/java/src/com/android/webview/chromium/DrawGLFunctor.java

Issue 1904453004: Transfer DrawGLFunctor ownership from AwContents to AwGLFunctor (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 unified diff | Download patch
OLDNEW
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 WebViewDelegate mWebViewDelegate;
28 private WebViewDelegate mWebViewDelegate;
29 View mContainerView;
30 29
31 public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) { 30 public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) {
32 mNativeDrawGLFunctor = nativeCreateGLFunctor(viewContext); 31 mDestroyRunnable = new DestroyRunnable(nativeCreateGLFunctor(viewContext ));
33 mDestroyRunnable = new DestroyRunnable(mNativeDrawGLFunctor);
34 mCleanupReference = new CleanupReference(this, mDestroyRunnable); 32 mCleanupReference = new CleanupReference(this, mDestroyRunnable);
35 mWebViewDelegate = webViewDelegate; 33 mWebViewDelegate = webViewDelegate;
36 } 34 }
37 35
38 public void detach() { 36 @Override
39 if (mWebViewDelegate != null && mContainerView != null) { 37 public void detach(View containerView) {
40 mWebViewDelegate.detachDrawGlFunctor(mContainerView, mNativeDrawGLFu nctor); 38 mWebViewDelegate.detachDrawGlFunctor(containerView, mDestroyRunnable.mNa tiveDrawGLFunctor);
41 }
42 } 39 }
43 40
44 private static final boolean sSupportFunctorReleasedCallback = 41 private static final boolean sSupportFunctorReleasedCallback =
45 (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) || "N".equals(Build. VERSION.CODENAME); 42 (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) || "N".equals(Build. VERSION.CODENAME);
46 public boolean requestDrawGL(Canvas canvas, View containerView, boolean wait ForCompletion,
47 Runnable releasedCallback) {
48 if (mDestroyRunnable.mNativeDrawGLFunctor == 0) {
49 throw new RuntimeException("requested DrawGL on already destroyed Dr awGLFunctor");
50 }
51 43
52 if (canvas != null && waitForCompletion) { 44 @Override
53 throw new IllegalArgumentException( 45 public boolean requestDrawGL(Canvas canvas, Runnable releasedCallback) {
54 "requested a blocking DrawGL with a not null canvas."); 46 assert canvas != null;
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) { 47 if (sSupportFunctorReleasedCallback) {
71 assert releasedCallback != null; 48 assert releasedCallback != null;
72 mWebViewDelegate.callDrawGlFunction( 49 mWebViewDelegate.callDrawGlFunction(
73 canvas, mDestroyRunnable.mNativeDrawGLFunctor, releasedCallb ack); 50 canvas, mDestroyRunnable.mNativeDrawGLFunctor, releasedCallb ack);
74 } else { 51 } else {
75 assert releasedCallback == null; 52 assert releasedCallback == null;
76 mWebViewDelegate.callDrawGlFunction(canvas, mDestroyRunnable.mNative DrawGLFunctor); 53 mWebViewDelegate.callDrawGlFunction(canvas, mDestroyRunnable.mNative DrawGLFunctor);
77 } 54 }
78 return true; 55 return true;
79 } 56 }
80 57
81 public static boolean supportsDrawGLFunctorReleasedCallback() { 58 @Override
59 public boolean requestInvokeGL(View containerView, boolean waitForCompletion ) {
60 if (!sSupportFunctorReleasedCallback
61 && !mWebViewDelegate.canInvokeDrawGlFunctor(containerView)) {
62 return false;
63 }
64
65 mWebViewDelegate.invokeDrawGlFunctor(
66 containerView, mDestroyRunnable.mNativeDrawGLFunctor, waitForCom pletion);
67 return true;
68 }
69
70 @Override
71 public boolean supportsDrawGLFunctorReleasedCallback() {
82 return sSupportFunctorReleasedCallback; 72 return sSupportFunctorReleasedCallback;
83 } 73 }
84 74
85 public static void setChromiumAwDrawGLFunction(long functionPointer) { 75 public static void setChromiumAwDrawGLFunction(long functionPointer) {
86 nativeSetChromiumAwDrawGLFunction(functionPointer); 76 nativeSetChromiumAwDrawGLFunction(functionPointer);
87 } 77 }
88 78
89 // Holds the core resources of the class, everything required to correctly c leanup. 79 // 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 80 // IMPORTANT: this class must not hold any reference back to the outer DrawG LFunctor
91 // instance, as that will defeat GC of that object. 81 // instance, as that will defeat GC of that object.
(...skipping 10 matching lines...) Expand all
102 assert mNativeDrawGLFunctor != 0; 92 assert mNativeDrawGLFunctor != 0;
103 nativeDestroyGLFunctor(mNativeDrawGLFunctor); 93 nativeDestroyGLFunctor(mNativeDrawGLFunctor);
104 mNativeDrawGLFunctor = 0; 94 mNativeDrawGLFunctor = 0;
105 } 95 }
106 } 96 }
107 97
108 private static native long nativeCreateGLFunctor(long viewContext); 98 private static native long nativeCreateGLFunctor(long viewContext);
109 private static native void nativeDestroyGLFunctor(long functor); 99 private static native void nativeDestroyGLFunctor(long functor);
110 private static native void nativeSetChromiumAwDrawGLFunction(long functionPo inter); 100 private static native void nativeSetChromiumAwDrawGLFunction(long functionPo inter);
111 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698