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/. */
7 #include "mozilla/dom/WebGPUBinding.h"
8 #include "mozilla/webgpu/ffi/wgpu.h"
9 #include "mozilla/webgpu/WebGPUTypes.h"
11 namespace mozilla::webgpu
{
14 void ConvertToExtent3D(const E
& aExtent
, ffi::WGPUExtent3d
* aExtentFFI
) {
16 if (aExtent
.IsRangeEnforcedUnsignedLongSequence()) {
17 const auto& seq
= aExtent
.GetAsRangeEnforcedUnsignedLongSequence();
18 aExtentFFI
->width
= seq
.Length() > 0 ? seq
[0] : 0;
19 aExtentFFI
->height
= seq
.Length() > 1 ? seq
[1] : 1;
20 aExtentFFI
->depth_or_array_layers
= seq
.Length() > 2 ? seq
[2] : 1;
21 } else if (aExtent
.IsGPUExtent3DDict()) {
22 const auto& dict
= aExtent
.GetAsGPUExtent3DDict();
23 aExtentFFI
->width
= dict
.mWidth
;
24 aExtentFFI
->height
= dict
.mHeight
;
25 aExtentFFI
->depth_or_array_layers
= dict
.mDepthOrArrayLayers
;
27 MOZ_CRASH("Unexpected extent type");
31 void ConvertExtent3DToFFI(const dom::GPUExtent3D
& aExtent
,
32 ffi::WGPUExtent3d
* aExtentFFI
) {
33 ConvertToExtent3D(aExtent
, aExtentFFI
);
36 void ConvertExtent3DToFFI(const dom::OwningGPUExtent3D
& aExtent
,
37 ffi::WGPUExtent3d
* aExtentFFI
) {
38 ConvertToExtent3D(aExtent
, aExtentFFI
);
41 ffi::WGPUExtent3d
ConvertExtent(const dom::GPUExtent3D
& aExtent
) {
42 ffi::WGPUExtent3d extent
= {};
43 ConvertToExtent3D(aExtent
, &extent
);
47 ffi::WGPUExtent3d
ConvertExtent(const dom::OwningGPUExtent3D
& aExtent
) {
48 ffi::WGPUExtent3d extent
= {};
49 ConvertToExtent3D(aExtent
, &extent
);
53 } // namespace mozilla::webgpu