Bug 1883853 [wpt PR 44937] - [wdspec] fix test_set_permission_origin_unknown, a=testonly
[gecko.git] / dom / webgpu / Adapter.h
blob4156588e8e3be0bcb9521287cab72da5e26e67b9
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 #ifndef GPU_Adapter_H_
7 #define GPU_Adapter_H_
9 #include <memory>
11 #include "mozilla/AlreadyAddRefed.h"
12 #include "mozilla/dom/NonRefcountedDOMObject.h"
13 #include "mozilla/webgpu/WebGPUTypes.h"
14 #include "nsPrintfCString.h"
15 #include "nsString.h"
16 #include "ObjectModel.h"
18 namespace mozilla {
19 class ErrorResult;
20 namespace dom {
21 class Promise;
22 struct GPUDeviceDescriptor;
23 struct GPUExtensions;
24 struct GPUFeatures;
25 enum class GPUFeatureName : uint8_t;
26 enum class WgpuBackend : uint8_t;
27 enum class WgpuDeviceType : uint8_t;
28 template <typename T>
29 class Sequence;
30 } // namespace dom
32 namespace webgpu {
33 class Device;
34 class Instance;
35 class SupportedFeatures;
36 class SupportedLimits;
37 class WebGPUChild;
38 namespace ffi {
39 struct WGPUAdapterInformation;
40 } // namespace ffi
42 class AdapterInfo final : public dom::NonRefcountedDOMObject {
43 private:
44 const std::shared_ptr<ffi::WGPUAdapterInformation> mAboutSupportInfo;
46 public:
47 explicit AdapterInfo(
48 const std::shared_ptr<ffi::WGPUAdapterInformation>& aAboutSupportInfo)
49 : mAboutSupportInfo(aAboutSupportInfo) {}
51 void GetVendor(nsString& s) const { s = nsString(); }
52 void GetArchitecture(nsString& s) const { s = nsString(); }
53 void GetDevice(nsString& s) const { s = nsString(); }
54 void GetDescription(nsString& s) const { s = nsString(); }
56 // Non-standard field getters; see also TODO BUGZILLA LINK
57 void GetWgpuName(nsString&) const;
58 uint32_t WgpuVendor() const;
59 uint32_t WgpuDevice() const;
60 void GetWgpuDeviceType(nsString&) const;
61 void GetWgpuDriver(nsString&) const;
62 void GetWgpuDriverInfo(nsString&) const;
63 void GetWgpuBackend(nsString&) const;
65 bool WrapObject(JSContext*, JS::Handle<JSObject*>,
66 JS::MutableHandle<JSObject*>);
69 inline auto ToHexCString(const uint64_t v) {
70 return nsPrintfCString("0x%" PRIx64, v);
73 class Adapter final : public ObjectBase, public ChildOf<Instance> {
74 public:
75 GPU_DECL_CYCLE_COLLECTION(Adapter)
76 GPU_DECL_JS_WRAP(Adapter)
78 RefPtr<WebGPUChild> mBridge;
80 private:
81 ~Adapter();
82 void Cleanup();
84 const RawId mId;
85 // Cant have them as `const` right now, since we wouldn't be able
86 // to unlink them in CC unlink.
87 RefPtr<SupportedFeatures> mFeatures;
88 RefPtr<SupportedLimits> mLimits;
90 const std::shared_ptr<ffi::WGPUAdapterInformation> mInfo;
92 public:
93 Adapter(Instance* const aParent, WebGPUChild* const aBridge,
94 const std::shared_ptr<ffi::WGPUAdapterInformation>& aInfo);
95 const RefPtr<SupportedFeatures>& Features() const;
96 const RefPtr<SupportedLimits>& Limits() const;
97 bool IsFallbackAdapter() const;
99 nsCString LabelOrId() const {
100 nsCString ret = this->CLabel();
101 if (ret.IsEmpty()) {
102 ret = ToHexCString(mId);
104 return ret;
107 already_AddRefed<dom::Promise> RequestDevice(
108 const dom::GPUDeviceDescriptor& aDesc, ErrorResult& aRv);
110 already_AddRefed<dom::Promise> RequestAdapterInfo(
111 const dom::Sequence<nsString>& aUnmaskHints, ErrorResult& aRv) const;
114 } // namespace webgpu
115 } // namespace mozilla
117 #endif // GPU_Adapter_H_