Fix regressed wl_shm format choosing, delay it until formats are available
This commit is contained in:
parent
6eec049e48
commit
3a90b4b9e8
2 changed files with 26 additions and 13 deletions
32
src/main.rs
32
src/main.rs
|
@ -59,7 +59,7 @@ pub struct State {
|
||||||
pub layer_shell: LayerShell,
|
pub layer_shell: LayerShell,
|
||||||
pub viewporter: WpViewporter,
|
pub viewporter: WpViewporter,
|
||||||
pub wallpaper_dir: PathBuf,
|
pub wallpaper_dir: PathBuf,
|
||||||
pub shm_format: wl_shm::Format,
|
pub shm_format: Option<wl_shm::Format>,
|
||||||
pub background_layers: Vec<BackgroundLayer>,
|
pub background_layers: Vec<BackgroundLayer>,
|
||||||
pub compositor_connection_task: ConnectionTask,
|
pub compositor_connection_task: ConnectionTask,
|
||||||
pub color_transform: ColorTransform,
|
pub color_transform: ColorTransform,
|
||||||
|
@ -67,6 +67,21 @@ pub struct State {
|
||||||
pub gpu: Option<Gpu>,
|
pub gpu: Option<Gpu>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl State {
|
||||||
|
fn shm_format(&mut self) -> wl_shm::Format {
|
||||||
|
*self.shm_format.get_or_insert_with(|| {
|
||||||
|
let mut format = wl_shm::Format::Xrgb8888;
|
||||||
|
// Consume less gpu memory by using Bgr888 if available,
|
||||||
|
// fall back to the always supported Xrgb8888 otherwise
|
||||||
|
if self.shm.formats().contains(&wl_shm::Format::Bgr888) {
|
||||||
|
format = wl_shm::Format::Bgr888
|
||||||
|
}
|
||||||
|
debug!("Using shm format: {format:?}");
|
||||||
|
format
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), ()> {
|
fn main() -> Result<(), ()> {
|
||||||
run().map_err(|e| { error!("{e:#}"); })
|
run().map_err(|e| { error!("{e:#}"); })
|
||||||
}
|
}
|
||||||
|
@ -104,15 +119,12 @@ fn run() -> anyhow::Result<()> {
|
||||||
let compositor_state = CompositorState::bind(&globals, &qh).unwrap();
|
let compositor_state = CompositorState::bind(&globals, &qh).unwrap();
|
||||||
let layer_shell = LayerShell::bind(&globals, &qh).unwrap();
|
let layer_shell = LayerShell::bind(&globals, &qh).unwrap();
|
||||||
let shm = Shm::bind(&globals, &qh).unwrap();
|
let shm = Shm::bind(&globals, &qh).unwrap();
|
||||||
let mut shm_format = wl_shm::Format::Xrgb8888;
|
let shm_format = if cli.pixelformat == Some(PixelFormat::Baseline) {
|
||||||
if cli.pixelformat != Some(PixelFormat::Baseline) {
|
debug!("Using shm format: {:?}", wl_shm::Format::Xrgb8888);
|
||||||
// Consume less gpu memory by using Bgr888 if available,
|
Some(wl_shm::Format::Xrgb8888)
|
||||||
// fall back to the always supported Xrgb8888 otherwise
|
} else {
|
||||||
if shm.formats().contains(&wl_shm::Format::Bgr888) {
|
None
|
||||||
shm_format = wl_shm::Format::Bgr888;
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
debug!("Using shm format: {shm_format:?}");
|
|
||||||
|
|
||||||
let registry_state = RegistryState::new(&globals);
|
let registry_state = RegistryState::new(&globals);
|
||||||
|
|
||||||
|
|
|
@ -923,7 +923,8 @@ fn load_wallpapers(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let shm_stride = match state.shm_format {
|
let shm_format = state.shm_format();
|
||||||
|
let shm_stride = match shm_format {
|
||||||
wl_shm::Format::Xrgb8888 => width as usize * 4,
|
wl_shm::Format::Xrgb8888 => width as usize * 4,
|
||||||
wl_shm::Format::Bgr888 => {
|
wl_shm::Format::Bgr888 => {
|
||||||
// Align buffer stride to both 4 and pixel format
|
// Align buffer stride to both 4 and pixel format
|
||||||
|
@ -1044,7 +1045,7 @@ fn load_wallpapers(
|
||||||
width as u32,
|
width as u32,
|
||||||
height as u32,
|
height as u32,
|
||||||
shm_stride,
|
shm_stride,
|
||||||
state.shm_format,
|
shm_format,
|
||||||
state.color_transform,
|
state.color_transform,
|
||||||
&mut resizer,
|
&mut resizer,
|
||||||
) {
|
) {
|
||||||
|
@ -1057,7 +1058,7 @@ fn load_wallpapers(
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
shm_stride.try_into().unwrap(),
|
shm_stride.try_into().unwrap(),
|
||||||
state.shm_format,
|
shm_format,
|
||||||
(),
|
(),
|
||||||
qh,
|
qh,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue