screencopy: unconditionally create copy for shm
This commit is contained in:
parent
156785d7c8
commit
17de1650a0
6 changed files with 35 additions and 134 deletions
|
|
@ -481,16 +481,6 @@ pub trait GfxTexture: Debug {
|
|||
fn size(&self) -> (i32, i32);
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
fn into_any(self: Rc<Self>) -> Rc<dyn Any>;
|
||||
fn read_pixels(
|
||||
self: Rc<Self>,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
format: &'static Format,
|
||||
shm: &[Cell<u8>],
|
||||
) -> Result<(), GfxError>;
|
||||
fn dmabuf(&self) -> Option<&DmaBuf>;
|
||||
fn format(&self) -> &'static Format;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")]
|
||||
|
|
|
|||
|
|
@ -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<Rc<Framebuffer>, 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<Self>,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
_stride: i32,
|
||||
format: &Format,
|
||||
shm: &[Cell<u8>],
|
||||
) -> 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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -543,21 +543,6 @@ impl GfxTexture for VulkanImage {
|
|||
self
|
||||
}
|
||||
|
||||
fn read_pixels(
|
||||
self: Rc<Self>,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
format: &'static Format,
|
||||
shm: &[Cell<u8>],
|
||||
) -> 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),
|
||||
|
|
|
|||
|
|
@ -300,20 +300,6 @@ impl GfxTexture for TestGfxImage {
|
|||
self
|
||||
}
|
||||
|
||||
fn read_pixels(
|
||||
self: Rc<Self>,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
format: &'static Format,
|
||||
shm: &[Cell<u8>],
|
||||
) -> Result<(), GfxError> {
|
||||
self.deref()
|
||||
.read_pixels(x, y, width, height, stride, format, shm)
|
||||
}
|
||||
|
||||
fn dmabuf(&self) -> Option<&DmaBuf> {
|
||||
match self {
|
||||
TestGfxImage::Shm(_) => None,
|
||||
|
|
|
|||
104
src/state.rs
104
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<dyn GfxTexture>,
|
||||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue