Kotlin: Don't wrap Future, WaitStatus or other async related entities.

We supply a callback interface and coroutine adapter designed for
Kotlin apps. The remaining entities are present in dawn.json but not useful
for Kotlin, so likely just to confuse.

Test: ./gradlew connectedAndroidTest
Bug: b/446603126
Change-Id: Id7726e9f1189273da37a85357fc4a52fb8831cf4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/267754
Reviewed-by: Tarun Saini <sainitarun@google.com>
Commit-Queue: Jim Blackler <jimblackler@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index 94451d6..73e5ab2 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -798,6 +798,10 @@
     params_kotlin['jni_primitives'] = kotlin_json['jni_primitives']
     params_kotlin['jni_signatures'] = kotlin_json['jni_signatures']
     kt_file_path = params_kotlin['kotlin_package'].replace('.', '/')
+    customize_api = kotlin_json["customize_api"]
+    customize_objects = customize_api["objects"]
+    customize_structures = customize_api["structures"]
+    customize_enums = customize_api["enums"]
 
     def kotlin_record_members(members):
         # Members are sorted so that those with default parameters appear after those without.
@@ -926,6 +930,11 @@
                         and argument.type.category == 'structure'):
                     return argument
 
+        # If the function should return an omitted structure, we return nothing instead.
+        if method.returns and method.returns.type.category == 'structure' and not include_structure(
+                method.returns.type):
+            return None
+
         # Return values are not treated as optional to keep the Kotlin API simple.
         # Methods are expected to return an object if declared. If they can't, dawn may raise an
         # error (converted to a Kotlin exception); otherwise JNI will throw NullPointerException.
@@ -934,18 +943,30 @@
             method.returns.type, method.returns.annotation, False,
             method.json_data) if method.returns else None
 
-    # TODO(b/352047733): Replace methods that require special handling with an exceptions list.
-    def include_method(method):
+    def include_method(obj, method):
         if method.returns and method.returns.type.category == 'function pointer':
             # Kotlin doesn't support returning functions.
             return False
-        return True
 
-    # Whether to create structure converters (or use handwritten converters).
+        if obj is None:
+            return True
+
+        # Is the method marked omitted in dawn_kotlin.json?
+        return customize_objects.get(obj.name.get(),
+                                     {}).get("methods", {}).get(
+                                         method.name.get(),
+                                         {}).get('omitted') is not True
+
     def include_structure(structure):
         if structure.name.canonical_case() == "string view":
             return False
-        return True
+        # Is the structure marked omitted in dawn_kotlin.json?
+        return customize_structures.get(structure.name.get(),
+                                        {}).get('omitted') is not True
+
+    def include_enum(enum):
+        return customize_enums.get(enum.name.get(),
+                                   {}).get('omitted') is not True
 
     def jni_name(type):
         return kt_file_path + '/' + type.name.CamelCase()
@@ -971,14 +992,15 @@
     params_kotlin['kotlin_return'] = kotlin_return
     params_kotlin['include_method'] = include_method
     params_kotlin['include_structure'] = include_structure
+    params_kotlin['include_enum'] = include_enum
     params_kotlin['kotlin_record_members'] = kotlin_record_members
     params_kotlin['jni_name'] = jni_name
-    params_kotlin['has_kotlin_classes'] = (
-        by_category['callback function'] + by_category['enum'] +
-        by_category['function pointer'] + by_category['object'] + [
-            structure for structure in by_category['structure']
-            if include_structure(structure)
-        ])
+    params_kotlin['has_kotlin_classes'] = by_category['callback function'] + [
+        enum for enum in by_category['enum'] if include_enum(enum)
+    ] + by_category['function pointer'] + by_category['object'] + [
+        structure for structure in by_category['structure']
+        if include_structure(structure)
+    ]
 
     return params_kotlin
 
@@ -1695,7 +1717,7 @@
 
             by_category = params_kotlin['by_category']
             for structure in by_category['structure']:
