Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update softbuffer #82

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
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 @@
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
Loading