diff options
author | Lucas Montenegro <40044087+lucasMontenegro@users.noreply.github.com> | 2023-12-20 02:57:48 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-20 05:57:48 +0000 |
commit | 256ab5353b9145dbda103ec48cf4d10f32f6912a (patch) | |
tree | 8ac740b2c48d64d86b65ece9e7e60a0c7506e24d | |
parent | 8bbcf0abafc22cd840cd03f36b5b3b7d2d815493 (diff) | |
download | servo-256ab5353b9145dbda103ec48cf4d10f32f6912a.tar.gz servo-256ab5353b9145dbda103ec48cf4d10f32f6912a.zip |
These changes fix #30843 (#30888)
Signed-off-by: Lucas Fabián Montenegro <40044087+lucasMontenegro@users.noreply.github.com>
-rw-r--r-- | components/constellation/constellation.rs | 63 | ||||
-rw-r--r-- | components/script/dom/htmlcanvaselement.rs | 14 | ||||
-rw-r--r-- | components/shared/script/script_msg.rs | 2 |
3 files changed, 39 insertions, 40 deletions
diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index ebfd83260da..feb02548338 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -2043,42 +2043,37 @@ where return warn!("Browsing context group not found"); }; let webgpu_chan = match browsing_context_group.webgpus.entry(host) { - Entry::Vacant(v) => v - .insert( - match WebGPU::new( - self.webrender_wgpu.webrender_api.create_sender(), - self.webrender_document, - self.webrender_wgpu.webrender_external_images.clone(), - self.webrender_wgpu.wgpu_image_map.clone(), - ) { - Some(webgpu) => { - let msg = ConstellationControlMsg::SetWebGPUPort(webgpu.1); - if let Err(e) = source_pipeline.event_loop.send(msg) { - warn!( - "{}: Failed to send SetWebGPUPort to pipeline ({:?})", - source_pipeline_id, e - ); - } - webgpu.0 - }, - None => { - return warn!("Failed to create new WebGPU thread"); - }, - }, - ) - .clone(), - Entry::Occupied(o) => o.get().clone(), + Entry::Vacant(v) => WebGPU::new( + self.webrender_wgpu.webrender_api.create_sender(), + self.webrender_document, + self.webrender_wgpu.webrender_external_images.clone(), + self.webrender_wgpu.wgpu_image_map.clone(), + ) + .map(|webgpu| { + let msg = ConstellationControlMsg::SetWebGPUPort(webgpu.1); + if let Err(e) = source_pipeline.event_loop.send(msg) { + warn!( + "{}: Failed to send SetWebGPUPort to pipeline ({:?})", + source_pipeline_id, e + ); + } + v.insert(webgpu.0).clone() + }), + Entry::Occupied(o) => Some(o.get().clone()), }; match request { - FromScriptMsg::RequestAdapter(response_sender, options, ids) => { - let adapter_request = WebGPURequest::RequestAdapter { - sender: response_sender, - options, - ids, - }; - if webgpu_chan.0.send((None, adapter_request)).is_err() { - return warn!("Failed to send request adapter message on WebGPU channel"); - } + FromScriptMsg::RequestAdapter(response_sender, options, ids) => match webgpu_chan { + None => warn!("Failed to send request adapter message, missing WebGPU channel"), + Some(webgpu_chan) => { + let adapter_request = WebGPURequest::RequestAdapter { + sender: response_sender, + options, + ids, + }; + if webgpu_chan.0.send((None, adapter_request)).is_err() { + warn!("Failed to send request adapter message on WebGPU channel"); + } + }, }, FromScriptMsg::GetWebGPUChan(response_sender) => { if response_sender.send(webgpu_chan).is_err() { diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index bb35853f706..e412457753a 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -269,11 +269,15 @@ impl HTMLCanvasElement { .global() .script_to_constellation_chan() .send(ScriptMsg::GetWebGPUChan(sender)); - let window = window_from_node(self); - let channel = receiver.recv().expect("Failed to get WebGPU channel"); - let context = GPUCanvasContext::new(window.upcast::<GlobalScope>(), self, channel); - *self.context.borrow_mut() = Some(CanvasContext::WebGPU(Dom::from_ref(&*context))); - Some(context) + receiver + .recv() + .expect("Failed to get WebGPU channel") + .map(|channel| { + let window = window_from_node(self); + let context = GPUCanvasContext::new(window.upcast::<GlobalScope>(), self, channel); + *self.context.borrow_mut() = Some(CanvasContext::WebGPU(Dom::from_ref(&*context))); + context + }) } /// Gets the base WebGLRenderingContext for WebGL or WebGL 2, if exists. diff --git a/components/shared/script/script_msg.rs b/components/shared/script/script_msg.rs index 42be2685ccf..614362575b3 100644 --- a/components/shared/script/script_msg.rs +++ b/components/shared/script/script_msg.rs @@ -263,7 +263,7 @@ pub enum ScriptMsg { SmallVec<[wgpu::id::AdapterId; 4]>, ), /// Get WebGPU channel - GetWebGPUChan(IpcSender<WebGPU>), + GetWebGPUChan(IpcSender<Option<WebGPU>>), /// Notify the constellation of a pipeline's document's title. TitleChanged(PipelineId, String), } |