script/dom/webgpu/
gpuadapterinfo.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use wgpu_types::AdapterInfo;
7
8use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPUAdapterInfoMethods;
9use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
10use crate::dom::bindings::root::DomRoot;
11use crate::dom::bindings::str::DOMString;
12use crate::dom::globalscope::GlobalScope;
13use crate::script_runtime::CanGc;
14
15#[dom_struct]
16pub(crate) struct GPUAdapterInfo {
17    reflector_: Reflector,
18    #[ignore_malloc_size_of = "defined in wgpu-types"]
19    #[no_trace]
20    info: AdapterInfo,
21}
22
23impl GPUAdapterInfo {
24    fn new_inherited(info: AdapterInfo) -> Self {
25        Self {
26            reflector_: Reflector::new(),
27            info,
28        }
29    }
30
31    pub(crate) fn new(global: &GlobalScope, info: AdapterInfo, can_gc: CanGc) -> DomRoot<Self> {
32        reflect_dom_object(Box::new(Self::new_inherited(info)), global, can_gc)
33    }
34}
35
36// TODO: wgpu does not expose right fields right now
37impl GPUAdapterInfoMethods<crate::DomTypeHolder> for GPUAdapterInfo {
38    /// <https://gpuweb.github.io/gpuweb/#dom-gpuadapterinfo-vendor>
39    fn Vendor(&self) -> DOMString {
40        DOMString::new()
41    }
42
43    /// <https://gpuweb.github.io/gpuweb/#dom-gpuadapterinfo-architecture>
44    fn Architecture(&self) -> DOMString {
45        DOMString::new()
46    }
47
48    /// <https://gpuweb.github.io/gpuweb/#dom-gpuadapterinfo-device>
49    fn Device(&self) -> DOMString {
50        DOMString::new()
51    }
52
53    /// <https://gpuweb.github.io/gpuweb/#dom-gpuadapterinfo-description>
54    fn Description(&self) -> DOMString {
55        DOMString::from_string(self.info.driver_info.clone())
56    }
57}