From 17de1650a03f1071b8a41b3efd49999e26b502b1 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 6 Oct 2024 11:31:47 +0200 Subject: [PATCH] screencopy: unconditionally create copy for shm --- src/gfx_api.rs | 10 --- src/gfx_apis/gl.rs | 2 - src/gfx_apis/gl/renderer/texture.rs | 24 +------ src/gfx_apis/vulkan/image.rs | 15 ---- src/it/test_gfx_api.rs | 14 ---- src/state.rs | 104 +++++++++------------------- 6 files changed, 35 insertions(+), 134 deletions(-) diff --git a/src/gfx_api.rs b/src/gfx_api.rs index d36b2e11..abf53af2 100644 --- a/src/gfx_api.rs +++ b/src/gfx_api.rs @@ -481,16 +481,6 @@ pub trait GfxTexture: Debug { fn size(&self) -> (i32, i32); fn as_any(&self) -> &dyn Any; fn into_any(self: Rc) -> Rc; - fn read_pixels( - self: Rc, - x: i32, - y: i32, - width: i32, - height: i32, - stride: i32, - format: &'static Format, - shm: &[Cell], - ) -> Result<(), GfxError>; fn dmabuf(&self) -> Option<&DmaBuf>; fn format(&self) -> &'static Format; } diff --git a/src/gfx_apis/gl.rs b/src/gfx_apis/gl.rs index dd45501a..284e8131 100644 --- a/src/gfx_apis/gl.rs +++ b/src/gfx_apis/gl.rs @@ -185,8 +185,6 @@ enum RenderError { ExternalUnsupported, #[error("OpenGL context does not support any formats")] NoSupportedFormats, - #[error("Cannot convert a shm texture into a framebuffer")] - ShmTextureToFb, #[error("Could not create EGLSyncKHR")] CreateEglSync, #[error("Could not destroy EGLSyncKHR")] diff --git a/src/gfx_apis/gl/renderer/texture.rs b/src/gfx_apis/gl/renderer/texture.rs index 5400273a..a4172059 100644 --- a/src/gfx_apis/gl/renderer/texture.rs +++ b/src/gfx_apis/gl/renderer/texture.rs @@ -7,7 +7,7 @@ use { }, gfx_apis::gl::{ gl::texture::GlTexture, - renderer::{context::GlRenderContext, framebuffer::Framebuffer}, + renderer::context::GlRenderContext, sys::{ GLint, GL_CLAMP_TO_EDGE, GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_UNPACK_ROW_LENGTH_EXT, @@ -45,13 +45,6 @@ impl Texture { pub fn height(&self) -> i32 { self.gl.height } - - pub fn to_framebuffer(&self) -> Result, RenderError> { - match &self.gl.img { - Some(img) => self.ctx.image_to_fb(img), - _ => Err(RenderError::ShmTextureToFb), - } - } } impl GfxTexture for Texture { @@ -67,21 +60,6 @@ impl GfxTexture for Texture { self } - fn read_pixels( - self: Rc, - x: i32, - y: i32, - width: i32, - height: i32, - _stride: i32, - format: &Format, - shm: &[Cell], - ) -> Result<(), GfxError> { - self.to_framebuffer()? - .copy_to_shm(x, y, width, height, format, shm) - .map_err(|e| e.into()) - } - fn dmabuf(&self) -> Option<&DmaBuf> { self.gl.img.as_ref().map(|i| &i.dmabuf) } diff --git a/src/gfx_apis/vulkan/image.rs b/src/gfx_apis/vulkan/image.rs index d40ae715..082ea2a8 100644 --- a/src/gfx_apis/vulkan/image.rs +++ b/src/gfx_apis/vulkan/image.rs @@ -543,21 +543,6 @@ impl GfxTexture for VulkanImage { self } - fn read_pixels( - self: Rc, - x: i32, - y: i32, - width: i32, - height: i32, - stride: i32, - format: &'static Format, - shm: &[Cell], - ) -> Result<(), GfxError> { - self.renderer - .read_pixels(&self, x, y, width, height, stride, format, shm) - .map_err(|e| e.into()) - } - fn dmabuf(&self) -> Option<&DmaBuf> { match &self.ty { VulkanImageMemory::DmaBuf(b) => Some(&b.template.dmabuf), diff --git a/src/it/test_gfx_api.rs b/src/it/test_gfx_api.rs index e8b092c4..0ec0cb4e 100644 --- a/src/it/test_gfx_api.rs +++ b/src/it/test_gfx_api.rs @@ -300,20 +300,6 @@ impl GfxTexture for TestGfxImage { self } - fn read_pixels( - self: Rc, - x: i32, - y: i32, - width: i32, - height: i32, - stride: i32, - format: &'static Format, - shm: &[Cell], - ) -> Result<(), GfxError> { - self.deref() - .read_pixels(x, y, width, height, stride, format, shm) - } - fn dmabuf(&self) -> Option<&DmaBuf> { match self { TestGfxImage::Shm(_) => None, diff --git a/src/state.rs b/src/state.rs index 1871084b..fbf862f0 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1006,17 +1006,6 @@ impl State { ) } - fn have_hardware_cursor(&self) -> bool { - if let Some(group) = self.cursor_user_group_hardware_cursor.get() { - if let Some(user) = group.active() { - if user.get().is_some() { - return true; - } - } - } - false - } - pub fn perform_shm_screencopy( &self, src: &Rc, @@ -1032,66 +1021,41 @@ impl State { transform: Transform, scale: Scale, ) -> Result<(), ShmScreencopyError> { - let (src_width, src_height) = src.size(); - let mut needs_copy = capture.rect.x1() < x_off - || capture.rect.x2() > x_off + src_width - || capture.rect.y1() < y_off - || capture.rect.y2() > y_off + src_height - || self.have_hardware_cursor(); - if let Some((target_width, target_height)) = size { - if (target_width, target_height) != (src_width, src_height) { - needs_copy = true; - } - } - let acc = if needs_copy { - let Some(ctx) = self.render_ctx.get() else { - return Err(ShmScreencopyError::NoRenderContext); - }; - let fb = ctx - .create_fb(capture.rect.width(), capture.rect.height(), stride, format) - .map_err(ShmScreencopyError::CreateTemporaryFb)?; - self.perform_screencopy( - src, - None, - acquire_sync, - ReleaseSync::None, - &fb, - AcquireSync::Unnecessary, - ReleaseSync::None, - transform, - position, - true, - x_off - capture.rect.x1(), - y_off - capture.rect.y1(), - size, - transform, - scale, - ) - .map_err(ShmScreencopyError::CopyToTemporary)?; - mem.access(|mem| { - fb.copy_to_shm( - 0, - 0, - capture.rect.width(), - capture.rect.height(), - stride, - format, - mem, - ) - }) - } else { - mem.access(|mem| { - src.clone().read_pixels( - capture.rect.x1() - x_off, - capture.rect.y1() - y_off, - capture.rect.width(), - capture.rect.height(), - stride, - format, - mem, - ) - }) + let Some(ctx) = self.render_ctx.get() else { + return Err(ShmScreencopyError::NoRenderContext); }; + let fb = ctx + .create_fb(capture.rect.width(), capture.rect.height(), stride, format) + .map_err(ShmScreencopyError::CreateTemporaryFb)?; + self.perform_screencopy( + src, + None, + acquire_sync, + ReleaseSync::None, + &fb, + AcquireSync::Unnecessary, + ReleaseSync::None, + transform, + position, + true, + x_off - capture.rect.x1(), + y_off - capture.rect.y1(), + size, + transform, + scale, + ) + .map_err(ShmScreencopyError::CopyToTemporary)?; + let acc = mem.access(|mem| { + fb.copy_to_shm( + 0, + 0, + capture.rect.width(), + capture.rect.height(), + stride, + format, + mem, + ) + }); match acc { Ok(res) => res.map_err(ShmScreencopyError::ReadPixels), Err(e) => {