mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
webgpu: implement get image for webgpu canvas (#35237)
* Implement `get_image_data` for WebGPU canvas Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Update expectations Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Add docs Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
42b581a6f6
commit
35835af857
6 changed files with 50 additions and 40 deletions
|
@ -154,6 +154,11 @@ pub enum WebGPURequest {
|
|||
texture_id: id::TextureId,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
},
|
||||
/// Obtains image from latest presentation buffer (same as wr update)
|
||||
GetImage {
|
||||
context_id: WebGPUContextId,
|
||||
sender: IpcSender<IpcSharedMemory>,
|
||||
},
|
||||
ValidateTextureDescriptor {
|
||||
device_id: id::DeviceId,
|
||||
texture_id: id::TextureId,
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::sync::{Arc, Mutex};
|
|||
|
||||
use arrayvec::ArrayVec;
|
||||
use euclid::default::Size2D;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
|
||||
use log::{error, warn};
|
||||
use malloc_size_of::MallocSizeOf;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -382,6 +382,22 @@ impl crate::WGPU {
|
|||
);
|
||||
}
|
||||
|
||||
pub(crate) fn get_image(&self, context_id: WebGPUContextId) -> IpcSharedMemory {
|
||||
let webgpu_contexts = self.wgpu_image_map.lock().unwrap();
|
||||
let context_data = webgpu_contexts.get(&context_id).unwrap();
|
||||
let buffer_size = context_data.image_desc.buffer_size();
|
||||
let data = if let Some(present_buffer) = context_data
|
||||
.swap_chain
|
||||
.as_ref()
|
||||
.and_then(|swap_chain| swap_chain.data.as_ref())
|
||||
{
|
||||
IpcSharedMemory::from_bytes(present_buffer.slice())
|
||||
} else {
|
||||
IpcSharedMemory::from_byte(0, buffer_size as usize)
|
||||
};
|
||||
data
|
||||
}
|
||||
|
||||
pub(crate) fn update_context(
|
||||
&self,
|
||||
context_id: WebGPUContextId,
|
||||
|
|
|
@ -531,6 +531,9 @@ impl WGPU {
|
|||
log::error!("Error occured in SwapChainPresent: {e:?}");
|
||||
}
|
||||
},
|
||||
WebGPURequest::GetImage { context_id, sender } => {
|
||||
sender.send(self.get_image(context_id)).unwrap()
|
||||
},
|
||||
WebGPURequest::ValidateTextureDescriptor {
|
||||
device_id,
|
||||
texture_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue