summaryrefslogtreecommitdiffstats
path: root/tiny_skia/src/window/compositor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tiny_skia/src/window/compositor.rs')
-rw-r--r--tiny_skia/src/window/compositor.rs76
1 files changed, 13 insertions, 63 deletions
diff --git a/tiny_skia/src/window/compositor.rs b/tiny_skia/src/window/compositor.rs
index 5a0097df..6e4bb6ef 100644
--- a/tiny_skia/src/window/compositor.rs
+++ b/tiny_skia/src/window/compositor.rs
@@ -11,13 +11,9 @@ pub struct Compositor<Theme> {
_theme: PhantomData<Theme>,
}
-pub enum Surface {
- Cpu {
- window: softbuffer::GraphicsContext,
- buffer: Vec<u32>,
- },
- #[cfg(feature = "gpu")]
- Gpu { pixels: pixels::Pixels },
+pub struct Surface {
+ window: softbuffer::GraphicsContext,
+ buffer: Vec<u32>,
}
impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
@@ -40,29 +36,11 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
width: u32,
height: u32,
) -> Surface {
- #[cfg(feature = "gpu")]
- {
- let surface_texture =
- pixels::SurfaceTexture::new(width, height, window);
-
- if let Ok(pixels) =
- pixels::PixelsBuilder::new(width, height, surface_texture)
- .texture_format(pixels::wgpu::TextureFormat::Bgra8UnormSrgb)
- .build()
- {
- log::info!("GPU surface created");
-
- return Surface::Gpu { pixels };
- }
- }
-
let window =
unsafe { softbuffer::GraphicsContext::new(window, window) }
.expect("Create softbuffer for window");
- log::info!("CPU surface created");
-
- Surface::Cpu {
+ Surface {
window,
buffer: vec![0; width as usize * height as usize],
}
@@ -74,19 +52,7 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
width: u32,
height: u32,
) {
- match surface {
- Surface::Cpu { buffer, .. } => {
- buffer.resize((width * height) as usize, 0);
- }
- #[cfg(feature = "gpu")]
- Surface::Gpu { pixels } => {
- pixels
- .resize_surface(width, height)
- .expect("Resize surface");
-
- pixels.resize_buffer(width, height).expect("Resize buffer");
- }
- }
+ surface.buffer.resize((width * height) as usize, 0);
}
fn fetch_information(&self) -> Information {
@@ -140,15 +106,9 @@ pub fn present<Theme, T: AsRef<str>>(
) -> Result<(), compositor::SurfaceError> {
let physical_size = viewport.physical_size();
- let buffer = match surface {
- Surface::Cpu { buffer, .. } => bytemuck::cast_slice_mut(buffer),
- #[cfg(feature = "gpu")]
- Surface::Gpu { pixels } => pixels.frame_mut(),
- };
-
let drawn = backend.draw(
&mut tiny_skia::PixmapMut::from_bytes(
- buffer,
+ bytemuck::cast_slice_mut(&mut surface.buffer),
physical_size.width,
physical_size.height,
)
@@ -161,22 +121,12 @@ pub fn present<Theme, T: AsRef<str>>(
);
if drawn {
- match surface {
- Surface::Cpu { window, buffer } => {
- window.set_buffer(
- buffer,
- physical_size.width as u16,
- physical_size.height as u16,
- );
-
- Ok(())
- }
- #[cfg(feature = "gpu")]
- Surface::Gpu { pixels } => {
- pixels.render().map_err(|_| compositor::SurfaceError::Lost)
- }
- }
- } else {
- Ok(())
+ surface.window.set_buffer(
+ &surface.buffer,
+ physical_size.width as u16,
+ physical_size.height as u16,
+ );
}
+
+ Ok(())
}