Skip to content

Commit 6f5d97e

Browse files
committed
DROP ME: Temporary config value for blur_strength
1 parent f6029e7 commit 6f5d97e

12 files changed

Lines changed: 119 additions & 24 deletions

File tree

cosmic-comp-config/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub struct AppearanceConfig {
5454
pub clip_floating_windows: bool,
5555
pub clip_tiled_windows: bool,
5656
pub shadow_tiled_windows: bool,
57+
pub blur_strength: u8,
5758
}
5859

5960
impl Default for AppearanceConfig {
@@ -62,6 +63,7 @@ impl Default for AppearanceConfig {
6263
clip_floating_windows: true,
6364
clip_tiled_windows: true,
6465
shadow_tiled_windows: false,
66+
blur_strength: 9,
6567
}
6668
}
6769
}

src/backend/render/cursor.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ pub fn draw_surface_cursor<R>(
135135
surface: &wl_surface::WlSurface,
136136
location: Point<f64, Logical>,
137137
scale: impl Into<Scale<f64>>,
138+
blur_strength: usize,
138139
push: &mut dyn FnMut(CursorRenderElement<R>, Point<i32, Physical>),
139140
) where
140141
R: Renderer + ImportAll + AsGlowRenderer,
@@ -161,6 +162,7 @@ pub fn draw_surface_cursor<R>(
161162
1.0,
162163
false,
163164
[0; 4],
165+
blur_strength,
164166
Kind::Cursor,
165167
&mut |elem| push(elem.into(), h),
166168
None,
@@ -173,6 +175,7 @@ pub fn draw_dnd_icon<R>(
173175
surface: &wl_surface::WlSurface,
174176
location: Point<f64, Logical>,
175177
scale: impl Into<Scale<f64>>,
178+
blur_strength: usize,
176179
push: &mut dyn FnMut(SurfaceRenderElement<R>),
177180
) where
178181
R: Renderer + ImportAll + AsGlowRenderer,
@@ -194,6 +197,7 @@ pub fn draw_dnd_icon<R>(
194197
1.0,
195198
false,
196199
[0; 4],
200+
blur_strength,
197201
FRAME_TIME_FILTER,
198202
push,
199203
None,
@@ -272,6 +276,7 @@ pub fn draw_cursor<R>(
272276
scale: Scale<f64>,
273277
buffer_scale: f64,
274278
time: Time<Monotonic>,
279+
blur_strength: usize,
275280
draw_default: bool,
276281
push: &mut dyn FnMut(CursorRenderElement<R>, Point<i32, Physical>),
277282
) where
@@ -344,6 +349,6 @@ pub fn draw_cursor<R>(
344349
hotspot.to_physical_precise_round(scale),
345350
);
346351
} else if let CursorImageStatus::Surface(ref wl_surface) = cursor_status {
347-
draw_surface_cursor(renderer, wl_surface, location, scale, push);
352+
draw_surface_cursor(renderer, wl_surface, location, scale, blur_strength, push);
348353
}
349354
}

src/backend/render/mod.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ pub fn cursor_elements<'a, 'frame, R>(
479479
seats: impl Iterator<Item = &'a Seat<State>>,
480480
zoom_state: Option<&ZoomState>,
481481
theme: &Theme,
482+
blur_strength: usize,
482483
now: Time<Monotonic>,
483484
output: &Output,
484485
mode: CursorMode,
@@ -514,6 +515,7 @@ pub fn cursor_elements<'a, 'frame, R>(
514515
scale.into(),
515516
zoom_scale,
516517
now,
518+
blur_strength,
517519
mode != CursorMode::NotDefault,
518520
&mut |elem, hotspot| {
519521
push(CosmicElement::Cursor(RescaleRenderElement::from_element(
@@ -539,6 +541,7 @@ pub fn cursor_elements<'a, 'frame, R>(
539541
&dnd_icon.surface,
540542
(location + dnd_icon.offset.to_f64()).to_i32_round(),
541543
scale,
544+
blur_strength,
542545
&mut |elem| push(CosmicElement::Dnd(elem)),
543546
);
544547
}
@@ -722,6 +725,7 @@ where
722725
return Ok(Vec::new());
723726
}
724727
let theme = shell_ref.theme().clone();
728+
let blur_strength = shell_ref.appearance_config().blur_strength as usize;
725729
let scale = output.current_scale().fractional_scale();
726730
// we don't want to hold a shell lock across `cursor_elements`,
727731
// that is prone to deadlock with the main-thread on some grabs.
@@ -732,6 +736,7 @@ where
732736
seats.iter(),
733737
zoom_level,
734738
&theme,
739+
blur_strength,
735740
now,
736741
output,
737742
cursor_mode,
@@ -843,6 +848,7 @@ where
843848
1.0,
844849
false,
845850
[0; 4],
851+
blur_strength,
846852
FRAME_TIME_FILTER,
847853
&mut |elem| {
848854
elements.extend(
@@ -873,6 +879,7 @@ where
873879
1.0,
874880
false,
875881
[0; 4],
882+
blur_strength,
876883
FRAME_TIME_FILTER,
877884
&mut |elem| {
878885
elements.extend(
@@ -900,6 +907,7 @@ where
900907
1.0,
901908
false,
902909
[0; 4],
910+
blur_strength,
903911
FRAME_TIME_FILTER,
904912
&mut |elem| elements.extend(crop_to_output(elem.into()).map(Into::into)),
905913
None,
@@ -1043,6 +1051,7 @@ fn session_lock_elements<R>(
10431051
1.0,
10441052
false,
10451053
[0; 4],
1054+
0,
10461055
FRAME_TIME_FILTER,
10471056
push,
10481057
None,
@@ -1511,7 +1520,19 @@ where
15111520
CosmicMappedRenderElement<R>: RenderElement<R>,
15121521
WorkspaceRenderElement<R>: RenderElement<R>,
15131522
{
1514-
let elements: Vec<CosmicElement<R>> = workspace_elements(
1523+
let mut elements: Vec<CosmicElement<R>> = if let Some(additional_damage) = additional_damage {
1524+
let output_geo = output.geometry().to_local(output).as_logical();
1525+
additional_damage
1526+
.into_iter()
1527+
.filter_map(|rect| rect.intersection(output_geo))
1528+
.map(DamageElement::new)
1529+
.map(CosmicElement::from)
1530+
.collect()
1531+
} else {
1532+
Vec::new()
1533+
};
1534+
1535+
elements.extend(workspace_elements(
15151536
gpu,
15161537
renderer,
15171538
shell,
@@ -1522,17 +1543,7 @@ where
15221543
current,
15231544
cursor_mode,
15241545
element_filter,
1525-
)?;
1526-
1527-
if let Some(additional_damage) = additional_damage {
1528-
let output_geo = output.geometry().to_local(output).as_logical();
1529-
let additional_damage_elements: Vec<_> = additional_damage
1530-
.into_iter()
1531-
.filter_map(|rect| rect.intersection(output_geo))
1532-
.map(DamageElement::new)
1533-
.collect();
1534-
damage_tracker.damage_output(age, &additional_damage_elements)?;
1535-
}
1546+
)?);
15361547

15371548
let res = damage_tracker.render_output(
15381549
renderer,

src/backend/render/wayland/blur_effect.rs

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{
22
borrow::{Borrow, BorrowMut},
33
sync::{
4-
Arc, Mutex,
4+
Arc, LazyLock, Mutex,
55
atomic::{AtomicBool, Ordering},
66
},
77
};
@@ -27,6 +27,7 @@ use smithay::{
2727
},
2828
wayland::compositor::SurfaceData,
2929
};
30+
use tracing::info;
3031

3132
use crate::{
3233
backend::render::{element::AsGlowRenderer, wayland::clipped_surface::ClippingShader},
@@ -36,9 +37,50 @@ use crate::{
3637
pub static BLUR_DOWNSAMPLE_SHADER: &str = include_str!("../shaders/blur_downsample.frag");
3738
pub static BLUR_UPSAMPLE_SHADER: &str = include_str!("../shaders/blur_upsample.frag");
3839

39-
const PASSES: usize = 3;
40-
const OFFSET: f64 = 1.1;
4140
const NOISE: f32 = 0.03;
41+
const MAX_STEPS: usize = 15;
42+
43+
#[derive(Debug, Clone, Copy, PartialEq)]
44+
struct BlurParameters {
45+
passes: usize,
46+
offset: f64,
47+
extended_radius: i32,
48+
}
49+
50+
static BLUR_PARAMS: LazyLock<Vec<BlurParameters>> = LazyLock::new(|| {
51+
let mut params = Vec::new();
52+
53+
let mut remaining_steps = MAX_STEPS as isize;
54+
let offsets = [
55+
// min offset, max offset, extended radius to avoid artifacts
56+
(1.0, 2.0, 10),
57+
(2.0, 3.0, 20),
58+
(2.0, 5.0, 50),
59+
(3.0, 8.0, 150),
60+
];
61+
62+
let sum = offsets.iter().map(|(min, max, _)| *max - *min).sum::<f64>();
63+
for (i, (min, max, extended_radius)) in offsets.into_iter().enumerate() {
64+
let mut iter_num = f64::ceil((max - min) / sum * (MAX_STEPS as f64)) as usize;
65+
remaining_steps -= iter_num as isize;
66+
67+
if remaining_steps < 0 {
68+
iter_num = iter_num.saturating_add_signed(remaining_steps);
69+
}
70+
71+
let diff = max - min;
72+
for j in 1..=iter_num {
73+
params.push(BlurParameters {
74+
passes: i + 1,
75+
offset: min + (diff / iter_num as f64) * j as f64,
76+
extended_radius,
77+
});
78+
}
79+
}
80+
81+
info!("Computed blur values: {:#?}", &params);
82+
params
83+
});
4284

4385
#[derive(Debug, Clone)]
4486
pub struct BlurShaders {
@@ -125,6 +167,7 @@ impl BlurElement {
125167
geometry: Rectangle<f64, Logical>,
126168
output_scale: f64,
127169
radii: [u8; 4],
170+
strength: usize,
128171
) -> Result<Option<Self>, R::Error> {
129172
let mut blur_region_state = states.cached_state.get::<ComputedBlurRegionCachedState>();
130173
let Some(region) = blur_region_state.current().blur_region.as_ref() else {
@@ -133,7 +176,7 @@ impl BlurElement {
133176

134177
let geo = geometry.to_physical_precise_round(output_scale);
135178
let mut extended_geo = geo;
136-
let radius = OFFSET * 2.0f64.powf(PASSES as f64);
179+
let radius = BLUR_PARAMS[strength.min(MAX_STEPS - 1)].extended_radius as f64;
137180
extended_geo.loc -= Point::<f64, Physical>::new(radius, radius);
138181
extended_geo.size += Size::<f64, Physical>::new(radius, radius).upscale(2.);
139182

@@ -187,6 +230,7 @@ impl BlurElement {
187230
output_scale,
188231
&mut *state.lock().unwrap(),
189232
uniforms,
233+
strength,
190234
)?))
191235
}
192236

@@ -197,19 +241,24 @@ impl BlurElement {
197241
output_scale: f64,
198242
state: &mut BlurState,
199243
uniforms: Vec<Uniform<'static>>,
244+
strength: usize,
200245
) -> Result<Self, R::Error> {
201246
let renderer_id = renderer.glow_renderer().context_id();
202247
let src = geometry.size.to_buffer(output_scale, Transform::Normal);
248+
let params = &BLUR_PARAMS[strength.min(MAX_STEPS - 1)];
203249

204250
let dirty = !(state
205251
.renderer_id
206252
.as_ref()
207253
.is_some_and(|id| id == &renderer_id)
254+
&& state.offset == params.offset
255+
&& state.passes == params.passes
208256
&& &state.region == region
209257
&& state.src == src);
258+
210259
state.renderer_id = Some(renderer_id);
211-
state.offset = OFFSET * output_scale; // we want the blur result to be stable across scaling;
212-
state.passes = PASSES;
260+
state.offset = params.offset;
261+
state.passes = params.passes;
213262
state.region = region.clone();
214263
state.src = src;
215264
if dirty {

src/backend/render/wayland/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub fn push_render_elements_from_surface_tree<R>(
3535
alpha: f32,
3636
should_clip: bool,
3737
radii: [u8; 4],
38+
blur_strength: usize,
3839
kind: impl Into<KindEvaluation>,
3940
push_above: &mut dyn FnMut(SurfaceRenderElement<R>),
4041
mut push_below: Option<&mut dyn FnMut(SurfaceRenderElement<R>)>,
@@ -87,7 +88,12 @@ pub fn push_render_elements_from_surface_tree<R>(
8788
) {
8889
Ok(Some(surface)) => {
8990
blur = BlurElement::from_surface(
90-
renderer, states, geometry, scale.x, radii,
91+
renderer,
92+
states,
93+
geometry,
94+
scale.x,
95+
radii,
96+
blur_strength,
9197
);
9298
let elem: SurfaceRenderElement<R> = if radii.iter().any(|r| *r != 0)
9399
&& should_clip

src/shell/element/stack.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ impl CosmicStack {
649649
window_loc,
650650
scale,
651651
alpha,
652+
p.appearance_conf.lock().unwrap().blur_strength as usize,
652653
&mut |elem| push(elem.into()),
653654
)
654655
})
@@ -804,6 +805,7 @@ impl CosmicStack {
804805
scanout_override,
805806
radii.is_some(),
806807
radii.unwrap_or([0; 4]),
808+
appearance.blur_strength as usize,
807809
&mut |elem| push_above(elem.into()),
808810
Some(&mut |elem| push_below(elem.into())),
809811
);

src/shell/element/surface.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ impl CosmicSurface {
740740
location: Point<i32, Physical>,
741741
scale: Scale<f64>,
742742
alpha: f32,
743+
blur_strength: usize,
743744
push: &mut dyn FnMut(SurfaceRenderElement<R>),
744745
) where
745746
R: Renderer + ImportAll + AsGlowRenderer,
@@ -763,6 +764,7 @@ impl CosmicSurface {
763764
alpha,
764765
false,
765766
[0; 4],
767+
blur_strength,
766768
FRAME_TIME_FILTER,
767769
push,
768770
None,
@@ -782,6 +784,7 @@ impl CosmicSurface {
782784
scanout_override: Option<bool>,
783785
should_clip: bool,
784786
radii: [u8; 4],
787+
blur_strength: usize,
785788
push_above: &mut dyn FnMut(SurfaceRenderElement<R>),
786789
push_below: Option<&mut dyn FnMut(SurfaceRenderElement<R>)>,
787790
) where
@@ -804,6 +807,7 @@ impl CosmicSurface {
804807
alpha,
805808
should_clip,
806809
radii,
810+
blur_strength,
807811
scanout_override
808812
.map(|val| {
809813
if val {
@@ -832,6 +836,7 @@ impl CosmicSurface {
832836
alpha,
833837
should_clip,
834838
radii,
839+
blur_strength,
835840
scanout_override
836841
.map(|val| {
837842
if val {

0 commit comments

Comments
 (0)