Skip to content

Commit 85436fa

Browse files
committed
screencopy: Accumulate buffer damage
1 parent 7670bfb commit 85436fa

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/backend/wayland/buffer.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cctk::{
2-
screencopy::Formats,
2+
screencopy::{Formats, Rect},
33
wayland_client::{
44
Connection, Dispatch, QueueHandle,
55
protocol::{wl_buffer, wl_shm, wl_shm_pool},
@@ -20,6 +20,7 @@ use crate::utils;
2020
pub struct Buffer {
2121
pub backing: Arc<BufferSource>,
2222
pub buffer: wl_buffer::WlBuffer,
23+
pub buffer_damage: Vec<Rect>,
2324
pub size: (u32, u32),
2425
#[cfg(feature = "no-subsurfaces")]
2526
pub mmap: memmap2::Mmap,
@@ -52,6 +53,13 @@ impl AppData {
5253
#[cfg(feature = "no-subsurfaces")]
5354
let mmap = unsafe { memmap2::Mmap::map(&fd).unwrap() };
5455

56+
let full_damage = vec![Rect {
57+
x: 0,
58+
y: 0,
59+
width: width as i32,
60+
height: height as i32,
61+
}];
62+
5563
Buffer {
5664
backing: Arc::new(
5765
Shmbuf {
@@ -65,6 +73,7 @@ impl AppData {
6573
.into(),
6674
),
6775
buffer,
76+
buffer_damage: full_damage,
6877
#[cfg(feature = "no-subsurfaces")]
6978
mmap,
7079
size: (width, height),
@@ -148,6 +157,13 @@ impl AppData {
148157
)
149158
.0;
150159

160+
let full_damage = vec![Rect {
161+
x: 0,
162+
y: 0,
163+
width: width as i32,
164+
height: height as i32,
165+
}];
166+
151167
Ok(Some(Buffer {
152168
backing: Arc::new(
153169
Dmabuf {
@@ -160,6 +176,7 @@ impl AppData {
160176
.into(),
161177
),
162178
buffer,
179+
buffer_damage: full_damage,
163180
size: (width, height),
164181
}))
165182
}

src/backend/wayland/screencopy.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,9 @@ impl ScreencopySession {
6969
// TODO
7070
// let node = back.node().and_then(|x| x.to_str().map(|x| x.to_string()));
7171

72-
// TODO: accumulate damage
73-
let (width, height) = back.size;
74-
let full_damage = &[Rect {
75-
x: 0,
76-
y: 0,
77-
width: width as i32,
78-
height: height as i32,
79-
}];
80-
8172
self.session.capture(
8273
&back.buffer,
83-
full_damage,
74+
&back.buffer_damage,
8475
qh,
8576
FrameData {
8677
frame_data: Default::default(),
@@ -185,7 +176,13 @@ impl ScreencopyHandler for AppData {
185176
session.attach_buffer_and_commit(&capture_clone, &conn, &qh);
186177
});
187178

188-
let front = session.buffers.as_mut().unwrap().first_mut().unwrap();
179+
// Clear `buffer_damage` for front buffer; accumulate for other buffers.
180+
session.buffers.as_mut().unwrap()[0].buffer_damage.clear();
181+
for buffer in &mut session.buffers.as_mut().unwrap()[1..] {
182+
buffer.buffer_damage.extend_from_slice(&frame.damage);
183+
}
184+
185+
let front = &session.buffers.as_ref().unwrap()[0];
189186
let (buffer, release) = SubsurfaceBuffer::new(front.backing.clone());
190187
session.release = Some(release);
191188
let image = CaptureImage {

0 commit comments

Comments
 (0)