mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Initial implementation of WebGPU API
This commit is contained in:
parent
47e39af0f3
commit
12893aa010
30 changed files with 923 additions and 7 deletions
63
components/script/dom/gpuadapter.rs
Normal file
63
components/script/dom/gpuadapter.rs
Normal file
|
@ -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()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue