blob: 37282dd121e84c62931c02810e37d92907b45762 [file] [log] [blame]
Austin Engcc2516a2023-10-17 20:57:54 +00001//* Copyright 2020 The Dawn & Tint Authors
Shrek Shaod7304d12021-12-14 01:06:15 +00002//*
Austin Engcc2516a2023-10-17 20:57:54 +00003//* Redistribution and use in source and binary forms, with or without
4//* modification, are permitted provided that the following conditions are met:
Shrek Shaod7304d12021-12-14 01:06:15 +00005//*
Austin Engcc2516a2023-10-17 20:57:54 +00006//* 1. Redistributions of source code must retain the above copyright notice, this
7//* list of conditions and the following disclaimer.
Shrek Shaod7304d12021-12-14 01:06:15 +00008//*
Austin Engcc2516a2023-10-17 20:57:54 +00009//* 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 Wallez1bf31672020-01-15 15:39:12 +000012//*
Austin Engcc2516a2023-10-17 20:57:54 +000013//* 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 Wallez1bf31672020-01-15 15:39:12 +000016//*
Austin Engcc2516a2023-10-17 20:57:54 +000017//* 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 Wallez1bf31672020-01-15 15:39:12 +000027//*
28//*
Shrek Shaod7304d12021-12-14 01:06:15 +000029{% include 'BSD_LICENSE' %}
Shrek Shao71a363b2022-02-09 19:42:51 +000030{% 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 %}
fujunwei76bda372021-11-23 08:47:35 +000035#ifndef {{metadata.api.upper()}}_H_
36#define {{metadata.api.upper()}}_H_
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000037
Corentin Wallez8d45d442023-05-23 08:16:55 +000038{% set API = metadata.c_prefix %}
39#if defined({{API}}_SHARED_LIBRARY)
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000040# if defined(_WIN32)
Corentin Wallez8d45d442023-05-23 08:16:55 +000041# if defined({{API}}_IMPLEMENTATION)
42# define {{API}}_EXPORT __declspec(dllexport)
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000043# else
Corentin Wallez8d45d442023-05-23 08:16:55 +000044# define {{API}}_EXPORT __declspec(dllimport)
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000045# endif
46# else // defined(_WIN32)
Corentin Wallez8d45d442023-05-23 08:16:55 +000047# if defined({{API}}_IMPLEMENTATION)
48# define {{API}}_EXPORT __attribute__((visibility("default")))
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000049# else
Corentin Wallez8d45d442023-05-23 08:16:55 +000050# define {{API}}_EXPORT
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000051# endif
52# endif // defined(_WIN32)
Corentin Wallez8d45d442023-05-23 08:16:55 +000053#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 Wallez2c8b5c62019-10-21 20:04:10 +000072
73#include <stdint.h>
74#include <stddef.h>
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000075
fujunwei4e876902021-11-25 08:44:01 +000076{% for constant in by_category["constant"] %}
Corentin Wallez8d45d442023-05-23 08:16:55 +000077 #define {{API}}_{{constant.name.SNAKE_CASE()}} {{constant.value}}
fujunwei4e876902021-11-25 08:44:01 +000078{% endfor %}
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000079
Corentin Wallez8d45d442023-05-23 08:16:55 +000080typedef uint32_t {{API}}Flags;
Loko Kung440a30c2023-08-04 23:41:21 +000081typedef uint32_t {{API}}Bool;
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000082
83{% for type in by_category["object"] %}
Corentin Wallez8d45d442023-05-23 08:16:55 +000084 typedef struct {{as_cType(type.name)}}Impl* {{as_cType(type.name)}} {{API}}_OBJECT_ATTRIBUTE;
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000085{% endfor %}
86
Brandon Jones112b7fd2023-05-17 01:52:30 +000087// Structure forward declarations
88{% for type in by_category["structure"] %}
89 struct {{as_cType(type.name)}};
90{% endfor %}
91
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000092{% 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 Wallez8d45d442023-05-23 08:16:55 +000098 } {{as_cType(type.name)}} {{API}}_ENUM_ATTRIBUTE;
Corentin Wallez2c8b5c62019-10-21 20:04:10 +000099 {% if type.category == "bitmask" %}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000100 typedef {{API}}Flags {{as_cType(type.name)}}Flags {{API}}_ENUM_ATTRIBUTE;
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000101 {% endif %}
102
Kai Ninomiya930e9182021-09-17 19:44:43 +0000103{% endfor -%}
Brandon Jones112b7fd2023-05-17 01:52:30 +0000104{% 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 Wallez8d45d442023-05-23 08:16:55 +0000110 {% if not loop.first %}, {% endif %}
111 {% if arg.type.category == "structure" %}struct {% endif %}{{as_annotated_cType(arg)}}
Brandon Jones112b7fd2023-05-17 01:52:30 +0000112 {%- endfor -%}
113 {%- endif -%}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000114 ) {{API}}_FUNCTION_ATTRIBUTE;
Brandon Jones112b7fd2023-05-17 01:52:30 +0000115{% endfor %}
116
Corentin Wallez8d45d442023-05-23 08:16:55 +0000117typedef struct {{API}}ChainedStruct {
118 struct {{API}}ChainedStruct const * next;
119 {{API}}SType sType;
120} {{API}}ChainedStruct {{API}}_STRUCTURE_ATTRIBUTE;
Corentin Wallez2b24c3d2020-01-15 09:54:42 +0000121
Corentin Wallez8d45d442023-05-23 08:16:55 +0000122typedef struct {{API}}ChainedStructOut {
123 struct {{API}}ChainedStructOut * next;
124 {{API}}SType sType;
125} {{API}}ChainedStructOut {{API}}_STRUCTURE_ATTRIBUTE;
Austin Engbffc9662021-09-17 15:36:00 +0000126
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000127{% for type in by_category["structure"] %}
Corentin Walleza45561b2022-07-14 12:58:25 +0000128 {% for root in type.chain_roots %}
129 // Can be chained in {{as_cType(root.name)}}
130 {% endfor %}
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000131 typedef struct {{as_cType(type.name)}} {
Austin Engbffc9662021-09-17 15:36:00 +0000132 {% set Out = "Out" if type.output else "" %}
Kai Ninomiya7d174a12021-09-21 17:36:27 +0000133 {% set const = "const " if not type.output else "" %}
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000134 {% if type.extensible %}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000135 {{API}}ChainedStruct{{Out}} {{const}}* nextInChain;
Corentin Wallez2b24c3d2020-01-15 09:54:42 +0000136 {% endif %}
137 {% if type.chained %}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000138 {{API}}ChainedStruct{{Out}} chain;
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000139 {% endif %}
140 {% for member in type.members %}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000141 {% if member.optional %}
142 {{API}}_NULLABLE {{as_annotated_cType(member)}};
143 {% else %}
144 {{as_annotated_cType(member)}};
145 {% endif-%}
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000146 {% endfor %}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000147 } {{as_cType(type.name)}} {{API}}_STRUCTURE_ATTRIBUTE;
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000148
149{% endfor %}
Brandon Jones58a471a2021-02-08 19:48:06 +0000150{% 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 Wallez2c8b5c62019-10-21 20:04:10 +0000156#ifdef __cplusplus
157extern "C" {
158#endif
159
Corentin Wallez8d45d442023-05-23 08:16:55 +0000160#if !defined({{API}}_SKIP_PROCS)
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000161
fujunwei23f71622021-12-02 07:41:21 +0000162{% 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 Wallez8d45d442023-05-23 08:16:55 +0000167 ) {{API}}_FUNCTION_ATTRIBUTE;
fujunwei23f71622021-12-02 07:41:21 +0000168{% endfor %}
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000169
Corentin Wallezaca8c4a2019-11-22 14:02:52 +0000170{% for type in by_category["object"] if len(c_methods(type)) > 0 %}
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000171 // Procs of {{type.name.CamelCase()}}
Corentin Wallezaca8c4a2019-11-22 14:02:52 +0000172 {% for method in c_methods(type) %}
Loko Kungcd162942023-06-01 19:03:05 +0000173 typedef {{as_cReturnType(method.return_type)}} (*{{as_cProc(type.name, method.name)}})(
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000174 {{-as_cType(type.name)}} {{as_varName(type.name)}}
175 {%- for arg in method.arguments -%}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000176 ,{{" "}}
177 {%- if arg.optional %}{{API}}_NULLABLE {% endif -%}
178 {{as_annotated_cType(arg)}}
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000179 {%- endfor -%}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000180 ) {{API}}_FUNCTION_ATTRIBUTE;
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000181 {% endfor %}
182
183{% endfor %}
Austin Eng643625a2023-08-09 00:59:33 +0000184
Corentin Wallez8d45d442023-05-23 08:16:55 +0000185#endif // !defined({{API}}_SKIP_PROCS)
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000186
Corentin Wallez8d45d442023-05-23 08:16:55 +0000187#if !defined({{API}}_SKIP_DECLARATIONS)
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000188
fujunwei23f71622021-12-02 07:41:21 +0000189{% for function in by_category["function"] %}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000190 {{API}}_EXPORT {{as_cType(function.return_type.name)}} {{as_cMethod(None, function.name)}}(
fujunwei23f71622021-12-02 07:41:21 +0000191 {%- for arg in function.arguments -%}
Kai Ninomiyabe98f272023-09-11 20:47:26 +0000192 {% if not loop.first %}, {% endif -%}
193 {%- if arg.optional %}{{API}}_NULLABLE {% endif -%}
194 {{as_annotated_cType(arg)}}
fujunwei23f71622021-12-02 07:41:21 +0000195 {%- endfor -%}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000196 ) {{API}}_FUNCTION_ATTRIBUTE;
fujunwei23f71622021-12-02 07:41:21 +0000197{% endfor %}
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000198
Corentin Wallezaca8c4a2019-11-22 14:02:52 +0000199{% for type in by_category["object"] if len(c_methods(type)) > 0 %}
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000200 // Methods of {{type.name.CamelCase()}}
Corentin Wallezaca8c4a2019-11-22 14:02:52 +0000201 {% for method in c_methods(type) %}
Loko Kungcd162942023-06-01 19:03:05 +0000202 {{API}}_EXPORT {{as_cReturnType(method.return_type)}} {{as_cMethod(type.name, method.name)}}(
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000203 {{-as_cType(type.name)}} {{as_varName(type.name)}}
204 {%- for arg in method.arguments -%}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000205 ,{{" "}}
206 {%- if arg.optional %}{{API}}_NULLABLE {% endif -%}
207 {{as_annotated_cType(arg)}}
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000208 {%- endfor -%}
Corentin Wallez8d45d442023-05-23 08:16:55 +0000209 ) {{API}}_FUNCTION_ATTRIBUTE;
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000210 {% endfor %}
211
212{% endfor %}
Austin Eng643625a2023-08-09 00:59:33 +0000213
Corentin Wallez8d45d442023-05-23 08:16:55 +0000214#endif // !defined({{API}}_SKIP_DECLARATIONS)
Corentin Wallez2c8b5c62019-10-21 20:04:10 +0000215
216#ifdef __cplusplus
217} // extern "C"
218#endif
219
fujunwei76bda372021-11-23 08:47:35 +0000220#endif // {{metadata.api.upper()}}_H_