Skip to main content

script_webgpu/
gpudevicelostinfo.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 std::marker::PhantomData;
6
7use dom_struct::dom_struct;
8use js::context::JSContext;
9use malloc_size_of_derive::MallocSizeOf;
10use script_bindings::DomTypes;
11use script_bindings::codegen::GenericBindings::WebGPUBinding::{
12    GPUDeviceLostInfoMethods, GPUDeviceLostInfoWrap, GPUDeviceLostReason,
13};
14use script_bindings::reflector::{Reflector, reflect_dom_object_with_wrap};
15
16use crate::JSTraceable;
17use crate::dom::bindings::root::DomRoot;
18use crate::dom::bindings::str::DOMString;
19
20#[dom_struct]
21pub struct GPUDeviceLostInfo<D: DomTypes> {
22    reflector_: Reflector,
23    message: DOMString,
24    reason: GPUDeviceLostReason,
25    #[no_trace = "PhantomData does not exist"]
26    phantom: PhantomData<D>,
27}
28
29impl<D> GPUDeviceLostInfo<D>
30where
31    D: DomTypes<GPUDeviceLostInfo = GPUDeviceLostInfo<D>>,
32{
33    fn new_inherited(message: DOMString, reason: GPUDeviceLostReason) -> Self {
34        Self {
35            reflector_: Reflector::new(),
36            message,
37            reason,
38            phantom: PhantomData,
39        }
40    }
41
42    pub fn new(
43        cx: &mut JSContext,
44        global: &D::GlobalScope,
45        message: DOMString,
46        reason: GPUDeviceLostReason,
47    ) -> DomRoot<Self> {
48        reflect_dom_object_with_wrap::<D, _, _>(
49            Box::new(GPUDeviceLostInfo::new_inherited(message, reason)),
50            global,
51            cx,
52            GPUDeviceLostInfoWrap::<D>,
53        )
54    }
55}
56
57impl<D: DomTypes> GPUDeviceLostInfoMethods<D> for GPUDeviceLostInfo<D> {
58    /// <https://gpuweb.github.io/gpuweb/#dom-gpudevicelostinfo-message>
59    fn Message(&self) -> DOMString {
60        self.message.clone()
61    }
62
63    /// <https://gpuweb.github.io/gpuweb/#dom-gpudevicelostinfo-reason>
64    fn Reason(&self) -> GPUDeviceLostReason {
65        self.reason
66    }
67}