Skip to content

gpui: Support rounded content masks#5

Merged
BumpyClock merged 1 commit into
mainfrom
rounded-content-masks
Jul 15, 2026
Merged

gpui: Support rounded content masks#5
BumpyClock merged 1 commit into
mainfrom
rounded-content-masks

Conversation

@BumpyClock

Copy link
Copy Markdown
Owner

Summary

  • extend ContentMask with rounded clip geometry while preserving rectangular clip bounds
  • propagate rounded descendant clipping through scene primitives and Metal, DirectX, and WGPU shaders
  • keep element shadows outside their own descendant clip and preserve contained nested rounded clips
  • cover GPU buffer layouts and single-axis overflow border insets

Verification

  • cargo check --manifest-path /Volumes/Portkey/Projects/gpui/Cargo.toml -p gpui -p gpui_wgpu -p gpui_macos --all-targets
  • WGSL validated with Naga
  • GPUI Component Story Gallery launched against this GPUI revision; Floating Sidebar rounded material clip inspected at runtime
  • local CodeRabbit reviews completed; actionable findings fixed
  • independent local review completed; remaining review comments adjudicated as non-blocking

Platform notes

  • Metal and WGPU compiled locally on macOS
  • DirectX/HLSL implementation updated for parity; local Windows compilation unavailable because the MSVC lib.exe toolchain is not installed on this host

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Added support for rounded content clipping with per-corner radii.
    • Improved clipping behavior for borders and mixed overflow settings.
    • Applied rounded masks consistently across rendered elements, including surfaces, sprites, shadows, paths, and layers.
  • Bug Fixes

    • Corrected hit testing and mask intersections for rounded and transformed content.
    • Improved rendering accuracy when combining clipping regions and visible borders.

Walkthrough

This change extends ContentMask with rounded geometry, updates overflow and hitbox calculations, transports complete masks through GPU renderers, and applies rounded alpha masking across Metal and WGSL rendering paths.

Changes

Rounded Content Masks

Layer / File(s) Summary
Mask geometry and hit testing
crates/gpui/src/window.rs, crates/gpui/src/style.rs, crates/gpui/src/elements/*
ContentMask now supports rounded bounds and corner radii; overflow clipping, scaling, intersections, hitbox containment, and list masking use the updated representation.
GPU mask transport and layout
crates/gpui/src/scene.rs, crates/gpui_macos/src/metal_renderer.rs, crates/gpui_wgpu/src/wgpu_renderer.rs, crates/gpui_windows/src/directx_renderer.rs
Renderer payloads and localization preserve complete masks, path vertices carry mask data, and GPU layout assertions are updated.
Rounded fragment masking
crates/gpui_macos/src/shaders.metal, crates/gpui_wgpu/src/shaders.wgsl
Shader helpers apply rounded content-mask alpha to quads, shadows, blur, paths, retained layers, underlines, sprites, surfaces, and subpixel rendering.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StyleOverflowMask
  participant WindowContentMask
  participant WgpuRenderer
  participant GPUShaders
  StyleOverflowMask->>WindowContentMask: create rounded ContentMask
  WindowContentMask->>WgpuRenderer: localize complete mask
  WgpuRenderer->>GPUShaders: upload mask geometry
  GPUShaders->>GPUShaders: apply rounded mask alpha
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding rounded content mask support.
Description check ✅ Passed The description is directly related to the changeset and accurately summarizes the rounded-mask work.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rounded-content-masks

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/gpui/src/window.rs`:
- Around line 1743-1772: The ContentMask::intersect method currently retains
only one rounded geometry when rounded bounds partially overlap, allowing pixels
outside the descendant clip. Update ContentMask and its intersect logic to
represent and enforce both rounded constraints, or their exact intersection,
while preserving rectangular intersection behavior; add a test covering
partially overlapping ancestor and child rounded masks, including the child’s
excluded corner.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0163f453-daf6-45b5-8a53-e0ae030ac7ae

📥 Commits

Reviewing files that changed from the base of the PR and between 24cfa81 and a89b8f6.

⛔ Files ignored due to path filters (1)
  • crates/gpui_windows/src/shaders.hlsl is excluded by !**/*.hlsl
📒 Files selected for processing (10)
  • crates/gpui/src/elements/list.rs
  • crates/gpui/src/elements/uniform_list.rs
  • crates/gpui/src/scene.rs
  • crates/gpui/src/style.rs
  • crates/gpui/src/window.rs
  • crates/gpui_macos/src/metal_renderer.rs
  • crates/gpui_macos/src/shaders.metal
  • crates/gpui_wgpu/src/shaders.wgsl
  • crates/gpui_wgpu/src/wgpu_renderer.rs
  • crates/gpui_windows/src/directx_renderer.rs

Comment thread crates/gpui/src/window.rs
Comment on lines 1743 to +1772
/// Intersect the content mask with the given content mask.
///
/// Rectangular bounds intersect exactly. When both masks are rounded, the inner clip is kept
/// if its complete rectangular bounds fit inside the ancestor's rounded geometry. Otherwise,
/// the existing ancestor clip (`other`) is retained; content masks currently carry one rounded
/// geometry.
pub fn intersect(&self, other: &Self) -> Self {
let bounds = self.bounds.intersect(&other.bounds);
ContentMask { bounds }
let self_is_rounded = self.corner_radii != Corners::default();
let other_is_rounded = other.corner_radii != Corners::default();
let (rounded_bounds, corner_radii) = if self_is_rounded
&& (!other_is_rounded
|| rounded_rect_contains_bounds(
other.rounded_bounds,
other.corner_radii,
self.bounds,
)) {
(self.rounded_bounds, self.corner_radii)
} else if other_is_rounded {
(other.rounded_bounds, other.corner_radii)
} else {
(bounds, Corners::default())
};

ContentMask {
bounds,
rounded_bounds,
corner_radii,
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Preserve both rounded clips when their bounds partially overlap.

intersect drops the descendant's rounded geometry whenever its full rectangle is not inside the ancestor’s rounded shape. For an ancestor (0,0,100×100,r=20) and child (0,0,50×50,r=10), point (49,1) passes the retained ancestor mask but is outside the child’s top-right corner. Rendering and hit testing therefore leak outside the descendant clip.

Represent both rounded constraints (or their exact intersection) and add a partially overlapping test.

Also applies to: 6290-6305

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/gpui/src/window.rs` around lines 1743 - 1772, The
ContentMask::intersect method currently retains only one rounded geometry when
rounded bounds partially overlap, allowing pixels outside the descendant clip.
Update ContentMask and its intersect logic to represent and enforce both rounded
constraints, or their exact intersection, while preserving rectangular
intersection behavior; add a test covering partially overlapping ancestor and
child rounded masks, including the child’s excluded corner.

@BumpyClock
BumpyClock merged commit 692d54d into main Jul 15, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant