script/dom/webgl/
webglobject.rs1use canvas_traits::webgl::{WebGLCommand, WebGLContextId, WebGLMsgSender};
6use dom_struct::dom_struct;
8use script_bindings::root::DomRoot;
9use script_bindings::weakref::WeakRef;
10
11use crate::dom::bindings::cell::DomRefCell;
12use crate::dom::bindings::codegen::Bindings::WebGLObjectBinding::WebGLObjectMethods;
13use crate::dom::bindings::reflector::Reflector;
14use crate::dom::bindings::str::USVString;
15use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
16use crate::dom::webglrenderingcontext::{Operation, capture_webgl_backtrace};
17
18#[dom_struct]
19pub(crate) struct WebGLObject {
20 reflector_: Reflector,
21 #[no_trace]
22 webgl_sender: WebGLMsgSender,
23 context: WeakRef<WebGLRenderingContext>,
24 label: DomRefCell<USVString>,
25}
26
27impl WebGLObject {
28 pub(crate) fn new_inherited(context: &WebGLRenderingContext) -> WebGLObject {
29 WebGLObject {
30 reflector_: Reflector::new(),
31 webgl_sender: context.sender().clone(),
32 context: WeakRef::new(context),
33 label: DomRefCell::new(USVString::default()),
34 }
35 }
36
37 pub(crate) fn context(&self) -> Option<DomRoot<WebGLRenderingContext>> {
41 self.context.root()
42 }
43
44 #[inline]
45 pub(crate) fn context_id(&self) -> WebGLContextId {
46 self.webgl_sender.context_id()
47 }
48
49 #[inline]
50 pub(crate) fn send_with_fallibility(&self, command: WebGLCommand, fallibility: Operation) {
51 let result = self.webgl_sender.send(command, capture_webgl_backtrace());
52 if matches!(fallibility, Operation::Infallible) {
53 result.expect("Operation failed");
54 }
55 }
56
57 #[inline]
58 pub(crate) fn send_command(&self, command: WebGLCommand) {
59 self.send_with_fallibility(command, Operation::Infallible);
60 }
61}
62
63impl WebGLObjectMethods<crate::DomTypeHolder> for WebGLObject {
64 fn Label(&self) -> USVString {
66 self.label.borrow().clone()
67 }
68
69 fn SetLabel(&self, value: USVString) {
71 *self.label.borrow_mut() = value;
72 }
73}