From 378f826c26ca309dafe1372c69ce7aafdac7e516 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Thu, 13 May 2021 14:33:10 +0200 Subject: [PATCH] swapchain: do not convert buffers automatically anymore --- examples/raw_drm.rs | 2 +- src/backend/allocator/mod.rs | 2 +- src/backend/allocator/swapchain.rs | 40 ++++++------------------------ 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/examples/raw_drm.rs b/examples/raw_drm.rs index 261b7b8..a01c645 100644 --- a/examples/raw_drm.rs +++ b/examples/raw_drm.rs @@ -133,7 +133,7 @@ fn main() { pub struct DrmHandlerImpl { swapchain: - Swapchain, DumbBuffer, framebuffer::Handle, DumbBuffer>, + Swapchain, DumbBuffer, framebuffer::Handle>, current: Slot, framebuffer::Handle>, surface: Rc>, } diff --git a/src/backend/allocator/mod.rs b/src/backend/allocator/mod.rs index 7cbe4da..e3218dc 100644 --- a/src/backend/allocator/mod.rs +++ b/src/backend/allocator/mod.rs @@ -22,7 +22,7 @@ pub mod dumb; pub mod gbm; mod swapchain; -pub use swapchain::{Slot, Swapchain, SwapchainError}; +pub use swapchain::{Slot, Swapchain}; pub use drm_fourcc::{ DrmFormat as Format, DrmFourcc as Fourcc, DrmModifier as Modifier, DrmVendor as Vendor, diff --git a/src/backend/allocator/swapchain.rs b/src/backend/allocator/swapchain.rs index 64a8821..fc8defb 100644 --- a/src/backend/allocator/swapchain.rs +++ b/src/backend/allocator/swapchain.rs @@ -1,4 +1,3 @@ -use std::convert::TryInto; use std::ops::Deref; use std::sync::{ atomic::{AtomicBool, Ordering}, @@ -37,16 +36,15 @@ pub const SLOT_CAP: usize = 4; /// you can store then in the buffer slots userdata, where it gets freed, if the buffer gets allocated, but /// is still valid, if the buffer was just re-used. So instead of creating a framebuffer handle for each new /// buffer, you can skip creation, if the userdata already contains a framebuffer handle. -pub struct Swapchain, B: Buffer + TryInto, U: 'static, D: Buffer = B> { +pub struct Swapchain, B: Buffer, U: 'static> { /// Allocator used by the swapchain pub allocator: A, - _original_buffer_format: std::marker::PhantomData, width: u32, height: u32, format: Format, - slots: [Slot; SLOT_CAP], + slots: [Slot; SLOT_CAP], } /// Slot of a swapchain containing an allocated buffer and its userdata. @@ -110,35 +108,16 @@ impl Drop for Slot { } } -/// Error that can happen on acquiring a buffer -#[derive(Debug, thiserror::Error)] -pub enum SwapchainError +impl Swapchain where - E1: std::error::Error + 'static, - E2: std::error::Error + 'static, -{ - /// The allocator returned an error - #[error("Failed to allocate a new buffer: {0}")] - AllocationError(#[source] E1), - /// The buffer could not be successfully converted into the desired format - #[error("Failed to convert a new buffer: {0}")] - ConversionError(#[source] E2), -} - -impl Swapchain -where - A: Allocator, - B: Buffer + TryInto, - D: Buffer, - E1: std::error::Error + 'static, - E2: std::error::Error + 'static, + A: Allocator, + B: Buffer, U: 'static, { /// Create a new swapchain with the desired allocator and dimensions and pixel format for the created buffers. - pub fn new(allocator: A, width: u32, height: u32, format: Format) -> Swapchain { + pub fn new(allocator: A, width: u32, height: u32, format: Format) -> Swapchain { Swapchain { allocator, - _original_buffer_format: std::marker::PhantomData, width, height, format, @@ -150,15 +129,12 @@ where /// /// The swapchain has an internal maximum of four re-usable buffers. /// This function returns the first free one. - pub fn acquire(&mut self) -> Result>, SwapchainError> { + pub fn acquire(&mut self) -> Result>, A::Error> { if let Some(free_slot) = self.slots.iter_mut().find(|s| !s.acquired.load(Ordering::SeqCst)) { if free_slot.buffer.is_none() { free_slot.buffer = Arc::new(Some( self.allocator - .create_buffer(self.width, self.height, self.format) - .map_err(SwapchainError::AllocationError)? - .try_into() - .map_err(SwapchainError::ConversionError)?, + .create_buffer(self.width, self.height, self.format)? )); } assert!(free_slot.buffer.is_some());