summaryrefslogtreecommitdiffstats
path: root/tiny_skia/src/window
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-26 00:49:27 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-26 00:50:25 +0100
commit744f3028f484c44899fed56d9190387569828a95 (patch)
treee3dbc48e7179c23a6bf23adcb49b6f74d95dc944 /tiny_skia/src/window
parentdf5d66423de141a009bbed993d99d491ed6373c9 (diff)
downloadiced-744f3028f484c44899fed56d9190387569828a95.tar.gz
iced-744f3028f484c44899fed56d9190387569828a95.tar.bz2
iced-744f3028f484c44899fed56d9190387569828a95.zip
Use `Surface::buffer` directly for drawing in `iced_tiny_skia`
... with a nice little color trick :^)
Diffstat (limited to 'tiny_skia/src/window')
-rw-r--r--tiny_skia/src/window/compositor.rs30
1 files changed, 11 insertions, 19 deletions
diff --git a/tiny_skia/src/window/compositor.rs b/tiny_skia/src/window/compositor.rs
index 8bb52a03..2bd5831e 100644
--- a/tiny_skia/src/window/compositor.rs
+++ b/tiny_skia/src/window/compositor.rs
@@ -12,7 +12,6 @@ pub struct Compositor<Theme> {
pub struct Surface {
window: softbuffer::GraphicsContext,
- pixels: tiny_skia::Pixmap,
buffer: Vec<u32>,
}
@@ -40,13 +39,9 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
unsafe { softbuffer::GraphicsContext::new(window, window) }
.expect("Create softbuffer for window");
- let pixels = tiny_skia::Pixmap::new(width, height)
- .expect("Create pixmap for window");
-
Surface {
window,
- pixels,
- buffer: vec![0; (width * height) as usize],
+ buffer: vec![0; width as usize * height as usize],
}
}
@@ -56,9 +51,6 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
width: u32,
height: u32,
) {
- surface.pixels = tiny_skia::Pixmap::new(width, height)
- .expect("Create pixmap for window");
-
surface.buffer.resize((width * height) as usize, 0);
}
@@ -110,26 +102,26 @@ pub fn present<Theme, T: AsRef<str>>(
background_color: Color,
overlay: &[T],
) -> Result<(), compositor::SurfaceError> {
+ let physical_size = viewport.physical_size();
+
backend.draw(
- &mut surface.pixels,
+ &mut tiny_skia::PixmapMut::from_bytes(
+ bytemuck::cast_slice_mut(&mut surface.buffer),
+ physical_size.width,
+ physical_size.height,
+ )
+ .expect("Create pixel map"),
primitives,
viewport,
background_color,
overlay,
);
- for (i, pixel) in surface.pixels.pixels_mut().iter().enumerate() {
- surface.buffer[i] = u32::from(pixel.red()) << 16
- | u32::from(pixel.green()) << 8
- | u32::from(pixel.blue());
- }
-
surface.window.set_buffer(
&surface.buffer,
- surface.pixels.width() as u16,
- surface.pixels.height() as u16,
+ physical_size.width as u16,
+ physical_size.height as u16,
);
- // TODO
Ok(())
}