Skip to content
51 changes: 50 additions & 1 deletion internal/backends/linuxkms/renderer/sw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const SOFTWARE_RENDER_SUPPORTED_DRM_FOURCC_FORMATS: &[drm::buffer::DrmFourcc] =
// Preferred formats
drm::buffer::DrmFourcc::Xrgb8888,
drm::buffer::DrmFourcc::Argb8888,
// drm::buffer::DrmFourcc::Bgra8888,
drm::buffer::DrmFourcc::Bgra8888,
// drm::buffer::DrmFourcc::Rgba8888,

// 16-bit formats
Expand Down Expand Up @@ -61,6 +61,10 @@ const SOFTWARE_RENDER_SUPPORTED_DRM_FOURCC_FORMATS: &[drm::buffer::DrmFourcc] =
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
struct DumbBufferPixelXrgb888(pub u32);

#[repr(transparent)]
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
struct DumbBufferPixelBgra8888(pub u32);

impl From<DumbBufferPixelXrgb888> for PremultipliedRgbaColor {
#[inline]
fn from(pixel: DumbBufferPixelXrgb888) -> Self {
Expand All @@ -86,6 +90,31 @@ impl From<PremultipliedRgbaColor> for DumbBufferPixelXrgb888 {
}
}

impl From<DumbBufferPixelBgra8888> for PremultipliedRgbaColor {
#[inline]
fn from(pixel: DumbBufferPixelBgra8888) -> Self {
let v = pixel.0;
PremultipliedRgbaColor {
red: (v >> 0) as u8,
green: (v >> 8) as u8,
blue: (v >> 16) as u8,
alpha: (v >> 24) as u8,
}
}
}

impl From<PremultipliedRgbaColor> for DumbBufferPixelBgra8888 {
#[inline]
fn from(pixel: PremultipliedRgbaColor) -> Self {
Self(
(pixel.alpha as u32) << 24
| ((pixel.blue as u32) << 16) // B and R swapped
| ((pixel.green as u32) << 8)
| (pixel.red as u32),
)
}
}

impl TargetPixel for DumbBufferPixelXrgb888 {
fn blend(&mut self, color: PremultipliedRgbaColor) {
let mut x = PremultipliedRgbaColor::from(*self);
Expand All @@ -102,6 +131,20 @@ impl TargetPixel for DumbBufferPixelXrgb888 {
}
}

impl TargetPixel for DumbBufferPixelBgra8888 {
fn blend(&mut self, color: PremultipliedRgbaColor) {
let mut x = PremultipliedRgbaColor::from(*self);
x.blend(color);
*self = x.into();
}
fn from_rgb(r: u8, g: u8, b: u8) -> Self {
Self(0xff000000 | ((b as u32) << 16) | ((g as u32) << 8) | (r as u32))
}
fn background() -> Self {
Self(0)
}
}

impl SoftwareRendererAdapter {
pub fn new(
device_opener: &crate::DeviceOpener,
Expand Down Expand Up @@ -165,6 +208,12 @@ impl crate::fullscreenwindowadapter::FullscreenRenderer for SoftwareRendererAdap
bytemuck::cast_slice_mut(pixels.as_mut());
self.renderer.render(buffer, self.size.width as usize);
}

drm::buffer::DrmFourcc::Bgra8888 => {
let buffer: &mut [DumbBufferPixelBgra8888] =
bytemuck::cast_slice_mut(pixels.as_mut());
self.renderer.render(buffer, self.size.width as usize);
}
drm::buffer::DrmFourcc::Rgb565 => {
let buffer: &mut [i_slint_core::software_renderer::Rgb565Pixel] =
bytemuck::cast_slice_mut(pixels.as_mut());
Expand Down
Loading