From a7d2834a6d15466eecca29bb6357d3539cb652cd Mon Sep 17 00:00:00 2001 From: Billy Messenger Date: Thu, 22 Jul 2021 13:08:13 -0500 Subject: add custom error for Compositor::draw() --- graphics/src/window/compositor.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'graphics/src/window/compositor.rs') diff --git a/graphics/src/window/compositor.rs b/graphics/src/window/compositor.rs index 7342245c..9f7cb43f 100644 --- a/graphics/src/window/compositor.rs +++ b/graphics/src/window/compositor.rs @@ -43,9 +43,6 @@ pub trait Compositor: Sized { /// Draws the output primitives to the next frame of the given [`SwapChain`]. /// - /// This will return an error if drawing could not be completed on this frame. - /// If an error occurs, try calling this again on the next frame. - /// /// [`SwapChain`]: Self::SwapChain fn draw>( &mut self, @@ -55,5 +52,33 @@ 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), +} + +impl std::error::Error for CompositorDrawError {} + +impl std::fmt::Display for CompositorDrawError { + 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 + ), + } + } } -- cgit