mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Initial implementation of GPUDevice for WebGPU
Added the WebIDL bindigs for GPUDevice, GPUObjectDescriptorBase, GPUDeviceDescriptor, GPUObjectBase Implemented the `requestDevice` function of `GPUAdapter`
This commit is contained in:
parent
7aa68c8fe7
commit
b15d2bb7d7
11 changed files with 270 additions and 16 deletions
91
components/script/dom/gpudevice.rs
Normal file
91
components/script/dom/gpudevice.rs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue