add SurfaceError::TextureDestroyed

This commit is contained in:
teoxoy 2024-10-11 16:30:32 +02:00 committed by Teodor Tanasoaia
parent 39629d0de0
commit 26624c04e0

View File

@ -43,6 +43,8 @@ pub enum SurfaceError {
Device(#[from] DeviceError), Device(#[from] DeviceError),
#[error("Surface image is already acquired")] #[error("Surface image is already acquired")]
AlreadyAcquired, AlreadyAcquired,
#[error("Texture has been destroyed")]
TextureDestroyed,
#[error("Acquired frame is still referenced")] #[error("Acquired frame is still referenced")]
StillReferenced, StillReferenced,
} }
@ -271,15 +273,13 @@ impl Global {
.take() .take()
.ok_or(SurfaceError::AlreadyAcquired)?; .ok_or(SurfaceError::AlreadyAcquired)?;
let result = match texture let result = match texture.inner.snatch(&mut device.snatchable_lock.write()) {
.inner None => return Err(SurfaceError::TextureDestroyed),
.snatch(&mut device.snatchable_lock.write()) Some(resource::TextureInner::Surface { raw }) => {
.unwrap()
{
resource::TextureInner::Surface { raw } => unsafe {
let raw_surface = surface.raw(device.backend()).unwrap(); let raw_surface = surface.raw(device.backend()).unwrap();
queue.raw().present(raw_surface, raw) let raw_queue = queue.raw();
}, unsafe { raw_queue.present(raw_surface, raw) }
}
_ => unreachable!(), _ => unreachable!(),
}; };
@ -323,12 +323,9 @@ impl Global {
.take() .take()
.ok_or(SurfaceError::AlreadyAcquired)?; .ok_or(SurfaceError::AlreadyAcquired)?;
match texture match texture.inner.snatch(&mut device.snatchable_lock.write()) {
.inner None => return Err(SurfaceError::TextureDestroyed),
.snatch(&mut device.snatchable_lock.write()) Some(resource::TextureInner::Surface { raw }) => {
.unwrap()
{
resource::TextureInner::Surface { raw } => {
let raw_surface = surface.raw(device.backend()).unwrap(); let raw_surface = surface.raw(device.backend()).unwrap();
unsafe { raw_surface.discard_texture(raw) }; unsafe { raw_surface.discard_texture(raw) };
} }