Skip to content

Commit 3652977

Browse files
committed
WIP postprocess shaders
1 parent 0ad4a5a commit 3652977

File tree

11 files changed

+250
-54
lines changed

11 files changed

+250
-54
lines changed

cosmic-comp-config/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use cosmic_config::{cosmic_config_derive::CosmicConfigEntry, CosmicConfigEntry};
44
use serde::{Deserialize, Serialize};
5-
use std::collections::HashMap;
5+
use std::{collections::HashMap, path::PathBuf};
66

77
pub mod input;
88
pub mod workspace;
@@ -31,6 +31,8 @@ pub struct CosmicCompConfig {
3131
pub focus_follows_cursor_delay: u64,
3232
/// Let X11 applications scale themselves
3333
pub descale_xwayland: bool,
34+
/// Path to postprocess shader applied to whole screen
35+
pub postprocess_shader_path: Option<PathBuf>,
3436
}
3537

3638
impl Default for CosmicCompConfig {
@@ -60,6 +62,7 @@ impl Default for CosmicCompConfig {
6062
cursor_follows_focus: false,
6163
focus_follows_cursor_delay: 250,
6264
descale_xwayland: false,
65+
postprocess_shader_path: None,
6366
}
6467
}
6568
}

src/backend/kms/device.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ impl State {
266266

267267
{
268268
for (conn, maybe_crtc) in connectors {
269+
let postprocess_shader = self.backend.kms().postprocess_shader.clone();
269270
match device.connector_added(
270271
self.backend.kms().primary_node.as_ref(),
271272
conn,
@@ -274,6 +275,7 @@ impl State {
274275
&self.common.event_loop_handle,
275276
self.common.shell.clone(),
276277
self.common.startup_done.clone(),
278+
postprocess_shader,
277279
) {
278280
Ok((output, should_expose)) => {
279281
if should_expose {
@@ -359,6 +361,7 @@ impl State {
359361
}
360362

361363
for (conn, maybe_crtc) in changes.added {
364+
let postprocess_shader = backend.postprocess_shader.clone();
362365
match device.connector_added(
363366
backend.primary_node.as_ref(),
364367
conn,
@@ -367,6 +370,7 @@ impl State {
367370
&self.common.event_loop_handle,
368371
self.common.shell.clone(),
369372
self.common.startup_done.clone(),
373+
postprocess_shader,
370374
) {
371375
Ok((output, should_expose)) => {
372376
if should_expose {
@@ -518,6 +522,7 @@ impl Device {
518522
evlh: &LoopHandle<'static, State>,
519523
shell: Arc<RwLock<Shell>>,
520524
startup_done: Arc<AtomicBool>,
525+
postprocess_shader: Option<String>,
521526
) -> Result<(Output, bool)> {
522527
let output = self
523528
.outputs
@@ -582,7 +587,8 @@ impl Device {
582587
shell,
583588
startup_done,
584589
) {
585-
Ok(data) => {
590+
Ok(mut data) => {
591+
data.set_postprocess_shader(postprocess_shader);
586592
self.surfaces.insert(crtc, data);
587593
true
588594
}

src/backend/kms/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ pub struct KmsState {
7272
pub software_renderer: Option<GlowRenderer>,
7373
pub api: GpuManager<GbmGlowBackend<DrmDeviceFd>>,
7474

75+
postprocess_shader: Option<String>,
76+
7577
session: LibSeatSession,
7678
libinput: Libinput,
7779

@@ -140,6 +142,8 @@ pub fn init_backend(
140142
software_renderer,
141143
api: GpuManager::new(GbmGlowBackend::new()).context("Failed to initialize gpu backend")?,
142144

145+
postprocess_shader: None,
146+
143147
session,
144148
libinput: libinput_context,
145149

@@ -660,6 +664,7 @@ impl KmsState {
660664
loop_handle,
661665
shell.clone(),
662666
startup_done.clone(),
667+
self.postprocess_shader.clone(),
663668
)?;
664669
if output.mirroring().is_none() {
665670
w += output.geometry().size.w as u32;
@@ -926,4 +931,13 @@ impl KmsState {
926931

927932
Ok(all_outputs)
928933
}
934+
935+
pub fn update_postprocess_shader(&mut self, shader: Option<&str>) {
936+
self.postprocess_shader = shader.map(|x| x.to_owned());
937+
for device in self.drm_devices.values_mut() {
938+
for surface in device.surfaces.values_mut() {
939+
surface.set_postprocess_shader(self.postprocess_shader.clone());
940+
}
941+
}
942+
}
929943
}

0 commit comments

Comments
 (0)