summaryrefslogtreecommitdiffstats
path: root/tiny_skia
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-04-05 19:30:07 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-04-05 19:30:07 +0200
commit940a47eafd098dce3567a95c38dc8697b0fc7115 (patch)
treea0bc0627efa629e98f63ccd66ef9b6964b458006 /tiny_skia
parent92d61e5c592818745abbab245a82cb14b262ae67 (diff)
downloadiced-940a47eafd098dce3567a95c38dc8697b0fc7115.tar.gz
iced-940a47eafd098dce3567a95c38dc8697b0fc7115.tar.bz2
iced-940a47eafd098dce3567a95c38dc8697b0fc7115.zip
Revert "Use `softbuffer` fork with owned pixel buffer"
This reverts commit 92d61e5c592818745abbab245a82cb14b262ae67. The owned pixel buffer zeroes the data in some platforms. `softbuffer` will need some first-class support for damage regions.
Diffstat (limited to 'tiny_skia')
-rw-r--r--tiny_skia/Cargo.toml5
-rw-r--r--tiny_skia/src/window/compositor.rs42
2 files changed, 17 insertions, 30 deletions
diff --git a/tiny_skia/Cargo.toml b/tiny_skia/Cargo.toml
index db590fc2..349f6903 100644
--- a/tiny_skia/Cargo.toml
+++ b/tiny_skia/Cargo.toml
@@ -10,6 +10,7 @@ geometry = ["iced_graphics/geometry"]
[dependencies]
raw-window-handle = "0.5"
+softbuffer = "0.2"
tiny-skia = "0.8"
bytemuck = "1"
rustc-hash = "1.1"
@@ -21,10 +22,6 @@ version = "0.7"
path = "../graphics"
features = ["tiny-skia"]
-[dependencies.softbuffer]
-git = "https://github.com/rust-windowing/softbuffer"
-rev = "872c66a4c05fd7cb6cb133154f75fdce45a175a6"
-
[dependencies.cosmic-text]
features = ["std", "swash"]
git = "https://github.com/pop-os/cosmic-text"
diff --git a/tiny_skia/src/window/compositor.rs b/tiny_skia/src/window/compositor.rs
index 5b1e56a4..6e4bb6ef 100644
--- a/tiny_skia/src/window/compositor.rs
+++ b/tiny_skia/src/window/compositor.rs
@@ -5,7 +5,6 @@ use crate::{Backend, Renderer, Settings};
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use std::marker::PhantomData;
-use std::num::NonZeroU32;
pub struct Compositor<Theme> {
clip_mask: tiny_skia::ClipMask,
@@ -13,7 +12,8 @@ pub struct Compositor<Theme> {
}
pub struct Surface {
- window: softbuffer::Surface,
+ window: softbuffer::GraphicsContext,
+ buffer: Vec<u32>,
}
impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
@@ -36,20 +36,14 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
width: u32,
height: u32,
) -> Surface {
- let platform = unsafe { softbuffer::Context::new(window) }
- .expect("Create softbuffer context");
+ let window =
+ unsafe { softbuffer::GraphicsContext::new(window, window) }
+ .expect("Create softbuffer for window");
- let mut window = unsafe { softbuffer::Surface::new(&platform, window) }
- .expect("Create softbuffer surface");
-
- window
- .resize(
- NonZeroU32::new(width).unwrap(),
- NonZeroU32::new(height).unwrap(),
- )
- .expect("Resize surface");
-
- Surface { window }
+ Surface {
+ window,
+ buffer: vec![0; width as usize * height as usize],
+ }
}
fn configure_surface(
@@ -58,13 +52,7 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
width: u32,
height: u32,
) {
- surface
- .window
- .resize(
- NonZeroU32::new(width).unwrap(),
- NonZeroU32::new(height).unwrap(),
- )
- .expect("Resize surface");
+ surface.buffer.resize((width * height) as usize, 0);
}
fn fetch_information(&self) -> Information {
@@ -118,11 +106,9 @@ pub fn present<Theme, T: AsRef<str>>(
) -> Result<(), compositor::SurfaceError> {
let physical_size = viewport.physical_size();
- let mut buffer = surface.window.buffer_mut().expect("Get window buffer");
-
let drawn = backend.draw(
&mut tiny_skia::PixmapMut::from_bytes(
- bytemuck::cast_slice_mut(&mut buffer),
+ bytemuck::cast_slice_mut(&mut surface.buffer),
physical_size.width,
physical_size.height,
)
@@ -135,7 +121,11 @@ pub fn present<Theme, T: AsRef<str>>(
);
if drawn {
- let _ = buffer.present();
+ surface.window.set_buffer(
+ &surface.buffer,
+ physical_size.width as u16,
+ physical_size.height as u16,
+ );
}
Ok(())