2018-07-18 09:40:26 +00:00
|
|
|
//* Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//*
|
|
|
|
//* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
//* you may not use this file except in compliance with the License.
|
|
|
|
//* You may obtain a copy of the License at
|
|
|
|
//*
|
|
|
|
//* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//*
|
|
|
|
//* Unless required by applicable law or agreed to in writing, software
|
|
|
|
//* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//* See the License for the specific language governing permissions and
|
|
|
|
//* limitations under the License.
|
|
|
|
|
2019-10-28 22:15:47 +00:00
|
|
|
#include "mock_webgpu.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2019-03-28 10:44:41 +00:00
|
|
|
using namespace testing;
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
namespace {
|
|
|
|
{% for type in by_category["object"] %}
|
2019-11-22 14:02:52 +00:00
|
|
|
{% for method in c_methods(type) if len(method.arguments) < 10 %}
|
2017-04-20 18:38:20 +00:00
|
|
|
{{as_cType(method.return_type.name)}} Forward{{as_MethodSuffix(type.name, method.name)}}(
|
|
|
|
{{-as_cType(type.name)}} self
|
|
|
|
{%- for arg in method.arguments -%}
|
|
|
|
, {{as_annotated_cType(arg)}}
|
|
|
|
{%- endfor -%}
|
|
|
|
) {
|
2017-05-16 20:05:51 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
return object->procs->{{as_MethodSuffix(type.name, method.name)}}(self
|
2017-04-20 18:38:20 +00:00
|
|
|
{%- for arg in method.arguments -%}
|
|
|
|
, {{as_varName(arg.name)}}
|
|
|
|
{%- endfor -%}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcTableAsClass::~ProcTableAsClass() {
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:15:47 +00:00
|
|
|
void ProcTableAsClass::GetProcTableAndDevice(DawnProcTable* table, WGPUDevice* device) {
|
2017-04-20 18:38:20 +00:00
|
|
|
*device = GetNewDevice();
|
|
|
|
|
|
|
|
{% for type in by_category["object"] %}
|
2019-11-22 14:02:52 +00:00
|
|
|
{% for method in c_methods(type) if len(method.arguments) < 10 %}
|
2017-04-20 18:38:20 +00:00
|
|
|
table->{{as_varName(type.name, method.name)}} = reinterpret_cast<{{as_cProc(type.name, method.name)}}>(Forward{{as_MethodSuffix(type.name, method.name)}});
|
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:15:47 +00:00
|
|
|
void ProcTableAsClass::DeviceSetUncapturedErrorCallback(WGPUDevice self,
|
|
|
|
WGPUErrorCallback callback,
|
|
|
|
void* userdata) {
|
2017-05-16 20:05:51 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->deviceErrorCallback = callback;
|
2019-12-18 18:59:20 +00:00
|
|
|
object->userdata = userdata;
|
2017-05-16 20:05:51 +00:00
|
|
|
|
2019-08-27 21:43:56 +00:00
|
|
|
OnDeviceSetUncapturedErrorCallback(self, callback, userdata);
|
2017-05-16 20:05:51 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 18:59:20 +00:00
|
|
|
void ProcTableAsClass::DeviceSetDeviceLostCallback(WGPUDevice self,
|
|
|
|
WGPUDeviceLostCallback callback,
|
|
|
|
void* userdata) {
|
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->deviceLostCallback = callback;
|
|
|
|
object->userdata = userdata;
|
|
|
|
|
|
|
|
OnDeviceSetDeviceLostCallback(self, callback, userdata);
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:15:47 +00:00
|
|
|
bool ProcTableAsClass::DevicePopErrorScope(WGPUDevice self,
|
|
|
|
WGPUErrorCallback callback,
|
|
|
|
void* userdata) {
|
2019-09-04 22:54:03 +00:00
|
|
|
return OnDevicePopErrorScopeCallback(self, callback, userdata);
|
|
|
|
}
|
|
|
|
|
2020-07-14 12:30:14 +00:00
|
|
|
void ProcTableAsClass::BufferMapAsync(WGPUBuffer self,
|
|
|
|
WGPUMapModeFlags mode,
|
|
|
|
size_t offset,
|
|
|
|
size_t size,
|
|
|
|
WGPUBufferMapCallback callback,
|
|
|
|
void* userdata) {
|
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->mapAsyncCallback = callback;
|
|
|
|
object->userdata = userdata;
|
|
|
|
|
|
|
|
OnBufferMapAsyncCallback(self, callback, userdata);
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:15:47 +00:00
|
|
|
void ProcTableAsClass::FenceOnCompletion(WGPUFence self,
|
2018-12-03 16:57:34 +00:00
|
|
|
uint64_t value,
|
2019-10-28 22:15:47 +00:00
|
|
|
WGPUFenceOnCompletionCallback callback,
|
2019-05-29 13:03:50 +00:00
|
|
|
void* userdata) {
|
2018-12-03 16:57:34 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->fenceOnCompletionCallback = callback;
|
2019-12-18 18:59:20 +00:00
|
|
|
object->userdata = userdata;
|
2018-12-03 16:57:34 +00:00
|
|
|
|
|
|
|
OnFenceOnCompletionCallback(self, value, callback, userdata);
|
|
|
|
}
|
|
|
|
|
2020-10-19 01:56:08 +00:00
|
|
|
void ProcTableAsClass::DeviceCreateReadyComputePipeline(
|
|
|
|
WGPUDevice self,
|
|
|
|
WGPUComputePipelineDescriptor const * descriptor,
|
|
|
|
WGPUCreateReadyComputePipelineCallback callback,
|
|
|
|
void* userdata) {
|
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->createReadyComputePipelineCallback = callback;
|
|
|
|
object->userdata = userdata;
|
|
|
|
|
|
|
|
OnDeviceCreateReadyComputePipelineCallback(self, descriptor, callback, userdata);
|
|
|
|
}
|
|
|
|
|
2020-10-21 04:37:41 +00:00
|
|
|
void ProcTableAsClass::DeviceCreateReadyRenderPipeline(
|
|
|
|
WGPUDevice self,
|
|
|
|
WGPURenderPipelineDescriptor const * descriptor,
|
|
|
|
WGPUCreateReadyRenderPipelineCallback callback,
|
|
|
|
void* userdata) {
|
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->createReadyRenderPipelineCallback = callback;
|
|
|
|
object->userdata = userdata;
|
|
|
|
|
|
|
|
OnDeviceCreateReadyRenderPipelineCallback(self, descriptor, callback, userdata);
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:15:47 +00:00
|
|
|
void ProcTableAsClass::CallDeviceErrorCallback(WGPUDevice device,
|
|
|
|
WGPUErrorType type,
|
|
|
|
const char* message) {
|
2017-05-17 15:16:00 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(device);
|
2019-12-18 18:59:20 +00:00
|
|
|
object->deviceErrorCallback(type, message, object->userdata);
|
2017-05-17 15:16:00 +00:00
|
|
|
}
|
2019-12-18 18:59:20 +00:00
|
|
|
|
|
|
|
void ProcTableAsClass::CallDeviceLostCallback(WGPUDevice device, const char* message) {
|
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(device);
|
|
|
|
object->deviceLostCallback(message, object->userdata);
|
|
|
|
}
|
|
|
|
|
2020-07-14 12:30:14 +00:00
|
|
|
void ProcTableAsClass::CallMapAsyncCallback(WGPUBuffer buffer, WGPUBufferMapAsyncStatus status) {
|
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(buffer);
|
|
|
|
object->mapAsyncCallback(status, object->userdata);
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:15:47 +00:00
|
|
|
void ProcTableAsClass::CallFenceOnCompletionCallback(WGPUFence fence,
|
|
|
|
WGPUFenceCompletionStatus status) {
|
2018-12-03 16:57:34 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(fence);
|
2019-12-18 18:59:20 +00:00
|
|
|
object->fenceOnCompletionCallback(status, object->userdata);
|
2018-12-03 16:57:34 +00:00
|
|
|
}
|
|
|
|
|
2020-10-19 01:56:08 +00:00
|
|
|
void ProcTableAsClass::CallDeviceCreateReadyComputePipelineCallback(WGPUDevice device,
|
|
|
|
WGPUCreateReadyPipelineStatus status,
|
|
|
|
WGPUComputePipeline pipeline,
|
|
|
|
const char* message) {
|
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(device);
|
|
|
|
object->createReadyComputePipelineCallback(status, pipeline, message, object->userdata);
|
|
|
|
}
|
|
|
|
|
2020-10-21 04:37:41 +00:00
|
|
|
void ProcTableAsClass::CallDeviceCreateReadyRenderPipelineCallback(WGPUDevice device,
|
|
|
|
WGPUCreateReadyPipelineStatus status,
|
|
|
|
WGPURenderPipeline pipeline,
|
|
|
|
const char* message) {
|
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(device);
|
|
|
|
object->createReadyRenderPipelineCallback(status, pipeline, message, object->userdata);
|
|
|
|
}
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
{{as_cType(type.name)}} ProcTableAsClass::GetNew{{type.name.CamelCase()}}() {
|
2017-11-23 21:04:26 +00:00
|
|
|
mObjects.emplace_back(new Object);
|
|
|
|
mObjects.back()->procs = this;
|
|
|
|
return reinterpret_cast<{{as_cType(type.name)}}>(mObjects.back().get());
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
{% endfor %}
|
2018-08-22 13:37:29 +00:00
|
|
|
|
2020-04-16 18:08:23 +00:00
|
|
|
MockProcTable::MockProcTable() = default;
|
|
|
|
|
|
|
|
MockProcTable::~MockProcTable() = default;
|
2019-03-28 10:44:41 +00:00
|
|
|
|
|
|
|
void MockProcTable::IgnoreAllReleaseCalls() {
|
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
EXPECT_CALL(*this, {{as_MethodSuffix(type.name, Name("release"))}}(_)).Times(AnyNumber());
|
|
|
|
{% endfor %}
|
|
|
|
}
|