gpui-fast-linux 0.1.1

gpui_linux: GPUI with gpui-fast rendering and layout optimizations
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
// Modified by Longbridge for gpui-fast.
//! Window composition on X11 (zed-industries/zed#62379).
//!
//! X11 draws every GPUI composition surface into the window itself: a child
//! window with the same ARGB visual as its parent replaces the parent's pixels
//! instead of blending over them, so GPUI overlays cannot be child windows.
//! Native surfaces are child windows, and the GPUI content stacked above one
//! is cut out of its shape (the SHAPE extension) so the window's pixels and
//! input show through.

use std::{
    any::Any,
    cell::RefCell,
    num::NonZeroU32,
    rc::{Rc, Weak},
};

use anyhow::{Context as _, anyhow};
use collections::FxHashMap;
use gpui::{
    Bounds, ComposedScene, CompositionSurfaceId, ContentMask, DevicePixels,
    PlatformCompositionSurface, PlatformCompositionSurfaceContent, PlatformSurfaceAttachment,
    PlatformWindow, Point, ScaledPixels, Scene,
};
use gpui_util::ResultExt as _;
use raw_window_handle as rwh;
use x11rb::{
    connection::{Connection as _, RequestConnection as _},
    protocol::{
        shape::{self, ConnectionExt as _},
        xinput::{self, ConnectionExt as _},
        xproto::{self, ConnectionExt as _},
    },
    xcb_ffi::XCBConnection,
};

use crate::linux::{X11Window, XINPUT_ALL_DEVICE_GROUPS, check_reply, xcb_flush};

/// An X11 window's composition state, held by `X11WindowState`.
pub(crate) struct Composition(Rc<RefCell<X11Composition>>);

impl Composition {
    pub(crate) fn new(
        xcb: &Rc<XCBConnection>,
        x_window: xproto::Window,
        depth: u8,
        visual_id: u32,
    ) -> Self {
        Self(Rc::new(RefCell::new(X11Composition {
            xcb: xcb.clone(),
            x_window,
            depth,
            visual_id,
            base_surface: None,
            native_surfaces: Vec::new(),
            order: Vec::new(),
            occluders: FxHashMap::default(),
        })))
    }

    /// Destroys the native surfaces' child windows; called when the window
    /// is dropped, before its renderer and X window are destroyed.
    pub(crate) fn destroy(&self) {
        self.0.borrow_mut().destroy();
    }
}

struct X11Composition {
    xcb: Rc<XCBConnection>,
    x_window: xproto::Window,
    depth: u8,
    visual_id: u32,
    base_surface: Option<CompositionSurfaceId>,
    native_surfaces: Vec<Weak<RefCell<X11NativeSurfaceState>>>,
    order: Vec<PlatformCompositionSurface>,
    occluders: FxHashMap<CompositionSurfaceId, Vec<Bounds<DevicePixels>>>,
}

struct X11NativeSurfaceState {
    xcb: Rc<XCBConnection>,
    x_window: xproto::Window,
    parent_window: xproto::Window,
    bounds: Bounds<DevicePixels>,
    parent_origin: Point<DevicePixels>,
    visible: bool,
    mapped: bool,
    /// Window-coordinate rectangles of GPUI content stacked above this surface.
    occluders: Vec<Bounds<DevicePixels>>,
    applied_shape: Option<(Bounds<DevicePixels>, Vec<Bounds<DevicePixels>>)>,
    destroyed: bool,
}

