diff --git a/anvil/src/drawing.rs b/anvil/src/drawing.rs index 2063a7c..dc33336 100644 --- a/anvil/src/drawing.rs +++ b/anvil/src/drawing.rs @@ -338,6 +338,10 @@ pub fn import_bitmap>( ); 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(), + ) }) } diff --git a/src/backend/allocator/dmabuf.rs b/src/backend/allocator/dmabuf.rs index df2e119..090d160 100644 --- a/src/backend/allocator/dmabuf.rs +++ b/src/backend/allocator/dmabuf.rs @@ -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, - /// The width of this buffer - pub width: i32, - /// The height of this buffer - pub height: i32, + /// The size of this buffer + pub size: Size, /// 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 { + 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>, + 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, }, diff --git a/src/backend/allocator/dumb.rs b/src/backend/allocator/dumb.rs index 0ee8632..fab167a 100644 --- a/src/backend/allocator/dumb.rs +++ b/src/backend/allocator/dumb.rs @@ -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 { @@ -61,12 +62,9 @@ impl Allocator> for DrmDevice { } impl Buffer for DumbBuffer { - fn width(&self) -> u32 { - self.handle.size().0 - } - - fn height(&self) -> u32 { - self.handle.size().1 + fn size(&self) -> Size { + let (w, h) = self.handle.size(); + (w as i32, h as i32).into() } fn format(&self) -> Format { diff --git a/src/backend/allocator/gbm.rs b/src/backend/allocator/gbm.rs index 45b6ca2..f5bf9fd 100644 --- a/src/backend/allocator/gbm.rs +++ b/src/backend/allocator/gbm.rs @@ -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 Allocator> for GbmDevice { } impl Buffer for GbmBuffer { - fn width(&self) -> u32 { - self.width().unwrap_or(0) - } - - fn height(&self) -> u32 { - self.height().unwrap_or(0) + fn size(&self) -> Size { + ( + self.width().unwrap_or(0) as i32, + self.height().unwrap_or(0) as i32, + ) + .into() } fn format(&self) -> Format { diff --git a/src/backend/allocator/mod.rs b/src/backend/allocator/mod.rs index e9865b3..108f0bf 100644 --- a/src/backend/allocator/mod.rs +++ b/src/backend/allocator/mod.rs @@ -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; /// Pixel format of the buffer fn format(&self) -> Format; } diff --git a/src/backend/egl/display.rs b/src/backend/egl/display.rs index 8a7da5a..98542a8 100644 --- a/src/backend/egl/display.rs +++ b/src/backend/egl/display.rs @@ -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, diff --git a/src/backend/egl/mod.rs b/src/backend/egl/mod.rs index 2cd26b3..746cc67 100644 --- a/src/backend/egl/mod.rs +++ b/src/backend/egl/mod.rs @@ -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, - /// Width in pixels - pub width: u32, - /// Height in pixels - pub height: u32, + /// Size of the buffer + pub size: Size, /// If the y-axis is inverted or not pub y_inverted: bool, /// Format of these images diff --git a/src/backend/renderer/gles2/mod.rs b/src/backend/renderer/gles2/mod.rs index 0bb8769..9724b28 100644 --- a/src/backend/renderer/gles2/mod.rs +++ b/src/backend/renderer/gles2/mod.rs @@ -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, ) -> 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, egl_images: Option>, destruction_callback_sender: Sender, } @@ -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 { + 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(), })); diff --git a/src/wayland/dmabuf/mod.rs b/src/wayland/dmabuf/mod.rs index a572ba5..358f720 100644 --- a/src/wayland/dmabuf/mod.rs +++ b/src/wayland/dmabuf/mod.rs @@ -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;