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