Skip to content

Conversation

@madsmtm
Copy link
Member

@madsmtm madsmtm commented Jan 19, 2026

There is a very natural thing to do if we receive a damage rectangle outside supported bounds: Clamp it to be inside. This is also what's done by Wayland IIUC, and probably on other platforms as well, so let's do it in Softbuffer as well, and avoid the needless error case.

This also allows us to make present forward directly to present_with_damage, which is a nice internal simplification.

Finally, this exposed latent bugs with out-of-bounds damage regions on Windows, Web and X11, I've fixed those as well.

Tested on:

  • Android
  • CoreGraphics
  • KMS/DRM
  • Orbital
  • Wayland
  • Web
  • Win32
  • X11

@madsmtm madsmtm added the enhancement New feature or request label Jan 19, 2026
@madsmtm madsmtm force-pushed the madsmtm/remove-damage-out-of-range branch from 7540242 to 551b385 Compare January 19, 2026 17:58
@madsmtm madsmtm force-pushed the madsmtm/remove-damage-out-of-range branch from 551b385 to ab88d81 Compare January 19, 2026 19:27
Comment on lines +271 to +272
let x = rect.x.try_into().unwrap_or(i32::MAX);
let y = rect.y.try_into().unwrap_or(i32::MAX);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MIN or 0?

Comment on lines +151 to +154
// TODO: Android requires the damage rect _at lock time_
// Since we're faking the backing buffer _anyway_, we could even fake the surface lock
// and lock it here (if it doesn't influence timings).
let _ = damage;
Copy link
Member

@MarijnS95 MarijnS95 Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does this because the region can be expanded by the system, requesting the user to actually redraw a larger region. I'm not sure if/when this is used, or if corruption/artifacts occur when the enlarged damage region is not re-rendered.

EDIT: This comment was just moved, I don't remember why I didn't clarify that in the original place.

Comment on lines +337 to +338
rect.x.try_into().unwrap_or(u16::MAX),
rect.y.try_into().unwrap_or(u16::MAX),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, it seems that not having x or y means the rect should be infinitely large, starting at 0 rather than MAX (and ending at MAX, making it 0×0)?

Comment on lines +261 to +262
width: NonZeroU32::new(u32::MAX).unwrap(),
height: NonZeroU32::new(u32::MAX).unwrap(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NonZeroU32::MIN and ::MAX seem to be available since Rust 1.70, our MSRV is already 1.71.

Comment on lines +412 to +413
rect.width.get().min(buffer_width.get()).into(),
rect.height.get().min(buffer_height.get()).into(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the width/height take into account the x/y offset before calling .min()?

@MarijnS95
Copy link
Member

This is also what's done by Wayland IIUC

Maybe explicitly linking this portion of the documentation:

The compositor ignores the parts of the damage that fall outside of the surface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

3 participants