Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions anvil/src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ where
vec![Rectangle::from_loc_and_size(self.position, self.size).to_physical_precise_up(scale)]
}

fn opaque_regions(&self, _scale: impl Into<Scale<f64>>) -> Option<Vec<Rectangle<i32, Physical>>> {
None
}

fn draw(
&self,
_renderer: &mut R,
Expand Down Expand Up @@ -177,6 +181,10 @@ where
vec![Rectangle::from_loc_and_size((0, 0), (24 * 3, 35)).to_physical_precise_up(scale)]
}

fn opaque_regions(&self, _scale: impl Into<Scale<f64>>) -> Option<Vec<Rectangle<i32, Physical>>> {
None
}

fn draw(
&self,
_renderer: &mut R,
Expand Down
11 changes: 11 additions & 0 deletions src/backend/egl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,17 @@ impl EGLBufferReader {

Some((width, height).into())
}

/// Returns if the [`EGLBuffer`] has an alpha channel
///
/// Note: This will always return `true` for buffers with a
/// `TEXTURE_EXTERNAL_WL` format
pub fn egl_buffer_has_alpha(format: Format) -> bool {
!matches!(
format,
Format::RGB | Format::Y_UV | Format::Y_U_V | Format::Y_XUXV
)
}
}

#[cfg(feature = "use_system_lib")]
Expand Down
2 changes: 1 addition & 1 deletion src/backend/egl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl From<MakeCurrentError> for GraphicsSwapBuffersError {
/// Texture format types
#[repr(i32)]
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Format {
/// RGB format
RGB = ffi::egl::TEXTURE_RGB as i32,
Expand Down
35 changes: 35 additions & 0 deletions src/backend/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,41 @@ pub fn buffer_type(buffer: &wl_buffer::WlBuffer) -> Option<BufferType> {
None
}

/// Returns if the buffer has an alpha channel
///
/// Returns `None` if the type is not known to smithay
/// or otherwise not supported (e.g. not initialized using one of smithays [`crate::wayland`]-handlers).
///
/// Note: This is on a best-effort, but will never return false for a buffer
/// with a format that supports alpha.
#[cfg(feature = "wayland_frontend")]
pub fn buffer_has_alpha(buffer: &wl_buffer::WlBuffer) -> Option<bool> {
Comment thread
Drakulix marked this conversation as resolved.
if let Ok(dmabuf) = crate::wayland::dmabuf::get_dmabuf(buffer) {
return Some(crate::backend::allocator::format::has_alpha(dmabuf.0.format));
}

if let Ok(has_alpha) = crate::wayland::shm::with_buffer_contents(buffer, |_, data| {
crate::wayland::shm::has_alpha(data.format)
}) {
return Some(has_alpha);
}

// Not managed, check if this is an EGLBuffer
#[cfg(all(feature = "backend_egl", feature = "use_system_lib"))]
if let Some(format) = BUFFER_READER
.lock()
.unwrap()
.as_ref()
.and_then(|x| x.upgrade())
.and_then(|x| x.egl_buffer_contents(buffer).ok())
.map(|b| b.format)
{
return Some(crate::backend::egl::display::EGLBufferReader::egl_buffer_has_alpha(format));
}
Comment thread
Drakulix marked this conversation as resolved.

None
}

/// Returns the dimensions of a wl_buffer
///
/// *Note*: This will only return dimensions for buffer types known to smithay (see [`buffer_type`])
Expand Down
Loading