From e5010b8ab87b2e30feea366396bc060c8e793d8d Mon Sep 17 00:00:00 2001 From: Billy Messenger Date: Thu, 22 Jul 2021 13:23:36 -0500 Subject: redo custom error for Compositor::draw() --- graphics/src/window/compositor.rs | 41 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'graphics/src/window/compositor.rs') diff --git a/graphics/src/window/compositor.rs b/graphics/src/window/compositor.rs index 9f7cb43f..9811d95d 100644 --- a/graphics/src/window/compositor.rs +++ b/graphics/src/window/compositor.rs @@ -52,33 +52,32 @@ pub trait Compositor: Sized { background_color: Color, output: &::Output, overlay: &[T], - ) -> Result; + ) -> Result; } /// Result of an unsuccessful call to [`Compositor::draw`]. -#[derive(Debug)] -pub enum CompositorDrawError { - /// The swapchain is outdated. Try rendering again next frame. - SwapchainOutdated(Box), - /// A fatal swapchain error occured. Rendering cannot continue. - FatalSwapchainError(Box), +/// Result of an unsuccessful call to [`SwapChain::get_current_frame`]. +#[derive(Clone, PartialEq, Eq, Debug)] +pub enum SwapChainError { + /// A timeout was encountered while trying to acquire the next frame. + Timeout, + /// The underlying surface has changed, and therefore the swap chain must be updated. + Outdated, + /// The swap chain has been lost and needs to be recreated. + Lost, + /// There is no more memory left to allocate a new frame. + OutOfMemory, } -impl std::error::Error for CompositorDrawError {} +impl std::error::Error for SwapChainError {} -impl std::fmt::Display for CompositorDrawError { +impl std::fmt::Display for SwapChainError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - CompositorDrawError::SwapchainOutdated(e) => write!( - f, - "Swapchain is outdated: {}. Try rendering next frame.", - e - ), - CompositorDrawError::FatalSwapchainError(e) => write!( - f, - "Fatal swapchain error: {}. Rendering cannot continue.", - e - ), - } + write!(f, "{}", match self { + Self::Timeout => "A timeout was encountered while trying to acquire the next frame", + Self::Outdated => "The underlying surface has changed, and therefore the swap chain must be updated", + Self::Lost => "The swap chain has been lost and needs to be recreated", + Self::OutOfMemory => "There is no more memory left to allocate a new frame", + }) } } -- cgit