aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/gpuadapter.rs
diff options
context:
space:
mode:
authorZakor Gyula <gyula.zakor@h-lab.eu>2019-11-10 14:56:22 +0100
committerZakor Gyula <gyula.zakor@h-lab.eu>2019-11-21 08:30:26 +0100
commit12893aa0102f220f411b273a36ac1b4e25fa0ab7 (patch)
tree37362e455b8a1352fc88d39f8eb87170754c5d06 /components/script/dom/gpuadapter.rs
parent47e39af0f36227e8e98b3dc3511c225192bf3736 (diff)
downloadservo-12893aa0102f220f411b273a36ac1b4e25fa0ab7.tar.gz
servo-12893aa0102f220f411b273a36ac1b4e25fa0ab7.zip
Initial implementation of WebGPU API
Diffstat (limited to 'components/script/dom/gpuadapter.rs')
-rw-r--r--components/script/dom/gpuadapter.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/components/script/dom/gpuadapter.rs b/components/script/dom/gpuadapter.rs
new file mode 100644
index 00000000000..ec970439e8a
--- /dev/null
+++ b/components/script/dom/gpuadapter.rs
@@ -0,0 +1,63 @@
+/* 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::codegen::Bindings::GPUAdapterBinding::{self, GPUAdapterMethods};
+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 crate::script_runtime::JSContext as SafeJSContext;
+use dom_struct::dom_struct;
+use js::jsapi::{Heap, JSObject};
+use std::ptr::NonNull;
+use webgpu::WebGPUAdapter;
+
+#[dom_struct]
+pub struct GPUAdapter {
+ reflector_: Reflector,
+ name: DOMString,
+ #[ignore_malloc_size_of = "mozjs"]
+ extensions: Heap<*mut JSObject>,
+ adapter: WebGPUAdapter,
+}
+
+impl GPUAdapter {
+ pub fn new_inherited(
+ name: DOMString,
+ extensions: Heap<*mut JSObject>,
+ adapter: WebGPUAdapter,
+ ) -> GPUAdapter {
+ GPUAdapter {
+ reflector_: Reflector::new(),
+ name,
+ extensions,
+ adapter,
+ }
+ }
+
+ pub fn new(
+ global: &GlobalScope,
+ name: DOMString,
+ extensions: Heap<*mut JSObject>,
+ adapter: WebGPUAdapter,
+ ) -> DomRoot<GPUAdapter> {
+ reflect_dom_object(
+ Box::new(GPUAdapter::new_inherited(name, extensions, adapter)),
+ global,
+ GPUAdapterBinding::Wrap,
+ )
+ }
+}
+
+impl GPUAdapterMethods for GPUAdapter {
+ // https://gpuweb.github.io/gpuweb/#dom-gpuadapter-name
+ fn Name(&self) -> DOMString {
+ self.name.clone()
+ }
+
+ // https://gpuweb.github.io/gpuweb/#dom-gpuadapter-extensions
+ fn Extensions(&self, _cx: SafeJSContext) -> NonNull<JSObject> {
+ NonNull::new(self.extensions.get()).unwrap()
+ }
+}