Skip to main content

valo_dl/
list.rs

1use std::sync::atomic::{AtomicU64, Ordering};
2use std::sync::Arc;
3
4use valo_geometry::{Color, FillRule, Matrix, Path, Rect};
5
6use crate::{Bounds, Image, ImageFilter, Paint, Sampling};
7
8/// `Backdrop` filters the sampled scene before a save layer's children paint.
9///
10/// Compose image filters to control the order of backdrop effects. The layer's
11/// paint separately controls how the filtered backdrop and children composite.
12#[derive(Clone, Debug, PartialEq)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize))]
14pub struct Backdrop {
15    /// `filter` transforms the sampled scene in local coordinates.
16    pub filter: ImageFilter,
17    /// `shared_key` lets tiles reuse the first matching filtered snapshot,
18    /// which sees the scene as of the first tile. Use one key only for tiles
19    /// over the same background with the same filter.
20    pub shared_key: Option<u64>,
21}
22
23impl Backdrop {
24    /// `new` filters the backdrop with `filter` before foreground content paints.
25    pub fn new(filter: ImageFilter) -> Self {
26        Self {
27            filter,
28            shared_key: None,
29        }
30    }
31
32    /// `blur` creates an isotropic Gaussian backdrop blur in local units.
33    pub fn blur(sigma: f32) -> Self {
34        Self::new(ImageFilter::blur(sigma, sigma))
35    }
36
37    /// `shared` marks this backdrop as one tile of a keyed group.
38    pub fn shared(mut self, key: u64) -> Self {
39        self.shared_key = Some(key);
40        self
41    }
42}
43
44/// `ClipOp` controls how a clip shape changes the current clip.
45#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
46#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
47pub enum ClipOp {
48    /// `Intersect` retains pixels inside the clip shape.
49    #[default]
50    Intersect,
51    /// `Difference` retains pixels outside the clip shape.
52    Difference,
53}
54
55/// `Op` is one recorded display-list command.
56///
57/// Draw and clip operations include the bounds and ordering metadata resolved
58/// by [`crate::DisplayListBuilder`] at record time. A draw's `bounds` is where
59/// it may show, list-root space, cropped by the clip: the rect replay culls it
60/// by, [`Rect::EVERYTHING`] for a draw that fills a list with no clip.
61#[derive(Clone, Debug, PartialEq)]
62#[cfg_attr(feature = "serde", derive(serde::Serialize))]
63pub enum Op {
64    Save,
65    /// Open an offscreen layer scope, closed by the matching `Restore`. The
66    /// recorder works out every fact about the layer once and records it
67    /// here, the ones its children decide backpatched when the scope closes —
68    /// still record time; replay reads them, never works them out again.
69    SaveLayer {
70        paint: Paint,
71        /// The local-space crop the layer was opened with, as recorded: what
72        /// replaying the op passes again ([`crate::DisplayListBuilder::replay`]).
73        bounds_hint: Option<Rect>,
74        /// Set = this layer is a MASK: its composite converts
75        /// the texture to COVERAGE (luminance or alpha) and multiplies the
76        /// enclosing layer by it (DstIn over the whole enclosing extent, so
77        /// content outside the mask's ink disappears).
78        mask_composite: Option<MaskKind>,
79        /// The layer's content: the union of its children's bounds,
80        /// list-root space, cropped by the bounds hint and by the clips made
81        /// inside the layer but not by the clips around it, which a filter
82        /// on the layer reads past (Flutter's layer bounds). Never padded for
83        /// the layer's own filter, nor flooded: the renderer sizes the
84        /// layer's texture from it, the clip and the paint. Unbounded when a
85        /// child fills a clip the layer does not crop (Flutter's
86        /// `content_is_unbounded`).
87        scope_bounds: Bounds,
88        /// The clip where the layer opens, cropped by the bounds hint,
89        /// list-root space: unbounded when there is neither, empty when the
90        /// hint misses the clip. Bounds the layer's texture together with
91        /// the target.
92        clip_bounds: Bounds,
93        /// Slot count when the scope opened. Children continue the SAME
94        /// depth line as the parent (Impeller's global numbering,
95        /// `Canvas::current_depth_`); the layer's own pass rebases by
96        /// subtracting it. Impeller records one span (`total_content_depth`)
97        /// and counts during replay; valo's replay never counts, so it
98        /// records both ends of the span instead.
99        base_slot: u32,
100        /// The composite draw's slot — next on the same line, after the
101        /// children's span (so the span is composite_slot - base_slot - 1).
102        composite_slot: u32,
103        /// The composite paints the layer's whole clip whatever its children
104        /// draw: a destructive blend changes the parent where the layer is
105        /// transparent, a filter that colours transparent pixels colours
106        /// them everywhere, and a backdrop layer opens full of the filtered
107        /// parent (Flutter's `content_is_unbounded`). The layer's texture
108        /// then covers its clip.
109        floods_clip: bool,
110        /// An enclosing group's alpha can ride the composite instead of a
111        /// texture of the group: the paint blends `SrcOver` with no colour
112        /// or image filter to take the alpha in before it filters.
113        takes_group_opacity: bool,
114        /// The layer's own alpha can ride its children instead: they take a
115        /// group alpha and are pairwise disjoint, and the composite is
116        /// nothing but that alpha (`takes_group_opacity`), with no backdrop
117        /// to seed and no bounds hint to crop by. Replay may then skip the
118        /// texture and draw each child at its own slot (Impeller's opacity
119        /// peephole: elision changes nothing about depth).
120        can_elide: bool,
121        /// Set = the layer opens with the filtered scene already painted
122        /// beneath it. Filter parameters are in local coordinates. Children
123        /// paint afterward, and the composite applies group alpha to the
124        /// filtered backdrop and children as one image — Flutter's
125        /// `saveLayer(bounds, paint, backdrop)`.
126        backdrop: Option<Backdrop>,
127    },
128    Restore,
129    /// Appends to the current transform (canvas semantics: applies to
130    /// subsequently drawn geometry first).
131    Transform(Matrix),
132    /// Fills the whole clip with `paint`: Flutter's `DrawPaintOp`, which
133    /// Impeller draws over its render target's every texel and leaves the
134    /// clip to cut (`Canvas::DrawPaint`, with its `CoverGeometry`). A blend
135    /// mode that changes pixels a draw leaves transparent therefore changes
136    /// the whole clip. Its paint fills and takes no mask blur, as Flutter's
137    /// display list records it (`kDrawPaintFlags`). `bounds` is the clip
138    /// in force, [`Rect::EVERYTHING`] where nothing clips it; in a layer
139    /// that does not crop it the layer's content is unbounded, so the layer
140    /// covers its own clip.
141    DrawPaint {
142        paint: Paint,
143        bounds: Rect,
144        slot: u32,
145    },
146    DrawRect {
147        rect: Rect,
148        paint: Paint,
149        bounds: Rect,
150        slot: u32,
151    },
152    DrawPath {
153        path: Arc<Path>,
154        fill_rule: FillRule,
155        paint: Paint,
156        /// The path's ink in local coordinates, stroke included and before
157        /// any effect: what a layer for the paint's effects has to hold.
158        content_bounds: Rect,
159        bounds: Rect,
160        slot: u32,
161    },
162    /// A mask-blurred solid (r)rect in CLOSED FORM — one draw, no filter
163    /// passes; why a box shadow costs one quad (Impeller's
164    /// SolidRRectBlurContents). Recorded when a solid paint has `mask_blur`;
165    /// `radii` are per corner, clockwise from top-left ([0.0; 4] = sharp).
166    RRectBlur {
167        rect: Rect,
168        radii: [f32; 4],
169        paint: Paint,
170        bounds: Rect,
171        slot: u32,
172    },
173    /// The shadow an occluder of `path`'s shape casts: Flutter's
174    /// `DrawShadowOp` and `DrawShadowTransparentOccluderOp`, with the
175    /// parameters Flutter's `drawShadow` takes. It is resolved when it is
176    /// drawn, as Impeller's `DlDispatcherBase::drawShadow` resolves it
177    /// ([`crate::SpotShadow::resolve`]): the blur's radius divides by the
178    /// vertical scale of the whole transform it is drawn under, which only
179    /// playback knows.
180    DrawShadow {
181        path: Arc<Path>,
182        fill_rule: FillRule,
183        /// The occluder's colour, before the shadow tones it.
184        color: Color,
185        /// How far the occluder stands above the canvas, in logical pixels.
186        elevation: f32,
187        /// Whether the occluder lets light through. Recorded as Flutter
188        /// records it; Impeller draws the same shadow either way.
189        transparent_occluder: bool,
190        /// The pixel ratio of the view drawn into: what turns the elevation
191        /// into the occluder's height in device pixels.
192        device_pixel_ratio: f32,
193        /// Set when the path is a rectangle rounded by one circular radius,
194        /// zero for a sharp one, which the shadow then fills in closed form,
195        /// as `RRectBlur` does: a rectangle, a rounded rectangle with the
196        /// same radius at every corner, or a circle, as Impeller's
197        /// `SimplifyOrDrawPath` and `AttemptDrawBlur` find them. Any other
198        /// path is a mask-blurred fill.
199        round_rect: Option<(Rect, f32)>,
200        /// Where the shadow may show: the path moved and blurred as it is
201        /// resolved under the transform at record time, which stands in
202        /// for the one at playback as it does for a hairline's width
203        /// (Flutter's display list bounds its shadows under its own matrix
204        /// too). A list played back under a smaller scale than it was
205        /// recorded at blurs further than these bounds.
206        bounds: Rect,
207        slot: u32,
208    },
209    /// A clip to a path's shape, or to outside it, until its scope's
210    /// restore. The renderer cuts every draw in the scope to the bounds the
211    /// clips around it leave, with a scissor, and inside those bounds clips
212    /// by depth (Impeller's clips): it stencils the shape, then writes a
213    /// depth CEILING at `expiry_slot`, over the shape's exterior for
214    /// Intersect and its interior for Difference. Draws below the ceiling
215    /// fail the depth test there; draws after the scope's restore sit above
216    /// it, so restore renders nothing. An Intersect clip to a rectangle
217    /// along the pixel grid needs no ceiling when the scissor states it: one
218    /// that is not anti-aliased, wherever it lies, or one whose edges lie on
219    /// whole pixels.
220    ClipPath {
221        path: Arc<Path>,
222        fill_rule: FillRule,
223        op: ClipOp,
224        /// Whether the clip's edge is anti-aliased. An Intersect clip to an
225        /// axis-aligned rectangle that is not goes to the nearest whole
226        /// pixels; on any other clip the flag changes nothing.
227        anti_alias: bool,
228        /// The shape's bounds, list-root space, cropped by nothing.
229        bounds: Rect,
230        /// The shape is exactly `bounds`: a rectangle that the transform at
231        /// the clip only scales and moves, so its sides lie along the axes
232        /// of list-root space. Whether they lie along the target's pixel
233        /// grid is the replay's to say, which knows what the list is drawn
234        /// under.
235        is_axis_aligned_rect: bool,
236        /// The slot of the restore that ends this clip's scope (backpatched
237        /// by the builder when the scope closes — still record-time).
238        expiry_slot: u32,
239    },
240    /// Textured quad: `src` (texture px) → `dst` (local space). Sampling
241    /// picks filter/tiling; paint contributes tint (color as multiplier),
242    /// alpha, and blend.
243    DrawImage {
244        image: Image,
245        src: Rect,
246        dst: Rect,
247        sampling: Sampling,
248        paint: Paint,
249        bounds: Rect,
250        slot: u32,
251    },
252    /// Positioned glyphs from a laid-out paragraph — the TextFrame analog
253    /// (font id + glyph ids + positions, so this crate never depends on
254    /// the text stack). One op per placed run; `y` sits on the
255    /// baseline; the renderer picks bitmap/SDF/path per transform.
256    GlyphRun {
257        font: RunFont,
258        /// Blend/alpha/mask-blur apply like any draw; `paint.color` tints
259        /// mask glyphs (color glyphs keep their palette, alpha only).
260        paint: Paint,
261        glyphs: Arc<Vec<GlyphPos>>,
262        /// The text the glyphs show, when the run has it.
263        text: Option<RunText>,
264        /// The run's ink in local coordinates, stroke included and before
265        /// any effect: what a layer for the paint's effects has to hold.
266        content_bounds: Rect,
267        bounds: Rect,
268        slot: u32,
269    },
270    /// Embed another list by reference — the retained-layer composition op.
271    DrawDisplayList {
272        list: Arc<DisplayList>,
273        bounds: Rect,
274        /// Child slots are child-relative; replay offsets them by this.
275        base_slot: u32,
276        /// The embedder judges this subtree stable and heavy enough to
277        /// raster-cache (policy is the caller's; admission stays in the
278        /// renderer).
279        cache: bool,
280    },
281}
282
283/// `MaskKind` controls how a mask layer converts pixels into coverage.
284#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
285#[cfg_attr(feature = "serde", derive(serde::Serialize))]
286pub enum MaskKind {
287    /// `Luminance` derives coverage from premultiplied pixel luminance.
288    Luminance,
289    /// `Alpha` uses only the pixel alpha channel as coverage.
290    Alpha,
291}
292
293static NEXT_ID: AtomicU64 = AtomicU64::new(1);
294
295/// `DisplayList` is an immutable recording of drawing commands.
296///
297/// Display lists are GPU-free, thread-safe, and nestable. Wrap a list in
298/// [`Arc`] to share or replay it without copying its commands.
299///
300/// Two lists are equal when they record the same commands. A list is equal to itself
301/// without a comparison, and a nested list is compared the same way, so a scene that
302/// embeds the pictures its last frame did, unchanged, compares in the time of its own
303/// few commands: what a host asks before drawing a scene again.
304#[derive(Debug)]
305#[cfg_attr(feature = "serde", derive(serde::Serialize))]
306pub struct DisplayList {
307    id: u64,
308    pub(crate) ops: Vec<Op>,
309    /// Union of all draw bounds, list-root space.
310    pub(crate) bounds: Bounds,
311    /// Draw commands in this list, nested lists included.
312    pub(crate) draw_count: u32,
313    /// Depth slots consumed when replayed (draws + clip-scope restores),
314    /// nested lists included — the renderer derives its z quantum from this.
315    pub(crate) depth_slots: u32,
316    /// Per shared backdrop key: the union of the recorded regions of the
317    /// backdrop layers carrying it — the first one replayed blurs the whole
318    /// union once, and the rest reuse that blur.
319    pub(crate) backdrop_groups: Vec<BackdropGroup>,
320    /// Backdrop reads when replayed, shared or not, nested lists included.
321    /// A rasterized copy of such a list would freeze what it read.
322    pub(crate) backdrop_reads: u32,
323    /// Whether a group alpha distributes over the draws: every one
324    /// alpha-linear and none overlapping.
325    pub(crate) supports_opacity: bool,
326}
327
328/// `GlyphPos` identifies and positions one glyph within a glyph run.
329#[derive(Clone, Copy, Debug, PartialEq)]
330#[cfg_attr(feature = "serde", derive(serde::Serialize))]
331pub struct GlyphPos {
332    /// `id` is the glyph identifier in the run's font.
333    pub id: u32,
334    /// `x` is the glyph's local horizontal position in pixels.
335    pub x: f32,
336    /// `y` is the glyph's local baseline position in pixels.
337    pub y: f32,
338}
339
340/// `RunFont` is what a glyph run's glyphs are drawn with, as Skia's `SkFont` is: a face at a
341/// size, with the bold and italic it fakes.
342#[derive(Clone, Debug, PartialEq)]
343#[cfg_attr(feature = "serde", derive(serde::Serialize))]
344pub struct RunFont {
345    /// `face` is the font the glyphs come from, carried by value to raster (Skia's text blobs
346    /// hold `sk_sp<SkTypeface>`: nothing is registered renderer-side). Serialization keeps only
347    /// its raster identity.
348    #[cfg_attr(feature = "serde", serde(serialize_with = "serialize_font_uid"))]
349    pub face: Arc<valo_text::Font>,
350    /// `size` is the font size in pixels.
351    pub size: f32,
352    /// `synthesis` is the bold and italic the glyphs fake because the face lacks them;
353    /// [`valo_text::FontSynthesis::NONE`] draws the face as it is.
354    #[cfg_attr(feature = "serde", serde(serialize_with = "serialize_synthesis"))]
355    pub synthesis: valo_text::FontSynthesis,
356}
357
358/// `RunText` is the text a glyph run shows, as Skia's text blobs keep it (`allocRunText`): what a
359/// PDF reads back for selection and search. Drawing never reads it.
360#[derive(Clone, Debug, PartialEq)]
361#[cfg_attr(feature = "serde", derive(serde::Serialize))]
362pub struct RunText {
363    /// `text` is the run's text.
364    pub text: Arc<str>,
365    /// `clusters` holds one entry for each glyph: where the part of `text` it shows starts, in
366    /// UTF-8 bytes. Glyphs sharing a cluster show it together; a ligature is one glyph whose part
367    /// runs to the next cluster.
368    pub clusters: Arc<[u32]>,
369}
370
371/// `BackdropGroup` summarizes regions sharing one backdrop-filter key.
372#[derive(Clone, Debug)]
373#[cfg_attr(feature = "serde", derive(serde::Serialize))]
374pub struct BackdropGroup {
375    /// `key` identifies the shared backdrop group.
376    pub key: u64,
377    /// `union_bounds` encloses every region in the group.
378    pub union_bounds: Rect,
379    /// `filter` is shared when every region agrees; `None` disables reuse.
380    pub filter: Option<ImageFilter>,
381}
382
383fn next_id() -> u64 {
384    NEXT_ID.fetch_add(1, Ordering::Relaxed)
385}
386
387impl PartialEq for DisplayList {
388    fn eq(&self, other: &DisplayList) -> bool {
389        self.id == other.id || self.ops == other.ops
390    }
391}
392
393/// `Recording` is what a builder resolved about its ops while recording
394/// them, handed to the list it builds; see [`DisplayList`]'s fields.
395pub(crate) struct Recording {
396    pub bounds: Bounds,
397    pub depth_slots: u32,
398    pub supports_opacity: bool,
399}
400
401/// `Tally` is what a list's finished ops add up to, counted in one pass
402/// when the list is built: its draws, its backdrop reads and its shared
403/// backdrop groups (Impeller collects backdrop groups in a pass of its own,
404/// `FirstPassDispatcher::saveLayer`).
405#[derive(Default)]
406struct Tally {
407    draw_count: u32,
408    backdrop_reads: u32,
409    backdrop_groups: Vec<BackdropGroup>,
410}
411
412impl Tally {
413    fn of(ops: &[Op]) -> Self {
414        let mut tally = Self::default();
415        for op in ops {
416            tally.add(op);
417        }
418        tally
419    }
420
421    fn add(&mut self, op: &Op) {
422        match op {
423            Op::SaveLayer {
424                clip_bounds,
425                backdrop,
426                ..
427            } => {
428                self.draw_count += 1; // the composite
429                if let Some(backdrop) = backdrop {
430                    self.backdrop_reads += 1;
431                    self.join_backdrop_group(backdrop, clip_bounds);
432                }
433            }
434            Op::DrawDisplayList { list, .. } => {
435                self.draw_count += list.draw_count;
436                self.backdrop_reads += list.backdrop_reads;
437            }
438            Op::DrawPaint { .. }
439            | Op::DrawRect { .. }
440            | Op::DrawPath { .. }
441            | Op::RRectBlur { .. }
442            | Op::DrawShadow { .. }
443            | Op::DrawImage { .. }
444            | Op::GlyphRun { .. } => self.draw_count += 1,
445            Op::Save | Op::Restore | Op::Transform(_) | Op::ClipPath { .. } => {}
446        }
447    }
448
449    /// `join_backdrop_group` adds a keyed backdrop layer, whose clip is
450    /// `region`, to its group. An unclipped layer's region is every rect: a
451    /// group's union is a rect the planner cuts to its target.
452    fn join_backdrop_group(&mut self, backdrop: &Backdrop, region: &Bounds) {
453        let Some(key) = backdrop.shared_key else {
454            return;
455        };
456        let region = match region {
457            // Clipped away: the layer shows nowhere, so nothing reads its glass.
458            Bounds::Empty => return,
459            Bounds::Bounded(rect) => *rect,
460            Bounds::Unbounded => Rect::EVERYTHING,
461        };
462        match self.backdrop_groups.iter_mut().find(|g| g.key == key) {
463            Some(group) => {
464                group.union_bounds = group.union_bounds.union(&region);
465                if group.filter.as_ref() != Some(&backdrop.filter) {
466                    group.filter = None; // Different filters cannot share one snapshot.
467                }
468            }
469            None => self.backdrop_groups.push(BackdropGroup {
470                key,
471                union_bounds: region,
472                filter: Some(backdrop.filter.clone()),
473            }),
474        }
475    }
476}
477
478impl DisplayList {
479    pub(crate) fn new(ops: Vec<Op>, recording: Recording) -> Self {
480        let Recording {
481            bounds,
482            depth_slots,
483            supports_opacity,
484        } = recording;
485        let Tally {
486            draw_count,
487            backdrop_reads,
488            backdrop_groups,
489        } = Tally::of(&ops);
490        Self {
491            id: next_id(),
492            ops,
493            bounds,
494            draw_count,
495            depth_slots,
496            backdrop_groups,
497            backdrop_reads,
498            supports_opacity,
499        }
500    }
501
502    /// `id` returns the process-unique identity of this live display list.
503    ///
504    /// Deserialization creates a fresh identity; equal content does not imply
505    /// equal identity.
506    pub fn id(&self) -> u64 {
507        self.id
508    }
509
510    /// `ops` returns the recorded commands in replay order.
511    pub fn ops(&self) -> &[Op] {
512        &self.ops
513    }
514
515    /// `bounds` returns where the list's draws may show, in list
516    /// coordinates: nowhere, inside a rectangle, or, when a draw fills a clip
517    /// the list does not make, anywhere.
518    pub fn bounds(&self) -> Bounds {
519        self.bounds
520    }
521
522    /// `draw_count` returns the number of draws, including nested lists.
523    pub fn draw_count(&self) -> u32 {
524        self.draw_count
525    }
526
527    /// `depth_slots` returns the ordering slots required to replay this list.
528    pub fn depth_slots(&self) -> u32 {
529        self.depth_slots
530    }
531
532    /// `backdrop_reads` counts backdrop reads when replayed, shared or not,
533    /// nested lists included.
534    pub fn backdrop_reads(&self) -> u32 {
535        self.backdrop_reads
536    }
537
538    /// `supports_opacity` says whether a group alpha distributes over this
539    /// list's draws: every one alpha-linear and none overlapping. A layer
540    /// that embeds the list asks this instead of forfeiting elision
541    /// (Flutter's `can_apply_group_opacity`).
542    pub fn supports_opacity(&self) -> bool {
543        self.supports_opacity
544    }
545
546    /// `backdrop_group` returns the group recorded for `key`, if present.
547    pub fn backdrop_group(&self, key: u64) -> Option<&BackdropGroup> {
548        self.backdrop_groups.iter().find(|g| g.key == key)
549    }
550}
551
552#[cfg(feature = "serde")]
553fn serialize_font_uid<S: serde::Serializer>(
554    font: &std::sync::Arc<valo_text::Font>,
555    serializer: S,
556) -> Result<S::Ok, S::Error> {
557    serializer.serialize_u64(font.uid().0)
558}
559
560#[cfg(feature = "serde")]
561fn serialize_synthesis<S: serde::Serializer>(
562    synthesis: &valo_text::FontSynthesis,
563    serializer: S,
564) -> Result<S::Ok, S::Error> {
565    use serde::ser::SerializeStruct;
566    let mut fields = serializer.serialize_struct("FontSynthesis", 2)?;
567    fields.serialize_field("embolden", &synthesis.embolden)?;
568    fields.serialize_field("skew", &synthesis.skew)?;
569    fields.end()
570}
571
572#[cfg(test)]
573mod equality_tests {
574    use std::sync::Arc;
575
576    use super::*;
577    use crate::{DisplayListBuilder, Paint};
578
579    fn rects(count: u32) -> DisplayList {
580        let mut b = DisplayListBuilder::new();
581        let paint = Paint::default();
582        for i in 0..count {
583            b.draw_rect(Rect::new(0.0, i as f32 * 10.0, 5.0, 5.0), &paint);
584        }
585        b.build()
586    }
587
588    #[test]
589    fn lists_with_the_same_commands_are_equal_and_others_not() {
590        assert_eq!(rects(3), rects(3));
591        assert_ne!(rects(3), rects(4));
592    }
593
594    #[test]
595    fn a_scene_over_the_same_retained_picture_is_equal_by_identity() {
596        let picture = Arc::new(rects(3));
597        let scene = |picture: &Arc<DisplayList>| {
598            let mut b = DisplayListBuilder::new();
599            b.draw_display_list(picture);
600            b.build()
601        };
602        assert_eq!(scene(&picture), scene(&picture));
603        assert_ne!(scene(&picture), scene(&Arc::new(rects(4))));
604    }
605}