Skip to content

Commit

Permalink
add limit to number of damage rects we can send
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhbooth committed Jul 1, 2024
1 parent b9179b0 commit dcb3759
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
20 changes: 13 additions & 7 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use smithay_client_toolkit::shm::slot::SlotPool;
use smithay_client_toolkit::shm::Shm;

use crate::client_utils::SeatObject;
use crate::constants;
use crate::filtering;
use crate::prelude::*;
use crate::serialization::geometry::Point;
Expand Down Expand Up @@ -498,13 +499,18 @@ impl RemoteSurface {
"attaching a buffer failed, this probably means we're leaking buffers",
)?;
if let Some(damage_rects) = self.frame_damage.take() {
for damage_rect in damage_rects {
wl_surface.damage_buffer(
damage_rect.loc.x,
damage_rect.loc.y,
damage_rect.size.w,
damage_rect.size.h,
);
// avoid overwhelming wayland connection
if damage_rects.len() < constants::SENT_DAMAGE_LIMIT {
for damage_rect in damage_rects {
wl_surface.damage_buffer(
damage_rect.loc.x,
damage_rect.loc.y,
damage_rect.size.w,
damage_rect.size.h,
);
}
} else {
wl_surface.damage_buffer(0, 0, i32::MAX, i32::MAX);
}
} else {
wl_surface.damage_buffer(0, 0, i32::MAX, i32::MAX);
Expand Down
2 changes: 2 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// limit used to avoid overwhelming wayland connection
pub const SENT_DAMAGE_LIMIT: usize = 256;
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod channel_utils;
pub mod client;
pub mod client_utils;
pub mod compositor_utils;
pub mod constants;
pub mod control_server;
pub mod error_utils;
pub mod fallible_entry;
Expand Down
20 changes: 13 additions & 7 deletions src/xwayland_xdg_shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use tracing::Span;

use crate::args;
use crate::compositor_utils;
use crate::constants;
use crate::prelude::*;
use crate::serialization::geometry::Point;
use crate::serialization::geometry::Rectangle;
Expand Down Expand Up @@ -153,13 +154,18 @@ impl XWaylandSurface {
// ignore.
_ = buffer.active_buffer.attach_to(&surface);
if let Some(damage_rects) = &self.damage.take() {
for damage_rect in damage_rects {
surface.damage_buffer(
damage_rect.loc.x,
damage_rect.loc.y,
damage_rect.size.w,
damage_rect.size.h,
);
// avoid overwhelming wayland connection
if damage_rects.len() < constants::SENT_DAMAGE_LIMIT {
for damage_rect in damage_rects {
surface.damage_buffer(
damage_rect.loc.x,
damage_rect.loc.y,
damage_rect.size.w,
damage_rect.size.h,
);
}
} else {
surface.damage_buffer(0, 0, i32::MAX, i32::MAX);
}
} else {
surface.damage_buffer(0, 0, i32::MAX, i32::MAX);
Expand Down

0 comments on commit dcb3759

Please sign in to comment.