Bug 1856663 - Add more chunks for Android mochitest-plain. r=jmaher,taskgraph-reviewe...
[gecko.git] / dom / webgpu / Utility.cpp
blob8c8a03866b72eab7bb89f72ef5c111e7e48186d8
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/. */
6 #include "Utility.h"
7 #include "mozilla/dom/WebGPUBinding.h"
8 #include "mozilla/webgpu/ffi/wgpu.h"
9 #include "mozilla/webgpu/WebGPUTypes.h"
11 namespace mozilla::webgpu {
13 template <typename E>
14 void ConvertToExtent3D(const E& aExtent, ffi::WGPUExtent3d* aExtentFFI) {
15 *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;
26 } else {
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);
44 return extent;
47 ffi::WGPUExtent3d ConvertExtent(const dom::OwningGPUExtent3D& aExtent) {
48 ffi::WGPUExtent3d extent = {};
49 ConvertToExtent3D(aExtent, &extent);
50 return extent;
53 } // namespace mozilla::webgpu