mirror of
https://github.com/servo/servo.git
synced 2025-06-08 16:43:28 +00:00
Added the WebIDL bindigs for GPUDevice, GPUObjectDescriptorBase, GPUDeviceDescriptor, GPUObjectBase Implemented the `requestDevice` function of `GPUAdapter`
91 lines
2.8 KiB
Rust
91 lines
2.8 KiB
Rust
/* 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;
|
|
}
|
|
}
|