cbf_compositor/model/composition.rs
1use crate::model::{geometry::Rect, ids::CompositionItemId, target::SurfaceTarget};
2
3/// Background drawing policy for a scene item.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum BackgroundPolicy {
6 /// The item should use a non-transparent background.
7 Opaque,
8 /// The item should clear its background to transparent.
9 Transparent,
10}
11
12impl From<BackgroundPolicy> for cbf::data::background::BackgroundPolicy {
13 fn from(value: BackgroundPolicy) -> Self {
14 match value {
15 BackgroundPolicy::Opaque => Self::Opaque,
16 BackgroundPolicy::Transparent => Self::Transparent,
17 }
18 }
19}
20
21/// Hit-test behavior for one scene item.
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum HitTestPolicy {
24 /// The item never receives pointer hit-tests.
25 Passthrough,
26 /// The item's full bounds participate in hit-testing.
27 Bounds,
28 /// Only the latest pushed hit-test snapshot participates in hit-testing.
29 RegionSnapshot,
30}
31
32/// How a hit-test snapshot interprets its listed regions.
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum HitTestRegionMode {
35 /// Listed regions consume pointer input and all other bounds pass through.
36 ConsumeListedRegions,
37 /// Listed regions pass pointer input through and all other bounds consume it.
38 PassthroughListedRegions,
39}
40
41/// Coordinate space used by pushed hit-test regions.
42#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub enum HitTestCoordinateSpace {
44 /// Item-local CSS pixel coordinates with an origin at the item's top-left.
45 ItemLocalCssPx,
46}
47
48/// Axis-aligned rectangle used by hit-test snapshots.
49#[derive(Debug, Clone, Copy, PartialEq)]
50pub struct HitTestRegion {
51 /// Left edge in the chosen coordinate space.
52 pub x: f32,
53 /// Top edge in the chosen coordinate space.
54 pub y: f32,
55 /// Rectangle width.
56 pub width: f32,
57 /// Rectangle height.
58 pub height: f32,
59}
60
61impl HitTestRegion {
62 /// Create a new hit-test region rectangle.
63 pub const fn new(x: f32, y: f32, width: f32, height: f32) -> Self {
64 Self {
65 x,
66 y,
67 width,
68 height,
69 }
70 }
71}
72
73/// Cached hit-test snapshot for one scene item.
74#[derive(Debug, Clone, PartialEq)]
75pub struct HitTestRegionSnapshot {
76 /// Monotonic identifier used to discard stale async updates.
77 pub snapshot_id: u64,
78 /// Coordinate space for every region in this snapshot.
79 pub coordinate_space: HitTestCoordinateSpace,
80 /// Interpretation mode for the listed regions.
81 pub mode: HitTestRegionMode,
82 /// Regions interpreted according to [`Self::mode`].
83 pub regions: Vec<HitTestRegion>,
84}
85
86/// Declarative description of one scene item inside a compositor window.
87#[derive(Debug, Clone, PartialEq)]
88pub struct CompositionItemSpec {
89 /// Stable identifier for this scene item.
90 pub item_id: CompositionItemId,
91 /// Browser-managed surface shown by this item.
92 pub target: SurfaceTarget,
93 /// Item bounds in compositor-window coordinates.
94 pub bounds: Rect,
95 /// Whether the item should currently be visible.
96 pub visible: bool,
97 /// Hit-test behavior for the item.
98 pub hit_test: HitTestPolicy,
99 /// Background drawing policy for the item.
100 pub background: BackgroundPolicy,
101}
102
103/// Full scene description for one compositor-managed window.
104#[derive(Debug, Clone, Default, PartialEq)]
105pub struct WindowCompositionSpec {
106 /// Scene items to show in the window, ordered from front to back.
107 pub items: Vec<CompositionItemSpec>,
108}