@@ -22,7 +22,7 @@ const SOFTWARE_RENDER_SUPPORTED_DRM_FOURCC_FORMATS: &[drm::buffer::DrmFourcc] =
2222 // Preferred formats
2323 drm:: buffer:: DrmFourcc :: Xrgb8888 ,
2424 drm:: buffer:: DrmFourcc :: Argb8888 ,
25- // drm::buffer::DrmFourcc::Bgra8888,
25+ drm:: buffer:: DrmFourcc :: Bgra8888 ,
2626 // drm::buffer::DrmFourcc::Rgba8888,
2727
2828 // 16-bit formats
@@ -61,6 +61,10 @@ const SOFTWARE_RENDER_SUPPORTED_DRM_FOURCC_FORMATS: &[drm::buffer::DrmFourcc] =
6161#[ derive( Copy , Clone , bytemuck:: Pod , bytemuck:: Zeroable ) ]
6262struct DumbBufferPixelXrgb888 ( pub u32 ) ;
6363
64+ #[ repr( transparent) ]
65+ #[ derive( Copy , Clone , bytemuck:: Pod , bytemuck:: Zeroable ) ]
66+ struct DumbBufferPixelBgra8888 ( pub u32 ) ;
67+
6468impl From < DumbBufferPixelXrgb888 > for PremultipliedRgbaColor {
6569 #[ inline]
6670 fn from ( pixel : DumbBufferPixelXrgb888 ) -> Self {
@@ -86,6 +90,31 @@ impl From<PremultipliedRgbaColor> for DumbBufferPixelXrgb888 {
8690 }
8791}
8892
93+ impl From < DumbBufferPixelBgra8888 > for PremultipliedRgbaColor {
94+ #[ inline]
95+ fn from ( pixel : DumbBufferPixelBgra8888 ) -> Self {
96+ let v = pixel. 0 ;
97+ PremultipliedRgbaColor {
98+ red : ( v >> 0 ) as u8 ,
99+ green : ( v >> 8 ) as u8 ,
100+ blue : ( v >> 16 ) as u8 ,
101+ alpha : ( v >> 24 ) as u8 ,
102+ }
103+ }
104+ }
105+
106+ impl From < PremultipliedRgbaColor > for DumbBufferPixelBgra8888 {
107+ #[ inline]
108+ fn from ( pixel : PremultipliedRgbaColor ) -> Self {
109+ Self (
110+ ( pixel. alpha as u32 ) << 24
111+ | ( ( pixel. blue as u32 ) << 16 ) // B and R swapped
112+ | ( ( pixel. green as u32 ) << 8 )
113+ | ( pixel. red as u32 ) ,
114+ )
115+ }
116+ }
117+
89118impl TargetPixel for DumbBufferPixelXrgb888 {
90119 fn blend ( & mut self , color : PremultipliedRgbaColor ) {
91120 let mut x = PremultipliedRgbaColor :: from ( * self ) ;
@@ -102,6 +131,20 @@ impl TargetPixel for DumbBufferPixelXrgb888 {
102131 }
103132}
104133
134+ impl TargetPixel for DumbBufferPixelBgra8888 {
135+ fn blend ( & mut self , color : PremultipliedRgbaColor ) {
136+ let mut x = PremultipliedRgbaColor :: from ( * self ) ;
137+ x. blend ( color) ;
138+ * self = x. into ( ) ;
139+ }
140+ fn from_rgb ( r : u8 , g : u8 , b : u8 ) -> Self {
141+ Self ( 0xff000000 | ( ( b as u32 ) << 16 ) | ( ( g as u32 ) << 8 ) | ( r as u32 ) )
142+ }
143+ fn background ( ) -> Self {
144+ Self ( 0 )
145+ }
146+ }
147+
105148impl SoftwareRendererAdapter {
106149 pub fn new (
107150 device_opener : & crate :: DeviceOpener ,
@@ -165,6 +208,12 @@ impl crate::fullscreenwindowadapter::FullscreenRenderer for SoftwareRendererAdap
165208 bytemuck:: cast_slice_mut ( pixels. as_mut ( ) ) ;
166209 self . renderer . render ( buffer, self . size . width as usize ) ;
167210 }
211+
212+ drm:: buffer:: DrmFourcc :: Bgra8888 => {
213+ let buffer: & mut [ DumbBufferPixelBgra8888 ] =
214+ bytemuck:: cast_slice_mut ( pixels. as_mut ( ) ) ;
215+ self . renderer . render ( buffer, self . size . width as usize ) ;
216+ }
168217 drm:: buffer:: DrmFourcc :: Rgb565 => {
169218 let buffer: & mut [ i_slint_core:: software_renderer:: Rgb565Pixel ] =
170219 bytemuck:: cast_slice_mut ( pixels. as_mut ( ) ) ;
0 commit comments