impl X11NativeSurfaceState {
    fn apply(&mut self) -> anyhow::Result<()> {
        if self.destroyed {
            return Ok(());
        }
        let origin = self.bounds.origin - self.parent_origin;
        check_reply(
            || "X11 ConfigureWindow for a native surface failed.",
            self.xcb.configure_window(
                self.x_window,
                &xproto::ConfigureWindowAux::new()
                    .x(origin.x.0)
                    .y(origin.y.0)
                    .width(self.bounds.size.width.0.max(1) as u32)
                    .height(self.bounds.size.height.0.max(1) as u32),
            ),
        )?;
        self.apply_shape()?;
        let should_map = self.visible && !self.bounds.is_empty();
        if should_map != self.mapped {
            if should_map {
                check_reply(
                    || "X11 MapWindow for a native surface failed.",
                    self.xcb.map_window(self.x_window),
                )?;
            } else {
                check_reply(
                    || "X11 UnmapWindow for a native surface failed.",
                    self.xcb.unmap_window(self.x_window),
                )?;
            }
            self.mapped = should_map;
        }
        xcb_flush(&self.xcb);
        Ok(())
    }

    fn apply_shape(&mut self) -> anyhow::Result<()> {
        let local_bounds = Bounds::new(Point::default(), self.bounds.size);
        let cutouts = self
            .occluders
            .iter()
            .map(|occluder| {
                let occluder = Bounds::new(occluder.origin - self.bounds.origin, occluder.size);
                occluder.intersect(&local_bounds)
            })
            .filter(|occluder| !occluder.is_empty())
            .collect::<Vec<_>>();
        let shape = (self.bounds, cutouts);
        if self.applied_shape.as_ref() == Some(&shape) {
            return Ok(());
        }
        let (_, cutouts) = &shape;
        if cutouts.is_empty() {
            check_reply(
                || "X11 ShapeMask reset for a native surface failed.",
                self.xcb.shape_mask(
                    shape::SO::SET,
                    shape::SK::BOUNDING,
                    self.x_window,
                    0,
                    0,
                    x11rb::NONE,
                ),
            )?;
        } else {
            check_reply(
                || "X11 ShapeRectangles for a native surface failed.",
                self.xcb.shape_rectangles(
                    shape::SO::SET,
                    shape::SK::BOUNDING,
                    xproto::ClipOrdering::UNSORTED,
                    self.x_window,
                    0,
                    0,
                    &[x11_rectangle(local_bounds)],
                ),
            )?;
            check_reply(
                || "X11 ShapeRectangles cutout for a native surface failed.",
                self.xcb.shape_rectangles(
                    shape::SO::SUBTRACT,
                    shape::SK::BOUNDING,
                    xproto::ClipOrdering::UNSORTED,
                    self.x_window,
                    0,
                    0,
                    &cutouts
                        .iter()
                        .copied()
                        .map(x11_rectangle)
                        .collect::<Vec<_>>(),
                ),
            )?;
        }
        self.applied_shape = Some(shape);
        Ok(())
    }

    fn destroy(&mut self) {
        if std::mem::replace(&mut self.destroyed, true) {
            return;
        }
        check_reply(
            || "X11 DestroyWindow for a native surface failed.",
            self.xcb.destroy_window(self.x_window),
        )
        .log_err();
        xcb_flush(&self.xcb);
    }
}

fn x11_rectangle(bounds: Bounds<DevicePixels>) -> xproto::Rectangle {
    xproto::Rectangle {
        x: bounds.origin.x.0.clamp(i16::MIN as i32, i16::MAX as i32) as i16,
        y: bounds.origin.y.0.clamp(i16::MIN as i32, i16::MAX as i32) as i16,
        width: bounds.size.width.0.clamp(0, u16::MAX as i32) as u16,
        height: bounds.size.height.0.clamp(0, u16::MAX as i32) as u16,
    }
}

/// Past this many rectangles an occluding surface is cut out by its bounding
/// box, which keeps shape requests small for text-heavy overlays.
const MAX_OCCLUDER_RECTANGLES: usize = 256;

/// Returns the device-pixel rectangles covered by a scene's primitives.
///
/// Shadows are left out: a cutout can only show the window's pixels, not blend
/// a translucent shadow over the native content, so cutting out a shadow would
/// replace native content with GPUI's background around every overlay.
fn scene_occluders(scene: &Scene) -> Vec<Bounds<DevicePixels>> {
    fn clipped(
        bounds: Bounds<ScaledPixels>,
        content_mask: &ContentMask<ScaledPixels>,
    ) -> Bounds<ScaledPixels> {
        bounds.intersect(&content_mask.bounds)
    }

    let mut rectangles = Vec::new();
    rectangles.extend(
        scene
            .quads
            .iter()
            .map(|quad| clipped(quad.bounds, &quad.content_mask)),
    );
    rectangles.extend(
        scene
            .paths
            .iter()
            .map(|path| clipped(path.bounds, &path.content_mask)),
    );
    rectangles.extend(
        scene
            .underlines
            .iter()
            .map(|underline| clipped(underline.bounds, &underline.content_mask)),
    );
    rectangles.extend(
        scene
            .monochrome_sprites
            .iter()
            .map(|sprite| clipped(sprite.bounds, &sprite.content_mask)),
    );
    rectangles.extend(
        scene
            .subpixel_sprites
            .iter()
            .map(|sprite| clipped(sprite.bounds, &sprite.content_mask)),
    );
    rectangles.extend(
        scene
            .polychrome_sprites
            .iter()
            .map(|sprite| clipped(sprite.bounds, &sprite.content_mask)),
    );
    rectangles.extend(
        scene
            .surfaces
            .iter()
            .map(|surface| clipped(surface.bounds, &surface.content_mask)),
    );

    let mut rectangles = rectangles
        .into_iter()
        .map(|bounds| {
            let origin = bounds
                .origin
                .map(|value| DevicePixels(value.0.floor() as i32));
            let corner = bounds
                .bottom_right()
                .map(|value| DevicePixels(value.0.ceil() as i32));
            Bounds::from_corners(origin, corner)
        })
        .filter(|bounds| !bounds.is_empty())
        .collect::<Vec<_>>();

    // Content usually sits on a background quad, so most rectangles are
    // covered by a larger one.
    rectangles.sort_by_key(|bounds| std::cmp::Reverse(bounds.size.width.0 * bounds.size.height.0));
    let mut kept: Vec<Bounds<DevicePixels>> = Vec::new();
    for rectangle in rectangles {
        let covered = kept.iter().any(|kept| {
            kept.origin.x <= rectangle.origin.x
                && kept.origin.y <= rectangle.origin.y
                && kept.bottom_right().x >= rectangle.bottom_right().x
                && kept.bottom_right().y >= rectangle.bottom_right().y
        });
        if !covered {
            kept.push(rectangle);
        }
    }
    if kept.len() > MAX_OCCLUDER_RECTANGLES {
        let union = kept
            .iter()
            .copied()
            .reduce(|union, bounds| union.union(&bounds))
            .into_iter()
            .collect();
        return union;
    }
    kept
}

/// A child window slot for content produced outside GPUI's renderer. Its
/// `platform_handle` is a `raw_window_handle::RawWindowHandle::Xcb`, which the
/// producer must stop presenting to before this attachment is dropped.
struct X11NativeSurface {
    state: Rc<RefCell<X11NativeSurfaceState>>,
    visual_id: u32,
}

impl PlatformSurfaceAttachment for X11NativeSurface {
    fn set_bounds(&self, bounds: Bounds<DevicePixels>) -> anyhow::Result<()> {
        let mut state = self.state.borrow_mut();
        state.bounds = bounds;
        state.apply()
    }

    fn bounds(&self) -> Bounds<DevicePixels> {
        self.state.borrow().bounds
    }

    fn set_parent_origin(&self, origin: Point<DevicePixels>) -> anyhow::Result<()> {
        let mut state = self.state.borrow_mut();
        state.parent_origin = origin;
        state.apply()
    }

    fn set_visible(&self, visible: bool) -> anyhow::Result<()> {
        let mut state = self.state.borrow_mut();
        state.visible = visible;
        state.apply()
    }

