dawn_wire::server: Simplify ForwardToServer usage with C++17

This uses template parameter type deduction to pass the member function
pointer and then extract the types that compose it. Which means that the
member function pointer only needs to be written once.

The order of arguments of the Server::On*Callback methods is changed to
put the userdata first. This helps make template type deduction simpler.

Bug: dawn:824
Change-Id: I4e2bc33dfd52a11620dea51b40508eca6c878d72
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/75071
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez
2022-01-06 09:09:49 +00:00
committed by Dawn LUCI CQ
parent 2994d2e7b9
commit 31f12242da
7 changed files with 75 additions and 111 deletions

View File

@@ -80,7 +80,7 @@ namespace dawn_wire { namespace server {
// client does the default size computation, we should always have a valid actual size here
// in server. All other invalid actual size can be caught by dawn native side validation.
if (offset64 > std::numeric_limits<size_t>::max() || size64 >= WGPU_WHOLE_MAP_SIZE) {
OnBufferMapAsyncCallback(WGPUBufferMapAsyncStatus_Error, userdata.get());
OnBufferMapAsyncCallback(userdata.get(), WGPUBufferMapAsyncStatus_Error);
return true;
}
@@ -90,11 +90,9 @@ namespace dawn_wire { namespace server {
userdata->offset = offset;
userdata->size = size;
mProcs.bufferMapAsync(
buffer->handle, mode, offset, size,
ForwardToServer<decltype(
&Server::OnBufferMapAsyncCallback)>::Func<&Server::OnBufferMapAsyncCallback>(),
userdata.release());
mProcs.bufferMapAsync(buffer->handle, mode, offset, size,
ForwardToServer<&Server::OnBufferMapAsyncCallback>,
userdata.release());
return true;
}
@@ -227,7 +225,7 @@ namespace dawn_wire { namespace server {
static_cast<size_t>(offset), static_cast<size_t>(size));
}
void Server::OnBufferMapAsyncCallback(WGPUBufferMapAsyncStatus status, MapUserdata* data) {
void Server::OnBufferMapAsyncCallback(MapUserdata* data, WGPUBufferMapAsyncStatus status) {
// Skip sending the callback if the buffer has already been destroyed.
auto* bufferData = BufferObjects().Get(data->buffer.id);
if (bufferData == nullptr || bufferData->generation != data->buffer.generation) {