1 //* Copyright 2017 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 #ifndef DAWN_DAWN_H_ 16 #define DAWN_DAWN_H_ 17 18 #include "dawn/dawn_export.h" 19 20 #include <stdint.h> 21 #include <stddef.h> 22 #include <stdbool.h> 23 24 const uint64_t DAWN_WHOLE_SIZE = 0xffffffffffffffffULL; // UINT64_MAX 25 26 {% for type in by_category["object"] %} 27 typedef struct {{as_cType(type.name)}}Impl* {{as_cType(type.name)}}; 28 {% endfor %} 29 30 {% for type in by_category["enum"] + by_category["bitmask"] %} 31 typedef enum { 32 {% for value in type.values %} 33 {{as_cEnum(type.name, value.name)}} = 0x{{format(value.value, "08X")}}, 34 {% endfor %} 35 {{as_cEnum(type.name, Name("force32"))}} = 0x7FFFFFFF 36 } {{as_cType(type.name)}}; 37 38 {% endfor %} 39 40 {% for type in by_category["structure"] %} 41 typedef struct {{as_cType(type.name)}} { 42 {% if type.extensible %} 43 const void* nextInChain; 44 {% endif %} 45 {% for member in type.members %} 46 {{as_annotated_cType(member)}}; 47 {% endfor %} 48 } {{as_cType(type.name)}}; 49 50 {% endfor %} 51 52 // Custom types depending on the target language 53 typedef void (*DawnDeviceErrorCallback)(const char* message, void* userdata); 54 typedef void (*DawnBufferCreateMappedCallback)(DawnBufferMapAsyncStatus status, 55 DawnCreateBufferMappedResult result, 56 void* userdata); 57 typedef void (*DawnBufferMapReadCallback)(DawnBufferMapAsyncStatus status, 58 const void* data, 59 uint64_t dataLength, 60 void* userdata); 61 typedef void (*DawnBufferMapWriteCallback)(DawnBufferMapAsyncStatus status, 62 void* data, 63 uint64_t dataLength, 64 void* userdata); 65 typedef void (*DawnFenceOnCompletionCallback)(DawnFenceCompletionStatus status, void* userdata); 66 67 #ifdef __cplusplus 68 extern "C" { 69 #endif 70 71 {% for type in by_category["object"] %} 72 // Procs of {{type.name.CamelCase()}} 73 {% for method in native_methods(type) %} 74 typedef {{as_cType(method.return_type.name)}} (*{{as_cProc(type.name, method.name)}})( 75 {{-as_cType(type.name)}} {{as_varName(type.name)}} 76 {%- for arg in method.arguments -%} 77 , {{as_annotated_cType(arg)}} 78 {%- endfor -%} 79 ); 80 {% endfor %} 81 82 {% endfor %} 83 84 struct DawnProcTable_s { 85 {% for type in by_category["object"] %} 86 {% for method in native_methods(type) %} 87 {{as_cProc(type.name, method.name)}} {{as_varName(type.name, method.name)}}; 88 {% endfor %} 89 90 {% endfor %} 91 }; 92 typedef struct DawnProcTable_s DawnProcTable; 93 94 // Stuff below is for convenience and will forward calls to a static DawnProcTable. 95 96 // Set which DawnProcTable will be used 97 DAWN_EXPORT void dawnSetProcs(const DawnProcTable* procs); 98 99 {% for type in by_category["object"] %} 100 // Methods of {{type.name.CamelCase()}} 101 {% for method in native_methods(type) %} 102 DAWN_EXPORT {{as_cType(method.return_type.name)}} {{as_cMethod(type.name, method.name)}}( 103 {{-as_cType(type.name)}} {{as_varName(type.name)}} 104 {%- for arg in method.arguments -%} 105 , {{as_annotated_cType(arg)}} 106 {%- endfor -%} 107 ); 108 {% endfor %} 109 110 {% endfor %} 111 112 #ifdef __cplusplus 113 } // extern "C" 114 #endif 115 116 #endif // DAWN_DAWN_H_ 117