cranpose-render-wgpu 0.1.84

WGPU renderer backend for Cranpose
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
692
//! Scene structures for GPU rendering

use crate::surface_requirements::SurfaceRequirementSet;
use cranpose_core::NodeId;
pub use cranpose_render_common::graph_scene::{ClickAction, HitRegion, Scene};
use cranpose_ui::{TextLayoutOptions, TextStyle};
use cranpose_ui_graphics::{
    ArcGeometry, BlendMode, Brush, Color, ColorFilter, ImageBitmap, ImageSampling, Point, Rect,
    RenderEffect, RoundedCornerShape, Stroke,
};
use std::rc::Rc;

#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct SnapAnchor {
    pub origin: Point,
    pub device_pixel_step: f32,
}

impl SnapAnchor {
    pub(crate) fn rigid(origin: Point) -> Self {
        Self {
            origin,
            device_pixel_step: 1.0,
        }
    }
}

/// A pending solid recolor of one retained replay shape: a bare 16-byte
/// color write into the slot's paint mirror. Planned producer-side, applied
/// by the present-side replay store; crosses the frame boundary inside
/// [`ReplayFrameOps`](crate::frame_packet::ReplayFrameOps).
#[derive(Clone, Copy)]
pub(crate) struct ColorPatch {
    pub slot: u32,
    pub shape_index: u32,
    pub color: [f32; 4],
}

/// A capture request from the identity feed: the shape range this frame's
/// ordinary emission pushed for one capture-marked span. Planned
/// producer-side, honored by the present-side replay store; crosses the
/// frame boundary inside [`ReplayFrameOps`](crate::frame_packet::ReplayFrameOps).
pub(crate) struct PendingFeedCapture {
    pub key: (cranpose_render_common::graph::DrawCommandId, u32),
    pub shape_start: usize,
    pub shape_count: usize,
    pub fingerprint: u64,
    pub capture_clip: Option<Rect>,
    /// Frame ordinal at queue time. The store honors a capture only against
    /// that same frame's scene — its shape indices are meaningless in any
    /// other, and capturing there would retain wrong content under a
    /// confirmed identity.
    pub frame: u64,
}

#[derive(Clone)]
pub(crate) struct DrawShape {
    pub rect: Rect,
    pub local_rect: Rect,
    pub quad: [[f32; 2]; 4],
    pub snap_anchor: Option<SnapAnchor>,
    pub brush: Brush,
    pub shape: Option<RoundedCornerShape>,
    /// `Some` strokes the outline of `local_rect`/`shape` instead of filling
    /// it. `local_rect` and `quad` are already inflated by half the width.
    pub stroke: Option<Stroke>,
    /// `Some` replaces the rect geometry with a circular band, in `local_rect`
    /// units. Mutually exclusive with `stroke`/`shape`.
    pub arc: Option<ArcGeometry>,
    pub z_index: usize,
    pub clip: Option<Rect>,
    pub blend_mode: BlendMode,
    pub motion_context_animated: bool,
}

impl DrawShape {
    /// A shape that needs the analytic stroke or arc path in the shader.
    #[cfg(test)]
    pub fn has_stroke_or_arc(&self) -> bool {
        self.stroke.is_some() || self.arc.is_some()
    }
}

#[derive(Clone)]
pub(crate) struct TextDraw {
    pub node_id: NodeId,
    pub rect: Rect,
    pub snap_anchor: Option<SnapAnchor>,
    pub translated_content_context: bool,
    /// The render view of the node's text — content, styles and link identity,
    /// no link handlers — so the lowered scene payload is `Send`. `Arc` keeps
    /// the clones into shadow draws and retained scenes cheap.
    pub text: std::sync::Arc<cranpose_ui::text::RenderString>,
    pub color: Color,
    pub text_style: TextStyle,
    pub font_size: f32,
    pub scale: f32,
    pub layout_options: TextLayoutOptions,
    pub z_index: usize,
    pub clip: Option<Rect>,
}

/// How many `AnnotatedString` → `RenderString` conversions each thread keeps.
/// Matches the annotated-string hash cache in `render_paths.rs`: a scene has
/// at most a few hundred distinct strings, and entries die with their `Rc`.
const RENDER_STRING_MEMO_CAPACITY: usize = 2048;

thread_local! {
    static RENDER_STRING_MEMO: std::cell::RefCell<
        cranpose_core::collections::map::HashMap<usize, RenderStringMemoEntry>,
    > = std::cell::RefCell::new(cranpose_core::collections::map::HashMap::default());
}

struct RenderStringMemoEntry {
    text: std::rc::Weak<cranpose_ui::text::AnnotatedString>,
    render: std::sync::Arc<cranpose_ui::text::RenderString>,
}

/// Returns the shared [`cranpose_ui::text::RenderString`] for an
/// `AnnotatedString` about to be lowered into a [`TextDraw`], reusing the
/// conversion made on an earlier frame when the same `Rc` lowers again.
///
/// Steady-state scenes lower the same graph strings (and the same pooled
/// draw-scope strings) every frame; without this memo each frame would
/// re-clone every string's content and styles once per emitted draw. Entries
/// are weak-keyed by `Rc` identity — a dead entry can never validate, because
/// the `Weak` pins the allocation, so a pointer match plus a live strong
/// count proves it is the same string.
pub(crate) fn render_string_for(
    text: &Rc<cranpose_ui::text::AnnotatedString>,
) -> std::sync::Arc<cranpose_ui::text::RenderString> {
    RENDER_STRING_MEMO.with(|memo| {
        let mut memo = memo.borrow_mut();
        let key = Rc::as_ptr(text) as usize;
        if let Some(entry) = memo.get(&key) {
            if entry.text.strong_count() > 0 && entry.text.as_ptr() == Rc::as_ptr(text) {
                return std::sync::Arc::clone(&entry.render);
            }
        }

        let render = std::sync::Arc::new(text.render_string());
        if memo.len() >= RENDER_STRING_MEMO_CAPACITY {
            memo.retain(|_, entry| entry.text.strong_count() > 0);
            if memo.len() >= RENDER_STRING_MEMO_CAPACITY {
                memo.clear();
            }
        }
        memo.insert(
            key,
            RenderStringMemoEntry {
                text: Rc::downgrade(text),
                render: std::sync::Arc::clone(&render),
            },
        );
        render
    })
}

#[derive(Clone)]
pub(crate) struct ImageDraw {
    pub rect: Rect,
    pub local_rect: Rect,
    pub quad: [[f32; 2]; 4],
    pub snap_anchor: Option<SnapAnchor>,
    pub image: ImageBitmap,
    pub alpha: f32,
    pub color_filter: Option<ColorFilter>,
    pub sampling: ImageSampling,
    pub z_index: usize,
    pub clip: Option<Rect>,
    pub blend_mode: BlendMode,
    /// Source sub-region in image-pixel coordinates. `None` means full image.
    pub src_rect: Option<Rect>,
    pub motion_context_animated: bool,
}

/// CPU mirror of the shader's per-batch `SimilarityTransform`: rotate by the
/// angle whose (cos, sin) is `rot` and scale by `scale`, about `center`, in
/// device pixels. Freshly converted batches bind [`Self::IDENTITY`] through a
/// buffer shared renderer-wide; replayed batches bind their own value.
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct SimilarityTransform {
    pub(crate) center: [f32; 2],
    pub(crate) rot: [f32; 2],
    pub(crate) scale: f32,
    /// 1.0 makes the storage-mode shader read shape colors from the slot's
    /// retained paint buffer instead of `ShapeData.color`; 0.0 (identity,
    /// every fresh batch) keeps the in-record color.
    paint_select: f32,
    _pad: [f32; 2],
}

