Use softbuffer fork with owned pixel buffer
This commit is contained in:
parent
e134a82f4c
commit
92d61e5c59
2 changed files with 30 additions and 17 deletions
|
|
@ -10,7 +10,6 @@ geometry = ["iced_graphics/geometry"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
raw-window-handle = "0.5"
|
raw-window-handle = "0.5"
|
||||||
softbuffer = "0.2"
|
|
||||||
tiny-skia = "0.8"
|
tiny-skia = "0.8"
|
||||||
bytemuck = "1"
|
bytemuck = "1"
|
||||||
rustc-hash = "1.1"
|
rustc-hash = "1.1"
|
||||||
|
|
@ -22,6 +21,10 @@ version = "0.7"
|
||||||
path = "../graphics"
|
path = "../graphics"
|
||||||
features = ["tiny-skia"]
|
features = ["tiny-skia"]
|
||||||
|
|
||||||
|
[dependencies.softbuffer]
|
||||||
|
git = "https://github.com/rust-windowing/softbuffer"
|
||||||
|
rev = "872c66a4c05fd7cb6cb133154f75fdce45a175a6"
|
||||||
|
|
||||||
[dependencies.cosmic-text]
|
[dependencies.cosmic-text]
|
||||||
features = ["std", "swash"]
|
features = ["std", "swash"]
|
||||||
git = "https://github.com/pop-os/cosmic-text"
|
git = "https://github.com/pop-os/cosmic-text"
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use crate::{Backend, Renderer, Settings};
|
||||||
|
|
||||||
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
|
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
pub struct Compositor<Theme> {
|
pub struct Compositor<Theme> {
|
||||||
clip_mask: tiny_skia::ClipMask,
|
clip_mask: tiny_skia::ClipMask,
|
||||||
|
|
@ -12,8 +13,7 @@ pub struct Compositor<Theme> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Surface {
|
pub struct Surface {
|
||||||
window: softbuffer::GraphicsContext,
|
window: softbuffer::Surface,
|
||||||
buffer: Vec<u32>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
|
impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
|
||||||
|
|
@ -36,14 +36,20 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> Surface {
|
) -> Surface {
|
||||||
let window =
|
let platform = unsafe { softbuffer::Context::new(window) }
|
||||||
unsafe { softbuffer::GraphicsContext::new(window, window) }
|
.expect("Create softbuffer context");
|
||||||
.expect("Create softbuffer for window");
|
|
||||||
|
|
||||||
Surface {
|
let mut window = unsafe { softbuffer::Surface::new(&platform, window) }
|
||||||
window,
|
.expect("Create softbuffer surface");
|
||||||
buffer: vec![0; width as usize * height as usize],
|
|
||||||
}
|
window
|
||||||
|
.resize(
|
||||||
|
NonZeroU32::new(width).unwrap(),
|
||||||
|
NonZeroU32::new(height).unwrap(),
|
||||||
|
)
|
||||||
|
.expect("Resize surface");
|
||||||
|
|
||||||
|
Surface { window }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_surface(
|
fn configure_surface(
|
||||||
|
|
@ -52,7 +58,13 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) {
|
) {
|
||||||
surface.buffer.resize((width * height) as usize, 0);
|
surface
|
||||||
|
.window
|
||||||
|
.resize(
|
||||||
|
NonZeroU32::new(width).unwrap(),
|
||||||
|
NonZeroU32::new(height).unwrap(),
|
||||||
|
)
|
||||||
|
.expect("Resize surface");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_information(&self) -> Information {
|
fn fetch_information(&self) -> Information {
|
||||||
|
|
@ -106,9 +118,11 @@ pub fn present<Theme, T: AsRef<str>>(
|
||||||
) -> Result<(), compositor::SurfaceError> {
|
) -> Result<(), compositor::SurfaceError> {
|
||||||
let physical_size = viewport.physical_size();
|
let physical_size = viewport.physical_size();
|
||||||
|
|
||||||
|
let mut buffer = surface.window.buffer_mut().expect("Get window buffer");
|
||||||
|
|
||||||
let drawn = backend.draw(
|
let drawn = backend.draw(
|
||||||
&mut tiny_skia::PixmapMut::from_bytes(
|
&mut tiny_skia::PixmapMut::from_bytes(
|
||||||
bytemuck::cast_slice_mut(&mut surface.buffer),
|
bytemuck::cast_slice_mut(&mut buffer),
|
||||||
physical_size.width,
|
physical_size.width,
|
||||||
physical_size.height,
|
physical_size.height,
|
||||||
)
|
)
|
||||||
|
|
@ -121,11 +135,7 @@ pub fn present<Theme, T: AsRef<str>>(
|
||||||
);
|
);
|
||||||
|
|
||||||
if drawn {
|
if drawn {
|
||||||
surface.window.set_buffer(
|
let _ = buffer.present();
|
||||||
&surface.buffer,
|
|
||||||
physical_size.width as u16,
|
|
||||||
physical_size.height as u16,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue