fix: single blur surface per wl surface
This commit is contained in:
parent
6be49cb530
commit
5cc9f8d621
1 changed files with 23 additions and 49 deletions
|
|
@ -431,7 +431,7 @@ pub struct SctkState {
|
||||||
pub(crate) popups: Vec<SctkPopup>,
|
pub(crate) popups: Vec<SctkPopup>,
|
||||||
pub(crate) subsurfaces: Vec<SctkSubsurface>,
|
pub(crate) subsurfaces: Vec<SctkSubsurface>,
|
||||||
pub(crate) lock_surfaces: Vec<SctkLockSurface>,
|
pub(crate) lock_surfaces: Vec<SctkLockSurface>,
|
||||||
pub(crate) blur_surfaces: HashMap<core::window::Id, Vec<ExtBackgroundEffectSurfaceV1>>,
|
pub(crate) blur_surfaces: HashMap<core::window::Id, ExtBackgroundEffectSurfaceV1>,
|
||||||
pub(crate) corner_radii: HashMap<core::window::Id, (SctkCornerRadius, Option<CornerRadius>)>,
|
pub(crate) corner_radii: HashMap<core::window::Id, (SctkCornerRadius, Option<CornerRadius>)>,
|
||||||
pub(crate) touch_points: HashMap<touch::Finger, (WlSurface, Point)>,
|
pub(crate) touch_points: HashMap<touch::Finger, (WlSurface, Point)>,
|
||||||
|
|
||||||
|
|
@ -1134,9 +1134,7 @@ impl SctkState {
|
||||||
let l = self.layer_surfaces.remove(i);
|
let l = self.layer_surfaces.remove(i);
|
||||||
|
|
||||||
if let Some(blurred) = self.blur_surfaces.remove(&l.id) {
|
if let Some(blurred) = self.blur_surfaces.remove(&l.id) {
|
||||||
for s in blurred {
|
blurred.destroy();
|
||||||
s.destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ = self.corner_radii.remove(&id);
|
_ = self.corner_radii.remove(&id);
|
||||||
|
|
||||||
|
|
@ -1415,9 +1413,7 @@ impl SctkState {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(blurred) = self.blur_surfaces.remove(&id) {
|
if let Some(blurred) = self.blur_surfaces.remove(&id) {
|
||||||
for s in blurred {
|
blurred.destroy();
|
||||||
s.destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ = self.corner_radii.remove(&id);
|
_ = self.corner_radii.remove(&id);
|
||||||
|
|
||||||
|
|
@ -1545,9 +1541,7 @@ impl SctkState {
|
||||||
{
|
{
|
||||||
let surface = self.lock_surfaces.remove(i);
|
let surface = self.lock_surfaces.remove(i);
|
||||||
if let Some(blurred) = self.blur_surfaces.remove(&surface.id) {
|
if let Some(blurred) = self.blur_surfaces.remove(&surface.id) {
|
||||||
for s in blurred {
|
blurred.destroy();
|
||||||
s.destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ = self.corner_radii.remove(&id);
|
_ = self.corner_radii.remove(&id);
|
||||||
|
|
||||||
|
|
@ -1632,9 +1626,7 @@ impl SctkState {
|
||||||
}
|
}
|
||||||
for (destroyed, parent, id) in destroyed {
|
for (destroyed, parent, id) in destroyed {
|
||||||
if let Some(blurred) = self.blur_surfaces.remove(&id) {
|
if let Some(blurred) = self.blur_surfaces.remove(&id) {
|
||||||
for s in blurred {
|
blurred.destroy();
|
||||||
s.destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ = self.corner_radii.remove(&id);
|
_ = self.corner_radii.remove(&id);
|
||||||
|
|
||||||
|
|
@ -1790,45 +1782,27 @@ impl SctkState {
|
||||||
let existing_blur = self.blur_surfaces.entry(id);
|
let existing_blur = self.blur_surfaces.entry(id);
|
||||||
match (existing_blur, rectangles) {
|
match (existing_blur, rectangles) {
|
||||||
(Entry::Occupied(occupied_entry), None) => {
|
(Entry::Occupied(occupied_entry), None) => {
|
||||||
let blur_surfaces = occupied_entry.remove();
|
let blur_surface = occupied_entry.remove();
|
||||||
for region in blur_surfaces {
|
blur_surface.destroy();
|
||||||
region.destroy();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
(Entry::Occupied(mut occupied_entry), Some(rectangles)) => {
|
(Entry::Occupied(mut occupied_entry), Some(rectangles)) => {
|
||||||
let blur_surfaces = occupied_entry.get_mut();
|
let blur_surface = occupied_entry.get_mut();
|
||||||
let regions = rectangles.into_iter().map(|rect| {
|
|
||||||
let region = self
|
let region = self
|
||||||
.compositor_state
|
.compositor_state
|
||||||
.wl_compositor()
|
.wl_compositor()
|
||||||
.create_region(&self.queue_handle, ());
|
.create_region(&self.queue_handle, ());
|
||||||
|
for rect in rectangles.into_iter() {
|
||||||
region.add(
|
region.add(
|
||||||
rect.x.round() as i32,
|
rect.x.round() as i32,
|
||||||
rect.y.round() as i32,
|
rect.y.round() as i32,
|
||||||
rect.width.round() as i32,
|
rect.width.round() as i32,
|
||||||
rect.height.round() as i32,
|
rect.height.round() as i32,
|
||||||
);
|
);
|
||||||
region
|
|
||||||
}).collect::<Vec<_>>();
|
|
||||||
if regions.len() > blur_surfaces.len() {
|
|
||||||
// add extra blur surfaces if needed
|
|
||||||
for _ in blur_surfaces.len()..regions.len() {
|
|
||||||
let Some(extra_region) = self.ext_background_effect_manager.as_mut().map(|mgr| mgr.blur(s, &self.queue_handle)) else {
|
|
||||||
log::error!("Failed to create blur effect for surface");
|
|
||||||
return Ok(());
|
|
||||||
};
|
|
||||||
blur_surfaces.push(extra_region);
|
|
||||||
}
|
|
||||||
} else if regions.len() < blur_surfaces.len() {
|
|
||||||
for surface in blur_surfaces.iter().skip(regions.len()) {
|
|
||||||
surface.destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update existing blur surfaces
|
// update existing blur surfaces
|
||||||
for (blur_surface, region) in blur_surfaces.iter().zip(regions.into_iter()) {
|
|
||||||
blur_surface.set_blur_region(Some(®ion));
|
blur_surface.set_blur_region(Some(®ion));
|
||||||
}
|
|
||||||
},
|
},
|
||||||
(Entry::Vacant(..), None) => {
|
(Entry::Vacant(..), None) => {
|
||||||
// nothing to remove
|
// nothing to remove
|
||||||
|
|
@ -1838,23 +1812,23 @@ impl SctkState {
|
||||||
log::error!("Blur effect is not supported.");
|
log::error!("Blur effect is not supported.");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let blur_surfaces = rectangles.into_iter().map(|rect| {
|
|
||||||
let region = self
|
let region = self
|
||||||
.compositor_state
|
.compositor_state
|
||||||
.wl_compositor()
|
.wl_compositor()
|
||||||
.create_region(&self.queue_handle, ());
|
.create_region(&self.queue_handle, ());
|
||||||
|
for rect in rectangles {
|
||||||
region.add(
|
region.add(
|
||||||
rect.x.round() as i32,
|
rect.x.round() as i32,
|
||||||
rect.y.round() as i32,
|
rect.y.round() as i32,
|
||||||
rect.width.round() as i32,
|
rect.width.round() as i32,
|
||||||
rect.height.round() as i32,
|
rect.height.round() as i32,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let blur_manager = self.ext_background_effect_manager.as_mut().unwrap();
|
let blur_manager = self.ext_background_effect_manager.as_mut().unwrap();
|
||||||
let blur_surface = blur_manager.blur(s, &self.queue_handle);
|
let blur_surface = blur_manager.blur(s, &self.queue_handle);
|
||||||
blur_surface.set_blur_region(Some(®ion));
|
blur_surface.set_blur_region(Some(®ion));
|
||||||
blur_surface
|
_ = vacant_entry.insert(blur_surface);
|
||||||
}).collect::<Vec<_>>();
|
|
||||||
_ = vacant_entry.insert(blur_surfaces);
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue