mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
webgpu: Factor out swapchain to separate file (#33367)
* Move some stuff to swapchain.rs Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Use typed WebGPUContextId instead of u64 Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Extract create_swapchain function and move more stuff in it Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * extract destroy_swapchain Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * extract swapchain_present Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * extract update_wr_image callback Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * fixup 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
938fd8c12f
commit
687f356db9
9 changed files with 403 additions and 328 deletions
|
@ -3,6 +3,8 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use log::warn;
|
||||
use swapchain::WGPUImageMap;
|
||||
pub use swapchain::{PresentationData, WGPUExternalImages};
|
||||
use webrender::RenderApiSender;
|
||||
use wgpu_thread::WGPU;
|
||||
pub use {wgpu_core as wgc, wgpu_types as wgt};
|
||||
|
@ -12,30 +14,25 @@ mod poll_thread;
|
|||
mod wgpu_thread;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use euclid::default::Size2D;
|
||||
pub use gpu_error::{Error, ErrorFilter, PopError};
|
||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
pub use render_commands::RenderCommand;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_config::pref;
|
||||
use webrender_api::{DocumentId, ImageData, ImageDescriptor, ImageKey};
|
||||
use webrender_traits::{
|
||||
WebrenderExternalImageApi, WebrenderExternalImageRegistry, WebrenderImageSource,
|
||||
};
|
||||
use wgc::id;
|
||||
use webrender_api::DocumentId;
|
||||
use webrender_traits::WebrenderExternalImageRegistry;
|
||||
|
||||
mod gpu_error;
|
||||
mod ipc_messages;
|
||||
mod render_commands;
|
||||
pub mod swapchain;
|
||||
pub use identity::*;
|
||||
pub use ipc_messages::recv::*;
|
||||
pub use ipc_messages::to_dom::*;
|
||||
pub use ipc_messages::to_script::*;
|
||||
pub use wgpu_thread::PRESENTATION_BUFFER_COUNT;
|
||||
pub use swapchain::PRESENTATION_BUFFER_COUNT;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct WebGPU(pub IpcSender<WebGPURequest>);
|
||||
|
@ -45,7 +42,7 @@ impl WebGPU {
|
|||
webrender_api_sender: RenderApiSender,
|
||||
webrender_document: DocumentId,
|
||||
external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,
|
||||
wgpu_image_map: Arc<Mutex<HashMap<u64, PresentationData>>>,
|
||||
wgpu_image_map: WGPUImageMap,
|
||||
) -> Option<(Self, IpcReceiver<WebGPUMsg>)> {
|
||||
if !pref!(dom.webgpu.enabled) {
|
||||
return None;
|
||||
|
@ -100,46 +97,3 @@ impl WebGPU {
|
|||
.map_err(|_| "Failed to send Exit message")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct WGPUExternalImages {
|
||||
pub images: Arc<Mutex<HashMap<u64, PresentationData>>>,
|
||||
pub locked_ids: HashMap<u64, Vec<u8>>,
|
||||
}
|
||||
|
||||
impl WebrenderExternalImageApi for WGPUExternalImages {
|
||||
fn lock(&mut self, id: u64) -> (WebrenderImageSource, Size2D<i32>) {
|
||||
let size;
|
||||
let data;
|
||||
if let Some(present_data) = self.images.lock().unwrap().get(&id) {
|
||||
size = present_data.size;
|
||||
data = present_data.data.clone();
|
||||
} else {
|
||||
size = Size2D::new(0, 0);
|
||||
data = Vec::new();
|
||||
}
|
||||
let _ = self.locked_ids.insert(id, data);
|
||||
(
|
||||
WebrenderImageSource::Raw(self.locked_ids.get(&id).unwrap().as_slice()),
|
||||
size,
|
||||
)
|
||||
}
|
||||
|
||||
fn unlock(&mut self, id: u64) {
|
||||
let _ = self.locked_ids.remove(&id);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PresentationData {
|
||||
device_id: id::DeviceId,
|
||||
queue_id: id::QueueId,
|
||||
pub data: Vec<u8>,
|
||||
pub size: Size2D<i32>,
|
||||
unassigned_buffer_ids: ArrayVec<id::BufferId, PRESENTATION_BUFFER_COUNT>,
|
||||
available_buffer_ids: ArrayVec<id::BufferId, PRESENTATION_BUFFER_COUNT>,
|
||||
queued_buffer_ids: ArrayVec<id::BufferId, PRESENTATION_BUFFER_COUNT>,
|
||||
buffer_stride: u32,
|
||||
image_key: ImageKey,
|
||||
image_desc: ImageDescriptor,
|
||||
image_data: ImageData,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue