mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-09 05:27:49 +00:00
dawn_wire/client: Add ToAPI and FromAPI helpers.
In the client code, we often need to translate between WGPUObject (the API type) to Object* (the internal client type). This added a bunch of reinterpret_casts that make the code less readable and more fragile. This CL adds FromAPI and ToAPI helpers in the autogenerated ApiObjects_autogen.h header, that convert between API and internal types in a type-safe way. Bug: dawn:445 Change-Id: Ia1bf624f0315ced496b95cb660adf88abd916d71 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24063 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Stephen White <senorblanco@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
2f616dd108
commit
00d6215be9
@@ -16,10 +16,24 @@
|
||||
#define DAWNWIRE_CLIENT_APIOBJECTS_AUTOGEN_H_
|
||||
|
||||
namespace dawn_wire { namespace client {
|
||||
{% for type in by_category["object"] if not type.name.CamelCase() in client_special_objects %}
|
||||
struct {{type.name.CamelCase()}} : ObjectBase {
|
||||
using ObjectBase::ObjectBase;
|
||||
};
|
||||
|
||||
{% for type in by_category["object"] %}
|
||||
{% set Type = type.name.CamelCase() %}
|
||||
{% if type.name.CamelCase() in client_special_objects %}
|
||||
class {{Type}};
|
||||
{% else %}
|
||||
struct {{type.name.CamelCase()}} : ObjectBase {
|
||||
using ObjectBase::ObjectBase;
|
||||
};
|
||||
{% endif %}
|
||||
|
||||
inline {{Type}}* FromAPI(WGPU{{Type}} obj) {
|
||||
return reinterpret_cast<{{Type}}*>(obj);
|
||||
}
|
||||
inline WGPU{{Type}} ToAPI({{Type}}* obj) {
|
||||
return reinterpret_cast<WGPU{{Type}}>(obj);
|
||||
}
|
||||
|
||||
{% endfor %}
|
||||
}} // namespace dawn_wire::client
|
||||
|
||||
|
||||
Reference in New Issue
Block a user