aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/gputextureview.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/gputextureview.rs')
-rw-r--r--components/script/dom/gputextureview.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/components/script/dom/gputextureview.rs b/components/script/dom/gputextureview.rs
new file mode 100644
index 00000000000..7a6f60e3bfb
--- /dev/null
+++ b/components/script/dom/gputextureview.rs
@@ -0,0 +1,62 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+use crate::dom::bindings::cell::DomRefCell;
+use crate::dom::bindings::codegen::Bindings::GPUTextureViewBinding::GPUTextureViewMethods;
+use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
+use crate::dom::bindings::root::DomRoot;
+use crate::dom::bindings::str::DOMString;
+use crate::dom::globalscope::GlobalScope;
+use dom_struct::dom_struct;
+use std::cell::Cell;
+use webgpu::{WebGPUDevice, WebGPUTextureView};
+
+#[dom_struct]
+pub struct GPUTextureView {
+ reflector_: Reflector,
+ label: DomRefCell<Option<DOMString>>,
+ texture_view: WebGPUTextureView,
+ device: WebGPUDevice,
+ valid: Cell<bool>,
+}
+
+impl GPUTextureView {
+ fn new_inherited(
+ texture_view: WebGPUTextureView,
+ device: WebGPUDevice,
+ valid: bool,
+ ) -> GPUTextureView {
+ Self {
+ reflector_: Reflector::new(),
+ device,
+ label: DomRefCell::new(None),
+ texture_view,
+ valid: Cell::new(valid),
+ }
+ }
+
+ pub fn new(
+ global: &GlobalScope,
+ texture_view: WebGPUTextureView,
+ device: WebGPUDevice,
+ valid: bool,
+ ) -> DomRoot<GPUTextureView> {
+ reflect_dom_object(
+ Box::new(GPUTextureView::new_inherited(texture_view, device, valid)),
+ global,
+ )
+ }
+}
+
+impl GPUTextureViewMethods for GPUTextureView {
+ /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
+ fn GetLabel(&self) -> Option<DOMString> {
+ self.label.borrow().clone()
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
+ fn SetLabel(&self, value: Option<DOMString>) {
+ *self.label.borrow_mut() = value;
+ }
+}