impl SimilarityTransform {
    pub(crate) const IDENTITY: Self = Self {
        center: [0.0, 0.0],
        rot: [1.0, 0.0],
        scale: 1.0,
        paint_select: 0.0,
        _pad: [0.0; 2],
    };

    pub(crate) fn new(center: [f32; 2], angle: f32, scale: f32) -> Self {
        Self {
            center,
            rot: [angle.cos(), angle.sin()],
            scale,
            paint_select: 0.0,
            _pad: [0.0; 2],
        }
    }

    /// This transform with the retained paint buffer selected. Staged for
    /// replay draws only — recolor patches rewrite the slot's paint buffer,
    /// so its colors are live where the captured `ShapeData` ones are stale.
    #[cfg(not(target_arch = "wasm32"))]
    pub(crate) fn with_retained_paint(mut self) -> Self {
        self.paint_select = 1.0;
        self
    }
}

/// One replayed shape batch: GPU slots captured from an earlier frame's
/// converted shapes, drawn this frame under `transform`. The heavy per-shape
/// pipeline (emit, walk, convert, upload) never sees these shapes again —
/// the scene carries this one op where thousands of shape ops used to be.
#[derive(Clone, Copy, Debug)]
pub(crate) struct RetainedDraw {
    /// Renderer-side replay slot holding the retained buffers and bind group.
    pub slot: u32,
    pub transform: SimilarityTransform,
    /// Screen-space bounds of the transformed batch, for visibility checks.
    pub bounds: Rect,
    /// First shape drawn within the slot's capture — draws sharing a slot
    /// after a segment split cover disjoint ranges of it.
    pub first_shape: u32,
    /// How many shapes the retained batch draws (6 vertices each).
    pub shape_count: u32,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) enum DrawOpKind {
    Shape(usize),
    Image(usize),
    Text(usize),
    Shadow(usize),
    /// Index into [`CompositorScene::retained_draws`].
    Retained(usize),
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) struct DrawOp {
    pub z_index: usize,
    pub kind: DrawOpKind,
}

/// A shadow that requires GPU blur processing.
#[derive(Clone)]
pub(crate) struct ShadowDraw {
    /// Shapes to render to offscreen target before blur.
    /// Each shape carries its own blend mode (SrcOver for fill, DstOut for cutout).
    pub shapes: Vec<(DrawShape, BlendMode)>,
    /// Texts to render to offscreen target before blur.
    pub texts: Vec<TextDraw>,
    /// Gaussian blur radius in pixels.
    pub blur_radius: f32,
    /// Optional clip rect applied when compositing (inner shadows clip to element bounds).
    pub clip: Option<Rect>,
    /// Z-index for correct draw ordering.
    pub z_index: usize,
}

/// A scene span that should be rendered into an isolated surface.
#[derive(Clone)]
pub(crate) struct EffectLayer {
    pub rect: Rect,
    pub clip: Option<Rect>,
    pub snap_anchor: Option<SnapAnchor>,
    /// Optional effect to apply to the offscreen subtree.
    /// `None` means isolate/composite only (no post-effect shader).
    pub effect: Option<RenderEffect>,
    /// Blend mode used when compositing the offscreen subtree back to the parent.
    pub blend_mode: BlendMode,
    /// Alpha applied when compositing the offscreen subtree back to the parent.
    pub composite_alpha: f32,
    /// Z-index of the first draw item in this effect layer's subtree.
    pub z_start: usize,
    /// Z-index one past the last draw item in this effect layer's subtree.
    pub z_end: usize,
    /// Surface requirements that determine target scale and composite policy.
    pub requirements: SurfaceRequirementSet,
}

/// A backdrop effect applied to already-rendered content behind a node.
#[derive(Clone)]
pub(crate) struct BackdropLayer {
    pub node_id: Option<NodeId>,
    pub rect: Rect,
    pub clip: Option<Rect>,
    pub snap_anchor: Option<SnapAnchor>,
    pub effect: RenderEffect,
    /// Z-index at which this backdrop effect should be applied.
    pub z_index: usize,
}

pub(crate) struct CompositorScene {
    pub shapes: Vec<DrawShape>,
    pub images: Vec<ImageDraw>,
    pub texts: Vec<TextDraw>,
    pub shadow_draws: Vec<ShadowDraw>,
    pub draw_ops: Vec<DrawOp>,
    pub effect_layers: Vec<EffectLayer>,
    pub backdrop_layers: Vec<BackdropLayer>,
    pub retained_draws: Vec<RetainedDraw>,
    pub next_z: usize,
}

/// Last frame's element counts, used to pre-size the next frame's scene Vecs.
/// A fully animated scene re-collects every primitive each frame; growing the
/// Vecs from empty re-copies roughly twice the final payload through the
/// doubling schedule, which is pure overhead once the sizes are known.
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct SceneCapacityHint {
    pub shapes: usize,
    pub images: usize,
    pub texts: usize,
    pub shadow_draws: usize,
    pub draw_ops: usize,
    pub effect_layers: usize,
    pub backdrop_layers: usize,
}

/// How many dropped scenes' buffers each thread keeps for reuse. Scenes are
/// collected fresh every frame (root plus one per composited child layer);
/// for a heavy animated frame the draw vectors are megabytes, big enough
/// that dropping and reallocating them round-trips through mmap each frame.
const SCENE_BUFFER_POOL_LIMIT: usize = 4;

thread_local! {
    static SCENE_BUFFER_POOL: std::cell::RefCell<Vec<SceneBuffers>> =
        const { std::cell::RefCell::new(Vec::new()) };
}

/// The emptied-but-still-allocated vectors of a dropped [`CompositorScene`].
struct SceneBuffers {
    shapes: Vec<DrawShape>,
    images: Vec<ImageDraw>,
    texts: Vec<TextDraw>,
    shadow_draws: Vec<ShadowDraw>,
    draw_ops: Vec<DrawOp>,
    effect_layers: Vec<EffectLayer>,
    backdrop_layers: Vec<BackdropLayer>,
}

impl Drop for CompositorScene {
    fn drop(&mut self) {
        SCENE_BUFFER_POOL.with(|pool| {
            let mut pool = pool.borrow_mut();
            if pool.len() >= SCENE_BUFFER_POOL_LIMIT {
                return;
            }
            self.clear();
            pool.push(SceneBuffers {
                shapes: std::mem::take(&mut self.shapes),
                images: std::mem::take(&mut self.images),
                texts: std::mem::take(&mut self.texts),
                shadow_draws: std::mem::take(&mut self.shadow_draws),
                draw_ops: std::mem::take(&mut self.draw_ops),
                effect_layers: std::mem::take(&mut self.effect_layers),
                backdrop_layers: std::mem::take(&mut self.backdrop_layers),
            });
        });
    }
}

impl CompositorScene {
    pub fn new() -> Self {
        Self::with_capacity(SceneCapacityHint::default())
    }

    pub fn with_capacity(hint: SceneCapacityHint) -> Self {
        if let Some(buffers) = SCENE_BUFFER_POOL.with(|pool| pool.borrow_mut().pop()) {
            return Self {
                shapes: buffers.shapes,
                images: buffers.images,
                texts: buffers.texts,
                shadow_draws: buffers.shadow_draws,
                draw_ops: buffers.draw_ops,
                effect_layers: buffers.effect_layers,
                backdrop_layers: buffers.backdrop_layers,
                retained_draws: Vec::new(),
                next_z: 0,
            };
        }
        Self {
            shapes: Vec::with_capacity(hint.shapes),
            images: Vec::with_capacity(hint.images),
            texts: Vec::with_capacity(hint.texts),
            shadow_draws: Vec::with_capacity(hint.shadow_draws),
            draw_ops: Vec::with_capacity(hint.draw_ops),
            effect_layers: Vec::with_capacity(hint.effect_layers),
            backdrop_layers: Vec::with_capacity(hint.backdrop_layers),
            retained_draws: Vec::new(),
            next_z: 0,
        }
    }

