1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef WEBGPU_SERIALIZE_H_
7 #define WEBGPU_SERIALIZE_H_
8 
9 #include "WebGPUTypes.h"
10 #include "ipc/EnumSerializer.h"
11 #include "ipc/IPCMessageUtils.h"
12 #include "mozilla/dom/WebGPUBinding.h"
13 #include "mozilla/webgpu/ffi/wgpu.h"
14 
15 namespace IPC {
16 
17 #define DEFINE_IPC_SERIALIZER_ENUM_GUARD(something, guard) \
18   template <>                                              \
19   struct ParamTraits<something>                            \
20       : public ContiguousEnumSerializer<something, something(0), guard> {}
21 
22 #define DEFINE_IPC_SERIALIZER_DOM_ENUM(something) \
23   DEFINE_IPC_SERIALIZER_ENUM_GUARD(something, something::EndGuard_)
24 #define DEFINE_IPC_SERIALIZER_FFI_ENUM(something) \
25   DEFINE_IPC_SERIALIZER_ENUM_GUARD(something, something##_Sentinel)
26 
27 DEFINE_IPC_SERIALIZER_DOM_ENUM(mozilla::dom::GPUPowerPreference);
28 
29 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUHostMap);
30 
31 DEFINE_IPC_SERIALIZER_WITHOUT_FIELDS(mozilla::dom::GPUCommandBufferDescriptor);
32 
33 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::GPURequestAdapterOptions,
34                                   mPowerPreference, mForceFallbackAdapter);
35 
36 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ScopedError, operationError,
37                                   validationMessage);
38 
39 #undef DEFINE_IPC_SERIALIZER_FFI_ENUM
40 #undef DEFINE_IPC_SERIALIZER_DOM_ENUM
41 #undef DEFINE_IPC_SERIALIZER_ENUM_GUARD
42 
43 }  // namespace IPC
44 #endif  // WEBGPU_SERIALIZE_H_
45