1
0
Fork 0
forked from wry/wry

render: don't require framebuffer to perform shm screencopies

This commit is contained in:
Julian Orth 2024-02-28 13:41:08 +01:00
parent 69d63b7e83
commit 9de63bddf3
12 changed files with 65 additions and 76 deletions

View file

@ -178,8 +178,8 @@ enum RenderError {
ExternalUnsupported,
#[error("OpenGL context does not support any formats")]
NoSupportedFormats,
#[error("Unsupported operation")]
UnsupportedOperation,
#[error("Cannot convert a shm texture into a framebuffer")]
ShmTextureToFb,
}
#[derive(Default)]

View file

@ -6,7 +6,7 @@ use {
ResetStatus,
},
gfx_apis::gl::{
egl::{context::EglContext, display::EglDisplay},
egl::{context::EglContext, display::EglDisplay, image::EglImage},
ext::GL_OES_EGL_IMAGE_EXTERNAL,
gl::{
program::GlProgram, render_buffer::GlRenderBuffer, sys::GLint, texture::GlTexture,
@ -190,6 +190,20 @@ impl GlRenderContext {
format,
}))
}
pub fn image_to_fb(
self: &Rc<Self>,
img: &Rc<EglImage>,
) -> Result<Rc<Framebuffer>, RenderError> {
self.ctx.with_current(|| unsafe {
let rb = GlRenderBuffer::from_image(img, &self.ctx)?;
let fb = rb.create_framebuffer()?;
Ok(Rc::new(Framebuffer {
ctx: self.clone(),
gl: fb,
}))
})
}
}
impl GfxContext for GlRenderContext {

View file

@ -106,15 +106,16 @@ impl GfxFramebuffer for Framebuffer {
}
fn copy_to_shm(
&self,
self: Rc<Self>,
x: i32,
y: i32,
width: i32,
height: i32,
format: &Format,
_stride: i32,
format: &'static Format,
shm: &[Cell<u8>],
) -> Result<(), GfxError> {
self.copy_to_shm(x, y, width, height, format, shm);
(*self).copy_to_shm(x, y, width, height, format, shm);
Ok(())
}

View file

@ -2,9 +2,8 @@ use {
crate::{
gfx_api::{GfxError, GfxFramebuffer, GfxImage, GfxTexture},
gfx_apis::gl::{
egl::image::EglImage,
gl::{render_buffer::GlRenderBuffer, texture::GlTexture},
Framebuffer, GlRenderContext, RenderError, Texture,
egl::image::EglImage, gl::texture::GlTexture, Framebuffer, GlRenderContext,
RenderError, Texture,
},
},
std::rc::Rc,
@ -34,14 +33,7 @@ impl Image {
}
fn to_framebuffer(&self) -> Result<Rc<Framebuffer>, RenderError> {
self.ctx.ctx.with_current(|| unsafe {
let rb = GlRenderBuffer::from_image(&self.gl, &self.ctx.ctx)?;
let fb = rb.create_framebuffer()?;
Ok(Rc::new(Framebuffer {
ctx: self.ctx.clone(),
gl: fb,
}))
})
self.ctx.image_to_fb(&self.gl)
}
}

View file

@ -2,7 +2,11 @@ use {
crate::{
format::Format,
gfx_api::{GfxError, GfxTexture, TextureReservations},
gfx_apis::gl::{gl::texture::GlTexture, renderer::context::GlRenderContext, RenderError},
gfx_apis::gl::{
gl::texture::GlTexture,
renderer::{context::GlRenderContext, framebuffer::Framebuffer},
RenderError,
},
video::dmabuf::DmaBuf,
},
std::{
@ -34,6 +38,13 @@ 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 {
@ -51,15 +62,17 @@ impl GfxTexture for Texture {
fn read_pixels(
self: Rc<Self>,
_x: i32,
_y: i32,
_width: i32,
_height: i32,
x: i32,
y: i32,
width: i32,
height: i32,
_stride: i32,
_format: &Format,
_shm: &[Cell<u8>],
format: &Format,
shm: &[Cell<u8>],
) -> Result<(), GfxError> {
Err(RenderError::UnsupportedOperation.into())
self.to_framebuffer()?
.copy_to_shm(x, y, width, height, format, shm);
Ok(())
}
fn dmabuf(&self) -> Option<&DmaBuf> {

View file

@ -173,8 +173,6 @@ pub enum VulkanError {
height: i32,
stride: i32,
},
#[error("Unsupported operation")]
UnsupportedOperation,
}
impl From<VulkanError> for GfxError {

View file

@ -533,15 +533,18 @@ impl GfxFramebuffer for VulkanImage {
}
fn copy_to_shm(
&self,
_x: i32,
_y: i32,
_width: i32,
_height: i32,
_format: &Format,
_shm: &[Cell<u8>],
self: Rc<Self>,
x: i32,
y: i32,
width: i32,
height: i32,
stride: i32,
format: &'static Format,
shm: &[Cell<u8>],
) -> Result<(), GfxError> {
return Err(VulkanError::UnsupportedOperation.into());
self.renderer
.read_pixels(&self, x, y, width, height, stride, format, shm)
.map_err(|e| e.into())
}
fn format(&self) -> &'static Format {