    pub fn capacity_hint(&self) -> SceneCapacityHint {
        SceneCapacityHint {
            shapes: self.shapes.len(),
            images: self.images.len(),
            texts: self.texts.len(),
            shadow_draws: self.shadow_draws.len(),
            draw_ops: self.draw_ops.len(),
            effect_layers: self.effect_layers.len(),
            backdrop_layers: self.backdrop_layers.len(),
        }
    }

    pub fn clear(&mut self) {
        self.shapes.clear();
        self.images.clear();
        self.texts.clear();
        self.shadow_draws.clear();
        self.draw_ops.clear();
        self.effect_layers.clear();
        self.backdrop_layers.clear();
        self.retained_draws.clear();
        self.next_z = 0;
    }

    /// Pushes one retained-batch draw at the next z position and returns it.
    pub fn push_retained_draw(&mut self, draw: RetainedDraw) {
        if std::env::var_os("CRANPOSE_RETAINED_DIAG").is_some() {
            eprintln!(
                "[retained] slot={} first={} count={} center=({:.6},{:.6}) rot=({:.9},{:.9}) scale={:.9} bounds=({:.4},{:.4},{:.4},{:.4})",
                draw.slot,
                draw.first_shape,
                draw.shape_count,
                draw.transform.center[0],
                draw.transform.center[1],
                draw.transform.rot[0],
                draw.transform.rot[1],
                draw.transform.scale,
                draw.bounds.x,
                draw.bounds.y,
                draw.bounds.width,
                draw.bounds.height,
            );
        }
        let z_index = self.next_z;
        self.next_z += 1;
        self.retained_draws.push(draw);
        self.draw_ops.push(DrawOp {
            z_index,
            kind: DrawOpKind::Retained(self.retained_draws.len() - 1),
        });
    }

    pub fn push_shape(
        &mut self,
        rect: Rect,
        brush: Brush,
        shape: Option<RoundedCornerShape>,
        clip: Option<Rect>,
        blend_mode: BlendMode,
    ) {
        self.push_shape_with_geometry(
            rect,
            rect,
            rect_to_quad(rect),
            brush,
            shape,
            clip,
            blend_mode,
            false,
        );
    }

    #[allow(clippy::too_many_arguments)]
    pub fn push_shape_with_geometry(
        &mut self,
        rect: Rect,
        local_rect: Rect,
        quad: [[f32; 2]; 4],
        brush: Brush,
        shape: Option<RoundedCornerShape>,
        clip: Option<Rect>,
        blend_mode: BlendMode,
        motion_context_animated: bool,
    ) {
        self.push_shape_with_stroke_and_arc(
            rect,
            local_rect,
            quad,
            brush,
            shape,
            None,
            None,
            clip,
            blend_mode,
            motion_context_animated,
        );
    }

    #[allow(clippy::too_many_arguments)]
    pub fn push_shape_with_stroke_and_arc(
        &mut self,
        rect: Rect,
        local_rect: Rect,
        quad: [[f32; 2]; 4],
        brush: Brush,
        shape: Option<RoundedCornerShape>,
        stroke: Option<Stroke>,
        arc: Option<ArcGeometry>,
        clip: Option<Rect>,
        blend_mode: BlendMode,
        motion_context_animated: bool,
    ) {
        let z_index = self.next_z;
        self.next_z += 1;
        let index = self.shapes.len();
        self.shapes.push(DrawShape {
            rect,
            local_rect,
            quad,
            snap_anchor: None,
            brush,
            shape,
            stroke,
            arc,
            z_index,
            clip,
            blend_mode,
            motion_context_animated,
        });
        self.draw_ops.push(DrawOp {
            z_index,
            kind: DrawOpKind::Shape(index),
        });
    }

