Skip to content

Commit

Permalink
WIP postprocess shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Feb 19, 2025
1 parent 2864c57 commit 5227494
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 60 deletions.
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 @@ -48,6 +48,8 @@ pub struct CosmicCompConfig {
pub descale_xwayland: bool,
/// The threshold before windows snap themselves to output edges
pub edge_snap_threshold: u32,
/// Path to postprocess shader applied to whole screen
pub postprocess_shader_path: Option<PathBuf>,
}

impl Default for CosmicCompConfig {
Expand Down Expand Up @@ -79,6 +81,7 @@ impl Default for CosmicCompConfig {
focus_follows_cursor_delay: 250,
descale_xwayland: false,
edge_snap_threshold: 0,
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 @@ -266,6 +266,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 @@ -274,6 +275,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 @@ -359,6 +361,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 @@ -367,6 +370,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 @@ -518,6 +522,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 @@ -582,7 +587,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 @@ -72,6 +72,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 @@ -140,6 +142,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 @@ -660,6 +664,7 @@ impl KmsState {
loop_handle,
shell.clone(),
startup_done.clone(),
self.postprocess_shader.clone(),
)?;
if output.mirroring().is_none() {
w += output.geometry().size.w as u32;
Expand Down Expand Up @@ -927,4 +932,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 5227494

Please sign in to comment.