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

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 CleanupReference mCleanupReference;
26 private DestroyRunnable mDestroyRunnable; 27 private DestroyRunnable mDestroyRunnable;
27 private final long mNativeDrawGLFunctor; 28 private final long mNativeDrawGLFunctor;
28 private WebViewDelegate mWebViewDelegate; 29 private WebViewDelegate mWebViewDelegate;
29 View mContainerView; 30 View mContainerView;
boliu 2016/04/20 15:38:32 clean this stuff up again while you are at this
30 31
31 public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) { 32 public DrawGLFunctor(long viewContext, WebViewDelegate webViewDelegate) {
32 mNativeDrawGLFunctor = nativeCreateGLFunctor(viewContext); 33 mNativeDrawGLFunctor = nativeCreateGLFunctor(viewContext);
33 mDestroyRunnable = new DestroyRunnable(mNativeDrawGLFunctor); 34 mDestroyRunnable = new DestroyRunnable(mNativeDrawGLFunctor);
34 mCleanupReference = new CleanupReference(this, mDestroyRunnable); 35 mCleanupReference = new CleanupReference(this, mDestroyRunnable);
35 mWebViewDelegate = webViewDelegate; 36 mWebViewDelegate = webViewDelegate;
36 } 37 }
37 38
39 @Override
38 public void detach() { 40 public void detach() {
39 if (mWebViewDelegate != null && mContainerView != null) { 41 if (mWebViewDelegate != null && mContainerView != null) {
40 mWebViewDelegate.detachDrawGlFunctor(mContainerView, mNativeDrawGLFu nctor); 42 mWebViewDelegate.detachDrawGlFunctor(mContainerView, mNativeDrawGLFu nctor);
41 } 43 }
42 } 44 }
43 45
44 private static final boolean sSupportFunctorReleasedCallback = 46 private static final boolean sSupportFunctorReleasedCallback = (Build.VERSIO N.SDK_INT
45 (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) || "N".equals(Build. VERSION.CODENAME); 47 > Build.VERSION_CODES.M); // || "N".equals(Build.VERSION.CODENAME);
46 public boolean requestDrawGL(Canvas canvas, View containerView, boolean wait ForCompletion, 48
47 Runnable releasedCallback) { 49 @Override
50 public boolean requestDrawGL(View containerView, Canvas canvas, Runnable rel easedCallback) {
51 assert canvas != null;
52
48 if (mDestroyRunnable.mNativeDrawGLFunctor == 0) { 53 if (mDestroyRunnable.mNativeDrawGLFunctor == 0) {
49 throw new RuntimeException("requested DrawGL on already destroyed Dr awGLFunctor"); 54 throw new RuntimeException("requested DrawGL on already destroyed Dr awGLFunctor");
50 } 55 }
51 56
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)) { 57 if (!mWebViewDelegate.canInvokeDrawGlFunctor(containerView)) {
boliu 2016/04/20 15:38:32 yeah, don't need this check here :)
Tobias Sargeant 2016/04/20 16:00:31 The name kind of gave it away, but it *was* done i
boliu 2016/04/20 16:01:25 You can replace this check on the chromium side wi
58 return false; 58 return false;
59 } 59 }
60 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) { 61 if (sSupportFunctorReleasedCallback) {
71 assert releasedCallback != null; 62 assert releasedCallback != null;
72 mWebViewDelegate.callDrawGlFunction( 63 mWebViewDelegate.callDrawGlFunction(
73 canvas, mDestroyRunnable.mNativeDrawGLFunctor, releasedCallb ack); 64 canvas, mDestroyRunnable.mNativeDrawGLFunctor, releasedCallb ack);
74 } else { 65 } else {
75 assert releasedCallback == null; 66 assert releasedCallback == null;
76 mWebViewDelegate.callDrawGlFunction(canvas, mDestroyRunnable.mNative DrawGLFunctor); 67 mWebViewDelegate.callDrawGlFunction(canvas, mDestroyRunnable.mNative DrawGLFunctor);
77 } 68 }
78 return true; 69 return true;
79 } 70 }
80 71
81 public static boolean supportsDrawGLFunctorReleasedCallback() { 72 @Override
73 public boolean requestDrawGL(View containerView, boolean waitForCompletion) {
74 if (mDestroyRunnable.mNativeDrawGLFunctor == 0) {
75 throw new RuntimeException("requested DrawGL on already destroyed Dr awGLFunctor");
76 }
77
78 if (!mWebViewDelegate.canInvokeDrawGlFunctor(containerView)) {
boliu 2016/04/20 16:01:25 We can actually remove this on N, ie where sSuppor
79 return false;
80 }
81
82 mContainerView = containerView;
83
84 mWebViewDelegate.invokeDrawGlFunctor(
85 containerView, mDestroyRunnable.mNativeDrawGLFunctor, waitForCom pletion);
86 return true;
87 }
88
89 @Override
90 public boolean supportsDrawGLFunctorReleasedCallback() {
82 return sSupportFunctorReleasedCallback; 91 return sSupportFunctorReleasedCallback;
83 } 92 }
84 93
85 public static void setChromiumAwDrawGLFunction(long functionPointer) { 94 public static void setChromiumAwDrawGLFunction(long functionPointer) {
86 nativeSetChromiumAwDrawGLFunction(functionPointer); 95 nativeSetChromiumAwDrawGLFunction(functionPointer);
87 } 96 }
88 97
89 // Holds the core resources of the class, everything required to correctly c leanup. 98 // 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 99 // IMPORTANT: this class must not hold any reference back to the outer DrawG LFunctor
91 // instance, as that will defeat GC of that object. 100 // instance, as that will defeat GC of that object.
(...skipping 10 matching lines...) Expand all
102 assert mNativeDrawGLFunctor != 0; 111 assert mNativeDrawGLFunctor != 0;
103 nativeDestroyGLFunctor(mNativeDrawGLFunctor); 112 nativeDestroyGLFunctor(mNativeDrawGLFunctor);
104 mNativeDrawGLFunctor = 0; 113 mNativeDrawGLFunctor = 0;
105 } 114 }
106 } 115 }
107 116
108 private static native long nativeCreateGLFunctor(long viewContext); 117 private static native long nativeCreateGLFunctor(long viewContext);
109 private static native void nativeDestroyGLFunctor(long functor); 118 private static native void nativeDestroyGLFunctor(long functor);
110 private static native void nativeSetChromiumAwDrawGLFunction(long functionPo inter); 119 private static native void nativeSetChromiumAwDrawGLFunction(long functionPo inter);
111 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698