Skip to main content

cranpose_render_common/scene_store/
layer_props.rs

1// What a record holds beyond its fixed-size parts and its graphics layer:
2// pointer handling, bounds of its own, offscreen reasons. Only records that
3// have one of them take an entry.
4
5#[cfg(feature = "window-damage")]
6use cranpose_core::SceneUpdate;
7use cranpose_ui::{Point, Rect};
8
9use super::translate_run::TranslateRun;
10use crate::graph::{CachePolicy, HitTestNode, IsolationReasons};
11
12/// The properties of a record that has pointer handling, layer bounds other
13/// than its node rect, translated content, a reason to draw offscreen or a
14/// cache policy.
15#[derive(Clone, Default)]
16pub struct LayerProps {
17    /// The bounds of the layer, where its clip cuts, its transforms pivot and
18    /// an offscreen pass draws it, when they differ from the node rect.
19    pub layer_bounds: Option<Rect>,
20    /// Translation of the content when the record moves its content as one
21    /// translated block.
22    pub translated_content_offset: Point,
23    /// Pointer handling of the node, or `None` when the node has none.
24    pub hit_test: Option<HitTestNode>,
25    /// The reasons the record is drawn through its own offscreen buffer.
26    pub isolation: IsolationReasons,
27    /// Whether a renderer may keep the record's pixels between frames.
28    pub cache_policy: CachePolicy,
29    #[cfg(feature = "window-damage")]
30    pub(crate) content_run: ContentRun,
31    // The updates that changed the record's content only by moving it.
32    pub(crate) translate_run: TranslateRun,
33}
34
35impl LayerProps {
36    // Whether every property reads as its default, so the record needs no
37    // entry. The content run goes with the entry.
38    pub(crate) fn is_default(&self) -> bool {
39        self.layer_bounds.is_none()
40            && self.translated_content_offset == Point::default()
41            && self.hit_test.is_none()
42            && !self.isolation.has_any()
43            && self.cache_policy == CachePolicy::None
44    }
45}
46
47// The last scene update that changed what a record draws, and how many
48// updates in a row up to it did.
49#[cfg(feature = "window-damage")]
50#[derive(Clone, Copy, Debug, Default)]
51pub(crate) struct ContentRun {
52    last: SceneUpdate,
53    run: u32,
54}
55
56#[cfg(feature = "window-damage")]
57impl ContentRun {
58    pub(crate) fn note(&mut self, update: SceneUpdate) {
59        if self.run > 0 && self.last == update {
60            return;
61        }
62        self.run = if self.run > 0 && self.last.next() == update {
63            self.run + 1
64        } else {
65            1
66        };
67        self.last = update;
68    }
69
70    pub(crate) fn churns(self, update: SceneUpdate) -> bool {
71        self.run >= 2 && self.last == update
72    }
73}