Add --pixelformat cli argument

Enables setting --pixelformat=baseline
to force wl_buffers to use the wayland default xrgb8888
This commit is contained in:
Gergő Sályi 2024-05-11 00:55:54 +02:00
parent 1e05e8c5c3
commit abb85692e4
3 changed files with 29 additions and 13 deletions

View file

@ -1,4 +1,4 @@
use clap::Parser; use clap::{Parser, ValueEnum};
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, long_about = None, about = "\ #[command(author, version, long_about = None, about = "\
@ -77,6 +77,15 @@ pub struct Cli {
/// adjust brightness, eg. -b=-60 (default: 0) /// adjust brightness, eg. -b=-60 (default: 0)
#[arg(short, long)] #[arg(short, long)]
pub brightness: Option<i32>, pub brightness: Option<i32>,
/// wl_buffer pixel format (default: auto)
#[arg(long)]
pub pixelformat: Option<PixelFormat>,
/// directory with: wallpaper_dir/output/workspace_name.{jpg|png|...} /// directory with: wallpaper_dir/output/workspace_name.{jpg|png|...}
pub wallpaper_dir: String, pub wallpaper_dir: String,
} }
#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]
pub enum PixelFormat {
Auto,
Baseline,
}

View file

@ -35,7 +35,7 @@ use smithay_client_toolkit::reexports::protocols
::wp::viewporter::client::wp_viewporter::WpViewporter; ::wp::viewporter::client::wp_viewporter::WpViewporter;
use crate::{ use crate::{
cli::Cli, cli::{Cli, PixelFormat},
sway::{SwayConnectionTask, WorkspaceVisible}, sway::{SwayConnectionTask, WorkspaceVisible},
wayland::State, wayland::State,
}; };
@ -87,6 +87,8 @@ fn main()
layer_shell, layer_shell,
viewporter, viewporter,
wallpaper_dir, wallpaper_dir,
force_xrgb8888: cli.pixelformat
.is_some_and(|p| p == PixelFormat::Baseline),
pixel_format: None, pixel_format: None,
background_layers: Vec::new(), background_layers: Vec::new(),
sway_connection_task: SwayConnectionTask::new( sway_connection_task: SwayConnectionTask::new(

View file

@ -49,6 +49,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 force_xrgb8888: bool,
pub pixel_format: Option<wl_shm::Format>, pub pixel_format: Option<wl_shm::Format>,
pub background_layers: Vec<BackgroundLayer>, pub background_layers: Vec<BackgroundLayer>,
pub sway_connection_task: SwayConnectionTask, pub sway_connection_task: SwayConnectionTask,
@ -57,19 +58,23 @@ pub struct State {
} }
impl State { impl State {
fn pixel_format(&mut self) -> wl_shm::Format { fn pixel_format(&mut self) -> wl_shm::Format
{
*self.pixel_format.get_or_insert_with(|| { *self.pixel_format.get_or_insert_with(|| {
// Consume less gpu memory by using Bgr888 if available,
// fall back to the always supported Xrgb8888 otherwise
for format in self.shm.formats() {
if let wl_shm::Format::Bgr888 = format {
debug!("Using pixel format: {:?}", format);
return *format
}
// XXX: One may add Rgb888 and HDR support here
}
debug!("Using default pixel format: Xrgb8888");
if !self.force_xrgb8888 {
// Consume less gpu memory by using Bgr888 if available,
// fall back to the always supported Xrgb8888 otherwise
for format in self.shm.formats() {
if let wl_shm::Format::Bgr888 = format {
debug!("Using pixel format: {:?}", format);
return *format
}
// XXX: One may add Rgb888 and HDR support here
}
}
debug!("Using default pixel format: Xrgb8888");
wl_shm::Format::Xrgb8888 wl_shm::Format::Xrgb8888
}) })
} }