buffer: use Size instead of width/height
This commit is contained in:
parent
7dadd63e35
commit
1cf1d4739b
|
@ -338,6 +338,10 @@ pub fn import_bitmap<C: std::ops::Deref<Target = [u8]>>(
|
|||
);
|
||||
gl.BindTexture(ffi::TEXTURE_2D, 0);
|
||||
|
||||
Gles2Texture::from_raw(renderer, tex, image.width(), image.height())
|
||||
Gles2Texture::from_raw(
|
||||
renderer,
|
||||
tex,
|
||||
(image.width() as i32, image.height() as i32).into(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
//! the lifetime of the buffer. E.g. when you are only caching associated resources for a dmabuf.
|
||||
|
||||
use super::{Buffer, Format, Fourcc, Modifier};
|
||||
use crate::utils::{Buffer as BufferCoords, Size};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::os::unix::io::{IntoRawFd, RawFd};
|
||||
use std::sync::{Arc, Weak};
|
||||
|
@ -22,10 +23,8 @@ pub const MAX_PLANES: usize = 4;
|
|||
pub(crate) struct DmabufInternal {
|
||||
/// The submitted planes
|
||||
pub planes: Vec<Plane>,
|
||||
/// The width of this buffer
|
||||
pub width: i32,
|
||||
/// The height of this buffer
|
||||
pub height: i32,
|
||||
/// The size of this buffer
|
||||
pub size: Size<i32, BufferCoords>,
|
||||
/// The format in use
|
||||
pub format: Fourcc,
|
||||
/// The flags applied to it
|
||||
|
@ -107,12 +106,8 @@ impl Hash for WeakDmabuf {
|
|||
}
|
||||
|
||||
impl Buffer for Dmabuf {
|
||||
fn width(&self) -> u32 {
|
||||
self.0.width as u32
|
||||
}
|
||||
|
||||
fn height(&self) -> u32 {
|
||||
self.0.height as u32
|
||||
fn size(&self) -> Size<i32, BufferCoords> {
|
||||
self.0.size
|
||||
}
|
||||
|
||||
fn format(&self) -> Format {
|
||||
|
@ -172,8 +167,7 @@ impl Dmabuf {
|
|||
DmabufBuilder {
|
||||
internal: DmabufInternal {
|
||||
planes: Vec::with_capacity(MAX_PLANES),
|
||||
width: src.width() as i32,
|
||||
height: src.height() as i32,
|
||||
size: src.size(),
|
||||
format: src.format().code,
|
||||
flags,
|
||||
},
|
||||
|
@ -181,12 +175,15 @@ impl Dmabuf {
|
|||
}
|
||||
|
||||
/// Create a new Dmabuf builder
|
||||
pub fn builder(width: u32, height: u32, format: Fourcc, flags: DmabufFlags) -> DmabufBuilder {
|
||||
pub fn builder(
|
||||
size: impl Into<Size<i32, BufferCoords>>,
|
||||
format: Fourcc,
|
||||
flags: DmabufFlags,
|
||||
) -> DmabufBuilder {
|
||||
DmabufBuilder {
|
||||
internal: DmabufInternal {
|
||||
planes: Vec::with_capacity(MAX_PLANES),
|
||||
width: width as i32,
|
||||
height: height as i32,
|
||||
size: size.into(),
|
||||
format,
|
||||
flags,
|
||||
},
|
||||
|
|
|
@ -9,6 +9,7 @@ use drm::control::{dumbbuffer::DumbBuffer as Handle, Device as ControlDevice};
|
|||
|
||||
use super::{Allocator, Buffer, Format, Fourcc, Modifier};
|
||||
use crate::backend::drm::device::{DrmDevice, DrmDeviceInternal, FdWrapper};
|
||||
use crate::utils::{Buffer as BufferCoords, Size};
|
||||
|
||||
/// Wrapper around raw DumbBuffer handles.
|
||||
pub struct DumbBuffer<A: AsRawFd + 'static> {
|
||||
|
@ -61,12 +62,9 @@ impl<A: AsRawFd + 'static> Allocator<DumbBuffer<A>> for DrmDevice<A> {
|
|||
}
|
||||
|
||||
impl<A: AsRawFd + 'static> Buffer for DumbBuffer<A> {
|
||||
fn width(&self) -> u32 {
|
||||
self.handle.size().0
|
||||
}
|
||||
|
||||
fn height(&self) -> u32 {
|
||||
self.handle.size().1
|
||||
fn size(&self) -> Size<i32, BufferCoords> {
|
||||
let (w, h) = self.handle.size();
|
||||
(w as i32, h as i32).into()
|
||||
}
|
||||
|
||||
fn format(&self) -> Format {
|
||||
|
|
|
@ -8,6 +8,7 @@ use super::{
|
|||
dmabuf::{AsDmabuf, Dmabuf, DmabufFlags, MAX_PLANES},
|
||||
Allocator, Buffer, Format, Fourcc, Modifier,
|
||||
};
|
||||
use crate::utils::{Buffer as BufferCoords, Size};
|
||||
pub use gbm::{BufferObject as GbmBuffer, BufferObjectFlags as GbmBufferFlags, Device as GbmDevice};
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
|
@ -39,12 +40,12 @@ impl<A: AsRawFd + 'static, T> Allocator<GbmBuffer<T>> for GbmDevice<A> {
|
|||
}
|
||||
|
||||
impl<T> Buffer for GbmBuffer<T> {
|
||||
fn width(&self) -> u32 {
|
||||
self.width().unwrap_or(0)
|
||||
}
|
||||
|
||||
fn height(&self) -> u32 {
|
||||
self.height().unwrap_or(0)
|
||||
fn size(&self) -> Size<i32, BufferCoords> {
|
||||
(
|
||||
self.width().unwrap_or(0) as i32,
|
||||
self.height().unwrap_or(0) as i32,
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn format(&self) -> Format {
|
||||
|
|
|
@ -22,6 +22,7 @@ pub mod dumb;
|
|||
pub mod gbm;
|
||||
|
||||
mod swapchain;
|
||||
use crate::utils::{Buffer as BufferCoords, Size};
|
||||
pub use swapchain::{Slot, Swapchain};
|
||||
|
||||
pub use drm_fourcc::{
|
||||
|
@ -32,13 +33,15 @@ pub use drm_fourcc::{
|
|||
/// Common trait describing common properties of most types of buffers.
|
||||
pub trait Buffer {
|
||||
/// Width of the two-dimensional buffer
|
||||
fn width(&self) -> u32;
|
||||
/// Height of the two-dimensional buffer
|
||||
fn height(&self) -> u32;
|
||||
/// Size (w x h) of the two-dimensional buffer
|
||||
fn size(&self) -> (u32, u32) {
|
||||
(self.width(), self.height())
|
||||
fn width(&self) -> u32 {
|
||||
self.size().w as u32
|
||||
}
|
||||
/// Height of the two-dimensional buffer
|
||||
fn height(&self) -> u32 {
|
||||
self.size().h as u32
|
||||
}
|
||||
/// Size of the two-dimensional buffer
|
||||
fn size(&self) -> Size<i32, BufferCoords>;
|
||||
/// Pixel format of the buffer
|
||||
fn format(&self) -> Format;
|
||||
}
|
||||
|
|
|
@ -808,8 +808,7 @@ impl EGLBufferReader {
|
|||
|
||||
Ok(EGLBuffer {
|
||||
display: self.display.clone(),
|
||||
width: width as u32,
|
||||
height: height as u32,
|
||||
size: (width, height).into(),
|
||||
// y_inverted is negated here because the gles2 renderer
|
||||
// already inverts the buffer during rendering.
|
||||
y_inverted: !y_inverted,
|
||||
|
|
|
@ -32,6 +32,8 @@ pub use self::context::EGLContext;
|
|||
mod error;
|
||||
pub use self::error::*;
|
||||
use crate::backend::SwapBuffersError as GraphicsSwapBuffersError;
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
use crate::utils::{Buffer, Size};
|
||||
|
||||
use nix::libc::c_void;
|
||||
|
||||
|
@ -248,10 +250,8 @@ impl Format {
|
|||
#[derive(Debug)]
|
||||
pub struct EGLBuffer {
|
||||
display: Arc<EGLDisplayHandle>,
|
||||
/// Width in pixels
|
||||
pub width: u32,
|
||||
/// Height in pixels
|
||||
pub height: u32,
|
||||
/// Size of the buffer
|
||||
pub size: Size<i32, Buffer>,
|
||||
/// If the y-axis is inverted or not
|
||||
pub y_inverted: bool,
|
||||
/// Format of these images
|
||||
|
|
|
@ -34,7 +34,6 @@ use super::ImportEgl;
|
|||
use super::{ImportDma, ImportShm};
|
||||
#[cfg(all(feature = "wayland_frontend", feature = "use_system_lib"))]
|
||||
use crate::backend::egl::{display::EGLBufferReader, Format as EGLFormat};
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
use crate::utils::{Buffer, Rectangle};
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
use wayland_server::protocol::{wl_buffer, wl_shm};
|
||||
|
@ -82,16 +81,14 @@ impl Gles2Texture {
|
|||
pub unsafe fn from_raw(
|
||||
renderer: &Gles2Renderer,
|
||||
tex: ffi::types::GLuint,
|
||||
width: u32,
|
||||
height: u32,
|
||||
size: Size<i32, Buffer>,
|
||||
) -> Gles2Texture {
|
||||
Gles2Texture(Rc::new(Gles2TextureInternal {
|
||||
texture: tex,
|
||||
texture_kind: 0,
|
||||
is_external: false,
|
||||
y_inverted: false,
|
||||
width,
|
||||
height,
|
||||
size,
|
||||
egl_images: None,
|
||||
destruction_callback_sender: renderer.destruction_callback_sender.clone(),
|
||||
}))
|
||||
|
@ -104,8 +101,7 @@ struct Gles2TextureInternal {
|
|||
texture_kind: usize,
|
||||
is_external: bool,
|
||||
y_inverted: bool,
|
||||
width: u32,
|
||||
height: u32,
|
||||
size: Size<i32, Buffer>,
|
||||
egl_images: Option<Vec<EGLImage>>,
|
||||
destruction_callback_sender: Sender<CleanupResource>,
|
||||
}
|
||||
|
@ -132,10 +128,13 @@ enum CleanupResource {
|
|||
|
||||
impl Texture for Gles2Texture {
|
||||
fn width(&self) -> u32 {
|
||||
self.0.width
|
||||
self.0.size.w as u32
|
||||
}
|
||||
fn height(&self) -> u32 {
|
||||
self.0.height
|
||||
self.0.size.h as u32
|
||||
}
|
||||
fn size(&self) -> Size<i32, Buffer> {
|
||||
self.0.size
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -590,8 +589,7 @@ impl ImportShm for Gles2Renderer {
|
|||
texture_kind: shader_idx,
|
||||
is_external: false,
|
||||
y_inverted: false,
|
||||
width: width as u32,
|
||||
height: height as u32,
|
||||
size: (width, height).into(),
|
||||
egl_images: None,
|
||||
destruction_callback_sender: self.destruction_callback_sender.clone(),
|
||||
})
|
||||
|
@ -720,8 +718,7 @@ impl ImportEgl for Gles2Renderer {
|
|||
},
|
||||
is_external: egl.format == EGLFormat::External,
|
||||
y_inverted: egl.y_inverted,
|
||||
width: egl.width,
|
||||
height: egl.height,
|
||||
size: egl.size,
|
||||
egl_images: Some(egl.into_images()),
|
||||
destruction_callback_sender: self.destruction_callback_sender.clone(),
|
||||
}));
|
||||
|
@ -754,8 +751,7 @@ impl ImportDma for Gles2Renderer {
|
|||
texture_kind: if is_external { 2 } else { 0 },
|
||||
is_external,
|
||||
y_inverted: buffer.y_inverted(),
|
||||
width: buffer.width(),
|
||||
height: buffer.height(),
|
||||
size: buffer.size(),
|
||||
egl_images: Some(vec![image]),
|
||||
destruction_callback_sender: self.destruction_callback_sender.clone(),
|
||||
}));
|
||||
|
|
|
@ -260,12 +260,7 @@ where
|
|||
return;
|
||||
}
|
||||
|
||||
let mut buf = Dmabuf::builder(
|
||||
width as u32,
|
||||
height as u32,
|
||||
format,
|
||||
DmabufFlags::from_bits_truncate(flags),
|
||||
);
|
||||
let mut buf = Dmabuf::builder((width, height), format, DmabufFlags::from_bits_truncate(flags));
|
||||
let planes = std::mem::take(&mut self.pending_planes);
|
||||
for (i, plane) in planes.into_iter().enumerate() {
|
||||
let offset = plane.offset;
|
||||
|
@ -350,12 +345,7 @@ where
|
|||
return;
|
||||
}
|
||||
|
||||
let mut buf = Dmabuf::builder(
|
||||
width as u32,
|
||||
height as u32,
|
||||
format,
|
||||
DmabufFlags::from_bits_truncate(flags),
|
||||
);
|
||||
let mut buf = Dmabuf::builder((width, height), format, DmabufFlags::from_bits_truncate(flags));
|
||||
let planes = ::std::mem::take(&mut self.pending_planes);
|
||||
for (i, plane) in planes.into_iter().enumerate() {
|
||||
let offset = plane.offset;
|
||||
|
|
Loading…
Reference in New Issue