gfx: remove incompatible shm downloads
This commit is contained in:
parent
17de1650a0
commit
aca14d48dd
7 changed files with 27 additions and 176 deletions
|
|
@ -34,29 +34,21 @@ impl Debug for Framebuffer {
|
|||
}
|
||||
|
||||
impl Framebuffer {
|
||||
pub fn copy_to_shm(
|
||||
&self,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
format: &Format,
|
||||
shm: &[Cell<u8>],
|
||||
) -> Result<(), RenderError> {
|
||||
pub fn copy_to_shm(&self, shm: &[Cell<u8>]) -> Result<(), RenderError> {
|
||||
let format = self.gl.rb.format;
|
||||
let Some(shm_info) = &format.shm_info else {
|
||||
return Err(RenderError::UnsupportedShmFormat(format.name));
|
||||
};
|
||||
let gles = self.ctx.ctx.dpy.gles;
|
||||
let y = self.gl.height - y - height;
|
||||
let _ = self.ctx.ctx.with_current(|| {
|
||||
unsafe {
|
||||
(gles.glBindFramebuffer)(GL_FRAMEBUFFER, self.gl.fbo);
|
||||
(gles.glViewport)(0, 0, self.gl.width, self.gl.height);
|
||||
(gles.glReadnPixels)(
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
0,
|
||||
self.gl.width,
|
||||
self.gl.height,
|
||||
shm_info.gl_format as _,
|
||||
shm_info.gl_type as _,
|
||||
shm.len() as _,
|
||||
|
|
@ -112,19 +104,8 @@ impl GfxFramebuffer for Framebuffer {
|
|||
self.render(acquire_sync, ops, clear).map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn copy_to_shm(
|
||||
self: Rc<Self>,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
_stride: i32,
|
||||
format: &'static Format,
|
||||
shm: &[Cell<u8>],
|
||||
) -> Result<(), GfxError> {
|
||||
(*self)
|
||||
.copy_to_shm(x, y, width, height, format, shm)
|
||||
.map_err(|e| e.into())
|
||||
fn copy_to_shm(self: Rc<Self>, shm: &[Cell<u8>]) -> Result<(), GfxError> {
|
||||
(*self).copy_to_shm(shm).map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn format(&self) -> &'static Format {
|
||||
|
|
|
|||
|
|
@ -173,16 +173,6 @@ pub enum VulkanError {
|
|||
InvalidStride,
|
||||
#[error("Shm stride and height do not match buffer size")]
|
||||
InvalidBufferSize,
|
||||
#[error("The shm parameters are invalid x={x}, y={y}, width={width}, height={height}, stride={stride}")]
|
||||
InvalidShmParameters {
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
},
|
||||
#[error(transparent)]
|
||||
GfxError(GfxError),
|
||||
#[error("Buffer format {0} is not supported for shm buffers in Vulkan context")]
|
||||
UnsupportedShmFormat(&'static str),
|
||||
#[error("Only BO_USE_RENDERING and BO_USE_WRITE are supported")]
|
||||
|
|
|
|||
|
|
@ -510,18 +510,9 @@ impl GfxFramebuffer for VulkanImage {
|
|||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn copy_to_shm(
|
||||
self: Rc<Self>,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
format: &'static Format,
|
||||
shm: &[Cell<u8>],
|
||||
) -> Result<(), GfxError> {
|
||||
fn copy_to_shm(self: Rc<Self>, shm: &[Cell<u8>]) -> Result<(), GfxError> {
|
||||
self.renderer
|
||||
.read_pixels(&self, x, y, width, height, stride, format, shm)
|
||||
.read_all_pixels(&self, shm)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ use {
|
|||
crate::{
|
||||
async_engine::{AsyncEngine, SpawnedFuture},
|
||||
cpu_worker::PendingJob,
|
||||
format::{Format, XRGB8888},
|
||||
format::XRGB8888,
|
||||
gfx_api::{
|
||||
AcquireSync, BufferResv, BufferResvUser, GfxApiOpt, GfxFormat, GfxFramebuffer,
|
||||
GfxTexture, GfxWriteModifier, ReleaseSync, SyncFile,
|
||||
AcquireSync, BufferResv, BufferResvUser, GfxApiOpt, GfxFormat, GfxTexture,
|
||||
GfxWriteModifier, ReleaseSync, SyncFile,
|
||||
},
|
||||
gfx_apis::vulkan::{
|
||||
allocator::{VulkanAllocator, VulkanThreadedAllocator},
|
||||
|
|
@ -905,74 +905,20 @@ impl VulkanRenderer {
|
|||
frame.waiter.set(Some(future));
|
||||
}
|
||||
|
||||
pub fn read_pixels(
|
||||
self: &Rc<Self>,
|
||||
tex: &Rc<VulkanImage>,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
stride: i32,
|
||||
format: &'static Format,
|
||||
dst: &[Cell<u8>],
|
||||
) -> Result<(), VulkanError> {
|
||||
if x < 0 || y < 0 || width <= 0 || height <= 0 || stride <= 0 {
|
||||
return Err(VulkanError::InvalidShmParameters {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
stride,
|
||||
});
|
||||
}
|
||||
let width = width as u32;
|
||||
let height = height as u32;
|
||||
let stride = stride as u32;
|
||||
if x == 0 && y == 0 && width == tex.width && height == tex.height && format == tex.format {
|
||||
return self.read_all_pixels(tex, stride, dst);
|
||||
}
|
||||
let tmp_tex = self.create_shm_texture(
|
||||
format,
|
||||
width as i32,
|
||||
height as i32,
|
||||
stride as i32,
|
||||
&[],
|
||||
true,
|
||||
None,
|
||||
)?;
|
||||
(&*tmp_tex as &dyn GfxFramebuffer)
|
||||
.copy_texture(
|
||||
AcquireSync::None,
|
||||
ReleaseSync::None,
|
||||
&(tex.clone() as _),
|
||||
None,
|
||||
AcquireSync::None,
|
||||
ReleaseSync::None,
|
||||
x,
|
||||
y,
|
||||
)
|
||||
.map_err(VulkanError::GfxError)?;
|
||||
self.read_all_pixels(&tmp_tex, stride, dst)
|
||||
}
|
||||
|
||||
fn read_all_pixels(
|
||||
pub(super) fn read_all_pixels(
|
||||
self: &Rc<Self>,
|
||||
tex: &VulkanImage,
|
||||
stride: u32,
|
||||
dst: &[Cell<u8>],
|
||||
) -> Result<(), VulkanError> {
|
||||
let Some(shm_info) = &tex.format.shm_info else {
|
||||
return Err(VulkanError::UnsupportedShmFormat(tex.format.name));
|
||||
};
|
||||
if stride < tex.width * shm_info.bpp || stride % shm_info.bpp != 0 {
|
||||
return Err(VulkanError::InvalidStride);
|
||||
}
|
||||
let size = stride as u64 * tex.height as u64;
|
||||
let size = tex.stride as u64 * tex.height as u64;
|
||||
if size != dst.len() as u64 {
|
||||
return Err(VulkanError::InvalidBufferSize);
|
||||
}
|
||||
let region = BufferImageCopy::default()
|
||||
.buffer_row_length(stride / shm_info.bpp)
|
||||
.buffer_row_length(tex.stride / shm_info.bpp)
|
||||
.buffer_image_height(tex.height)
|
||||
.image_subresource(ImageSubresourceLayers {
|
||||
aspect_mask: ImageAspectFlags::COLOR,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue