diff --git a/Cargo.toml b/Cargo.toml index 075774745a..0f758bc110 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -154,7 +154,7 @@ resvg = "0.36" rustc-hash = "1.0" sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "2e9bf9f" } smol = "1.0" -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" } syntect = "5.1" sysinfo = "0.28" thiserror = "1.0" diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs index 0222a80f01..8c714bbbe0 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/src/window/compositor.rs b/tiny_skia/src/window/compositor.rs index 828e522f23..4fa60365de 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>, @@ -47,9 +48,14 @@ impl crate::graphics::Compositor for Compositor { height: u32, ) -> Surface { #[allow(unsafe_code)] - 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, @@ -176,11 +182,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/wgpu/src/image.rs b/wgpu/src/image.rs index 1053beae6d..c87cb5383e 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -426,6 +426,7 @@ impl Pipeline { handle, filter_method, bounds, + .. } => { if let Some(atlas_entry) = raster_cache.upload( device,