Skip to content

Commit 9a84cdb

Browse files
committed
Update orbital.rs
1 parent b11359f commit 9a84cdb

1 file changed

Lines changed: 18 additions & 30 deletions

File tree

src/backends/orbital.rs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ fn set_buffer(
236236
// Read the current width and size
237237
let (window_width, window_height) = window_size(window_fd);
238238

239+
let Some(urect) = util::union_damage(damage) else {
240+
syscall::fsync(window_fd).expect("failed to sync orbital window");
241+
return;
242+
};
243+
239244
{
240245
// Map window buffer
241246
let mut window_map =
@@ -246,32 +251,21 @@ fn set_buffer(
246251
// https://docs.rs/orbclient/0.3.48/src/orbclient/color.rs.html#25-29
247252
let window_data = unsafe { window_map.data_mut() };
248253

249-
// Copy each line, cropping to fit
250254
let width = width_u32 as usize;
251-
let height = height_u32 as usize;
252255

253-
// If window size hasn't changed (memory size is same) and we update everything,
254-
// or if at least one damage rect covers the full window, copy everything at once.
255-
if width == window_width && (damage.is_empty() || is_full_damage(damage, width, height)) {
256-
let total_pixels = width * height;
257-
window_data[..total_pixels].copy_from_slice(&buffer[..total_pixels]);
258-
} else {
259-
// Even if width is same, damaged areas can be anywhere inside the window.
260-
// If they don't cover the full width, we must jump over pixels to copy.
261-
if let Some(urect) = util::union_damage(damage) {
262-
let x = urect.x as usize;
263-
let y = urect.y as usize;
264-
let w = (urect.width.get() as usize).min(window_width.saturating_sub(x));
265-
let h = (urect.height.get() as usize).min(window_height.saturating_sub(y));
266-
267-
for (src_row, dst_row) in buffer
268-
.chunks_exact(width)
269-
.zip(window_data.chunks_exact_mut(window_width))
270-
.skip(y)
271-
.take(h)
272-
{
273-
dst_row[x..x + w].copy_from_slice(&src_row[x..x + w]);
274-
}
256+
let x = urect.x as usize;
257+
let y = urect.y as usize;
258+
let w = (urect.width.get() as usize).min(window_width.saturating_sub(x));
259+
let h = (urect.height.get() as usize).min(window_height.saturating_sub(y));
260+
261+
if let Some(urect) = util::union_damage(damage) {
262+
for (src_row, dst_row) in buffer
263+
.chunks_exact(width)
264+
.zip(window_data.chunks_exact_mut(window_width))
265+
.skip(y)
266+
.take(h)
267+
{
268+
dst_row[x..x + w].copy_from_slice(&src_row[x..x + w]);
275269
}
276270
}
277271

@@ -281,9 +275,3 @@ fn set_buffer(
281275
// Tell orbital to show the latest window data
282276
syscall::fsync(window_fd).expect("failed to sync orbital window");
283277
}
284-
285-
fn is_full_damage(damage: &[Rect], width: usize, height: usize) -> bool {
286-
damage.iter().any(|r| {
287-
r.x == 0 && r.y == 0 && r.width.get() as usize >= width && r.height.get() as usize >= height
288-
})
289-
}

0 commit comments

Comments
 (0)