mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
reuse ImageKey for gpucanvascontext (#33517)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
3a0d27b231
commit
bab769a7cf
4 changed files with 22 additions and 37 deletions
|
@ -2,8 +2,6 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use std::cell::Cell;
|
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use euclid::default::Size2D;
|
use euclid::default::Size2D;
|
||||||
|
@ -98,7 +96,7 @@ pub struct GPUCanvasContext {
|
||||||
// TODO: can we have wgpu surface that is hw accelerated inside wr ...
|
// TODO: can we have wgpu surface that is hw accelerated inside wr ...
|
||||||
#[ignore_malloc_size_of = "Defined in webrender"]
|
#[ignore_malloc_size_of = "Defined in webrender"]
|
||||||
#[no_trace]
|
#[no_trace]
|
||||||
webrender_image: Cell<Option<webrender_api::ImageKey>>,
|
webrender_image: ImageKey,
|
||||||
#[no_trace]
|
#[no_trace]
|
||||||
context_id: WebGPUContextId,
|
context_id: WebGPUContextId,
|
||||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-currenttexture-slot>
|
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-currenttexture-slot>
|
||||||
|
@ -111,12 +109,12 @@ impl GPUCanvasContext {
|
||||||
if let Err(e) = channel.0.send(WebGPURequest::CreateContext(sender)) {
|
if let Err(e) = channel.0.send(WebGPURequest::CreateContext(sender)) {
|
||||||
warn!("Failed to send CreateContext ({:?})", e);
|
warn!("Failed to send CreateContext ({:?})", e);
|
||||||
}
|
}
|
||||||
let external_id = receiver.recv().unwrap();
|
let (external_id, webrender_image) = receiver.recv().unwrap();
|
||||||
Self {
|
Self {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
channel,
|
channel,
|
||||||
canvas,
|
canvas,
|
||||||
webrender_image: Cell::new(None),
|
webrender_image,
|
||||||
context_id: WebGPUContextId(external_id.0),
|
context_id: WebGPUContextId(external_id.0),
|
||||||
texture: MutNullableDom::default(),
|
texture: MutNullableDom::default(),
|
||||||
}
|
}
|
||||||
|
@ -135,12 +133,7 @@ impl GPUCanvasContext {
|
||||||
|
|
||||||
impl GPUCanvasContext {
|
impl GPUCanvasContext {
|
||||||
fn layout_handle(&self) -> HTMLCanvasDataSource {
|
fn layout_handle(&self) -> HTMLCanvasDataSource {
|
||||||
let image_key = if self.webrender_image.get().is_some() {
|
HTMLCanvasDataSource::WebGPU(self.webrender_image)
|
||||||
self.webrender_image.get().unwrap()
|
|
||||||
} else {
|
|
||||||
ImageKey::DUMMY
|
|
||||||
};
|
|
||||||
HTMLCanvasDataSource::WebGPU(image_key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_swap_chain_present(&self) {
|
pub fn send_swap_chain_present(&self) {
|
||||||
|
@ -251,8 +244,6 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 8
|
// Step 8
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
|
||||||
|
|
||||||
let mut buffer_ids = ArrayVec::<id::BufferId, PRESENTATION_BUFFER_COUNT>::new();
|
let mut buffer_ids = ArrayVec::<id::BufferId, PRESENTATION_BUFFER_COUNT>::new();
|
||||||
for _ in 0..PRESENTATION_BUFFER_COUNT {
|
for _ in 0..PRESENTATION_BUFFER_COUNT {
|
||||||
buffer_ids.push(self.global().wgpu_id_hub().create_buffer_id());
|
buffer_ids.push(self.global().wgpu_id_hub().create_buffer_id());
|
||||||
|
@ -265,7 +256,7 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
|
||||||
queue_id: configuration.device.GetQueue().id().0,
|
queue_id: configuration.device.GetQueue().id().0,
|
||||||
buffer_ids,
|
buffer_ids,
|
||||||
context_id: self.context_id,
|
context_id: self.context_id,
|
||||||
sender,
|
image_key: self.webrender_image,
|
||||||
format,
|
format,
|
||||||
size: units::DeviceIntSize::new(size.width as i32, size.height as i32),
|
size: units::DeviceIntSize::new(size.width as i32, size.height as i32),
|
||||||
})
|
})
|
||||||
|
@ -275,24 +266,23 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
|
||||||
&configuration.device.CreateTexture(&text_desc).unwrap(),
|
&configuration.device.CreateTexture(&text_desc).unwrap(),
|
||||||
));
|
));
|
||||||
|
|
||||||
self.webrender_image.set(Some(receiver.recv().unwrap()));
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-unconfigure>
|
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-unconfigure>
|
||||||
fn Unconfigure(&self) {
|
fn Unconfigure(&self) {
|
||||||
if let Some(image_key) = self.webrender_image.take() {
|
if let Some(texture) = self.texture.take() {
|
||||||
if let Err(e) = self.channel.0.send(WebGPURequest::DestroySwapChain {
|
if let Err(e) = self.channel.0.send(WebGPURequest::DestroySwapChain {
|
||||||
context_id: self.context_id,
|
context_id: self.context_id,
|
||||||
image_key,
|
image_key: self.webrender_image,
|
||||||
}) {
|
}) {
|
||||||
warn!(
|
warn!(
|
||||||
"Failed to send DestroySwapChain-ImageKey({:?}) ({})",
|
"Failed to send DestroySwapChain-ImageKey({:?}) ({})",
|
||||||
image_key, e
|
self.webrender_image, e
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
drop(texture);
|
||||||
}
|
}
|
||||||
self.texture.take();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-getcurrenttexture>
|
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-getcurrenttexture>
|
||||||
|
|
|
@ -103,7 +103,7 @@ pub enum WebGPURequest {
|
||||||
/// present only on ASYNC versions
|
/// present only on ASYNC versions
|
||||||
async_sender: Option<IpcSender<WebGPUResponse>>,
|
async_sender: Option<IpcSender<WebGPUResponse>>,
|
||||||
},
|
},
|
||||||
CreateContext(IpcSender<WebGPUContextId>),
|
CreateContext(IpcSender<(WebGPUContextId, ImageKey)>),
|
||||||
CreatePipelineLayout {
|
CreatePipelineLayout {
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
pipeline_layout_id: id::PipelineLayoutId,
|
pipeline_layout_id: id::PipelineLayoutId,
|
||||||
|
@ -134,7 +134,7 @@ pub enum WebGPURequest {
|
||||||
queue_id: id::QueueId,
|
queue_id: id::QueueId,
|
||||||
buffer_ids: ArrayVec<id::BufferId, PRESENTATION_BUFFER_COUNT>,
|
buffer_ids: ArrayVec<id::BufferId, PRESENTATION_BUFFER_COUNT>,
|
||||||
context_id: WebGPUContextId,
|
context_id: WebGPUContextId,
|
||||||
sender: IpcSender<ImageKey>,
|
image_key: ImageKey,
|
||||||
format: ImageFormat,
|
format: ImageFormat,
|
||||||
size: DeviceIntSize,
|
size: DeviceIntSize,
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::collections::HashMap;
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::sync::{Arc, Mutex, MutexGuard};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use euclid::default::Size2D;
|
use euclid::default::Size2D;
|
||||||
|
@ -234,7 +234,6 @@ impl crate::WGPU {
|
||||||
format: ImageFormat,
|
format: ImageFormat,
|
||||||
size: DeviceIntSize,
|
size: DeviceIntSize,
|
||||||
image_key: ImageKey,
|
image_key: ImageKey,
|
||||||
mut wr: MutexGuard<RenderApi>,
|
|
||||||
) {
|
) {
|
||||||
let image_desc = ImageDescriptor {
|
let image_desc = ImageDescriptor {
|
||||||
format,
|
format,
|
||||||
|
@ -265,7 +264,10 @@ impl crate::WGPU {
|
||||||
|
|
||||||
let mut txn = Transaction::new();
|
let mut txn = Transaction::new();
|
||||||
txn.add_image(image_key, image_desc, image_data, None);
|
txn.add_image(image_key, image_desc, image_data, None);
|
||||||
wr.send_transaction(self.webrender_document, txn);
|
self.webrender_api
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.send_transaction(self.webrender_document, txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copies data async from provided texture using encoder_id to available staging presentation buffer
|
/// Copies data async from provided texture using encoder_id to available staging presentation buffer
|
||||||
|
|
|
@ -410,7 +410,8 @@ impl WGPU {
|
||||||
.lock()
|
.lock()
|
||||||
.expect("Lock poisoned?")
|
.expect("Lock poisoned?")
|
||||||
.next_id(WebrenderImageHandlerType::WebGPU);
|
.next_id(WebrenderImageHandlerType::WebGPU);
|
||||||
if let Err(e) = sender.send(WebGPUContextId(id.0)) {
|
let image_key = self.webrender_api.lock().unwrap().generate_image_key();
|
||||||
|
if let Err(e) = sender.send((WebGPUContextId(id.0), image_key)) {
|
||||||
warn!("Failed to send ExternalImageId to new context ({})", e);
|
warn!("Failed to send ExternalImageId to new context ({})", e);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -517,20 +518,12 @@ impl WGPU {
|
||||||
queue_id,
|
queue_id,
|
||||||
buffer_ids,
|
buffer_ids,
|
||||||
context_id,
|
context_id,
|
||||||
sender,
|
image_key,
|
||||||
size,
|
size,
|
||||||
format,
|
format,
|
||||||
} => {
|
} => self.create_swapchain(
|
||||||
let wr = self.webrender_api.lock().unwrap();
|
device_id, queue_id, buffer_ids, context_id, format, size, image_key,
|
||||||
let image_key = wr.generate_image_key();
|
),
|
||||||
if let Err(e) = sender.send(image_key) {
|
|
||||||
warn!("Failed to send ImageKey ({})", e);
|
|
||||||
}
|
|
||||||
self.create_swapchain(
|
|
||||||
device_id, queue_id, buffer_ids, context_id, format, size, image_key,
|
|
||||||
wr,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
WebGPURequest::CreateTexture {
|
WebGPURequest::CreateTexture {
|
||||||
device_id,
|
device_id,
|
||||||
texture_id,
|
texture_id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue