diff options
Diffstat (limited to 'components/webgpu')
-rw-r--r-- | components/webgpu/Cargo.toml | 1 | ||||
-rw-r--r-- | components/webgpu/swapchain.rs | 27 |
2 files changed, 22 insertions, 6 deletions
diff --git a/components/webgpu/Cargo.toml b/components/webgpu/Cargo.toml index f25f160b1b0..39ca562affe 100644 --- a/components/webgpu/Cargo.toml +++ b/components/webgpu/Cargo.toml @@ -22,6 +22,7 @@ malloc_size_of = { workspace = true } serde = { workspace = true, features = ["serde_derive"] } servo_config = { path = "../config" } webgpu_traits = { workspace = true } +snapshot = { workspace = true } webrender = { workspace = true } webrender_api = { workspace = true } wgpu-core = { workspace = true, features = ["serde", "wgsl"] } diff --git a/components/webgpu/swapchain.rs b/components/webgpu/swapchain.rs index 6d61540581b..a3ca15b638d 100644 --- a/components/webgpu/swapchain.rs +++ b/components/webgpu/swapchain.rs @@ -10,9 +10,10 @@ use std::sync::{Arc, Mutex}; use arrayvec::ArrayVec; use compositing_traits::{WebrenderExternalImageApi, WebrenderImageSource}; use euclid::default::Size2D; -use ipc_channel::ipc::{IpcSender, IpcSharedMemory}; +use ipc_channel::ipc::IpcSender; use log::{error, warn}; use serde::{Deserialize, Serialize}; +use snapshot::{IpcSnapshot, Snapshot}; use webgpu_traits::{ ContextConfiguration, Error, PRESENTATION_BUFFER_COUNT, WebGPUContextId, WebGPUMsg, }; @@ -364,20 +365,34 @@ impl crate::WGPU { ); } - pub(crate) fn get_image(&self, context_id: WebGPUContextId) -> IpcSharedMemory { + pub(crate) fn get_image(&self, context_id: WebGPUContextId) -> IpcSnapshot { 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 size = context_data.image_desc.size().cast().cast_unit(); 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()) + let format = match context_data.image_desc.0.format { + ImageFormat::RGBA8 => snapshot::PixelFormat::RGBA, + ImageFormat::BGRA8 => snapshot::PixelFormat::BGRA, + _ => unimplemented!(), + }; + let alpha_mode = if context_data.image_desc.0.is_opaque() { + snapshot::AlphaMode::AsOpaque { + premultiplied: false, + } + } else { + snapshot::AlphaMode::Transparent { + premultiplied: true, + } + }; + Snapshot::from_vec(size, format, alpha_mode, present_buffer.slice().to_vec()) } else { - IpcSharedMemory::from_byte(0, buffer_size as usize) + Snapshot::cleared(size) }; - data + data.as_ipc() } pub(crate) fn update_context( |