Skip to content

Commit

Permalink
chore: update softbuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Nov 28, 2023
1 parent 8f932f4 commit 0f917ae
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions graphics/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
44 changes: 35 additions & 9 deletions tiny_skia/src/window/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
_theme: PhantomData<Theme>,
}

pub struct Surface {
window: softbuffer::GraphicsContext,
window: softbuffer::Surface,
buffer: Vec<u32>,
clip_mask: tiny_skia::Mask,
primitives: Option<Vec<Primitive>>,
Expand Down Expand Up @@ -47,9 +48,14 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
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,
Expand Down Expand Up @@ -176,11 +182,31 @@ pub fn present<T: AsRef<str>>(
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::<Vec<_>>();
b.copy_from_slice(&surface.buffer);
b.present_with_damage(&damage)
.map_err(|e| compositor::SurfaceError::Present(e.to_string()))?;
}

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions wgpu/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ impl Pipeline {
handle,
filter_method,
bounds,
..
} => {
if let Some(atlas_entry) = raster_cache.upload(
device,
Expand Down

0 comments on commit 0f917ae

Please sign in to comment.