From 7289b6091b61b0aa448a756cfe32211c78a4cce0 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Tue, 9 Jan 2024 07:19:15 -0800 Subject: WIP raw-window-handle 0.6 --- tiny_skia/src/window/compositor.rs | 56 ++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'tiny_skia/src') diff --git a/tiny_skia/src/window/compositor.rs b/tiny_skia/src/window/compositor.rs index d99b85d4..788d7297 100644 --- a/tiny_skia/src/window/compositor.rs +++ b/tiny_skia/src/window/compositor.rs @@ -4,33 +4,36 @@ use crate::graphics::damage; use crate::graphics::{Error, Viewport}; use crate::{Backend, Primitive, Renderer, Settings}; -use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; +use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; use std::collections::VecDeque; use std::marker::PhantomData; use std::num::NonZeroU32; -pub struct Compositor { - context: Option, +pub struct Compositor { + context: Option>, settings: Settings, _theme: PhantomData, } -pub struct Surface { - window: softbuffer::Surface, +pub struct Surface { + window: softbuffer::Surface, clip_mask: tiny_skia::Mask, // Primitives of existing buffers, by decreasing age primitives: VecDeque>, background_color: Color, } -impl crate::graphics::Compositor for Compositor { +// XXX avoid clone bound? +impl + crate::graphics::Compositor for Compositor +{ type Settings = Settings; type Renderer = Renderer; - type Surface = Surface; + type Surface = Surface; - fn new( + fn new( settings: Self::Settings, - compatible_window: Option<&W>, + compatible_window: Option, ) -> Result { Ok(new(settings, compatible_window)) } @@ -43,20 +46,19 @@ impl crate::graphics::Compositor for Compositor { ) } - fn create_surface( + fn create_surface( &mut self, - window: &W, + window: W, width: u32, height: u32, - ) -> Surface { - #[allow(unsafe_code)] + ) -> Surface { let window = if let Some(context) = self.context.as_ref() { - unsafe { softbuffer::Surface::new(context, window) } + softbuffer::Surface::new(context, window) .expect("Create softbuffer surface for window") } else { - let context = unsafe { softbuffer::Context::new(window) } + let context = softbuffer::Context::new(window.clone()) .expect("Create softbuffer context for window"); - unsafe { softbuffer::Surface::new(&context, window) } + softbuffer::Surface::new(&context, window) .expect("Create softbuffer surface for window") }; @@ -71,7 +73,7 @@ impl crate::graphics::Compositor for Compositor { fn configure_surface( &mut self, - surface: &mut Surface, + surface: &mut Surface, width: u32, height: u32, ) { @@ -90,7 +92,7 @@ impl crate::graphics::Compositor for Compositor { fn present>( &mut self, renderer: &mut Self::Renderer, - surface: &mut Self::Surface, + surface: &mut Surface, viewport: &Viewport, background_color: Color, overlay: &[T], @@ -128,13 +130,13 @@ impl crate::graphics::Compositor for Compositor { } } -pub fn new( +pub fn new( settings: Settings, - compatible_window: Option<&W>, -) -> Compositor { + compatible_window: Option, +) -> Compositor { #[allow(unsafe_code)] - let context = compatible_window - .and_then(|w| unsafe { softbuffer::Context::new(w) }.ok()); + let context = + compatible_window.and_then(|w| softbuffer::Context::new(w).ok()); Compositor { context, settings, @@ -142,9 +144,9 @@ pub fn new( } } -pub fn present>( +pub fn present>( backend: &mut Backend, - surface: &mut Surface, + surface: &mut Surface, primitives: &[Primitive], viewport: &Viewport, background_color: Color, @@ -216,8 +218,8 @@ pub fn present>( buffer.present().map_err(|_| compositor::SurfaceError::Lost) } -pub fn screenshot>( - surface: &mut Surface, +pub fn screenshot>( + surface: &mut Surface, backend: &mut Backend, primitives: &[Primitive], viewport: &Viewport, -- cgit