| 1 |
use alloc::{boxed::Box, vec::Vec}; |
| 2 |
|
| 3 |
use crate::{ |
| 4 |
DeviceError, DynCommandBuffer, DynFence, DynResource, DynSurface, DynSurfaceTexture, |
| 5 |
FenceValue, Queue, SurfaceError, |
| 6 |
}; |
| 7 |
|
| 8 |
use super::DynResourceExt as _; |
| 9 |
|
| 10 |
pub trait DynQueue: DynResource { |
| 11 |
unsafe fn submit( |
| 12 |
&self, |
| 13 |
command_buffers: &[&dyn DynCommandBuffer], |
| 14 |
surface_textures: &[&dyn DynSurfaceTexture], |
| 15 |
signal_fence: (&mut dyn DynFence, FenceValue), |
| 16 |
) -> Result<(), DeviceError>; |
| 17 |
unsafe fn present( |
| 18 |
&self, |
| 19 |
surface: &dyn DynSurface, |
| 20 |
texture: Box<dyn DynSurfaceTexture>, |
| 21 |
) -> Result<(), SurfaceError>; |
| 22 |
unsafe fn get_timestamp_period(&self) -> f32; |
| 23 |
} |
| 24 |
|
| 25 |
impl<Q: Queue + DynResource> DynQueue for Q { |
| 26 |
unsafe fn submit( |
| 27 |
&self, |
| 28 |
command_buffers: &[&dyn DynCommandBuffer], |
| 29 |
surface_textures: &[&dyn DynSurfaceTexture], |
| 30 |
signal_fence: (&mut dyn DynFence, FenceValue), |
| 31 |
) -> Result<(), DeviceError> { |
| 32 |
let command_buffers = command_buffers |
| 33 |
.iter() |
| 34 |
.map(|cb| (*cb).expect_downcast_ref()) |
| 35 |
.collect::<Vec<_>>(); |
| 36 |
let surface_textures = surface_textures |
| 37 |
.iter() |
| 38 |
.map(|surface| (*surface).expect_downcast_ref()) |
| 39 |
.collect::<Vec<_>>(); |
| 40 |
let signal_fence = (signal_fence.0.expect_downcast_mut(), signal_fence.1); |
| 41 |
unsafe { Q::submit(self, &command_buffers, &surface_textures, signal_fence) } |
| 42 |
} |
| 43 |
|
| 44 |
unsafe fn present( |
| 45 |
&self, |
| 46 |
surface: &dyn DynSurface, |
| 47 |
texture: Box<dyn DynSurfaceTexture>, |
| 48 |
) -> Result<(), SurfaceError> { |
| 49 |
let surface = surface.expect_downcast_ref(); |
| 50 |
unsafe { Q::present(self, surface, texture.unbox()) } |
| 51 |
} |
| 52 |
|
| 53 |
unsafe fn get_timestamp_period(&self) -> f32 { |
| 54 |
unsafe { Q::get_timestamp_period(self) } |
| 55 |
} |
| 56 |
} |