use std::cell::Cell; use smithay::{ backend::{ allocator::dmabuf::Dmabuf, renderer::{Frame, ImportDma, ImportShm, Renderer, Texture, TextureFilter, Transform}, SwapBuffersError, }, reexports::wayland_server::protocol::wl_buffer, utils::{Buffer, Physical, Rectangle, Size}, wayland::compositor::SurfaceData, }; pub struct DummyRenderer {} impl DummyRenderer { pub fn new() -> DummyRenderer { DummyRenderer {} } } impl Renderer for DummyRenderer { type Error = SwapBuffersError; type TextureId = DummyTexture; type Frame = DummyFrame; fn render( &mut self, _size: Size, _dst_transform: Transform, rendering: F, ) -> Result where F: FnOnce(&mut Self, &mut Self::Frame) -> R, { let mut frame = DummyFrame {}; Ok(rendering(self, &mut frame)) } fn upscale_filter(&mut self, _filter: TextureFilter) -> Result<(), Self::Error> { Ok(()) } fn downscale_filter(&mut self, _filter: TextureFilter) -> Result<(), Self::Error> { Ok(()) } } impl ImportShm for DummyRenderer { fn import_shm_buffer( &mut self, buffer: &wl_buffer::WlBuffer, surface: Option<&SurfaceData>, _damage: &[Rectangle], ) -> Result<::TextureId, ::Error> { use smithay::wayland::shm::with_buffer_contents; let ret = with_buffer_contents(&buffer, |slice, data| { let offset = data.offset as u32; let width = data.width as u32; let height = data.height as u32; let stride = data.stride as u32; let mut x = 0; for h in 0..height { for w in 0..width { x |= slice[(offset + w + h * stride) as usize]; } } if let Some(data) = surface { data.data_map.insert_if_missing(|| Cell::new(0u8)); data.data_map.get::>().unwrap().set(x); } (width, height) }); match ret { Ok((width, height)) => Ok(DummyTexture { width, height }), Err(e) => Err(SwapBuffersError::TemporaryFailure(Box::new(e))), } } } impl ImportDma for DummyRenderer { fn import_dmabuf( &mut self, _dmabuf: &Dmabuf, ) -> Result<::TextureId, ::Error> { unimplemented!() } } pub struct DummyFrame {} impl Frame for DummyFrame { type Error = SwapBuffersError; type TextureId = DummyTexture; fn clear(&mut self, _color: [f32; 4], _damage: &[Rectangle]) -> Result<(), Self::Error> { Ok(()) } fn render_texture_from_to( &mut self, _texture: &Self::TextureId, _src: Rectangle, _dst: Rectangle, _damage: &[Rectangle], _src_transform: Transform, _alpha: f32, ) -> Result<(), Self::Error> { Ok(()) } fn transformation(&self) -> Transform { Transform::Normal } } pub struct DummyTexture { width: u32, height: u32, } impl Texture for DummyTexture { fn width(&self) -> u32 { self.width } fn height(&self) -> u32 { self.height } }