aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/gpudevice.rs
diff options
context:
space:
mode:
authorIstvan Miklos <istvan.miklos@h-lab.eu>2019-11-12 12:56:57 +0100
committerIstvan Miklos <istvan.miklos@h-lab.eu>2019-12-05 11:50:33 +0100
commitb15d2bb7d70870e26e1834099bf5fdcdcbb8d673 (patch)
tree80f2ab39a3afe7c38ec4934070cff03642e80521 /components/script/dom/gpudevice.rs
parent7aa68c8fe7ca0865a7323ab1e5b9526efa588ca2 (diff)
downloadservo-b15d2bb7d70870e26e1834099bf5fdcdcbb8d673.tar.gz
servo-b15d2bb7d70870e26e1834099bf5fdcdcbb8d673.zip
Initial implementation of GPUDevice for WebGPU
Added the WebIDL bindigs for GPUDevice, GPUObjectDescriptorBase, GPUDeviceDescriptor, GPUObjectBase Implemented the `requestDevice` function of `GPUAdapter`
Diffstat (limited to 'components/script/dom/gpudevice.rs')
-rw-r--r--components/script/dom/gpudevice.rs91
1 files changed, 91 insertions, 0 deletions
diff --git a/components/script/dom/gpudevice.rs b/components/script/dom/gpudevice.rs
new file mode 100644
index 00000000000..d04ae97483a
--- /dev/null
+++ b/components/script/dom/gpudevice.rs
@@ -0,0 +1,91 @@
+/* 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::GPUDeviceBinding::{self, GPUDeviceMethods};
+use crate::dom::bindings::reflector::reflect_dom_object;
+use crate::dom::bindings::root::{Dom, DomRoot};
+use crate::dom::bindings::str::DOMString;
+use crate::dom::eventtarget::EventTarget;
+use crate::dom::globalscope::GlobalScope;
+use crate::dom::gpuadapter::GPUAdapter;
+use crate::script_runtime::JSContext as SafeJSContext;
+use dom_struct::dom_struct;
+use js::jsapi::{Heap, JSObject};
+use std::ptr::NonNull;
+use webgpu::WebGPUDevice;
+
+#[dom_struct]
+pub struct GPUDevice {
+ eventtarget: EventTarget,
+ adapter: Dom<GPUAdapter>,
+ #[ignore_malloc_size_of = "mozjs"]
+ extensions: Heap<*mut JSObject>,
+ #[ignore_malloc_size_of = "mozjs"]
+ limits: Heap<*mut JSObject>,
+ label: DomRefCell<Option<DOMString>>,
+ device: WebGPUDevice,
+}
+
+impl GPUDevice {
+ fn new_inherited(
+ adapter: &GPUAdapter,
+ extensions: Heap<*mut JSObject>,
+ limits: Heap<*mut JSObject>,
+ device: WebGPUDevice,
+ ) -> GPUDevice {
+ Self {
+ eventtarget: EventTarget::new_inherited(),
+ adapter: Dom::from_ref(adapter),
+ extensions,
+ limits,
+ label: DomRefCell::new(None),
+ device,
+ }
+ }
+
+ #[allow(unsafe_code)]
+ pub fn new(
+ global: &GlobalScope,
+ adapter: &GPUAdapter,
+ extensions: Heap<*mut JSObject>,
+ limits: Heap<*mut JSObject>,
+ device: WebGPUDevice,
+ ) -> DomRoot<GPUDevice> {
+ reflect_dom_object(
+ Box::new(GPUDevice::new_inherited(
+ adapter, extensions, limits, device,
+ )),
+ global,
+ GPUDeviceBinding::Wrap,
+ )
+ }
+}
+
+impl GPUDeviceMethods for GPUDevice {
+ /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-adapter
+ fn Adapter(&self) -> DomRoot<GPUAdapter> {
+ DomRoot::from_ref(&self.adapter)
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-extensions
+ fn Extensions(&self, _cx: SafeJSContext) -> NonNull<JSObject> {
+ NonNull::new(self.extensions.get()).unwrap()
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-limits
+ fn Limits(&self, _cx: SafeJSContext) -> NonNull<JSObject> {
+ NonNull::new(self.extensions.get()).unwrap()
+ }
+
+ /// 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;
+ }
+}