Skip to content

Commit

Permalink
WIP postprocess shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Dec 13, 2024
1 parent d6fe62e commit 1e71985
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 61 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion cosmic-comp-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use cosmic_config::{cosmic_config_derive::CosmicConfigEntry, CosmicConfigEntry};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::{collections::HashMap, path::PathBuf};

pub mod input;
pub mod workspace;
Expand Down Expand Up @@ -31,6 +31,8 @@ pub struct CosmicCompConfig {
pub focus_follows_cursor_delay: u64,
/// Let X11 applications scale themselves
pub descale_xwayland: bool,
/// Path to postprocess shader applied to whole screen
pub postprocess_shader_path: Option<PathBuf>,
}

impl Default for CosmicCompConfig {
Expand Down Expand Up @@ -60,6 +62,7 @@ impl Default for CosmicCompConfig {
cursor_follows_focus: false,
focus_follows_cursor_delay: 250,
descale_xwayland: false,
postprocess_shader_path: None,
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/backend/kms/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ impl State {

{
for (conn, maybe_crtc) in connectors {
let postprocess_shader = self.backend.kms().postprocess_shader.clone();
match device.connector_added(
self.backend.kms().primary_node.as_ref(),
conn,
Expand All @@ -234,6 +235,7 @@ impl State {
&self.common.event_loop_handle,
self.common.shell.clone(),
self.common.startup_done.clone(),
postprocess_shader,
) {
Ok((output, should_expose)) => {
if should_expose {
Expand Down Expand Up @@ -324,6 +326,7 @@ impl State {
}

for (conn, maybe_crtc) in changes.added {
let postprocess_shader = backend.postprocess_shader.clone();
match device.connector_added(
backend.primary_node.as_ref(),
conn,
Expand All @@ -332,6 +335,7 @@ impl State {
&self.common.event_loop_handle,
self.common.shell.clone(),
self.common.startup_done.clone(),
postprocess_shader,
) {
Ok((output, should_expose)) => {
if should_expose {
Expand Down Expand Up @@ -480,6 +484,7 @@ impl Device {
evlh: &LoopHandle<'static, State>,
shell: Arc<RwLock<Shell>>,
startup_done: Arc<AtomicBool>,
postprocess_shader: Option<String>,
) -> Result<(Output, bool)> {
let output = self
.outputs
Expand Down Expand Up @@ -543,7 +548,8 @@ impl Device {
shell,
startup_done,
) {
Ok(data) => {
Ok(mut data) => {
data.set_postprocess_shader(postprocess_shader);
self.surfaces.insert(crtc, data);
true
}
Expand Down
14 changes: 14 additions & 0 deletions src/backend/kms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub struct KmsState {
pub software_renderer: Option<GlowRenderer>,
pub api: GpuManager<GbmGlowBackend<DrmDeviceFd>>,

postprocess_shader: Option<String>,

session: LibSeatSession,
libinput: Libinput,
}
Expand Down Expand Up @@ -130,6 +132,8 @@ pub fn init_backend(
software_renderer,
api: GpuManager::new(GbmGlowBackend::new()).context("Failed to initialize gpu backend")?,

postprocess_shader: None,

session,
libinput: libinput_context,
});
Expand Down Expand Up @@ -623,6 +627,7 @@ impl KmsState {
loop_handle,
shell.clone(),
startup_done.clone(),
self.postprocess_shader.clone(),
)?;
if output.mirroring().is_none() {
w += output.config().transformed_size().w as u32;
Expand Down Expand Up @@ -759,4 +764,13 @@ impl KmsState {

Ok(all_outputs)
}

pub fn update_postprocess_shader(&mut self, shader: Option<&str>) {
self.postprocess_shader = shader.map(|x| x.to_owned());
for device in self.drm_devices.values_mut() {
for surface in device.surfaces.values_mut() {
surface.set_postprocess_shader(self.postprocess_shader.clone());
}
}
}
}
Loading

0 comments on commit 1e71985

Please sign in to comment.