mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 14:01:08 +01:00
introduce DynSurface
This commit is contained in:
1 parent
70f7641193
commit
4e5721350f
3 files changed
+79
-6
No files matched your search
@@ -1,8 +1,10 @@
|
||||
mod command;
|
||||
mod device;
|
||||
mod surface;
|
||||
|
||||
pub use self::command::DynCommandEncoder;
|
||||
pub use self::device::DynDevice;
|
||||
pub use command::DynCommandEncoder;
|
||||
pub use device::DynDevice;
|
||||
pub use surface::{DynAcquiredSurfaceTexture, DynSurface};
|
||||
|
||||
use std::any::Any;
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
use crate::{
|
||||
DynDevice, DynFence, DynResource, DynSurfaceTexture, Surface, SurfaceConfiguration,
|
||||
SurfaceError,
|
||||
};
|
||||
|
||||
use super::DynResourceExt as _;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DynAcquiredSurfaceTexture {
|
||||
pub texture: Box<dyn DynSurfaceTexture>,
|
||||
/// The presentation configuration no longer matches
|
||||
/// the surface properties exactly, but can still be used to present
|
||||
/// to the surface successfully.
|
||||
pub suboptimal: bool,
|
||||
}
|
||||
|
||||
pub trait DynSurface: DynResource {
|
||||
unsafe fn configure(
|
||||
&self,
|
||||
device: &dyn DynDevice,
|
||||
config: &SurfaceConfiguration,
|
||||
) -> Result<(), SurfaceError>;
|
||||
|
||||
unsafe fn unconfigure(&self, device: &dyn DynDevice);
|
||||
|
||||
unsafe fn acquire_texture(
|
||||
&self,
|
||||
timeout: Option<std::time::Duration>,
|
||||
fence: &dyn DynFence,
|
||||
) -> Result<Option<DynAcquiredSurfaceTexture>, SurfaceError>;
|
||||
|
||||
unsafe fn discard_texture(&self, texture: Box<dyn DynSurfaceTexture>);
|
||||
}
|
||||
|
||||
impl<S: Surface + DynResource> DynSurface for S {
|
||||
unsafe fn configure(
|
||||
&self,
|
||||
device: &dyn DynDevice,
|
||||
config: &SurfaceConfiguration,
|
||||
) -> Result<(), SurfaceError> {
|
||||
let device = device.expect_downcast_ref();
|
||||
unsafe { S::configure(self, device, config) }
|
||||
}
|
||||
|
||||
unsafe fn unconfigure(&self, device: &dyn DynDevice) {
|
||||
let device = device.expect_downcast_ref();
|
||||
unsafe { S::unconfigure(self, device) }
|
||||
}
|
||||
|
||||
unsafe fn acquire_texture(
|
||||
&self,
|
||||
timeout: Option<std::time::Duration>,
|
||||
fence: &dyn DynFence,
|
||||
) -> Result<Option<DynAcquiredSurfaceTexture>, SurfaceError> {
|
||||
let fence = fence.expect_downcast_ref();
|
||||
unsafe { S::acquire_texture(self, timeout, fence) }.map(|acquired| {
|
||||
acquired.map(|ast| {
|
||||
let texture = Box::new(ast.texture);
|
||||
let suboptimal = ast.suboptimal;
|
||||
DynAcquiredSurfaceTexture {
|
||||
texture,
|
||||
suboptimal,
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
unsafe fn discard_texture(&self, texture: Box<dyn DynSurfaceTexture>) {
|
||||
unsafe { S::discard_texture(self, texture.unbox()) }
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -266,10 +266,10 @@ mod dynamic;
|
||||
|
||||
pub(crate) use dynamic::impl_dyn_resource;
|
||||
pub use dynamic::{
|
||||
DynAccelerationStructure, DynBindGroup, DynBindGroupLayout, DynBuffer, DynCommandBuffer,
|
||||
DynCommandEncoder, DynComputePipeline, DynDevice, DynFence, DynPipelineCache,
|
||||
DynPipelineLayout, DynQuerySet, DynRenderPipeline, DynResource, DynSampler, DynShaderModule,
|
||||
DynSurfaceTexture, DynTexture, DynTextureView,
|
||||
DynAccelerationStructure, DynAcquiredSurfaceTexture, DynBindGroup, DynBindGroupLayout,
|
||||
DynBuffer, DynCommandBuffer, DynCommandEncoder, DynComputePipeline, DynDevice, DynFence,
|
||||
DynPipelineCache, DynPipelineLayout, DynQuerySet, DynRenderPipeline, DynResource, DynSampler,
|
||||
DynShaderModule, DynSurface, DynSurfaceTexture, DynTexture, DynTextureView,
|
||||
};
|
||||
|
||||
use std::{
|
||||
|
||||
Reference in new issue
Block a user