From 5fc49edc55a0e64c4c46ca55eddafe9d4e8232e1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 18 Jan 2024 10:06:30 +0100 Subject: Make `compatible_window` mandatory in `Compositor` --- tiny_skia/src/window/compositor.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'tiny_skia/src') diff --git a/tiny_skia/src/window/compositor.rs b/tiny_skia/src/window/compositor.rs index b5e9bcd8..86400aa0 100644 --- a/tiny_skia/src/window/compositor.rs +++ b/tiny_skia/src/window/compositor.rs @@ -9,7 +9,7 @@ use std::marker::PhantomData; use std::num::NonZeroU32; pub struct Compositor { - context: Option>>, + context: softbuffer::Context>, settings: Settings, _theme: PhantomData, } @@ -32,7 +32,7 @@ impl crate::graphics::Compositor for Compositor { fn new( settings: Self::Settings, - compatible_window: Option, + compatible_window: W, ) -> Result { Ok(new(settings, compatible_window)) } @@ -51,17 +51,11 @@ impl crate::graphics::Compositor for Compositor { width: u32, height: u32, ) -> Surface { - let window = if let Some(context) = self.context.as_ref() { - softbuffer::Surface::new(context, Box::new(window.clone()) as _) - .expect("Create softbuffer surface for window") - } else { - let context = - softbuffer::Context::new(Box::new(window.clone()) as _) - .expect("Create softbuffer context for window"); - - softbuffer::Surface::new(&context, Box::new(window.clone()) as _) - .expect("Create softbuffer surface for window") - }; + let window = softbuffer::Surface::new( + &self.context, + Box::new(window.clone()) as _, + ) + .expect("Create softbuffer surface for window"); Surface { window, @@ -133,11 +127,11 @@ impl crate::graphics::Compositor for Compositor { pub fn new( settings: Settings, - compatible_window: Option, + compatible_window: W, ) -> Compositor { #[allow(unsafe_code)] - let context = compatible_window - .and_then(|w| softbuffer::Context::new(Box::new(w) as _).ok()); + let context = softbuffer::Context::new(Box::new(compatible_window) as _) + .expect("Create softbuffer context"); Compositor { context, -- cgit