aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/globalscope.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r--components/script/dom/globalscope.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs
index d20f9084fcc..a6427224882 100644
--- a/components/script/dom/globalscope.rs
+++ b/components/script/dom/globalscope.rs
@@ -5,6 +5,7 @@
use crate::dom::bindings::cell::{DomRefCell, RefMut};
use crate::dom::bindings::codegen::Bindings::BroadcastChannelBinding::BroadcastChannelMethods;
use crate::dom::bindings::codegen::Bindings::EventSourceBinding::EventSourceBinding::EventSourceMethods;
+use crate::dom::bindings::codegen::Bindings::GPUValidationErrorBinding::GPUError;
use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{
ImageBitmapOptions, ImageBitmapSource,
};
@@ -34,6 +35,9 @@ use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
use crate::dom::eventsource::EventSource;
use crate::dom::eventtarget::EventTarget;
use crate::dom::file::File;
+use crate::dom::gpudevice::GPUDevice;
+use crate::dom::gpuoutofmemoryerror::GPUOutOfMemoryError;
+use crate::dom::gpuvalidationerror::GPUValidationError;
use crate::dom::htmlscriptelement::ScriptId;
use crate::dom::identityhub::Identities;
use crate::dom::imagebitmap::ImageBitmap;
@@ -126,6 +130,7 @@ use std::sync::Arc;
use std::thread::JoinHandle;
use time::{get_time, Timespec};
use uuid::Uuid;
+use webgpu::{identity::WebGPUOpResult, WebGPUDevice};
#[derive(JSTraceable)]
pub struct AutoCloseWorker {
@@ -293,6 +298,9 @@ pub struct GlobalScope {
#[ignore_malloc_size_of = "defined in wgpu"]
gpu_id_hub: Arc<Mutex<Identities>>,
+ /// WebGPU devices
+ gpu_devices: DomRefCell<HashMap<WebGPUDevice, Dom<GPUDevice>>>,
+
// https://w3c.github.io/performance-timeline/#supportedentrytypes-attribute
#[ignore_malloc_size_of = "mozjs"]
frozen_supported_performance_entry_types: DomRefCell<Option<Heap<JSVal>>>,
@@ -752,6 +760,7 @@ impl GlobalScope {
is_headless,
user_agent,
gpu_id_hub,
+ gpu_devices: DomRefCell::new(HashMap::new()),
frozen_supported_performance_entry_types: DomRefCell::new(Default::default()),
https_state: Cell::new(HttpsState::None),
console_group_stack: DomRefCell::new(Vec::new()),
@@ -2995,6 +3004,35 @@ impl GlobalScope {
self.gpu_id_hub.clone()
}
+ pub fn add_gpu_device(&self, device: &GPUDevice) {
+ self.gpu_devices
+ .borrow_mut()
+ .insert(device.id(), Dom::from_ref(device));
+ }
+
+ pub fn remove_gpu_device(&self, device: WebGPUDevice) {
+ let _ = self.gpu_devices.borrow_mut().remove(&device);
+ }
+
+ pub fn handle_wgpu_msg(&self, device: WebGPUDevice, scope: u64, result: WebGPUOpResult) {
+ let result = match result {
+ WebGPUOpResult::Success => Ok(()),
+ WebGPUOpResult::ValidationError(m) => {
+ let val_err = GPUValidationError::new(&self, DOMString::from_string(m));
+ Err(GPUError::GPUValidationError(val_err))
+ },
+ WebGPUOpResult::OutOfMemoryError => {
+ let oom_err = GPUOutOfMemoryError::new(&self);
+ Err(GPUError::GPUOutOfMemoryError(oom_err))
+ },
+ };
+ self.gpu_devices
+ .borrow()
+ .get(&device)
+ .expect("GPUDevice not found")
+ .handle_server_msg(scope, result);
+ }
+
pub(crate) fn current_group_label(&self) -> Option<DOMString> {
self.console_group_stack
.borrow()