[M73 fork] Fallback to old functor if needed

AOSP does not have DrawFn functor yet, so fallback to old functor at run
time if we detect DrawFn is not supported.

Change-Id: I2e3400a400d8a02456ad5f9fd9a8ce9f44915de5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1558723
Reviewed-by: Richard Coles <torne@chromium.org>
Cr-Commit-Position: refs/branch-heads/3683@{#920}
Cr-Branched-From: e51029943e0a38dd794b73caaf6373d5496ae783-refs/heads/master@{#625896}
diff --git a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumAwInit.java b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumAwInit.java
index a873c92..91de510 100644
--- a/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumAwInit.java
+++ b/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumAwInit.java
@@ -302,7 +302,11 @@
         try (ScopedSysTraceEvent e = ScopedSysTraceEvent.scoped(
                      "WebViewChromiumAwInit.initPlatSupportLibrary")) {
             if (BuildInfo.isAtLeastQ()) {
-                AwDrawFnImpl.setDrawFnFunctionTable(DrawFunctor.getDrawFnFunctionTable());
+                try {
+                    AwDrawFnImpl.setDrawFnFunctionTable(DrawFunctor.getDrawFnFunctionTable());
+                } catch (Throwable exception) {
+                    // Not supported in AOSP yet.
+                }
             }
             DrawGLFunctor.setChromiumAwDrawGLFunction(AwContents.getAwDrawGLFunction());
             AwContents.setAwDrawSWFunctionTable(GraphicsUtils.getDrawSWFunctionTable());
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index 66abf11..78192d0 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -3461,7 +3461,7 @@
                 AwFunctor newFunctor;
                 AwDrawFnImpl.DrawFnAccess drawFnAccess =
                         mNativeDrawFunctorFactory.getDrawFnAccess();
-                if (drawFnAccess != null) {
+                if (AwDrawFnImpl.isEnabled() && drawFnAccess != null) {
                     newFunctor = new AwDrawFnImpl(drawFnAccess);
                 } else {
                     newFunctor = new AwGLFunctor(mNativeDrawFunctorFactory, mContainerView);
diff --git a/android_webview/java/src/org/chromium/android_webview/AwDrawFnImpl.java b/android_webview/java/src/org/chromium/android_webview/AwDrawFnImpl.java
index cdbc5dc..86c4d17a 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwDrawFnImpl.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwDrawFnImpl.java
@@ -13,6 +13,12 @@
  */
 @JNINamespace("android_webview")
 public class AwDrawFnImpl implements AwFunctor {
+    private static boolean sEnabled;
+
+    public static boolean isEnabled() {
+        return sEnabled;
+    }
+
     private long mNativeAwDrawFnImpl;
     private final DrawFnAccess mAccess;
     private final int mHandle;
@@ -36,6 +42,7 @@
 
     public static void setDrawFnFunctionTable(long functionTablePointer) {
         nativeSetDrawFnFunctionTable(functionTablePointer);
+        sEnabled = true;
     }
 
     @Override