    #[allow(clippy::too_many_arguments)]
    pub fn push_image_with_geometry(
        &mut self,
        rect: Rect,
        local_rect: Rect,
        quad: [[f32; 2]; 4],
        image: ImageBitmap,
        alpha: f32,
        color_filter: Option<ColorFilter>,
        sampling: ImageSampling,
        clip: Option<Rect>,
        src_rect: Option<Rect>,
        blend_mode: BlendMode,
        motion_context_animated: bool,
    ) {
        let z_index = self.next_z;
        self.next_z += 1;
        let index = self.images.len();
        self.images.push(ImageDraw {
            rect,
            local_rect,
            quad,
            snap_anchor: None,
            image,
            alpha: alpha.clamp(0.0, 1.0),
            color_filter,
            sampling,
            z_index,
            clip,
            blend_mode,
            src_rect,
            motion_context_animated,
        });
        self.draw_ops.push(DrawOp {
            z_index,
            kind: DrawOpKind::Image(index),
        });
    }

    #[allow(clippy::too_many_arguments)]
    pub fn push_text(
        &mut self,
        node_id: NodeId,
        rect: Rect,
        text: Rc<cranpose_ui::text::AnnotatedString>,
        color: Color,
        text_style: TextStyle,
        font_size: f32,
        scale: f32,
        layout_options: TextLayoutOptions,
        clip: Option<Rect>,
    ) {
        let z_index = self.next_z;
        self.next_z += 1;
        let index = self.texts.len();
        self.texts.push(TextDraw {
            node_id,
            rect,
            snap_anchor: None,
            translated_content_context: false,
            text: render_string_for(&text),
            color,
            text_style,
            font_size,
            scale,
            layout_options,
            z_index,
            clip,
        });
        self.draw_ops.push(DrawOp {
            z_index,
            kind: DrawOpKind::Text(index),
        });
    }

    pub fn push_shadow_draw(&mut self, mut draw: ShadowDraw) {
        let z_index = self.next_z;
        self.next_z += 1;
        let index = self.shadow_draws.len();
        draw.z_index = z_index;
        self.shadow_draws.push(draw);
        self.draw_ops.push(DrawOp {
            z_index,
            kind: DrawOpKind::Shadow(index),
        });
    }

    #[allow(clippy::too_many_arguments)]
    pub fn push_effect_layer_with_requirements(
        &mut self,
        rect: Rect,
        clip: Option<Rect>,
        effect: Option<RenderEffect>,
        blend_mode: BlendMode,
        composite_alpha: f32,
        z_start: usize,
        z_end: usize,
        requirements: SurfaceRequirementSet,
    ) {
        self.effect_layers.push(EffectLayer {
            rect,
            clip,
            snap_anchor: None,
            effect,
            blend_mode,
            composite_alpha,
            z_start,
            z_end,
            requirements,
        });
    }

    #[allow(clippy::too_many_arguments)]
    pub fn push_effect_layer(
        &mut self,
        rect: Rect,
        clip: Option<Rect>,
        effect: Option<RenderEffect>,
        blend_mode: BlendMode,
        composite_alpha: f32,
        z_start: usize,
        z_end: usize,
    ) {
        let requirements = effect
            .as_ref()
            .map(|_| {
                SurfaceRequirementSet::default()
                    .with(crate::surface_requirements::SurfaceRequirement::RenderEffect)
            })
            .unwrap_or_default();
        self.push_effect_layer_with_requirements(
            rect,
            clip,
            effect,
            blend_mode,
            composite_alpha,
            z_start,
            z_end,
            requirements,
        );
    }
}

impl Default for CompositorScene {
    fn default() -> Self {
        Self::new()
    }
}

use crate::rect_to_quad;