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:
Corentin Wallez
2020-06-30 18:39:50 +00:00
committed by Commit Bot service account
parent 2f616dd108
commit 00d6215be9
5 changed files with 38 additions and 26 deletions

View File

@@ -44,11 +44,11 @@ namespace dawn_wire { namespace client {
}
ReservedTexture Client::ReserveTexture(WGPUDevice cDevice) {
Device* device = reinterpret_cast<Device*>(cDevice);
Device* device = FromAPI(cDevice);
ObjectAllocator<Texture>::ObjectAndSerial* allocation = TextureAllocator().New(device);
ReservedTexture result;
result.texture = reinterpret_cast<WGPUTexture>(allocation->object.get());
result.texture = ToAPI(allocation->object.get());
result.id = allocation->object->id;
result.generation = allocation->generation;
return result;