Skip to content

Remove NonZero from Rect.width and Rect.height#345

Open
madsmtm wants to merge 1 commit intomasterfrom
madsmtm/unnonzero-rect
Open

Remove NonZero from Rect.width and Rect.height#345
madsmtm wants to merge 1 commit intomasterfrom
madsmtm/unnonzero-rect

Conversation

@madsmtm
Copy link
Member

@madsmtm madsmtm commented Mar 15, 2026

These now use u32 instead of NonZeroU32. A zero-sized damage rectangle can very easily be ignored, meaning that there is no real downside of allowing the user to specify them.

Part of #238.

Split out from #295, this should make sense to do regardless of what we end up doing with surface widths/heights.

See relatedly #314 which also relaxed the checks on damage regions.

Tested on:

  • Wayland (tier 1)
  • Win32 (tier 1)
  • XCB / Xlib (tier 1)
  • Web (tier 2)
  • DRM/KMS (tier 3)

These now use `u32` instead of `NonZeroU32`. This is always valid, a
zero-sized damage rectangle can just be ignored.
@madsmtm madsmtm added enhancement New feature or request DS - Wayland DS - Web WebAssembly / WASM backend DS - Win32 Windows backend DS - X11 Xlib / Xcb backend DS - DRM/KMS labels Mar 15, 2026
Comment on lines +394 to +396
/// Zero-sized damage regions (rectangles with `width` or `height` equal to `0`) may be
/// completely ignored, or may end up increasing the "union" damage region to contain the
/// zero-sized rectangle too. This is platform-specific, and should not be relied upon.
Copy link
Member Author

@madsmtm madsmtm Mar 15, 2026

Choose a reason for hiding this comment

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

I lied a bit above, there is actually a small wrinkle with zero-sized rects, and that's when you consider how they work in unions.

Consider something like:

buffer
    .present_with_damage(&[
        Rect {
            x: 10,
            y: 20,
            width: 30,
            height: 0,
        },
        Rect {
            x: 100,
            y: 200,
            width: 0,
            height: 40,
        },
    ])
    .unwrap();

If you naively union those, it'll present Rect { x: 10, y: 20, width: 100, height: 220 }, which might be undesirable?

I'll need to test all backends with it to see how they actually handle the rects in practice (whether they "union" them or ignore them). Also need to check what AppKit does.

I'm pretty sure they all ignore them, if so, we could probably document here (and implement in util::union_damage) that zero-sized rectangles are ignored too.

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

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

I don't think we should move away from nonzero for the same reasons I voiced here: #238 (comment)

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

Labels

DS - DRM/KMS DS - Wayland DS - Web WebAssembly / WASM backend DS - Win32 Windows backend DS - X11 Xlib / Xcb backend enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

2 participants