script/dom/webgl/
webglobject.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
5// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
6use dom_struct::dom_struct;
7
8use crate::dom::bindings::cell::DomRefCell;
9use crate::dom::bindings::codegen::Bindings::WebGLObjectBinding::WebGLObjectMethods;
10use crate::dom::bindings::reflector::Reflector;
11use crate::dom::bindings::root::Dom;
12use crate::dom::bindings::str::USVString;
13use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
14
15#[dom_struct]
16pub(crate) struct WebGLObject {
17    reflector_: Reflector,
18    context: Dom<WebGLRenderingContext>,
19    label: DomRefCell<USVString>,
20}
21
22impl WebGLObject {
23    pub(crate) fn new_inherited(context: &WebGLRenderingContext) -> WebGLObject {
24        WebGLObject {
25            reflector_: Reflector::new(),
26            context: Dom::from_ref(context),
27            label: DomRefCell::new(USVString::default()),
28        }
29    }
30
31    pub(crate) fn context(&self) -> &WebGLRenderingContext {
32        &self.context
33    }
34}
35
36impl WebGLObjectMethods<crate::DomTypeHolder> for WebGLObject {
37    /// <https://registry.khronos.org/webgl/specs/latest/1.0/#5.3>
38    fn Label(&self) -> USVString {
39        self.label.borrow().clone()
40    }
41
42    /// <https://registry.khronos.org/webgl/specs/latest/1.0/#5.3>
43    fn SetLabel(&self, value: USVString) {
44        *self.label.borrow_mut() = value;
45    }
46}