    fn platform_handle(&self) -> anyhow::Result<Box<dyn Any>> {
        let window = NonZeroU32::new(self.state.borrow().x_window)
            .context("native surface has no X11 window")?;
        let mut handle = rwh::XcbWindowHandle::new(window);
        handle.visual_id = NonZeroU32::new(self.visual_id);
        Ok(Box::new(rwh::RawWindowHandle::Xcb(handle)))
    }
}

impl Drop for X11NativeSurface {
    fn drop(&mut self) {
        self.state.borrow_mut().destroy();
    }
}

impl X11Composition {
    fn create_native_surface(&mut self) -> anyhow::Result<Rc<RefCell<X11NativeSurfaceState>>> {
        let window = self.xcb.generate_id()?;
        check_reply(
            || "X11 CreateWindow for a native surface failed.",
            self.xcb.create_window(
                self.depth,
                window,
                self.x_window,
                0,
                0,
                1,
                1,
                0,
                xproto::WindowClass::INPUT_OUTPUT,
                self.visual_id,
                &xproto::CreateWindowAux::new(),
            ),
        )?;
        // Selecting pointer events here keeps them from propagating to the
        // GPUI window, which would otherwise treat them as its own input.
        let selected = check_reply(
            || "X11 XiSelectEvents for a native surface failed.",
            self.xcb.xinput_xi_select_events(
                window,
                &[xinput::EventMask {
                    deviceid: XINPUT_ALL_DEVICE_GROUPS,
                    mask: vec![
                        xinput::XIEventMask::MOTION
                            | xinput::XIEventMask::BUTTON_PRESS
                            | xinput::XIEventMask::BUTTON_RELEASE,
                    ],
                }],
            ),
        );
        if let Err(error) = selected {
            check_reply(
                || "X11 DestroyWindow for a native surface failed.",
                self.xcb.destroy_window(window),
            )
            .log_err();
            return Err(error);
        }
        xcb_flush(&self.xcb);
        let state = Rc::new(RefCell::new(X11NativeSurfaceState {
            xcb: self.xcb.clone(),
            x_window: window,
            parent_window: self.x_window,
            bounds: Bounds::default(),
            parent_origin: Point::default(),
            visible: true,
            mapped: false,
            occluders: Vec::new(),
            applied_shape: None,
            destroyed: false,
        }));
        self.native_surfaces.push(Rc::downgrade(&state));
        Ok(state)
    }

    fn native_surface(
        &mut self,
        attachment: &dyn PlatformSurfaceAttachment,
    ) -> anyhow::Result<Rc<RefCell<X11NativeSurfaceState>>> {
        let handle = attachment
            .platform_handle()?
            .downcast::<rwh::RawWindowHandle>()
            .map_err(|_| anyhow!("native surface is not backed by an X11 window"))?;
        let rwh::RawWindowHandle::Xcb(handle) = *handle else {
            anyhow::bail!("native surface is not backed by an X11 window");
        };
        self.native_surfaces
            .retain(|surface| surface.strong_count() > 0);
        self.native_surfaces
            .iter()
            .filter_map(Weak::upgrade)
            .find(|surface| surface.borrow().x_window == handle.window.get())
            .context("native surface belongs to another window")
    }

    fn apply_order(&mut self) -> anyhow::Result<()> {
        let base = self
            .base_surface
            .context("composition has no GPUI base surface")?;
        let order = self.order.clone();
        let mut native_states = FxHashMap::default();
        for surface in &order {
            if let PlatformCompositionSurfaceContent::Native(attachment)
            | PlatformCompositionSurfaceContent::ExternalGpu(attachment) = &surface.content
            {
                native_states.insert(surface.id, self.native_surface(attachment.as_ref())?);
            }
        }

        let mut origins = FxHashMap::default();
        for surface in &order {
            origins.insert(surface.id, surface.window_origin);
        }
        origins.insert(base, Point::default());

        for (index, surface) in order.iter().enumerate() {
            let Some(state) = native_states.get(&surface.id) else {
                continue;
            };
            // A native child can only nest inside another native child; GPUI
            // surfaces are all drawn into the window itself.
            let (parent_window, parent_origin) = surface
                .parent
                .and_then(|parent| {
                    native_states.get(&parent).map(|parent_state| {
                        (
                            parent_state.borrow().x_window,
                            origins.get(&parent).copied().unwrap_or_default(),
                        )
                    })
                })
                .unwrap_or((self.x_window, Point::default()));

            let occluders = order[index + 1..]
                .iter()
                .filter(|above| above.id != base)
                .filter_map(|above| self.occluders.get(&above.id))
                .flatten()
                .copied()
                .collect::<Vec<_>>();

            let mut state = state.borrow_mut();
            if state.parent_window != parent_window {
                check_reply(
                    || "X11 ReparentWindow for a native surface failed.",
                    self.xcb
                        .reparent_window(state.x_window, parent_window, 0, 0),
                )?;
                state.parent_window = parent_window;
                // Reparenting unmaps a mapped window.
                state.mapped = false;
            }
            state.parent_origin = parent_origin;
            if let Some(bounds) = surface.window_bounds {
                state.bounds = bounds;
            }
            state.occluders = occluders;
            // Raising each surface in bottom-to-top order leaves siblings
            // stacked in composition order.
            check_reply(
                || "X11 ConfigureWindow stacking for a native surface failed.",
                self.xcb.configure_window(
                    state.x_window,
                    &xproto::ConfigureWindowAux::new().stack_mode(xproto::StackMode::ABOVE),
                ),
            )?;
            state.apply()?;
        }
        Ok(())
    }

    fn destroy(&mut self) {
        for surface in self
            .native_surfaces
            .drain(..)
            .filter_map(|surface| surface.upgrade())
        {
            surface.borrow_mut().destroy();
        }
        self.order.clear();
        self.occluders.clear();
        self.base_surface = None;
    }
}

/// `PlatformWindow::draw_composed`: draws every GPUI surface into the window
/// in composition order, so later surfaces paint over earlier ones as they
/// would when stacked, and cuts the overlays' content out of the native
/// surfaces below them.
pub(crate) fn draw_composed(window: &X11Window, scene: ComposedScene<'_>) {
    let composition = window.0.state.borrow().fast_composition.0.clone();
    let mut composition = composition.borrow_mut();
    let Some(base_surface) = composition.base_surface else {
        drop(composition);
        window.draw(scene.scene());
        return;
    };

    let track_occluders = composition
        .native_surfaces
        .iter()
        .any(|surface| surface.strong_count() > 0);
    let mut window_scene = Scene::default();
    let mut occluders = FxHashMap::default();
    for layer in scene.layers() {
        let mut layer_scene = Scene::default();
        for range in &layer.ranges {
            let replayed = window_scene
                .replay_balanced(range.clone(), scene.scene())
                .and_then(|()| {
                    if track_occluders && layer.surface != base_surface {
                        layer_scene.replay_balanced(range.clone(), scene.scene())
                    } else {
                        Ok(())
                    }
                });
            if let Err(error) = replayed {
                log::error!("replaying X11 composition scene: {error:#}");
                return;
            }
        }
        if track_occluders && layer.surface != base_surface {
            layer_scene.finish();
            occluders.insert(layer.surface, scene_occluders(&layer_scene));
        }
    }
    window_scene.finish();

    if occluders != composition.occluders {
        composition.occluders = occluders;
        composition.apply_order().log_err();
    }
    drop(composition);
    window.draw(&window_scene);
}

/// `PlatformWindow::enable_window_composition`: composition needs the SHAPE
/// extension to cut overlays out of native surfaces.
pub(crate) fn enable_window_composition(window: &X11Window) -> anyhow::Result<()> {
    let shape = window
        .0
        .xcb
        .extension_information(shape::X11_EXTENSION_NAME)
        .context("X11 QueryExtension for SHAPE failed")?;
    anyhow::ensure!(
        shape.is_some(),
        "the X11 server does not support the SHAPE extension"
    );
    Ok(())
}

/// `PlatformWindow::create_native_surface`: a child window of the window.
pub(crate) fn create_native_surface(
    window: &X11Window,
) -> anyhow::Result<Rc<dyn PlatformSurfaceAttachment>> {
    enable_window_composition(window)?;
    let composition = window.0.state.borrow().fast_composition.0.clone();
    let mut composition = composition.borrow_mut();
    let state = composition.create_native_surface()?;
    Ok(Rc::new(X11NativeSurface {
        state,
        visual_id: composition.visual_id,
    }))
}

/// `PlatformWindow::set_composition_order`: reparents, restacks and reshapes
/// the native surfaces in `surfaces`' order.
pub(crate) fn set_composition_order(
    window: &X11Window,
    surfaces: &[PlatformCompositionSurface],
) -> anyhow::Result<()> {
    let base_surface = surfaces
        .iter()
        .find_map(|surface| match surface.content {
            PlatformCompositionSurfaceContent::Gpui => Some(surface.id),
            PlatformCompositionSurfaceContent::Native(_)
            | PlatformCompositionSurfaceContent::ExternalGpu(_) => None,
        })
        .context("composition has no GPUI base surface")?;
    let composition = window.0.state.borrow().fast_composition.0.clone();
    let mut composition = composition.borrow_mut();
    composition.base_surface = Some(base_surface);
    composition.order = surfaces.to_vec();
    composition
        .occluders
        .retain(|id, _| surfaces.iter().any(|surface| surface.id == *id));
    composition.apply_order()
}

#[cfg(test)]
mod tests {
    use super::scene_occluders;
    use gpui::{Bounds, ContentMask, DevicePixels, Quad, ScaledPixels, Scene, Shadow, point, size};

    fn quad(bounds: Bounds<ScaledPixels>, mask: Bounds<ScaledPixels>) -> Quad {
        Quad {
            bounds,
            content_mask: ContentMask { bounds: mask },
            ..Default::default()
        }
    }

    fn scaled(x: f32, y: f32, width: f32, height: f32) -> Bounds<ScaledPixels> {
        Bounds::new(
            point(ScaledPixels(x), ScaledPixels(y)),
            size(ScaledPixels(width), ScaledPixels(height)),
        )
    }

    fn device(x: i32, y: i32, width: i32, height: i32) -> Bounds<DevicePixels> {
        Bounds::new(
            point(DevicePixels(x), DevicePixels(y)),
            size(DevicePixels(width), DevicePixels(height)),
        )
    }

    #[test]
    fn scene_occluders_skip_shadows_and_covered_rectangles() {
        let everything = scaled(0., 0., 1000., 1000.);
        let mut scene = Scene::default();
        scene.insert_primitive(Shadow {
            order: 0,
            blur_radius: ScaledPixels(24.),
            bounds: scaled(500., 500., 100., 100.),
            corner_radii: Default::default(),
            content_mask: ContentMask { bounds: everything },
            color: Default::default(),
            element_bounds: scaled(500., 500., 100., 100.),
            element_corner_radii: Default::default(),
            inset: 0,
            pad: 0,
        });
        scene.insert_primitive(quad(scaled(10., 10., 100., 50.), everything));
        scene.insert_primitive(quad(scaled(20.5, 20.5, 10., 10.), everything));
        scene.insert_primitive(quad(
            scaled(200., 0., 100., 100.),
            scaled(250., 0., 20., 40.),
        ));
        scene.finish();

        let mut occluders = scene_occluders(&scene);
        occluders.sort_by_key(|bounds| bounds.origin.x);
        assert_eq!(occluders, [device(10, 10, 100, 50), device(250, 0, 20, 40)]);
    }
}