These changes fix #30843 (#30888)

Signed-off-by: Lucas Fabián Montenegro <40044087+lucasMontenegro@users.noreply.github.com>
This commit is contained in:
Lucas Montenegro 2023-12-20 02:57:48 -03:00 committed by GitHub
parent 8bbcf0abaf
commit 256ab5353b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 40 deletions

View file

@ -2043,42 +2043,37 @@ where
return warn!("Browsing context group not found"); return warn!("Browsing context group not found");
}; };
let webgpu_chan = match browsing_context_group.webgpus.entry(host) { let webgpu_chan = match browsing_context_group.webgpus.entry(host) {
Entry::Vacant(v) => v Entry::Vacant(v) => WebGPU::new(
.insert( self.webrender_wgpu.webrender_api.create_sender(),
match WebGPU::new( self.webrender_document,
self.webrender_wgpu.webrender_api.create_sender(), self.webrender_wgpu.webrender_external_images.clone(),
self.webrender_document, self.webrender_wgpu.wgpu_image_map.clone(),
self.webrender_wgpu.webrender_external_images.clone(), )
self.webrender_wgpu.wgpu_image_map.clone(), .map(|webgpu| {
) { let msg = ConstellationControlMsg::SetWebGPUPort(webgpu.1);
Some(webgpu) => { if let Err(e) = source_pipeline.event_loop.send(msg) {
let msg = ConstellationControlMsg::SetWebGPUPort(webgpu.1); warn!(
if let Err(e) = source_pipeline.event_loop.send(msg) { "{}: Failed to send SetWebGPUPort to pipeline ({:?})",
warn!( source_pipeline_id, e
"{}: Failed to send SetWebGPUPort to pipeline ({:?})", );
source_pipeline_id, e }
); v.insert(webgpu.0).clone()
} }),
webgpu.0 Entry::Occupied(o) => Some(o.get().clone()),
},
None => {
return warn!("Failed to create new WebGPU thread");
},
},
)
.clone(),
Entry::Occupied(o) => o.get().clone(),
}; };
match request { match request {
FromScriptMsg::RequestAdapter(response_sender, options, ids) => { FromScriptMsg::RequestAdapter(response_sender, options, ids) => match webgpu_chan {
let adapter_request = WebGPURequest::RequestAdapter { None => warn!("Failed to send request adapter message, missing WebGPU channel"),
sender: response_sender, Some(webgpu_chan) => {
options, let adapter_request = WebGPURequest::RequestAdapter {
ids, sender: response_sender,
}; options,
if webgpu_chan.0.send((None, adapter_request)).is_err() { ids,
return warn!("Failed to send request adapter message on WebGPU channel"); };
} if webgpu_chan.0.send((None, adapter_request)).is_err() {
warn!("Failed to send request adapter message on WebGPU channel");
}
},
}, },
FromScriptMsg::GetWebGPUChan(response_sender) => { FromScriptMsg::GetWebGPUChan(response_sender) => {
if response_sender.send(webgpu_chan).is_err() { if response_sender.send(webgpu_chan).is_err() {

View file

@ -269,11 +269,15 @@ impl HTMLCanvasElement {
.global() .global()
.script_to_constellation_chan() .script_to_constellation_chan()
.send(ScriptMsg::GetWebGPUChan(sender)); .send(ScriptMsg::GetWebGPUChan(sender));
let window = window_from_node(self); receiver
let channel = receiver.recv().expect("Failed to get WebGPU channel"); .recv()
let context = GPUCanvasContext::new(window.upcast::<GlobalScope>(), self, channel); .expect("Failed to get WebGPU channel")
*self.context.borrow_mut() = Some(CanvasContext::WebGPU(Dom::from_ref(&*context))); .map(|channel| {
Some(context) 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. /// Gets the base WebGLRenderingContext for WebGL or WebGL 2, if exists.

View file

@ -263,7 +263,7 @@ pub enum ScriptMsg {
SmallVec<[wgpu::id::AdapterId; 4]>, SmallVec<[wgpu::id::AdapterId; 4]>,
), ),
/// Get WebGPU channel /// Get WebGPU channel
GetWebGPUChan(IpcSender<WebGPU>), GetWebGPUChan(IpcSender<Option<WebGPU>>),
/// Notify the constellation of a pipeline's document's title. /// Notify the constellation of a pipeline's document's title.
TitleChanged(PipelineId, String), TitleChanged(PipelineId, String),
} }