Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Postprocess shader support #1058

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 @@ -926,4 +931,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
Loading