use crate::layout::render_list::RenderList;
#[derive(Clone)]
pub struct SharedWgpuContext {
pub instance: wgpu::Instance,
pub adapter: wgpu::Adapter,
pub device: wgpu::Device,
pub queue: wgpu::Queue,
pub surface_format: wgpu::TextureFormat,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct WgpuViewportRect {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
}
#[derive(Clone, Copy)]
pub struct WgpuFrameInfo<'a> {
#[cfg_attr(not(feature = "raster"), allow(dead_code))]
render_list: &'a RenderList,
pub surface_width: u32,
pub surface_height: u32,
}
impl<'a> WgpuFrameInfo<'a> {
pub(crate) fn new(render_list: &'a RenderList, surface_width: u32, surface_height: u32) -> Self {
Self {
render_list,
surface_width,
surface_height,
}
}
#[cfg(feature = "raster")]
pub fn viewport(&self, image_id: u64) -> Option<WgpuViewportRect> {
self
.render_list
.images
.iter()
.find(|image| image.image_id == image_id)
.map(|image| WgpuViewportRect {
x: image.x,
y: image.y,
width: image.width,
height: image.height,
})
}
}
pub trait WgpuFrameExtension {
fn initialize(&mut self, _gpu: &SharedWgpuContext) {}
fn prepare(&mut self, _gpu: &SharedWgpuContext, _frame: WgpuFrameInfo<'_>) {}
fn wants_redraw(&self) -> bool {
false
}
fn shutdown(&mut self) {}
}
pub(crate) struct WgpuFrameExtensionEntry {
pub extension: Box<dyn WgpuFrameExtension>,
pub initialized: bool,
}
impl WgpuFrameExtensionEntry {
pub fn new(extension: Box<dyn WgpuFrameExtension>) -> Self {
Self {
extension,
initialized: false,
}
}
}