-                if structure.name.get() != "string view":
+                if params_kotlin['include_structure'](structure):
                     renders.append(
                         FileRender('art/api_kotlin_structure.kt',
                                    'java/' + jni_name(structure) + '.kt', [
@@ -1731,13 +1753,14 @@
 
             for enum in (params_kotlin['by_category']['bitmask'] +
                          params_kotlin['by_category']['enum']):
-                renders.append(
-                    FileRender(
-                        'art/api_kotlin_enum.kt',
-                        'java/' + jni_name(enum) + '.kt',
-                        [RENDER_PARAMS_BASE, params_kotlin, {
-                            'enum': enum
-                        }]))
+                if params_kotlin['include_enum'](enum):
+                    renders.append(
+                        FileRender('art/api_kotlin_enum.kt',
+                                   'java/' + jni_name(enum) + '.kt', [
+                                       RENDER_PARAMS_BASE, params_kotlin, {
+                                           'enum': enum
+                                       }
+                                   ]))
 
             renders.append(
                 FileRender('art/api_kotlin_constants.kt',
diff --git a/generator/templates/art/api_kotlin_async_helpers.kt b/generator/templates/art/api_kotlin_async_helpers.kt
index 001ec98..d0ed73e 100644
--- a/generator/templates/art/api_kotlin_async_helpers.kt
+++ b/generator/templates/art/api_kotlin_async_helpers.kt
@@ -33,7 +33,7 @@
 
 //* Provide an async wrapper for the 'callback info' type of async methods.
 {% for obj in by_category['object'] %}
-    {% for method in obj.methods if has_callbackInfoStruct(method) %}
+    {% for method in obj.methods if has_callbackInfoStruct(method) and include_method(obj, method) %}
         {% set callback_info = method.arguments[-1].type %}
         {% set callback_function = callback_info.members[-1].type %}
         {% set return_name = callback_function.name.chunks[:-1] | map('title') | join + 'Return' %}
diff --git a/generator/templates/art/api_kotlin_functions.kt b/generator/templates/art/api_kotlin_functions.kt
index 25303a9..c45a7d1 100644
--- a/generator/templates/art/api_kotlin_functions.kt
+++ b/generator/templates/art/api_kotlin_functions.kt
@@ -30,7 +30,7 @@
 
 {% from 'art/api_kotlin_types.kt' import kotlin_annotation, kotlin_declaration, kotlin_definition with context %}
 
-{% for function in by_category['function'] if include_method(function) %}
+{% for function in by_category['function'] if include_method(None, function) %}
     @FastNative
     {{ kotlin_annotation(kotlin_return(function)) }} public external fun {{ function.name.camelCase() }}(
         {%- for arg in function.arguments -%}
diff --git a/generator/templates/art/api_kotlin_object.kt b/generator/templates/art/api_kotlin_object.kt
index 6d4f831..dd944c5 100644
--- a/generator/templates/art/api_kotlin_object.kt
+++ b/generator/templates/art/api_kotlin_object.kt
@@ -35,7 +35,7 @@
 {% from 'art/api_kotlin_types.kt' import kotlin_annotation, kotlin_declaration, kotlin_definition with context %}
 
 public class {{ obj.name.CamelCase() }}(public val handle: Long): AutoCloseable {
-    {% for method in obj.methods if include_method(method) %}
+    {% for method in obj.methods if include_method(obj, method) %}
         @FastNative
         @JvmName("{{ method.name.camelCase() }}")
         {% for arg in kotlin_record_members(method.arguments) %}
diff --git a/generator/templates/art/methods.cpp b/generator/templates/art/methods.cpp
index da7be2c..4795416 100644
--- a/generator/templates/art/methods.cpp
+++ b/generator/templates/art/methods.cpp
@@ -189,7 +189,7 @@
 } {% endmacro %}
 
 {% for obj in by_category['object'] %}
-    {% for method in obj.methods if include_method(method) %}
+    {% for method in obj.methods if include_method(obj, method) %}
         {{ render_method(method, obj) }}
     {% endfor %}
 
@@ -207,7 +207,7 @@
 {% endfor %}
 
 //* Global functions don't have an associated class.
-{% for function in by_category['function'] if include_method(function) %}
+{% for function in by_category['function'] if include_method(None, function) %}
     {{ render_method(function, None) }}
 {% endfor %}
 
diff --git a/src/dawn/dawn_kotlin.json b/src/dawn/dawn_kotlin.json
index d74f616..30a0848 100644
--- a/src/dawn/dawn_kotlin.json
+++ b/src/dawn/dawn_kotlin.json
@@ -69,5 +69,36 @@
         "(See also @ref SentinelValues.)": "",
         "[defaults](@ref SentinelValues)": "defaults",
         "WGPUCallbackMode_": "CallbackMode."
+    },
+    "customize_api": {
+        "objects": {
+            "device": {
+                "methods": {
+                    "get lost future": {
+                        "omitted": true
+                    }
+                }
+            },
+            "instance": {
+                "methods": {
+                    "wait any": {
+                        "omitted": true
+                    }
+                }
+            }
+        },
+        "structures": {
+            "future": {
+                "omitted": true
+            },
+            "future wait info": {
+                "omitted": true
+            }
+        },
+        "enums": {
+            "wait status": {
+                "omitted": true
+            }
+        }
     }
 }
diff --git a/tools/android/BUILD.gn b/tools/android/BUILD.gn
index 587be04..848b761 100644
--- a/tools/android/BUILD.gn
+++ b/tools/android/BUILD.gn
@@ -107,8 +107,6 @@
     "java/androidx/webgpu/FragmentState.kt",
     "java/androidx/webgpu/FrontFace.kt",
     "java/androidx/webgpu/Functions.kt",
-    "java/androidx/webgpu/Future.kt",
-    "java/androidx/webgpu/FutureWaitInfo.kt",
     "java/androidx/webgpu/IndexFormat.kt",
     "java/androidx/webgpu/Instance.kt",
     "java/androidx/webgpu/InstanceDescriptor.kt",
@@ -208,7 +206,6 @@
     "java/androidx/webgpu/VertexState.kt",
     "java/androidx/webgpu/VertexStepMode.kt",
     "java/androidx/webgpu/WGSLLanguageFeatureName.kt",
-    "java/androidx/webgpu/WaitStatus.kt",
   ]
 }
 
diff --git a/tools/android/webgpu/src/test/java/androidx/webgpu/MappedNamedConstantsTest.kt b/tools/android/webgpu/src/test/java/androidx/webgpu/MappedNamedConstantsTest.kt
index ce0e598..d4af689 100644
--- a/tools/android/webgpu/src/test/java/androidx/webgpu/MappedNamedConstantsTest.kt
+++ b/tools/android/webgpu/src/test/java/androidx/webgpu/MappedNamedConstantsTest.kt
@@ -94,7 +94,6 @@
         ToneMappingMode::class,
         VertexFormat::class,
         VertexStepMode::class,
-        WaitStatus::class,
         WGSLLanguageFeatureName::class
     )