diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs index f7b8604581..c342ee5a40 100644 --- a/graphics/src/compositor.rs +++ b/graphics/src/compositor.rs @@ -93,6 +93,15 @@ pub enum SurfaceError { /// There is no more memory left to allocate a new frame. #[error("There is no more memory left to allocate a new frame")] OutOfMemory, + /// Resize Error + #[error("Resize Error")] + Resize, + /// Invalid dimensions + #[error("Invalid dimensions")] + InvalidDimensions, + /// Present Error + #[error("Present Error")] + Present(String), } /// Contains information about the graphics (e.g. graphics adapter, graphics backend). diff --git a/tiny_skia/Cargo.toml b/tiny_skia/Cargo.toml index 0f4e22153b..2f151e1783 100644 --- a/tiny_skia/Cargo.toml +++ b/tiny_skia/Cargo.toml @@ -17,7 +17,7 @@ geometry = ["iced_graphics/geometry"] [dependencies] raw-window-handle = "0.5" -softbuffer = { git = "https://github.com/pop-os/softbuffer", tag = "cosmic-2.0-old" } +softbuffer = { git = "https://github.com/pop-os/softbuffer", tag = "v0.3-cosmic" } tiny-skia = "0.10" cosmic-text = "0.9" bytemuck = "1" diff --git a/tiny_skia/src/window/compositor.rs b/tiny_skia/src/window/compositor.rs index 775cf9e5b8..676de450cc 100644 --- a/tiny_skia/src/window/compositor.rs +++ b/tiny_skia/src/window/compositor.rs @@ -6,13 +6,14 @@ use crate::{Backend, Primitive, Renderer, Settings}; use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; use std::marker::PhantomData; +use std::num::NonZeroU32; pub struct Compositor { _theme: PhantomData, } pub struct Surface { - window: softbuffer::GraphicsContext, + window: softbuffer::Surface, buffer: Vec, clip_mask: tiny_skia::Mask, primitives: Option>, @@ -39,9 +40,14 @@ impl crate::graphics::Compositor for Compositor { width: u32, height: u32, ) -> Surface { - let window = - unsafe { softbuffer::GraphicsContext::new(window, window) } - .expect("Create softbuffer for window"); + let window = unsafe { + softbuffer::Surface::new( + &softbuffer::Context::new(window) + .expect("Failed to create softbuffer context"), + window, + ) + } + .expect("Create softbuffer for window"); Surface { window, @@ -168,11 +174,31 @@ pub fn present>( overlay, ); - surface.window.set_buffer( - &surface.buffer, - physical_size.width as u16, - physical_size.height as u16, - ); + surface + .window + .resize( + NonZeroU32::new(physical_size.width as u32) + .ok_or_else(|| compositor::SurfaceError::InvalidDimensions)?, + NonZeroU32::new(physical_size.height as u32) + .ok_or_else(|| compositor::SurfaceError::InvalidDimensions)?, + ) + .map_err(|_| compositor::SurfaceError::Resize)?; + if let Ok(mut b) = surface.window.buffer_mut() { + let damage = damage + .iter() + .filter_map(|r| { + Some(softbuffer::Rect { + x: r.x as u32, + y: r.y as u32, + width: NonZeroU32::new(r.width as u32)?, + height: NonZeroU32::new(r.height as u32)?, + }) + }) + .collect::>(); + b.copy_from_slice(&surface.buffer); + b.present_with_damage(&damage) + .map_err(|e| compositor::SurfaceError::Present(e.to_string()))?; + } Ok(()) } diff --git a/widget/src/image.rs b/widget/src/image.rs index 7be47d1ea9..a3b7a1fd5e 100644 --- a/widget/src/image.rs +++ b/widget/src/image.rs @@ -14,6 +14,9 @@ use crate::core::{ use std::hash::Hash; +#[cfg(feature = "a11y")] +use std::borrow::Cow; + pub use image::Handle; /// Creates a new [`Viewer`] with the given image `Handle`.