• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //* Copyright 2020 The Dawn Authors
2 //*
3 //* Licensed under the Apache License, Version 2.0 (the "License");
4 //* you may not use this file except in compliance with the License.
5 //* You may obtain a copy of the License at
6 //*
7 //*     http://www.apache.org/licenses/LICENSE-2.0
8 //*
9 //* Unless required by applicable law or agreed to in writing, software
10 //* distributed under the License is distributed on an "AS IS" BASIS,
11 //* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //* See the License for the specific language governing permissions and
13 //* limitations under the License.
14 //*
15 //*
16 //* This template itself is part of the Dawn source and follows Dawn's license
17 //* but the generated file is used for "Web API native". The template comments
18 //* using //* at the top of the file are removed during generation such that
19 //* the resulting file starts with the BSD 3-Clause comment.
20 //*
21 //*
22 // BSD 3-Clause License
23 //
24 // Copyright (c) {{metadata.copyright_year}}, "{{metadata.api}} native" developers
25 // All rights reserved.
26 //
27 // Redistribution and use in source and binary forms, with or without
28 // modification, are permitted provided that the following conditions are met:
29 //
30 // 1. Redistributions of source code must retain the above copyright notice, this
31 //    list of conditions and the following disclaimer.
32 //
33 // 2. Redistributions in binary form must reproduce the above copyright notice,
34 //    this list of conditions and the following disclaimer in the documentation
35 //    and/or other materials provided with the distribution.
36 //
37 // 3. Neither the name of the copyright holder nor the names of its
38 //    contributors may be used to endorse or promote products derived from
39 //    this software without specific prior written permission.
40 //
41 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
45 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
47 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
48 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 #ifndef {{metadata.api.upper()}}_H_
52 #define {{metadata.api.upper()}}_H_
53 
54 {% set c_prefix = metadata.c_prefix %}
55 #if defined({{c_prefix}}_SHARED_LIBRARY)
56 #    if defined(_WIN32)
57 #        if defined({{c_prefix}}_IMPLEMENTATION)
58 #            define {{c_prefix}}_EXPORT __declspec(dllexport)
59 #        else
60 #            define {{c_prefix}}_EXPORT __declspec(dllimport)
61 #        endif
62 #    else  // defined(_WIN32)
63 #        if defined({{c_prefix}}_IMPLEMENTATION)
64 #            define {{c_prefix}}_EXPORT __attribute__((visibility("default")))
65 #        else
66 #            define {{c_prefix}}_EXPORT
67 #        endif
68 #    endif  // defined(_WIN32)
69 #else       // defined({{c_prefix}}_SHARED_LIBRARY)
70 #    define {{c_prefix}}_EXPORT
71 #endif  // defined({{c_prefix}}_SHARED_LIBRARY)
72 
73 #include <stdint.h>
74 #include <stddef.h>
75 #include <stdbool.h>
76 
77 {% for constant in by_category["constant"] %}
78     #define {{c_prefix}}_{{constant.name.SNAKE_CASE()}} {{constant.value}}
79 {% endfor %}
80 
81 typedef uint32_t {{c_prefix}}Flags;
82 
83 {% for type in by_category["object"] %}
84     typedef struct {{as_cType(type.name)}}Impl* {{as_cType(type.name)}};
85 {% endfor %}
86 
87 {% for type in by_category["enum"] + by_category["bitmask"] %}
88     typedef enum {{as_cType(type.name)}} {
89         {% for value in type.values %}
90             {{as_cEnum(type.name, value.name)}} = 0x{{format(value.value, "08X")}},
91         {% endfor %}
92         {{as_cEnum(type.name, Name("force32"))}} = 0x7FFFFFFF
93     } {{as_cType(type.name)}};
94     {% if type.category == "bitmask" %}
95         typedef {{c_prefix}}Flags {{as_cType(type.name)}}Flags;
96     {% endif %}
97 
98 {% endfor -%}
99 
100 typedef struct {{c_prefix}}ChainedStruct {
101     struct {{c_prefix}}ChainedStruct const * next;
102     {{c_prefix}}SType sType;
103 } {{c_prefix}}ChainedStruct;
104 
105 typedef struct {{c_prefix}}ChainedStructOut {
106     struct {{c_prefix}}ChainedStructOut * next;
107     {{c_prefix}}SType sType;
108 } {{c_prefix}}ChainedStructOut;
109 
110 {% for type in by_category["structure"] %}
111     typedef struct {{as_cType(type.name)}} {
112         {% set Out = "Out" if type.output else "" %}
113         {% set const = "const " if not type.output else "" %}
114         {% if type.extensible %}
115             {{c_prefix}}ChainedStruct{{Out}} {{const}}* nextInChain;
116         {% endif %}
117         {% if type.chained %}
118             {{c_prefix}}ChainedStruct{{Out}} chain;
119         {% endif %}
120         {% for member in type.members %}
121             {{as_annotated_cType(member)}};
122         {% endfor %}
123     } {{as_cType(type.name)}};
124 
125 {% endfor %}
126 {% for typeDef in by_category["typedef"] %}
127     // {{as_cType(typeDef.name)}} is deprecated.
128     // Use {{as_cType(typeDef.type.name)}} instead.
129     typedef {{as_cType(typeDef.type.name)}} {{as_cType(typeDef.name)}};
130 
131 {% endfor %}
132 #ifdef __cplusplus
133 extern "C" {
134 #endif
135 
136 {% for type in by_category["function pointer"] %}
137     typedef {{as_cType(type.return_type.name)}} (*{{as_cType(type.name)}})(
138         {%- for arg in type.arguments -%}
139             {% if not loop.first %}, {% endif %}{{as_annotated_cType(arg)}}
140         {%- endfor -%}
141     );
142 {% endfor %}
143 
144 #if !defined({{c_prefix}}_SKIP_PROCS)
145 
146 {% for function in by_category["function"] %}
147     typedef {{as_cType(function.return_type.name)}} (*{{as_cProc(None, function.name)}})(
148             {%- for arg in function.arguments -%}
149                 {% if not loop.first %}, {% endif %}{{as_annotated_cType(arg)}}
150             {%- endfor -%}
151         );
152 {% endfor %}
153 
154 {% for type in by_category["object"] if len(c_methods(type)) > 0 %}
155     // Procs of {{type.name.CamelCase()}}
156     {% for method in c_methods(type) %}
157         typedef {{as_cType(method.return_type.name)}} (*{{as_cProc(type.name, method.name)}})(
158             {{-as_cType(type.name)}} {{as_varName(type.name)}}
159             {%- for arg in method.arguments -%}
160                 , {{as_annotated_cType(arg)}}
161             {%- endfor -%}
162         );
163     {% endfor %}
164 
165 {% endfor %}
166 #endif  // !defined({{c_prefix}}_SKIP_PROCS)
167 
168 #if !defined({{c_prefix}}_SKIP_DECLARATIONS)
169 
170 {% for function in by_category["function"] %}
171     {{c_prefix}}_EXPORT {{as_cType(function.return_type.name)}} {{as_cMethod(None, function.name)}}(
172             {%- for arg in function.arguments -%}
173                 {% if not loop.first %}, {% endif %}{{as_annotated_cType(arg)}}
174             {%- endfor -%}
175         );
176 {% endfor %}
177 
178 {% for type in by_category["object"] if len(c_methods(type)) > 0 %}
179     // Methods of {{type.name.CamelCase()}}
180     {% for method in c_methods(type) %}
181         {{c_prefix}}_EXPORT {{as_cType(method.return_type.name)}} {{as_cMethod(type.name, method.name)}}(
182             {{-as_cType(type.name)}} {{as_varName(type.name)}}
183             {%- for arg in method.arguments -%}
184                 , {{as_annotated_cType(arg)}}
185             {%- endfor -%}
186         );
187     {% endfor %}
188 
189 {% endfor %}
190 #endif  // !defined({{c_prefix}}_SKIP_DECLARATIONS)
191 
192 #ifdef __cplusplus
193 } // extern "C"
194 #endif
195 
196 #endif // {{metadata.api.upper()}}_H_
197