Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | //* Copyright 2020 The Dawn & Tint Authors |
Shrek Shao | d7304d1 | 2021-12-14 01:06:15 +0000 | [diff] [blame] | 2 | //* |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | //* Redistribution and use in source and binary forms, with or without |
| 4 | //* modification, are permitted provided that the following conditions are met: |
Shrek Shao | d7304d1 | 2021-12-14 01:06:15 +0000 | [diff] [blame] | 5 | //* |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | //* 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | //* list of conditions and the following disclaimer. |
Shrek Shao | d7304d1 | 2021-12-14 01:06:15 +0000 | [diff] [blame] | 8 | //* |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | //* 2. Redistributions in binary form must reproduce the above copyright notice, |
| 10 | //* this list of conditions and the following disclaimer in the documentation |
| 11 | //* and/or other materials provided with the distribution. |
Corentin Wallez | 1bf3167 | 2020-01-15 15:39:12 +0000 | [diff] [blame] | 12 | //* |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 13 | //* 3. Neither the name of the copyright holder nor the names of its |
| 14 | //* contributors may be used to endorse or promote products derived from |
| 15 | //* this software without specific prior written permission. |
Corentin Wallez | 1bf3167 | 2020-01-15 15:39:12 +0000 | [diff] [blame] | 16 | //* |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 17 | //* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | //* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | //* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | //* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 21 | //* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | //* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | //* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 24 | //* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | //* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | //* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Corentin Wallez | 1bf3167 | 2020-01-15 15:39:12 +0000 | [diff] [blame] | 27 | //* |
| 28 | //* |
Shrek Shao | d7304d1 | 2021-12-14 01:06:15 +0000 | [diff] [blame] | 29 | {% include 'BSD_LICENSE' %} |
Shrek Shao | 71a363b | 2022-02-09 19:42:51 +0000 | [diff] [blame] | 30 | {% if 'dawn' in enabled_tags %} |
| 31 | #ifdef __EMSCRIPTEN__ |
| 32 | #error "Do not include this header. Emscripten already provides headers needed for {{metadata.api}}." |
| 33 | #endif |
| 34 | {% endif %} |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 35 | #ifndef {{metadata.api.upper()}}_H_ |
| 36 | #define {{metadata.api.upper()}}_H_ |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 37 | |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 38 | {% set API = metadata.c_prefix %} |
| 39 | #if defined({{API}}_SHARED_LIBRARY) |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 40 | # if defined(_WIN32) |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 41 | # if defined({{API}}_IMPLEMENTATION) |
| 42 | # define {{API}}_EXPORT __declspec(dllexport) |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 43 | # else |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 44 | # define {{API}}_EXPORT __declspec(dllimport) |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 45 | # endif |
| 46 | # else // defined(_WIN32) |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 47 | # if defined({{API}}_IMPLEMENTATION) |
| 48 | # define {{API}}_EXPORT __attribute__((visibility("default"))) |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 49 | # else |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 50 | # define {{API}}_EXPORT |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 51 | # endif |
| 52 | # endif // defined(_WIN32) |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 53 | #else // defined({{API}}_SHARED_LIBRARY) |
| 54 | # define {{API}}_EXPORT |
| 55 | #endif // defined({{API}}_SHARED_LIBRARY) |
| 56 | |
| 57 | #if !defined({{API}}_OBJECT_ATTRIBUTE) |
| 58 | #define {{API}}_OBJECT_ATTRIBUTE |
| 59 | #endif |
| 60 | #if !defined({{API}}_ENUM_ATTRIBUTE) |
| 61 | #define {{API}}_ENUM_ATTRIBUTE |
| 62 | #endif |
| 63 | #if !defined({{API}}_STRUCTURE_ATTRIBUTE) |
| 64 | #define {{API}}_STRUCTURE_ATTRIBUTE |
| 65 | #endif |
| 66 | #if !defined({{API}}_FUNCTION_ATTRIBUTE) |
| 67 | #define {{API}}_FUNCTION_ATTRIBUTE |
| 68 | #endif |
| 69 | #if !defined({{API}}_NULLABLE) |
| 70 | #define {{API}}_NULLABLE |
| 71 | #endif |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 72 | |
| 73 | #include <stdint.h> |
| 74 | #include <stddef.h> |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 75 | |
fujunwei | 4e87690 | 2021-11-25 08:44:01 +0000 | [diff] [blame] | 76 | {% for constant in by_category["constant"] %} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 77 | #define {{API}}_{{constant.name.SNAKE_CASE()}} {{constant.value}} |
fujunwei | 4e87690 | 2021-11-25 08:44:01 +0000 | [diff] [blame] | 78 | {% endfor %} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 79 | |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 80 | typedef uint32_t {{API}}Flags; |
Loko Kung | 440a30c | 2023-08-04 23:41:21 +0000 | [diff] [blame] | 81 | typedef uint32_t {{API}}Bool; |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 82 | |
| 83 | {% for type in by_category["object"] %} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 84 | typedef struct {{as_cType(type.name)}}Impl* {{as_cType(type.name)}} {{API}}_OBJECT_ATTRIBUTE; |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 85 | {% endfor %} |
| 86 | |
Brandon Jones | 112b7fd | 2023-05-17 01:52:30 +0000 | [diff] [blame] | 87 | // Structure forward declarations |
| 88 | {% for type in by_category["structure"] %} |
| 89 | struct {{as_cType(type.name)}}; |
| 90 | {% endfor %} |
| 91 | |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 92 | {% for type in by_category["enum"] + by_category["bitmask"] %} |
| 93 | typedef enum {{as_cType(type.name)}} { |
| 94 | {% for value in type.values %} |
| 95 | {{as_cEnum(type.name, value.name)}} = 0x{{format(value.value, "08X")}}, |
| 96 | {% endfor %} |
| 97 | {{as_cEnum(type.name, Name("force32"))}} = 0x7FFFFFFF |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 98 | } {{as_cType(type.name)}} {{API}}_ENUM_ATTRIBUTE; |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 99 | {% if type.category == "bitmask" %} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 100 | typedef {{API}}Flags {{as_cType(type.name)}}Flags {{API}}_ENUM_ATTRIBUTE; |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 101 | {% endif %} |
| 102 | |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 103 | {% endfor -%} |
Brandon Jones | 112b7fd | 2023-05-17 01:52:30 +0000 | [diff] [blame] | 104 | {% for type in by_category["function pointer"] %} |
| 105 | typedef {{as_cType(type.return_type.name)}} (*{{as_cType(type.name)}})( |
| 106 | {%- if type.arguments == [] -%} |
| 107 | void |
| 108 | {%- else -%} |
| 109 | {%- for arg in type.arguments -%} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 110 | {% if not loop.first %}, {% endif %} |
| 111 | {% if arg.type.category == "structure" %}struct {% endif %}{{as_annotated_cType(arg)}} |
Brandon Jones | 112b7fd | 2023-05-17 01:52:30 +0000 | [diff] [blame] | 112 | {%- endfor -%} |
| 113 | {%- endif -%} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 114 | ) {{API}}_FUNCTION_ATTRIBUTE; |
Brandon Jones | 112b7fd | 2023-05-17 01:52:30 +0000 | [diff] [blame] | 115 | {% endfor %} |
| 116 | |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 117 | typedef struct {{API}}ChainedStruct { |
| 118 | struct {{API}}ChainedStruct const * next; |
| 119 | {{API}}SType sType; |
| 120 | } {{API}}ChainedStruct {{API}}_STRUCTURE_ATTRIBUTE; |
Corentin Wallez | 2b24c3d | 2020-01-15 09:54:42 +0000 | [diff] [blame] | 121 | |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 122 | typedef struct {{API}}ChainedStructOut { |
| 123 | struct {{API}}ChainedStructOut * next; |
| 124 | {{API}}SType sType; |
| 125 | } {{API}}ChainedStructOut {{API}}_STRUCTURE_ATTRIBUTE; |
Austin Eng | bffc966 | 2021-09-17 15:36:00 +0000 | [diff] [blame] | 126 | |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 127 | {% for type in by_category["structure"] %} |
Corentin Wallez | a45561b | 2022-07-14 12:58:25 +0000 | [diff] [blame] | 128 | {% for root in type.chain_roots %} |
| 129 | // Can be chained in {{as_cType(root.name)}} |
| 130 | {% endfor %} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 131 | typedef struct {{as_cType(type.name)}} { |
Austin Eng | bffc966 | 2021-09-17 15:36:00 +0000 | [diff] [blame] | 132 | {% set Out = "Out" if type.output else "" %} |
Kai Ninomiya | 7d174a1 | 2021-09-21 17:36:27 +0000 | [diff] [blame] | 133 | {% set const = "const " if not type.output else "" %} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 134 | {% if type.extensible %} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 135 | {{API}}ChainedStruct{{Out}} {{const}}* nextInChain; |
Corentin Wallez | 2b24c3d | 2020-01-15 09:54:42 +0000 | [diff] [blame] | 136 | {% endif %} |
| 137 | {% if type.chained %} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 138 | {{API}}ChainedStruct{{Out}} chain; |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 139 | {% endif %} |
| 140 | {% for member in type.members %} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 141 | {% if member.optional %} |
| 142 | {{API}}_NULLABLE {{as_annotated_cType(member)}}; |
| 143 | {% else %} |
| 144 | {{as_annotated_cType(member)}}; |
| 145 | {% endif-%} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 146 | {% endfor %} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 147 | } {{as_cType(type.name)}} {{API}}_STRUCTURE_ATTRIBUTE; |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 148 | |
| 149 | {% endfor %} |
Brandon Jones | 58a471a | 2021-02-08 19:48:06 +0000 | [diff] [blame] | 150 | {% for typeDef in by_category["typedef"] %} |
| 151 | // {{as_cType(typeDef.name)}} is deprecated. |
| 152 | // Use {{as_cType(typeDef.type.name)}} instead. |
| 153 | typedef {{as_cType(typeDef.type.name)}} {{as_cType(typeDef.name)}}; |
| 154 | |
| 155 | {% endfor %} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 156 | #ifdef __cplusplus |
| 157 | extern "C" { |
| 158 | #endif |
| 159 | |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 160 | #if !defined({{API}}_SKIP_PROCS) |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 161 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 162 | {% for function in by_category["function"] %} |
| 163 | typedef {{as_cType(function.return_type.name)}} (*{{as_cProc(None, function.name)}})( |
| 164 | {%- for arg in function.arguments -%} |
| 165 | {% if not loop.first %}, {% endif %}{{as_annotated_cType(arg)}} |
| 166 | {%- endfor -%} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 167 | ) {{API}}_FUNCTION_ATTRIBUTE; |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 168 | {% endfor %} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 169 | |
Corentin Wallez | aca8c4a | 2019-11-22 14:02:52 +0000 | [diff] [blame] | 170 | {% for type in by_category["object"] if len(c_methods(type)) > 0 %} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 171 | // Procs of {{type.name.CamelCase()}} |
Corentin Wallez | aca8c4a | 2019-11-22 14:02:52 +0000 | [diff] [blame] | 172 | {% for method in c_methods(type) %} |
Loko Kung | cd16294 | 2023-06-01 19:03:05 +0000 | [diff] [blame] | 173 | typedef {{as_cReturnType(method.return_type)}} (*{{as_cProc(type.name, method.name)}})( |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 174 | {{-as_cType(type.name)}} {{as_varName(type.name)}} |
| 175 | {%- for arg in method.arguments -%} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 176 | ,{{" "}} |
| 177 | {%- if arg.optional %}{{API}}_NULLABLE {% endif -%} |
| 178 | {{as_annotated_cType(arg)}} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 179 | {%- endfor -%} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 180 | ) {{API}}_FUNCTION_ATTRIBUTE; |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 181 | {% endfor %} |
| 182 | |
| 183 | {% endfor %} |
Austin Eng | 643625a | 2023-08-09 00:59:33 +0000 | [diff] [blame] | 184 | |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 185 | #endif // !defined({{API}}_SKIP_PROCS) |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 186 | |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 187 | #if !defined({{API}}_SKIP_DECLARATIONS) |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 188 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 189 | {% for function in by_category["function"] %} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 190 | {{API}}_EXPORT {{as_cType(function.return_type.name)}} {{as_cMethod(None, function.name)}}( |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 191 | {%- for arg in function.arguments -%} |
Kai Ninomiya | be98f27 | 2023-09-11 20:47:26 +0000 | [diff] [blame] | 192 | {% if not loop.first %}, {% endif -%} |
| 193 | {%- if arg.optional %}{{API}}_NULLABLE {% endif -%} |
| 194 | {{as_annotated_cType(arg)}} |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 195 | {%- endfor -%} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 196 | ) {{API}}_FUNCTION_ATTRIBUTE; |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 197 | {% endfor %} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 198 | |
Corentin Wallez | aca8c4a | 2019-11-22 14:02:52 +0000 | [diff] [blame] | 199 | {% for type in by_category["object"] if len(c_methods(type)) > 0 %} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 200 | // Methods of {{type.name.CamelCase()}} |
Corentin Wallez | aca8c4a | 2019-11-22 14:02:52 +0000 | [diff] [blame] | 201 | {% for method in c_methods(type) %} |
Loko Kung | cd16294 | 2023-06-01 19:03:05 +0000 | [diff] [blame] | 202 | {{API}}_EXPORT {{as_cReturnType(method.return_type)}} {{as_cMethod(type.name, method.name)}}( |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 203 | {{-as_cType(type.name)}} {{as_varName(type.name)}} |
| 204 | {%- for arg in method.arguments -%} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 205 | ,{{" "}} |
| 206 | {%- if arg.optional %}{{API}}_NULLABLE {% endif -%} |
| 207 | {{as_annotated_cType(arg)}} |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 208 | {%- endfor -%} |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 209 | ) {{API}}_FUNCTION_ATTRIBUTE; |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 210 | {% endfor %} |
| 211 | |
| 212 | {% endfor %} |
Austin Eng | 643625a | 2023-08-09 00:59:33 +0000 | [diff] [blame] | 213 | |
Corentin Wallez | 8d45d44 | 2023-05-23 08:16:55 +0000 | [diff] [blame] | 214 | #endif // !defined({{API}}_SKIP_DECLARATIONS) |
Corentin Wallez | 2c8b5c6 | 2019-10-21 20:04:10 +0000 | [diff] [blame] | 215 | |
| 216 | #ifdef __cplusplus |
| 217 | } // extern "C" |
| 218 | #endif |
| 219 | |
fujunwei | 76bda37 | 2021-11-23 08:47:35 +0000 | [diff] [blame] | 220 | #endif // {{metadata.api.upper()}}_H_ |