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 15, 2023
1 parent f20c85d commit 55968d6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
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
2 changes: 1 addition & 1 deletion tiny_skia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 All @@ -39,9 +40,14 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
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,
Expand Down Expand Up @@ -168,11 +174,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)

Check warning on line 180 in tiny_skia/src/window/compositor.rs

View workflow job for this annotation

GitHub Actions / all

unnecessary closure used to substitute value for `Option::None`

Check warning on line 180 in tiny_skia/src/window/compositor.rs

View workflow job for this annotation

GitHub Actions / all

casting to the same type is unnecessary (`u32` -> `u32`)

Check warning on line 180 in tiny_skia/src/window/compositor.rs

View workflow job for this annotation

GitHub Actions / all

unnecessary closure used to substitute value for `Option::None`

Check warning on line 180 in tiny_skia/src/window/compositor.rs

View workflow job for this annotation

GitHub Actions / all

casting to the same type is unnecessary (`u32` -> `u32`)
.ok_or_else(|| compositor::SurfaceError::InvalidDimensions)?,
NonZeroU32::new(physical_size.height as u32)

Check warning on line 182 in tiny_skia/src/window/compositor.rs

View workflow job for this annotation

GitHub Actions / all

unnecessary closure used to substitute value for `Option::None`

Check warning on line 182 in tiny_skia/src/window/compositor.rs

View workflow job for this annotation

GitHub Actions / all

casting to the same type is unnecessary (`u32` -> `u32`)

Check warning on line 182 in tiny_skia/src/window/compositor.rs

View workflow job for this annotation

GitHub Actions / all

unnecessary closure used to substitute value for `Option::None`

Check warning on line 182 in tiny_skia/src/window/compositor.rs

View workflow job for this annotation

GitHub Actions / all

casting to the same type is unnecessary (`u32` -> `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
3 changes: 3 additions & 0 deletions widget/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 55968d6

Please sign in to comment.